use of org.cristalise.kernel.persistency.outcome.OutcomeValidator in project kernel by cristal-ise.
the class MainTest method testScriptParsing.
@Test
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);
assert errors.length() == 0 : "Test script not valid to schema: " + errors;
Script testScript = new Script("TestScript", 0, null, testScriptString);
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() : "Script is not initialized when it should be";
Object result = testScript.execute();
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;
}
use of org.cristalise.kernel.persistency.outcome.OutcomeValidator in project kernel by cristal-ise.
the class Query method validateXML.
public void validateXML(String xml) throws InvalidDataException, ObjectNotFoundException {
Schema querySchema;
if (Gateway.getLookup() == null)
querySchema = new Schema("Query", 0, Gateway.getResource().getTextResource(null, "boot/OD/Query.xsd"));
else
querySchema = LocalObjectLoader.getSchema("Query", 0);
OutcomeValidator validator = new OutcomeValidator(querySchema);
String error = validator.validate(xml);
if (StringUtils.isBlank(error)) {
Logger.msg(5, "Query.validateXML() - DONE");
} else {
Logger.error("Query.validateXML() - $error");
Logger.error("\n============== XML ==============\n" + xml + "\n=================================\n");
throw new InvalidDataException(error);
}
}
use of org.cristalise.kernel.persistency.outcome.OutcomeValidator in project kernel by cristal-ise.
the class MainTest method testBootItems.
@Test
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("SM", new OutcomeValidator(getSchema("StateMachine", 0, "boot/OD/StateMachine.xsd")));
validators.put("OD", new SchemaValidator());
String bootItems = FileStringUtility.url2String(Gateway.getResource().getKernelResourceURL("boot/allbootitems.txt"));
StringTokenizer str = new StringTokenizer(bootItems, "\n\r");
while (str.hasMoreTokens()) {
String thisItem = str.nextToken();
StringTokenizer str2 = new StringTokenizer(thisItem, "/,");
String id = str2.nextToken();
String itemType = str2.nextToken(), resName = str2.nextToken();
Logger.msg(1, "Validating " + itemType + " " + resName);
OutcomeValidator validator = validators.get(itemType);
String data = Gateway.getResource().getTextResource(null, "boot/" + itemType + "/" + resName + (itemType.equals("OD") ? ".xsd" : ".xml"));
assert data != null : "Boot " + itemType + " data item " + thisItem + " not found";
String errors = validator.validate(data);
assert errors.length() == 0 : "Kernel resource " + itemType + " " + resName + " has errors :" + errors;
if (itemType.equals("CA") || itemType.equals("EA") || itemType.equals("SM")) {
Logger.msg(1, "Remarshalling " + itemType + " " + resName);
long then = System.currentTimeMillis();
Object unmarshalled = Gateway.getMarshaller().unmarshall(data);
assert unmarshalled != null;
String remarshalled = Gateway.getMarshaller().marshall(unmarshalled);
long now = System.currentTimeMillis();
Logger.msg("Marshall/remarshall of " + itemType + " " + resName + " took " + (now - then) + "ms");
errors = validator.validate(remarshalled);
assert errors.length() == 0 : "Remarshalled resource " + itemType + " " + resName + " has errors :" + errors + "\nRemarshalled form:\n" + remarshalled;
// 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();
}
if (itemType.equals("SC")) {
Logger.msg(1, "Parsing script " + resName);
new Script(resName, 0, null, data);
}
}
}
Aggregations