Search in sources :

Example 1 with SchemaValidator

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);
        }
    }
}
Also used : Script(org.cristalise.kernel.scripting.Script) OutcomeValidator(org.cristalise.kernel.persistency.outcome.OutcomeValidator) StringTokenizer(java.util.StringTokenizer) HashMap(java.util.HashMap) SchemaValidator(org.cristalise.kernel.persistency.outcome.SchemaValidator) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)1 StringTokenizer (java.util.StringTokenizer)1 OutcomeValidator (org.cristalise.kernel.persistency.outcome.OutcomeValidator)1 SchemaValidator (org.cristalise.kernel.persistency.outcome.SchemaValidator)1 Script (org.cristalise.kernel.scripting.Script)1 Test (org.junit.Test)1