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]);
}
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]);
}
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());
}
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]);
}
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());
}
Aggregations