use of org.kie.internal.builder.conf.AccumulateFunctionOption in project drools by kiegroup.
the class KnowledgeBuilderConfigurationTest method testAccumulateFunctionConfiguration.
@Test
public void testAccumulateFunctionConfiguration() {
Set<String> keySet = new HashSet<String>();
// in this use case, the application already has the instance of the accumulate function
AccumulateFunction function = new AverageAccumulateFunction();
// creating the option and storing in a local var just to make test easier
AccumulateFunctionOption option = AccumulateFunctionOption.get("avg", function);
// wiring the accumulate function using the type safe method
config.setOption(option);
// checking the type safe getOption() method
assertEquals(option, config.getOption(AccumulateFunctionOption.class, "avg"));
// checking string conversion
assertEquals("avg", config.getOption(AccumulateFunctionOption.class, "avg").getName());
assertEquals(function, config.getOption(AccumulateFunctionOption.class, "avg").getFunction());
// checking the string based getProperty() method
assertEquals(AverageAccumulateFunction.class.getName(), config.getProperty(AccumulateFunctionOption.PROPERTY_NAME + "avg"));
// check the key set
keySet.add("avg");
assertTrue(config.getOptionKeys(AccumulateFunctionOption.class).contains("avg"));
// wiring the accumulate function using the string based setProperty() method
config.setProperty(AccumulateFunctionOption.PROPERTY_NAME + "maximum", MaxAccumulateFunction.class.getName());
MaxAccumulateFunction max = new MaxAccumulateFunction();
// checking the type safe getOption() method
assertEquals(AccumulateFunctionOption.get("maximum", max), config.getOption(AccumulateFunctionOption.class, "maximum"));
// checking string conversion
assertEquals("maximum", config.getOption(AccumulateFunctionOption.class, "maximum").getName());
assertEquals(max.getClass().getName(), config.getOption(AccumulateFunctionOption.class, "maximum").getFunction().getClass().getName());
// checking the string based getProperty() method
assertEquals(MaxAccumulateFunction.class.getName(), config.getProperty(AccumulateFunctionOption.PROPERTY_NAME + "maximum"));
keySet.add("avg");
// wiring the inner class accumulate function using the string based setProperty() method
config.setProperty(AccumulateFunctionOption.PROPERTY_NAME + "inner", InnerAccumulateFuncion.class.getName());
InnerAccumulateFuncion inner = new InnerAccumulateFuncion();
// checking the type safe getOption() method
assertEquals(AccumulateFunctionOption.get("inner", inner), config.getOption(AccumulateFunctionOption.class, "inner"));
// checking string conversion
assertEquals("inner", config.getOption(AccumulateFunctionOption.class, "inner").getName());
assertEquals(inner.getClass().getName(), config.getOption(AccumulateFunctionOption.class, "inner").getFunction().getClass().getName());
// checking the string based getProperty() method
assertEquals(InnerAccumulateFuncion.class.getName(), config.getProperty(AccumulateFunctionOption.PROPERTY_NAME + "inner"));
keySet.add("avg");
assertTrue(config.getOptionKeys(AccumulateFunctionOption.class).containsAll(keySet));
// for( String key: config.getOptionKeys(AccumulateFunctionOption.class ) ){
// System.out.println( key + "->" + config.getOption(AccumulateFunctionOption.class, key).getClass().getName() );
// }
}
Aggregations