use of org.cristalise.kernel.persistency.outcome.SchemaValidator 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