use of org.drools.core.facttemplates.FactTemplateImpl in project drools by kiegroup.
the class Misc2Test method testFactTemplates.
@Test
public void testFactTemplates() {
// DROOLS-600
String drl = "package com.testfacttemplate;" + " rule \"test rule\" " + " dialect \"mvel\" " + " when " + " $test : TestFactTemplate( status == 1 ) " + " then " + " System.out.println( \"Hello World\" ); " + " end ";
KnowledgePackageImpl kPackage = new KnowledgePackageImpl("com.testfacttemplate");
FieldTemplate fieldTemplate = new FieldTemplateImpl("status", 0, Integer.class);
FactTemplate factTemplate = new FactTemplateImpl(kPackage, "TestFactTemplate", new FieldTemplate[] { fieldTemplate });
KnowledgeBuilder kBuilder = new KnowledgeBuilderImpl(kPackage);
StringReader rule = new StringReader(drl);
try {
((KnowledgeBuilderImpl) kBuilder).addPackageFromDrl(rule);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.drools.core.facttemplates.FactTemplateImpl in project drools by kiegroup.
the class PatternTest method testDeclarationsFactTemplate.
@Test
public void testDeclarationsFactTemplate() throws Exception {
InternalKnowledgePackage pkg = new KnowledgePackageImpl("org.store");
final FieldTemplate cheeseName = new FieldTemplateImpl("name", 0, String.class);
final FieldTemplate cheesePrice = new FieldTemplateImpl("price", 1, Integer.class);
final FieldTemplate[] fields = new FieldTemplate[] { cheeseName, cheesePrice };
final FactTemplate cheese = new FactTemplateImpl(pkg, "Cheese", fields);
final ObjectType type = new FactTemplateObjectType(cheese);
final Pattern col = new Pattern(0, type, "foo");
final Declaration dec = col.getDeclaration();
final InternalReadAccessor ext = dec.getExtractor();
assertEquals(Fact.class, ext.getExtractToClass());
final Fact stilton = cheese.createFact(10);
stilton.setFieldValue("name", "stilton");
stilton.setFieldValue("price", new Integer(200));
assertEquals(stilton, dec.getValue(null, stilton));
}
Aggregations