@org.junit.Test public void testGetProperties() { String first = "namespace x.y.z;\r\nimport a.b.c;\r\n\r\nprotocol Test {\r\n\t"; String second = "roleX A, B;\r\n;\r\n"; String document = first + second; String message = "Don't understand roleX"; String line = "5"; String col = "1"; String text = "line " + line + ":" + col + " " + message; java.util.Map<String, Object> result = ANTLRMessageUtil.getProperties(text, document); if (result == null) { fail("Result is null"); } Integer lineProp = (Integer) result.get(Journal.START_LINE); Integer colProp = (Integer) result.get(Journal.START_COLUMN); Integer posProp = (Integer) result.get(Journal.START_POSITION); if (lineProp == null) { fail("Line not found"); } if (lineProp.intValue() != 5) { fail("Line is not 5: " + lineProp); } if (colProp == null) { fail("Column not found"); } if (colProp.intValue() != 1) { fail("Column is not 1: " + colProp); } if (posProp == null) { fail("Position not found"); } if (posProp.intValue() != first.length()) { fail("Position is not " + first.length() + ": " + posProp); } }
@Test public void testTidyServiceDescriptions() { Object expression = null; try { java.io.InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(SCRIPT); if (is == null) { fail("Unable to locate '" + SCRIPT + "'"); } else { byte[] b = new byte[is.available()]; is.read(b); is.close(); // Compile expression expression = MVEL.compileExpression(new String(b)); } } catch (Exception e) { fail("Failed to test script: " + e); } java.util.Map<String, Object> vars = new java.util.HashMap<String, Object>(); java.util.Map<String, Object> internalVariables = new java.util.HashMap<String, Object>(); ActiveCollectionSource acs = new ActiveCollectionSource(); acs.getProperties().put("maxSnapshots", 3); ActiveMap map = new ActiveMap("TestMap"); acs.setActiveCollection(map); // Add some service definitions ServiceDefinition sd1 = new ServiceDefinition(); sd1.setServiceType("sd1"); acs.insert(sd1.getServiceType(), sd1); ServiceDefinition sd2 = new ServiceDefinition(); sd2.setServiceType("sd2"); acs.insert(sd2.getServiceType(), sd2); vars.put("acs", acs); vars.put("variables", internalVariables); MVEL.executeExpression(expression, vars); @SuppressWarnings("unchecked") java.util.List<Object> snapshots = (List<Object>) internalVariables.get("snapshots"); if (snapshots == null) { fail("No snapshots recorded"); } if (snapshots.size() != 1) { fail("Expecting 1 snapshot: " + snapshots.size()); } MVEL.executeExpression(expression, vars); if (snapshots.size() != 2) { fail("Expecting 2 snapshot: " + snapshots.size()); } MVEL.executeExpression(expression, vars); if (snapshots.size() != 3) { fail("Expecting 3 snapshot: " + snapshots.size()); } // Need to check that only three snapshots (as defined // by the cleanup cycle) will be retained MVEL.executeExpression(expression, vars); if (snapshots.size() != 3) { fail("Expecting 3 snapshot: " + snapshots.size()); } }