use of com.disney.groovity.compile.GroovityClassLoader in project groovity by disney.
the class TestCoreGroovity method testConf.
@Test
public void testConf() throws Exception {
Binding binding = new Binding();
CharArrayWriter writer = new CharArrayWriter();
binding.setVariable("out", writer);
Script confScript = groovity.load("/conf", binding);
GroovityClassLoader gcl = (GroovityClassLoader) confScript.getClass().getClassLoader();
groovity.run("/conf", binding);
String result = writer.toString();
Assert.assertEquals("|false||0||test|||", result);
writer.reset();
gcl.configure(new Configurator() {
@Override
public void init() {
}
@Override
public void destroy() {
}
@Override
public void configure(String sourcePath, Set<String> propertyNames, BiConsumer<String, String> propertySetter) {
propertySetter.accept("testDefaultBoolean", "true");
propertySetter.accept("testBooleanType", "foo");
propertySetter.accept("testDefaultInteger", "99");
propertySetter.accept("testIntegerType", "111");
propertySetter.accept("testDefaultString", "bar");
propertySetter.accept("testStringType", "zzz");
propertySetter.accept("testNull", "qq");
}
});
groovity.run("/conf", binding);
result = writer.toString();
Assert.assertEquals("|true|false|99|111|bar|zzz|qq|", result);
writer.reset();
logRecords.clear();
gcl.configure(new Configurator() {
@Override
public void init() {
}
@Override
public void destroy() {
}
@Override
public void configure(String sourcePath, Set<String> propertyNames, BiConsumer<String, String> propertySetter) {
propertySetter.accept("testDefaultInteger", "badOnPurpose");
propertySetter.accept("testIntegerType", "badOnPurpose");
}
});
groovity.run("/conf", binding);
result = writer.toString();
Assert.assertEquals("|false||0||test|||", result);
Assert.assertEquals(3, logRecords.size());
Assert.assertEquals(Level.WARNING, logRecords.get(0).getLevel());
Assert.assertEquals(Level.SEVERE, logRecords.get(1).getLevel());
Assert.assertEquals(Level.SEVERE, logRecords.get(2).getLevel());
}
Aggregations