|
Added
Link Here
|
| 1 |
/********************************************************************** |
| 2 |
Copyright (c) 2007, 2010 IBM Corporation and others. |
| 3 |
All rights reserved. This program and the accompanying materials |
| 4 |
are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
which accompanies this distribution, and is available at |
| 6 |
http://www.eclipse.org/legal/epl-v10.html |
| 7 |
$Id: ConfigGeneratorTest.java,v 1.5 2008/11/13 20:02:14 jkubasta Exp $ |
| 8 |
|
| 9 |
Contributors: |
| 10 |
IBM - initial implementation |
| 11 |
**********************************************************************/ |
| 12 |
|
| 13 |
package org.eclipse.hyades.use.cases.junit.iac.administrator.internal.test; |
| 14 |
|
| 15 |
import java.io.File; |
| 16 |
|
| 17 |
import junit.framework.TestCase; |
| 18 |
|
| 19 |
import org.eclipse.tptp.platform.iac.administrator.internal.common.AdminUtil; |
| 20 |
import org.eclipse.tptp.platform.iac.administrator.internal.common.CommonConstants; |
| 21 |
import org.eclipse.tptp.platform.iac.administrator.internal.config.ConfigGenerator; |
| 22 |
import org.w3c.dom.Document; |
| 23 |
|
| 24 |
/** |
| 25 |
* Note that this has to be run as a JUnit plug-in test |
| 26 |
* |
| 27 |
* Note: Test case moved from platform/org.eclipse.tptp.platform.iac.administrator/ |
| 28 |
* org.eclipse.tptp.platform.iac.administrator.internal.test as part of bug 302579. |
| 29 |
* |
| 30 |
* @author Navid Mehregani |
| 31 |
* |
| 32 |
*/ |
| 33 |
public class ConfigGeneratorTest extends TestCase { |
| 34 |
|
| 35 |
/* These values need to change to match location for the machine being tested */ |
| 36 |
public static String acHome = "C:\\Documents and Settings\\Administrator\\workspace_iac_poc\\org.eclipse.tptp.platform.ac.win_ia32\\agent_controller"; |
| 37 |
public static String javaExecutable = "C:\\java\\ibm_jdk1.5\\jre\\bin\\java.exe"; |
| 38 |
public static String pluginsFolder = "D:\\TPTP_Drivers\\TPTP-4.4.0-200702211545\\eclipse\\plugins"; |
| 39 |
|
| 40 |
/* Absolute path to the serviceconfig.xml file of Agent Controller */ |
| 41 |
private String configLocation = acHome + CommonConstants.FILE_SEPARATOR + "config" + CommonConstants.FILE_SEPARATOR + "serviceconfig.xml"; |
| 42 |
|
| 43 |
/* All the AC Plugins */ |
| 44 |
private File[] plugins = null; |
| 45 |
|
| 46 |
/* Config file */ |
| 47 |
private File configFile = new File(configLocation); |
| 48 |
|
| 49 |
protected void setUp() throws Exception |
| 50 |
{ |
| 51 |
/* Delete the config file before starting */ |
| 52 |
configFile.delete(); |
| 53 |
|
| 54 |
/* Get the AC plugins */ |
| 55 |
plugins = AdminUtil.getIACPlugins(); |
| 56 |
} |
| 57 |
|
| 58 |
public void testAllowAllWithNoSecurity() { |
| 59 |
ConfigGenerator configGenerator = new ConfigGenerator(); |
| 60 |
configGenerator.allowAllWithNoSecurity(acHome, javaExecutable, pluginsFolder, plugins); |
| 61 |
|
| 62 |
Document document = AdminUtil.parseFile(configLocation, false); |
| 63 |
|
| 64 |
/* Check java executable */ |
| 65 |
assertEquals(javaExecutable, AdminUtil.getAttributeWithMoreDetails(document, "Variable", "name", "JAVA_PATH", "value")); |
| 66 |
|
| 67 |
/* Check AC home */ |
| 68 |
assertEquals(acHome, AdminUtil.getAttributeWithMoreDetails(document, "Variable", "name", "RASERVER_HOME", "value")); |
| 69 |
|
| 70 |
/* Check accessibility */ |
| 71 |
assertEquals("ALL", AdminUtil.getAttributeOfElement(document, "Allow", "host", 0)); |
| 72 |
|
| 73 |
/* Check security */ |
| 74 |
assertEquals("false", AdminUtil.getElementValue(document, "SecurityEnabled", 0)); |
| 75 |
} |
| 76 |
|
| 77 |
public void testSetUpLocallyWithNoSecurity() { |
| 78 |
ConfigGenerator configGenerator = new ConfigGenerator(); |
| 79 |
configGenerator.setUpLocallyWithNoSecurity(acHome, javaExecutable, pluginsFolder, plugins); |
| 80 |
|
| 81 |
Document document = AdminUtil.parseFile(configLocation, false); |
| 82 |
|
| 83 |
/* Check java executable */ |
| 84 |
assertEquals(javaExecutable, AdminUtil.getAttributeWithMoreDetails(document, "Variable", "name", "JAVA_PATH", "value")); |
| 85 |
|
| 86 |
/* Check AC home */ |
| 87 |
assertEquals(acHome, AdminUtil.getAttributeWithMoreDetails(document, "Variable", "name", "RASERVER_HOME", "value")); |
| 88 |
|
| 89 |
/* Check accessibility */ |
| 90 |
assertEquals("LOCAL", AdminUtil.getAttributeOfElement(document, "Allow", "host", 0)); |
| 91 |
|
| 92 |
/* Check security */ |
| 93 |
assertEquals("false", AdminUtil.getElementValue(document, "SecurityEnabled", 0)); |
| 94 |
} |
| 95 |
|
| 96 |
public void testCustomAccessWithNoSecurity() { |
| 97 |
ConfigGenerator configGenerator = new ConfigGenerator(); |
| 98 |
|
| 99 |
/* Check with Null passed in for hosts */ |
| 100 |
configGenerator.customAccessWithNoSecurity(null, acHome, javaExecutable, pluginsFolder, plugins); |
| 101 |
Document document = AdminUtil.parseFile(configLocation, false); |
| 102 |
assertEquals(javaExecutable, AdminUtil.getAttributeWithMoreDetails(document, "Variable", "name", "JAVA_PATH", "value")); /* Check java executable */ |
| 103 |
assertEquals(acHome, AdminUtil.getAttributeWithMoreDetails(document, "Variable", "name", "RASERVER_HOME", "value")); /* Check AC home */ |
| 104 |
assertEquals("localhost", AdminUtil.getAttributeOfElement(document, "Allow", "host", 0)); /* Check accessibility */ |
| 105 |
assertEquals("false", AdminUtil.getElementValue(document, "SecurityEnabled", 0)); /* Check security */ |
| 106 |
|
| 107 |
/* Check with empty string passed in for hosts */ |
| 108 |
configGenerator.customAccessWithNoSecurity("", acHome, javaExecutable, pluginsFolder, plugins); |
| 109 |
document = AdminUtil.parseFile(configLocation, false); |
| 110 |
assertEquals("localhost", AdminUtil.getAttributeOfElement(document, "Allow", "host", 0)); |
| 111 |
|
| 112 |
/* Check with specific machines passed in for hosts */ |
| 113 |
configGenerator.customAccessWithNoSecurity("host1, host2, host3", acHome, javaExecutable, pluginsFolder, plugins); |
| 114 |
document = AdminUtil.parseFile(configLocation, false); |
| 115 |
assertEquals("host1", AdminUtil.getAttributeOfElement(document, "Allow", "host", 0)); |
| 116 |
assertEquals("host2", AdminUtil.getAttributeOfElement(document, "Allow", "host", 1)); |
| 117 |
assertEquals("host3", AdminUtil.getAttributeOfElement(document, "Allow", "host", 2)); |
| 118 |
} |
| 119 |
|
| 120 |
public void testAllowAllWithSecurity() { |
| 121 |
ConfigGenerator configGenerator = new ConfigGenerator(); |
| 122 |
|
| 123 |
/* Check with Null passed in for users */ |
| 124 |
configGenerator.allowAllWithSecurity(null, null, acHome, javaExecutable, pluginsFolder, plugins); |
| 125 |
Document document = AdminUtil.parseFile(configLocation, false); |
| 126 |
assertEquals(javaExecutable, AdminUtil.getAttributeWithMoreDetails(document, "Variable", "name", "JAVA_PATH", "value")); /* Check java executable */ |
| 127 |
assertEquals(acHome, AdminUtil.getAttributeWithMoreDetails(document, "Variable", "name", "RASERVER_HOME", "value")); /* Check AC home */ |
| 128 |
assertEquals("ALL", AdminUtil.getAttributeOfElement(document, "Allow", "host", 0)); /* Check accessibility */ |
| 129 |
assertEquals("true", AdminUtil.getElementValue(document, "SecurityEnabled", 0)); /* Check security */ |
| 130 |
assertEquals("ANY", AdminUtil.getElementValue(document, "UserDefinition", 0)); |
| 131 |
|
| 132 |
/* Check with empty string passed in for users */ |
| 133 |
configGenerator.allowAllWithSecurity("", "", acHome, javaExecutable, pluginsFolder, plugins); |
| 134 |
document = AdminUtil.parseFile(configLocation, false); |
| 135 |
assertEquals("true", AdminUtil.getElementValue(document, "SecurityEnabled", 0)); /* Check security */ |
| 136 |
assertEquals("ANY", AdminUtil.getElementValue(document, "UserDefinition", 0)); |
| 137 |
|
| 138 |
/* Check with specific users passed in for users */ |
| 139 |
configGenerator.allowAllWithSecurity("CUSTOM", "user1,user2,user3", acHome, javaExecutable, pluginsFolder, plugins); |
| 140 |
document = AdminUtil.parseFile(configLocation, false); |
| 141 |
assertEquals("true", AdminUtil.getElementValue(document, "SecurityEnabled", 0)); /* Check security */ |
| 142 |
assertEquals("user1,user2,user3", AdminUtil.getElementValue(document, "UserDefinition", 0)); |
| 143 |
} |
| 144 |
|
| 145 |
public void testSetUpLocallyWithSecurity() { |
| 146 |
ConfigGenerator configGenerator = new ConfigGenerator(); |
| 147 |
configGenerator.setUpLocallyWithSecurity("ANY", "user1, user2, user3", acHome, javaExecutable, pluginsFolder, plugins); |
| 148 |
|
| 149 |
Document document = AdminUtil.parseFile(configLocation, false); |
| 150 |
assertEquals(javaExecutable, AdminUtil.getAttributeWithMoreDetails(document, "Variable", "name", "JAVA_PATH", "value")); /* Check java executable */ |
| 151 |
assertEquals(acHome, AdminUtil.getAttributeWithMoreDetails(document, "Variable", "name", "RASERVER_HOME", "value")); /* Check AC home */ |
| 152 |
assertEquals("LOCAL", AdminUtil.getAttributeOfElement(document, "Allow", "host", 0)); /* Check accessibility */ |
| 153 |
assertEquals("true", AdminUtil.getElementValue(document, "SecurityEnabled", 0)); /* Check security */ |
| 154 |
assertEquals("user1,user2,user3", AdminUtil.getElementValue(document, "UserDefinition", 0)); |
| 155 |
} |
| 156 |
|
| 157 |
public void testCustomAccessWithSecurity() { |
| 158 |
ConfigGenerator configGenerator = new ConfigGenerator(); |
| 159 |
configGenerator.customAccessWithSecurity("host1, host2, host3","CUSTOM", "user1,user2,user3", acHome, javaExecutable, pluginsFolder, plugins); |
| 160 |
|
| 161 |
Document document = AdminUtil.parseFile(configLocation, false); |
| 162 |
assertEquals(javaExecutable, AdminUtil.getAttributeWithMoreDetails(document, "Variable", "name", "JAVA_PATH", "value")); /* Check java executable */ |
| 163 |
assertEquals(acHome, AdminUtil.getAttributeWithMoreDetails(document, "Variable", "name", "RASERVER_HOME", "value")); /* Check AC home */ |
| 164 |
assertEquals("host1", AdminUtil.getAttributeOfElement(document, "Allow", "host", 0)); /* Check accessibility */ |
| 165 |
assertEquals("host2", AdminUtil.getAttributeOfElement(document, "Allow", "host", 1)); /* Check accessibility */ |
| 166 |
assertEquals("host3", AdminUtil.getAttributeOfElement(document, "Allow", "host", 2)); /* Check accessibility */ |
| 167 |
assertEquals("true", AdminUtil.getElementValue(document, "SecurityEnabled", 0)); /* Check security */ |
| 168 |
assertEquals("user1,user2,user3", AdminUtil.getElementValue(document, "UserDefinition", 0)); |
| 169 |
} |
| 170 |
|
| 171 |
} |