VelocityTemplateParser { public List<String> getReferenceNames() { return this.visitor.getReferenceNames(); } VelocityTemplateParser(String templateString); List<String> getReferenceNames(); Template getTemplate(); void validateContext(Map<String, Object> context);  }
@Test public void testParseVelocityTemplate() { String templateString = "This alert ($category) was generated because $reason and $REASON from $source at $created_time"; VelocityTemplateParser parser = new VelocityTemplateParser(templateString); Assert.assertEquals(5, parser.getReferenceNames().size()); Assert.assertArrayEquals(new String[]{"category", "reason", "REASON", "source", "created_time"}, parser.getReferenceNames().toArray()); }
@Test(expected = ParseErrorException.class) public void testParseInvalidVelocityTemplate() { String templateString = "This alert ($category) was generated because $reason and $REASON from $source at $created_time #if() #fi"; VelocityTemplateParser parser = new VelocityTemplateParser(templateString); Assert.assertEquals(5, parser.getReferenceNames().size()); Assert.assertArrayEquals(new String[]{"category", "reason", "REASON", "source", "created_time"}, parser.getReferenceNames().toArray()); }