use of org.drools.kiesession.rulebase.InternalKnowledgeBase in project drools by kiegroup.
the class TraitTypeGenerationTest method testMultipleInheritanceWithPosition3.
@Test
public void testMultipleInheritanceWithPosition3() throws Exception {
// DROOLS-249
String drl = "package org.drools.test\n" + "declare trait PosTrait\n" + "@propertyReactive\n" + " field0 : int = 100 @position(0)\n" + " field1 : int = 101 @position(1)\n" + " field2 : int = 102 @position(0)\n" + "end\n" + "\n" + "declare trait MultiInhPosTrait extends PosTrait\n" + "@propertyReactive\n" + " mfield0 : int = 200 //@position(0)\n" + " mfield1 : int = 201 @position(2)\n" + "end";
KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kBuilder.add(new ByteArrayResource(drl.getBytes()), ResourceType.DRL);
if (kBuilder.hasErrors()) {
System.err.println(kBuilder.getErrors());
}
assertFalse(kBuilder.hasErrors());
InternalKnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowledgeBase.addPackages(kBuilder.getKnowledgePackages());
FactType sw = knowledgeBase.getFactType("org.drools.test", "MultiInhPosTrait");
assertEquals(5, sw.getFields().size());
assertEquals("field0", sw.getFields().get(0).getName());
assertEquals("field2", sw.getFields().get(1).getName());
assertEquals("field1", sw.getFields().get(2).getName());
assertEquals("mfield1", sw.getFields().get(3).getName());
assertEquals("mfield0", sw.getFields().get(4).getName());
}
use of org.drools.kiesession.rulebase.InternalKnowledgeBase in project drools by kiegroup.
the class TraitTypeGenerationTest method testMultipleInheritanceWithPosition5.
@Test
public void testMultipleInheritanceWithPosition5() throws Exception {
// DROOLS-249
String drl = "package org.drools.test\n" + "declare trait PosTrait\n" + "@propertyReactive\n" + " field0 : int = 100 @position(2)\n" + " field1 : int = 101 @position(1)\n" + " field2 : int = 102 @position(8)\n" + "end\n" + "\n" + "declare trait MultiInhPosTrait extends PosTrait\n" + "@propertyReactive\n" + " mfield0 : int = 200 @position(7)\n" + " mfield1 : int = 201 @position(2)\n" + "end";
KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kBuilder.add(new ByteArrayResource(drl.getBytes()), ResourceType.DRL);
if (kBuilder.hasErrors()) {
System.err.println(kBuilder.getErrors());
}
assertFalse(kBuilder.hasErrors());
InternalKnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowledgeBase.addPackages(kBuilder.getKnowledgePackages());
FactType sw = knowledgeBase.getFactType("org.drools.test", "MultiInhPosTrait");
assertEquals(5, sw.getFields().size());
assertEquals("field1", sw.getFields().get(0).getName());
assertEquals("field0", sw.getFields().get(1).getName());
assertEquals("mfield1", sw.getFields().get(2).getName());
assertEquals("mfield0", sw.getFields().get(3).getName());
assertEquals("field2", sw.getFields().get(4).getName());
}
use of org.drools.kiesession.rulebase.InternalKnowledgeBase in project drools by kiegroup.
the class VerifierKnowledgeBaseBuilder method newVerifierKnowledgeBase.
public KieBase newVerifierKnowledgeBase(VerifierConfiguration configuration) {
InternalKnowledgeBase verifierKnowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
if (configuration.getVerifyingResources() != null) {
for (Resource resource : configuration.getVerifyingResources().keySet()) {
kbuilder.add(resource, configuration.getVerifyingResources().get(resource));
}
}
if (kbuilder.hasErrors()) {
Iterator<KnowledgeBuilderError> errors = kbuilder.getErrors().iterator();
while (errors.hasNext()) {
this.errors.add(new VerifierError("Error compiling verifier rules: " + errors.next().getMessage()));
}
}
verifierKnowledgeBase.addPackages(kbuilder.getKnowledgePackages());
return verifierKnowledgeBase;
}
use of org.drools.kiesession.rulebase.InternalKnowledgeBase in project drools by kiegroup.
the class StreamsTest method testEventExpirationValue.
@Test(timeout = 10000)
public void testEventExpirationValue() {
final String drl1 = "package org.drools.pkg1\n" + "import " + StockTick.class.getCanonicalName() + ";\n" + "declare StockTick\n" + " @role(event)\n" + "end\n" + "rule X\n" + "when\n" + " StockTick()\n" + "then\n" + "end\n";
final String drl2 = "package org.drools.pkg2\n" + "import " + StockTick.class.getCanonicalName() + ";\n" + "declare StockTick\n" + " @role(event)\n" + "end\n" + "rule X\n" + "when\n" + " StockTick()\n" + "then\n" + "end\n";
final InternalKnowledgeBase kbase = (InternalKnowledgeBase) KieBaseUtil.getKieBaseFromKieModuleFromDrl("stream-test", kieBaseTestConfiguration, drl1, drl2);
final List<ObjectTypeNode> otns = kbase.getRete().getObjectTypeNodes();
final ObjectType stot = new ClassObjectType(StockTick.class);
for (final ObjectTypeNode otn : otns) {
if (otn.getObjectType().isAssignableFrom(stot)) {
assertEquals(NEVER_EXPIRES, otn.getExpirationOffset());
}
}
}
use of org.drools.kiesession.rulebase.InternalKnowledgeBase in project drools by kiegroup.
the class FieldConstraintTest method testPrimitiveLiteralConstraint.
/**
* <pre>
*
* Cheese( price == 5 )
*
* </pre>
*/
@Test
public void testPrimitiveLiteralConstraint() {
InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
;
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
final ClassFieldReader extractor = store.getReader(Cheese.class, "price");
AlphaNodeFieldConstraint constraint = ConstraintTestUtil.createCheesePriceEqualsConstraint(extractor, 5, useLambdaConstraint);
final Cheese cheddar = new Cheese("cheddar", 5);
final InternalFactHandle cheddarHandle = (InternalFactHandle) ksession.insert(cheddar);
// check constraint
assertTrue(constraint.isAllowed(cheddarHandle, ksession));
final Cheese stilton = new Cheese("stilton", 10);
final InternalFactHandle stiltonHandle = (InternalFactHandle) ksession.insert(stilton);
// check constraint
assertFalse(constraint.isAllowed(stiltonHandle, ksession));
}
Aggregations