summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorogattaz <olivier@gattaz.com>2014-06-05 16:51:07 +0200
committerogattaz <olivier@gattaz.com>2014-06-05 16:51:07 +0200
commit2fd193d7936084de91eae46e8c2763914d87ab71 (patch)
treeb136ed97e535f11d4b3433d16c26570c89430ce4 /src/test
parent1225792532f77e6e8f4a9addfc0c0a6cf56e89b8 (diff)
parente73468fd08cc27aa31f76a27c916e45d5987c628 (diff)
Merge branch 'master' of ssh://dev.cccs.uwe.ac.uk:22/var/git/cristal-kernel
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/LauncherTest.java75
-rw-r--r--src/test/java/MainTest.java36
-rw-r--r--src/test/java/OutcomeTest.java37
-rw-r--r--src/test/resources/NewServerPredefStepTest.js12
-rw-r--r--src/test/resources/outcomeTest.xml6
-rw-r--r--src/test/resources/server.conf (renamed from src/test/resources/properties.conf)0
-rw-r--r--src/test/resources/test.clc16
7 files changed, 160 insertions, 22 deletions
diff --git a/src/test/java/LauncherTest.java b/src/test/java/LauncherTest.java
new file mode 100644
index 0000000..4c772d1
--- /dev/null
+++ b/src/test/java/LauncherTest.java
@@ -0,0 +1,75 @@
+import java.util.Properties;
+
+import com.c2kernel.process.AbstractMain;
+import com.c2kernel.process.resource.BadArgumentsException;
+import com.c2kernel.utils.Logger;
+
+
+public class LauncherTest {
+
+ String[] args;
+ Properties props;
+
+ public LauncherTest() {
+ }
+
+ private void standardArgs() {
+ args = new String[8];
+ args[0] = "-logLevel";
+ args[1] = "0";
+ args[2] = "-logFile";
+ args[3] = "target/testlog.txt";
+ args[4] = "-config";
+ args[5] = LauncherTest.class.getResource("server.conf").getPath();
+ args[6] = "-connect";
+ args[7] = LauncherTest.class.getResource("test.clc").getPath();
+ }
+
+ public void testValidC2KArgs() throws Exception {
+
+ standardArgs();
+ Logger.msg("Testing valid startup args");
+ props = AbstractMain.readC2KArgs(args);
+
+ assert "MemoryOnlyClusterStorage".equals(props.get("ClusterStorage")) : "Config file properties not loaded";
+ assert "1553".equals(props.get("ItemServer.Proxy.port")) : "Connect file properties not loaded";
+ }
+
+ public void testWrongConfigFileName() throws Exception {
+ standardArgs();
+ args[5] = "filenotfound";
+ try {
+ props = AbstractMain.readC2KArgs(args);
+ assert false: "Invalid connect file not detected";
+ } catch (BadArgumentsException ex) { }
+ }
+
+ public void testWrongConnectFileName() throws Exception {
+ standardArgs();
+ args[7] = "alsonotfound";
+ try {
+ props = AbstractMain.readC2KArgs(args);
+ assert false : "Invalid connect file not detected";
+ } catch (BadArgumentsException ex) { }
+ }
+
+ public void testMissingConnectArg() throws Exception {
+ args = new String[2];
+ args[0] = "-config";
+ args[1] = LauncherTest.class.getResource("server.conf").getPath();
+ try {
+ props = AbstractMain.readC2KArgs(args);
+ assert false: "Missing connect file not detected";
+ } catch (BadArgumentsException ex) { }
+ }
+
+ public void testMissingConfigArg() throws Exception {
+ args = new String[2];
+ args[0] = "-connect";
+ args[1] = LauncherTest.class.getResource("test.clc").getPath();
+ try {
+ props = AbstractMain.readC2KArgs(args);
+ assert false: "Missing config file not detected";
+ } catch (BadArgumentsException ex) { }
+ }
+}
diff --git a/src/test/java/MainTest.java b/src/test/java/MainTest.java
index 2029dc2..4c70579 100644
--- a/src/test/java/MainTest.java
+++ b/src/test/java/MainTest.java
@@ -25,7 +25,7 @@ public class MainTest {
public MainTest() throws Exception {
Logger.addLogStream(System.out, 1);
- Properties props = FileStringUtility.loadConfigFile(MainTest.class.getResource("properties.conf").getPath());
+ Properties props = FileStringUtility.loadConfigFile(MainTest.class.getResource("server.conf").getPath());
Gateway.init(props);
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreComments(true);
@@ -49,12 +49,10 @@ public class MainTest {
String itemType = thisItem.substring(0,delim);
OutcomeValidator validator = validators.get(itemType);
String data = Gateway.getResource().getTextResource(null, "boot/"+thisItem+(itemType.equals("OD")?".xsd":".xml"));
- assert data!=null;
+ assert data!=null : "Boot "+itemType+" data item "+thisItem+" not found";
String errors = validator.validate(data);
- if (errors.length() > 0) {
- Logger.error("Kernel resource "+thisItem+" has errors :"+errors);
- }
- assert errors.length()==0;
+
+ assert errors.length()==0 : "Kernel resource "+thisItem+" has errors :"+errors;
if (itemType.equals("CA") || itemType.equals("EA") || itemType.equals("SM")) {
Logger.msg(1, "Remarshalling "+thisItem);
@@ -66,10 +64,7 @@ public class MainTest {
Logger.msg("Marshall/remarshall of "+thisItem+" took "+(now-then)+"ms");
castorTime+=(now-then);
errors = validator.validate(remarshalled);
- if (errors.length() > 0) {
- Logger.error("Remarshalled resource "+thisItem+" has errors :"+errors+"\nRemarshalled form:\n"+remarshalled);
- }
- assert errors.length()==0;
+ assert errors.length()==0 : "Remarshalled resource "+thisItem+" has errors :"+errors+"\nRemarshalled form:\n"+remarshalled;
// Diff xmlDiff = new Diff(data, remarshalled);
// if (!xmlDiff.identical()) {
@@ -91,29 +86,26 @@ public class MainTest {
OutcomeValidator valid = new OutcomeValidator(getSchema("Script", 0, "boot/OD/Script.xsd"));
String testScriptString = FileStringUtility.url2String(MainTest.class.getResource("TestScript.xml"));
String errors = valid.validate(testScriptString);
- if (errors.length()>0) {
- Logger.error("Test script not valid to schema: "+errors);
- }
- assert errors.length()==0;
+ assert errors.length()==0 : "Test script not valid to schema: "+errors;
Script testScript = new Script(testScriptString);
- assert testScript.getInputParams().size()==1;
- assert testScript.getInputParams().get("test")!=null;
+ assert testScript.getInputParams().size()==1 : "Script input param count wrong";
+ assert testScript.getInputParams().get("test")!=null : "Could not retrieve script input param value";
testScript.setInputParamValue("test", "Test");
- assert testScript.getInputParams().get("test").getInitialised();
+ assert testScript.getInputParams().get("test").getInitialised() : "Script is not initialized when it should be";
Object result = testScript.execute();
- assert result!=null;
- assert result instanceof String;
- assert ((String)result).equals("TestTest");
- }
+ assert result!=null : "Script returned null result";
+ assert result instanceof String : "Script failed to return a String";
+ assert ((String)result).equals("TestTest") : "Script failed to produce correct result: "+result;
+ }
public void testStateMachine() throws Exception {
Logger.msg("Validating test state machine");
String smXml = FileStringUtility.url2String(MainTest.class.getResource("TestStateMachine.xml"));
StateMachine sm = (StateMachine)Gateway.getMarshaller().unmarshall(smXml);
sm.validate();
- assert sm.isCoherent();
+ assert sm.isCoherent() : "Test StateMachine is reporting that it is not coherent";
}
}
diff --git a/src/test/java/OutcomeTest.java b/src/test/java/OutcomeTest.java
new file mode 100644
index 0000000..d90f2ea
--- /dev/null
+++ b/src/test/java/OutcomeTest.java
@@ -0,0 +1,37 @@
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import com.c2kernel.persistency.outcome.Outcome;
+import com.c2kernel.utils.FileStringUtility;
+
+
+public class OutcomeTest {
+
+ Outcome testOc;
+
+ public OutcomeTest() throws Exception {
+ String ocData = FileStringUtility.url2String(OutcomeTest.class.getResource("outcomeTest.xml"));
+ testOc = new Outcome("/Outcome/Test/0/0", ocData);
+ }
+
+ public void testDOMAccess() throws Exception {
+ assert "Field1contents".equals(testOc.getField("Field1")) : "getField() failed";
+ }
+
+ public void testXPath() throws Exception {
+ Node field1Node = testOc.getNodeByXPath("//Field1/text()");
+ assert field1Node!=null : "XPath for Element query failed";
+ assert field1Node.getNodeValue() != null : "Field1 node was null";
+ assert field1Node.getNodeValue().equals("Field1contents") : "Incorrect value for element node through XPath";
+ assert "Field1contents".equals(testOc.getFieldByXPath("//Field1")): "getFieldByXPath failed";
+ testOc.setFieldByXPath("//Field2", "NewField2");
+ assert "NewField2".equals(testOc.getFieldByXPath("//Field2")): "getFieldByXPath failed to retrieve updated value";
+ assert testOc.getNodeByXPath("//Field2/text()").getNodeValue() != null : "Field2 text node is null";
+ assert testOc.getNodeByXPath("//Field2/text()").getNodeValue().equals("NewField2") : "Failed to setFieldByXPath for element";
+ Node field2attr = testOc.getNodeByXPath("//Field2/@attr");
+ assert field2attr.getNodeValue().equals("attribute"): "Failed to retrieve attribute value via XPath";
+ NodeList field3nodes = testOc.getNodesByXPath("//Field3");
+ assert field3nodes.getLength()==2 : "getNodesByXPath returned wrong number of nodes";
+
+ }
+}
diff --git a/src/test/resources/NewServerPredefStepTest.js b/src/test/resources/NewServerPredefStepTest.js
new file mode 100644
index 0000000..64d3d29
--- /dev/null
+++ b/src/test/resources/NewServerPredefStepTest.js
@@ -0,0 +1,12 @@
+var serverPath=new com.c2kernel.lookup.DomainPath("/servers/pcuwe04.cern.ch");
+var serverItem=proxy.getProxy(serverPath);
+
+var predef = "AddDomainContext"; var params = new Array(1); params[0] = "/test/context"; agent.execute(serverItem, predef, params);
+var predef = "RemoveDomainContext"; agent.execute(serverItem, predef, params);
+params[0] = "/test"; agent.execute(serverItem, predef, params);
+var predef = "SetAgentPassword"; params = Array(2); params[0] = "dev"; params[1] = "hunter2"; agent.execute(serverItem, predef, params);
+com.c2kernel.process.Gateway.login("dev", "hunter2");
+var predef = "SetAgentRoles"; agent.execute(serverItem, predef, params); //Role shouldn't exist
+params = Array(3); params[0] = "dev"; params[1] = "Admin"; params[2] = "UserCode"; agent.execute(serverItem, predef, params);
+params = Array(2); params[0] = "dev"; params[1] = "Admin"; agent.execute(serverItem, predef, params);
+var predef = "RemoveAgent"; var params = new Array(1); params[0] = "dev"; agent.execute(serverItem, predef, params);
diff --git a/src/test/resources/outcomeTest.xml b/src/test/resources/outcomeTest.xml
new file mode 100644
index 0000000..563c72c
--- /dev/null
+++ b/src/test/resources/outcomeTest.xml
@@ -0,0 +1,6 @@
+<TestOutcome>
+ <Field1>Field1contents</Field1>
+ <Field2 attr="attribute"></Field2>
+ <Field3>repeating</Field3>
+ <Field3>element</Field3>
+</TestOutcome> \ No newline at end of file
diff --git a/src/test/resources/properties.conf b/src/test/resources/server.conf
index 476aeb0..476aeb0 100644
--- a/src/test/resources/properties.conf
+++ b/src/test/resources/server.conf
diff --git a/src/test/resources/test.clc b/src/test/resources/test.clc
new file mode 100644
index 0000000..be1d5d0
--- /dev/null
+++ b/src/test/resources/test.clc
@@ -0,0 +1,16 @@
+
+Name=Test Cristal Server
+
+// TCP server ports
+ItemServer.name=localhost
+ItemServer.iiop=1500
+ItemServer.Proxy.port=1553
+
+// LDAP Lookup config
+LDAP.GlobalPath=o=cern,c=ch
+LDAP.RootPath=cn=cristal
+LDAP.LocalPath=cn=test
+LDAP.port=389
+LDAP.host=localhost
+LDAP.user=cn=Manager,o=cern,c=ch
+LDAP.password=test