Search in sources :

Example 51 with RuleModel

use of org.drools.workbench.models.datamodel.rule.RuleModel in project drools by kiegroup.

the class RuleModelTest method testAddItemRhsAtSpecificPosition.

@Test
public void testAddItemRhsAtSpecificPosition() {
    final RuleModel model = new RuleModel();
    final ActionSetField a = new ActionSetField();
    model.addRhsItem(a);
    assertEquals(1, model.rhs.length);
    final ActionSetField b = new ActionSetField();
    model.addRhsItem(b);
    assertEquals(2, model.rhs.length);
    final ActionSetField c = new ActionSetField();
    model.addRhsItem(c, true);
    assertEquals(3, model.rhs.length);
    assertEquals(a, model.rhs[0]);
    assertEquals(b, model.rhs[1]);
    assertEquals(c, model.rhs[2]);
    final ActionSetField d = new ActionSetField();
    model.addRhsItem(d, false);
    assertEquals(4, model.rhs.length);
    assertEquals(d, model.rhs[0]);
    assertEquals(a, model.rhs[1]);
    assertEquals(b, model.rhs[2]);
    assertEquals(c, model.rhs[3]);
    final ActionSetField e = new ActionSetField();
    model.addRhsItem(e, 2);
    assertEquals(5, model.rhs.length);
    assertEquals(d, model.rhs[0]);
    assertEquals(a, model.rhs[1]);
    assertEquals(e, model.rhs[2]);
    assertEquals(b, model.rhs[3]);
    assertEquals(c, model.rhs[4]);
    // test auto-bound
    final ActionSetField f = new ActionSetField();
    final ActionSetField g = new ActionSetField();
    model.addRhsItem(f, -1);
    model.addRhsItem(g, 100);
    assertEquals(7, model.rhs.length);
    assertEquals(f, model.rhs[0]);
    assertEquals(d, model.rhs[1]);
    assertEquals(a, model.rhs[2]);
    assertEquals(e, model.rhs[3]);
    assertEquals(b, model.rhs[4]);
    assertEquals(c, model.rhs[5]);
    assertEquals(g, model.rhs[6]);
    model.moveRhsItemDown(5);
    model.moveRhsItemUp(3);
    assertEquals(7, model.rhs.length);
    assertEquals(f, model.rhs[0]);
    assertEquals(d, model.rhs[1]);
    assertEquals(e, model.rhs[2]);
    assertEquals(a, model.rhs[3]);
    assertEquals(b, model.rhs[4]);
    assertEquals(g, model.rhs[5]);
    assertEquals(c, model.rhs[6]);
    model.moveRhsItemUp(0);
    model.moveRhsItemDown(6);
    assertEquals(7, model.rhs.length);
    assertEquals(f, model.rhs[0]);
    assertEquals(d, model.rhs[1]);
    assertEquals(e, model.rhs[2]);
    assertEquals(a, model.rhs[3]);
    assertEquals(b, model.rhs[4]);
    assertEquals(g, model.rhs[5]);
    assertEquals(c, model.rhs[6]);
}
Also used : ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 52 with RuleModel

use of org.drools.workbench.models.datamodel.rule.RuleModel in project drools by kiegroup.

the class RuleModelTest method testAddItemLhsAtSpecificPosition.

@Test
public void testAddItemLhsAtSpecificPosition() {
    final RuleModel model = new RuleModel();
    final FactPattern a = new FactPattern();
    model.addLhsItem(a);
    assertEquals(1, model.lhs.length);
    final FactPattern b = new FactPattern();
    model.addLhsItem(b);
    assertEquals(2, model.lhs.length);
    final FactPattern c = new FactPattern();
    model.addLhsItem(c, true);
    assertEquals(3, model.lhs.length);
    assertEquals(a, model.lhs[0]);
    assertEquals(b, model.lhs[1]);
    assertEquals(c, model.lhs[2]);
    final FactPattern d = new FactPattern();
    model.addLhsItem(d, false);
    assertEquals(4, model.lhs.length);
    assertEquals(d, model.lhs[0]);
    assertEquals(a, model.lhs[1]);
    assertEquals(b, model.lhs[2]);
    assertEquals(c, model.lhs[3]);
    final FactPattern e = new FactPattern();
    model.addLhsItem(e, 2);
    assertEquals(5, model.lhs.length);
    assertEquals(d, model.lhs[0]);
    assertEquals(a, model.lhs[1]);
    assertEquals(e, model.lhs[2]);
    assertEquals(b, model.lhs[3]);
    assertEquals(c, model.lhs[4]);
    // test auto-bound
    final FactPattern f = new FactPattern();
    final FactPattern g = new FactPattern();
    model.addLhsItem(f, -1);
    model.addLhsItem(g, 100);
    assertEquals(7, model.lhs.length);
    assertEquals(f, model.lhs[0]);
    assertEquals(d, model.lhs[1]);
    assertEquals(a, model.lhs[2]);
    assertEquals(e, model.lhs[3]);
    assertEquals(b, model.lhs[4]);
    assertEquals(c, model.lhs[5]);
    assertEquals(g, model.lhs[6]);
    model.moveLhsItemDown(5);
    model.moveLhsItemUp(3);
    assertEquals(7, model.lhs.length);
    assertEquals(f, model.lhs[0]);
    assertEquals(d, model.lhs[1]);
    assertEquals(e, model.lhs[2]);
    assertEquals(a, model.lhs[3]);
    assertEquals(b, model.lhs[4]);
    assertEquals(g, model.lhs[5]);
    assertEquals(c, model.lhs[6]);
    model.moveLhsItemUp(0);
    model.moveLhsItemDown(6);
    assertEquals(7, model.lhs.length);
    assertEquals(f, model.lhs[0]);
    assertEquals(d, model.lhs[1]);
    assertEquals(e, model.lhs[2]);
    assertEquals(a, model.lhs[3]);
    assertEquals(b, model.lhs[4]);
    assertEquals(g, model.lhs[5]);
    assertEquals(c, model.lhs[6]);
}
Also used : FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 53 with RuleModel

use of org.drools.workbench.models.datamodel.rule.RuleModel in project drools by kiegroup.

the class RuleModelTest method testMetaData.

@Test
public void testMetaData() {
    final RuleModel m = new RuleModel();
    final RuleMetadata rm = new RuleMetadata("foo", "bar");
    // test add
    m.addMetadata(rm);
    assertEquals(1, m.metadataList.length);
    assertEquals(rm, m.metadataList[0]);
    // should be able to find it
    RuleMetadata gm = m.getMetaData("foo");
    assertNotNull(gm);
    // test add and remove
    final RuleMetadata rm2 = new RuleMetadata("foo2", "bar2");
    m.addMetadata(rm2);
    assertEquals(2, m.metadataList.length);
    assertEquals(rm2, m.metadataList[1]);
    assertEquals("@foo(bar)", rm.toString());
    m.removeMetadata(0);
    assertEquals(1, m.metadataList.length);
    assertEquals(rm2, m.metadataList[0]);
    assertEquals("@foo2(bar2)", (m.metadataList[0]).toString());
    // should be able to find it now that it was removed
    gm = m.getMetaData("foo");
    assertNull(gm);
    // test add via update method
    m.updateMetadata(rm);
    gm = m.getMetaData("foo");
    assertNotNull(gm);
    // test update of existing element
    rm.setValue("bar2");
    m.updateMetadata(rm);
    gm = m.getMetaData("foo");
    assertNotNull(gm);
    assertEquals("bar2", gm.getValue());
}
Also used : RuleMetadata(org.drools.workbench.models.datamodel.rule.RuleMetadata) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 54 with RuleModel

use of org.drools.workbench.models.datamodel.rule.RuleModel in project drools by kiegroup.

the class RuleModelTest method testAddItemLhs.

@Test
public void testAddItemLhs() {
    final RuleModel model = new RuleModel();
    final FactPattern x = new FactPattern();
    model.addLhsItem(x);
    assertEquals(1, model.lhs.length);
    final FactPattern y = new FactPattern();
    model.addLhsItem(y);
    assertEquals(2, model.lhs.length);
    assertEquals(x, model.lhs[0]);
    assertEquals(y, model.lhs[1]);
}
Also used : FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 55 with RuleModel

use of org.drools.workbench.models.datamodel.rule.RuleModel in project drools by kiegroup.

the class RuleModelTest method testBoundVariableFromOR.

@Test
public void testBoundVariableFromOR() throws Exception {
    final RuleModel model = new RuleModel();
    model.lhs = new IPattern[1];
    CompositeFactPattern compositeFactPattern = new CompositeFactPattern(CompositeFactPattern.COMPOSITE_TYPE_OR);
    model.lhs[0] = compositeFactPattern;
    FactPattern pattern1 = new FactPattern();
    pattern1.setBoundName("test");
    compositeFactPattern.addFactPattern(pattern1);
    FactPattern pattern2 = new FactPattern();
    SingleFieldConstraint constraint = new SingleFieldConstraint();
    pattern2.addConstraint(constraint);
    compositeFactPattern.addFactPattern(pattern2);
    List<String> boundVariablesInScope = model.getBoundVariablesInScope(constraint);
    assertEquals(1, boundVariablesInScope.size());
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Aggregations

RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)384 Test (org.junit.Test)352 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)223 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)216 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)215 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)201 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)201 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)145 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)134 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)91 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)85 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)63 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)47 ArrayList (java.util.ArrayList)44 IAction (org.drools.workbench.models.datamodel.rule.IAction)31 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)29 SingleFieldConstraintEBLeftSide (org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide)29 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)27 RuleAttribute (org.drools.workbench.models.datamodel.rule.RuleAttribute)25 List (java.util.List)24