Search in sources :

Example 6 with ConsequenceMetaData

use of org.drools.core.rule.ConsequenceMetaData in project drools by kiegroup.

the class RuleMetadataTest method testRetractWithFunction.

@Test
public void testRetractWithFunction() {
    String rule1 = "retract( getA($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.RETRACT, statment.getType());
    assertEquals("org.drools.A", statment.getFactClassName());
}
Also used : ConsequenceMetaData(org.drools.core.rule.ConsequenceMetaData) KieBase(org.kie.api.KieBase) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) Test(org.junit.Test)

Example 7 with ConsequenceMetaData

use of org.drools.core.rule.ConsequenceMetaData in project drools by kiegroup.

the class RuleMetadataTest method testInsert2.

@Test
public void testInsert2() {
    String rule1 = "insert( new B(1, $ab) );";
    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.INSERT, statment.getType());
    assertEquals(RuleMetadataTest.B.class.getName(), statment.getFactClassName());
}
Also used : ConsequenceMetaData(org.drools.core.rule.ConsequenceMetaData) KieBase(org.kie.api.KieBase) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) Test(org.junit.Test)

Example 8 with ConsequenceMetaData

use of org.drools.core.rule.ConsequenceMetaData in project drools by kiegroup.

the class RuleMetadataTest method testInsert.

@Test
public void testInsert() {
    String rule1 = "insert( new A(1, $bb, \"3\") );";
    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.INSERT, statment.getType());
    assertEquals("org.drools.A", statment.getFactClassName());
    assertEquals(3, statment.getFields().size());
    ConsequenceMetaData.Field field1 = statment.getFields().get(0);
    assertEquals("a", field1.getName());
    assertEquals("1", field1.getValue());
    assertTrue(field1.isLiteral());
    ConsequenceMetaData.Field field2 = statment.getFields().get(1);
    assertEquals("b", field2.getName());
    assertEquals("$bb", field2.getValue());
    assertFalse(field2.isLiteral());
    ConsequenceMetaData.Field field3 = statment.getFields().get(2);
    assertEquals("c", field3.getName());
    assertEquals("\"3\"", field3.getValue());
    assertTrue(field3.isLiteral());
}
Also used : ConsequenceMetaData(org.drools.core.rule.ConsequenceMetaData) KieBase(org.kie.api.KieBase) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) Test(org.junit.Test)

Aggregations

RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)8 ConsequenceMetaData (org.drools.core.rule.ConsequenceMetaData)8 Test (org.junit.Test)8 KieBase (org.kie.api.KieBase)8