Search in sources :

Example 1 with ConsequenceMetaData

use of org.drools.core.rule.ConsequenceMetaData 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());
}
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 2 with ConsequenceMetaData

use of org.drools.core.rule.ConsequenceMetaData 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());
}
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 3 with ConsequenceMetaData

use of org.drools.core.rule.ConsequenceMetaData 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());
}
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 4 with ConsequenceMetaData

use of org.drools.core.rule.ConsequenceMetaData 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());
}
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 5 with ConsequenceMetaData

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

the class RuleMetadataTest method testModify.

@Test
public void testModify() {
    String rule1 = "modify( $a ) { setA( 20 ), setB( $bb ) }";
    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());
}
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