use of org.kie.api.KieBase in project drools by kiegroup.
the class MarshallingTest method testAccumulate2.
@Test
public void testAccumulate2() throws Exception {
String str = "package org.drools\n" + "\n" + "import org.drools.compiler.Message\n" + "\n" + "rule MyRule\n" + " when\n" + " Number( intValue >= 5 ) from accumulate ( m: Message( ), count( m ) )\n" + " then\n" + " System.out.println(\"Found messages\");\n" + "end\n";
KieBase kBase = loadKnowledgeBaseFromString(str);
KieSession ksession = kBase.newKieSession();
ksession = getSerialisedStatefulKnowledgeSession(ksession, true);
ksession.insert(new Message());
ksession.insert(new Message());
ksession.insert(new Message());
ksession.insert(new Message());
ksession.insert(new Message());
((InternalWorkingMemory) ksession).flushPropagations();
assertEquals(1, ((InternalAgenda) ksession.getAgenda()).agendaSize());
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class RuleMetadataTest method testUpdate.
@Test
public void testUpdate() {
String rule1 = "$a.setA( 20 );\n $a.setB( $bb );\n update( $a );";
KieBase kbase = getKnowledgeBase(rule1);
RuleImpl rule = getRule(kbase, "R0");
ConsequenceMetaData consequenceMetaData = rule.getConsequenceMetaData();
assertEquals(1, consequenceMetaData.getStatements().size());
ConsequenceMetaData.Statement statment = consequenceMetaData.getStatements().get(0);
assertEquals(ConsequenceMetaData.Statement.Type.MODIFY, statment.getType());
assertEquals("org.drools.A", statment.getFactClassName());
assertEquals(2, statment.getFields().size());
ConsequenceMetaData.Field field1 = statment.getFields().get(0);
assertEquals("a", field1.getName());
assertEquals("20", field1.getValue());
assertTrue(field1.isLiteral());
ConsequenceMetaData.Field field2 = statment.getFields().get(1);
assertEquals("b", field2.getName());
assertEquals("$bb", field2.getValue());
assertFalse(field2.isLiteral());
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class RuleMetadataTest method testModify2.
@Test
public void testModify2() {
String rule1 = "modify( $a ) { setC( $bc ) };\n modify( $b ) { c = \"Hello\" };";
KieBase kbase = getKnowledgeBase(rule1);
RuleImpl rule = getRule(kbase, "R0");
ConsequenceMetaData consequenceMetaData = rule.getConsequenceMetaData();
assertEquals(2, consequenceMetaData.getStatements().size());
ConsequenceMetaData.Statement statment1 = consequenceMetaData.getStatements().get(0);
assertEquals(ConsequenceMetaData.Statement.Type.MODIFY, statment1.getType());
assertEquals("org.drools.A", statment1.getFactClassName());
assertEquals(1, statment1.getFields().size());
ConsequenceMetaData.Field field1 = statment1.getFields().get(0);
assertEquals("c", field1.getName());
assertEquals("$bc", field1.getValue());
assertFalse(field1.isLiteral());
ConsequenceMetaData.Statement statment2 = consequenceMetaData.getStatements().get(1);
assertEquals(ConsequenceMetaData.Statement.Type.MODIFY, statment2.getType());
assertEquals(RuleMetadataTest.B.class.getName(), statment2.getFactClassName());
assertEquals(1, statment2.getFields().size());
ConsequenceMetaData.Field field2 = statment2.getFields().get(0);
assertEquals("c", field2.getName());
assertEquals("\"Hello\"", field2.getValue());
assertTrue(field2.isLiteral());
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class RuleMetadataTest method testUpdate2.
@Test
public void testUpdate2() {
String rule1 = "$a.setC( $bc );\n $b.c = \"Hello\";\n update( $a );\n update( $b );";
KieBase kbase = getKnowledgeBase(rule1);
RuleImpl rule = getRule(kbase, "R0");
ConsequenceMetaData consequenceMetaData = rule.getConsequenceMetaData();
assertEquals(2, consequenceMetaData.getStatements().size());
ConsequenceMetaData.Statement statment1 = consequenceMetaData.getStatements().get(0);
assertEquals(ConsequenceMetaData.Statement.Type.MODIFY, statment1.getType());
assertEquals("org.drools.A", statment1.getFactClassName());
assertEquals(1, statment1.getFields().size());
ConsequenceMetaData.Field field1 = statment1.getFields().get(0);
assertEquals("c", field1.getName());
assertEquals("$bc", field1.getValue());
assertFalse(field1.isLiteral());
ConsequenceMetaData.Statement statment2 = consequenceMetaData.getStatements().get(1);
assertEquals(ConsequenceMetaData.Statement.Type.MODIFY, statment2.getType());
assertEquals(RuleMetadataTest.B.class.getName(), statment2.getFactClassName());
assertEquals(1, statment2.getFields().size());
ConsequenceMetaData.Field field2 = statment2.getFields().get(0);
assertEquals("c", field2.getName());
assertEquals("\"Hello\"", field2.getValue());
assertTrue(field2.isLiteral());
}
use of org.kie.api.KieBase in project drools by kiegroup.
the class RuleMetadataTest method testRetract.
@Test
public void testRetract() {
String rule1 = "retract( $b );";
KieBase kbase = getKnowledgeBase(rule1);
RuleImpl rule = getRule(kbase, "R0");
ConsequenceMetaData consequenceMetaData = rule.getConsequenceMetaData();
assertEquals(1, consequenceMetaData.getStatements().size());
ConsequenceMetaData.Statement statment = consequenceMetaData.getStatements().get(0);
assertEquals(ConsequenceMetaData.Statement.Type.RETRACT, statment.getType());
assertEquals(RuleMetadataTest.B.class.getName(), statment.getFactClassName());
}
Aggregations