diff options
Diffstat (limited to 'src/test/java/MainTest.java')
| -rw-r--r-- | src/test/java/MainTest.java | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/test/java/MainTest.java b/src/test/java/MainTest.java new file mode 100644 index 0000000..7aad26e --- /dev/null +++ b/src/test/java/MainTest.java @@ -0,0 +1,100 @@ +import java.util.HashMap;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+import org.custommonkey.xmlunit.XMLUnit;
+
+import com.c2kernel.common.ObjectNotFoundException;
+import com.c2kernel.persistency.outcome.OutcomeValidator;
+import com.c2kernel.persistency.outcome.Schema;
+import com.c2kernel.persistency.outcome.SchemaValidator;
+import com.c2kernel.process.Gateway;
+import com.c2kernel.scripting.Script;
+import com.c2kernel.utils.FileStringUtility;
+import com.c2kernel.utils.Logger;
+import com.c2kernel.utils.Resource;
+
+public class MainTest {
+
+
+
+ public MainTest() throws Exception {
+ Logger.addLogStream(System.out, 1);
+ Properties props = FileStringUtility.loadConfigFile(MainTest.class.getResource("properties.conf").getPath());
+ Gateway.init(props);
+ Resource.initKernelBaseURL();
+ XMLUnit.setIgnoreWhitespace(true);
+ XMLUnit.setIgnoreComments(true);
+ }
+
+ public void testBootItems() throws Exception {
+ HashMap<String, OutcomeValidator> validators = new HashMap<String, OutcomeValidator>();
+ validators.put("CA", new OutcomeValidator(getSchema("CompositeActivityDef", 0, "boot/OD/CompositeActivityDef.xsd")));
+ validators.put("EA", new OutcomeValidator(getSchema("ElementaryActivityDef", 0, "boot/OD/ElementaryActivityDef.xsd")));
+ validators.put("SC", new OutcomeValidator(getSchema("Script", 0, "boot/OD/Script.xsd")));
+ validators.put("OD", new SchemaValidator());
+
+ String bootItems = FileStringUtility.url2String(Resource.getKernelResourceURL("boot/allbootitems.txt"));
+ StringTokenizer str = new StringTokenizer(bootItems, "\n\r");
+ while (str.hasMoreTokens()) {
+ String thisItem = str.nextToken();
+ Logger.msg(1, "Validating "+thisItem);
+ int delim = thisItem.indexOf('/');
+ String itemType = thisItem.substring(0,delim);
+ OutcomeValidator validator = validators.get(itemType);
+ String data = Resource.getTextResource(null, "boot/"+thisItem+(itemType.equals("OD")?".xsd":".xml"));
+ assert data!=null;
+ String errors = validator.validate(data);
+ if (errors.length() > 0) {
+ Logger.error("Kernel resource "+thisItem+" has errors :"+errors);
+ }
+ assert errors.length()==0;
+
+ if (itemType.equals("CA") && !itemType.equals("EA")) {
+ Logger.msg(1, "Remarshalling "+thisItem);
+ Object unmarshalled = Gateway.getMarshaller().unmarshall(data);
+ assert unmarshalled!=null;
+ String remarshalled = Gateway.getMarshaller().marshall(unmarshalled);
+ errors = validator.validate(remarshalled);
+ if (errors.length() > 0) {
+ Logger.error("Remarshalled resource "+thisItem+" has errors :"+errors);
+ }
+ assert errors.length()==0;
+
+// Diff xmlDiff = new Diff(data, remarshalled);
+// if (!xmlDiff.identical()) {
+// Logger.msg("Difference found in remarshalled "+thisItem+": "+xmlDiff.toString());
+// Logger.msg("Original: "+data);
+// Logger.msg("Remarshalled: "+remarshalled);
+// }
+// assert xmlDiff.identical();
+ }
+ }
+ }
+
+ private Schema getSchema(String name, int version, String resPath) throws ObjectNotFoundException {
+ return new Schema(name, version, false, Resource.getTextResource(null, resPath));
+ }
+
+ public void testScriptParsing() throws Exception {
+ 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;
+
+ Script testScript = new Script(testScriptString);
+ assert testScript.getInputParams().size()==1;
+ assert testScript.getInputParams().get("test")!=null;
+
+ testScript.setInputParamValue("test", "Test");
+ assert testScript.getInputParams().get("test").getInitialised();
+
+ Object result = testScript.execute();
+ assert result!=null;
+ assert result instanceof String;
+ assert ((String)result).equals("TestTest");
+ }
+}
|
