summaryrefslogtreecommitdiff
path: root/src/test/java
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/java
parent1225792532f77e6e8f4a9addfc0c0a6cf56e89b8 (diff)
parente73468fd08cc27aa31f76a27c916e45d5987c628 (diff)
Merge branch 'master' of ssh://dev.cccs.uwe.ac.uk:22/var/git/cristal-kernel
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/LauncherTest.java75
-rw-r--r--src/test/java/MainTest.java36
-rw-r--r--src/test/java/OutcomeTest.java37
3 files changed, 126 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";
+
+ }
+}