use of org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testNotSoundsLikeAndNotMatches.
@Test
public void testNotSoundsLikeAndNotMatches() {
final String ruleName = "test not soundslike constraint";
final RuleModel model = new RuleModel();
model.name = ruleName;
final FactPattern pattern = new FactPattern("Person");
final CompositeFieldConstraint notMatchesAndNotSoundsLike = new CompositeFieldConstraint();
notMatchesAndNotSoundsLike.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_AND);
pattern.addConstraint(notMatchesAndNotSoundsLike);
final SingleFieldConstraint fieldNotSoundsLikeGoo = new SingleFieldConstraint();
fieldNotSoundsLikeGoo.setFieldType(DataType.TYPE_STRING);
fieldNotSoundsLikeGoo.setFieldName("field");
fieldNotSoundsLikeGoo.setOperator("not soundslike");
fieldNotSoundsLikeGoo.setValue("goo");
fieldNotSoundsLikeGoo.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
notMatchesAndNotSoundsLike.addConstraint(fieldNotSoundsLikeGoo);
final SingleFieldConstraint fieldNotMatchesGoo = new SingleFieldConstraint();
fieldNotMatchesGoo.setFieldType(DataType.TYPE_STRING);
fieldNotMatchesGoo.setFieldName("field");
fieldNotMatchesGoo.setOperator("not matches");
fieldNotMatchesGoo.setValue("goo");
fieldNotMatchesGoo.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
notMatchesAndNotSoundsLike.addConstraint(fieldNotMatchesGoo);
model.addLhsItem(pattern);
String expected = "rule \"" + ruleName + "\"" + "\tdialect \"mvel\"\n when " + "Person( field not soundslike \"goo\" && field not matches \"goo\" )" + "then" + "end";
checkMarshalling(expected, model);
}
use of org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testCompositeConstraintsRoundTrip.
@Test
public void testCompositeConstraintsRoundTrip() throws Exception {
RuleModel m = new RuleModel();
m.name = "with composite";
FactPattern p1 = new FactPattern("Person");
p1.setBoundName("p1");
m.addLhsItem(p1);
FactPattern p = new FactPattern("Goober");
m.addLhsItem(p);
CompositeFieldConstraint comp = new CompositeFieldConstraint();
comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
p.addConstraint(comp);
final SingleFieldConstraint X = new SingleFieldConstraint();
X.setFieldName("goo");
X.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
X.setValue("foo");
X.setOperator("==");
X.setConnectives(new ConnectiveConstraint[1]);
X.getConnectives()[0] = new ConnectiveConstraint();
X.getConnectives()[0].setConstraintValueType(ConnectiveConstraint.TYPE_LITERAL);
X.getConnectives()[0].setOperator("|| ==");
X.getConnectives()[0].setValue("bar");
comp.addConstraint(X);
final SingleFieldConstraint Y = new SingleFieldConstraint();
Y.setFieldName("goo2");
Y.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
Y.setValue("foo");
Y.setOperator("==");
comp.addConstraint(Y);
CompositeFieldConstraint comp2 = new CompositeFieldConstraint();
comp2.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_AND);
final SingleFieldConstraint Q1 = new SingleFieldConstraint();
Q1.setFieldName("goo");
Q1.setOperator("==");
Q1.setValue("whee");
Q1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
comp2.addConstraint(Q1);
final SingleFieldConstraint Q2 = new SingleFieldConstraint();
Q2.setFieldName("gabba");
Q2.setOperator("==");
Q2.setValue("whee");
Q2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
comp2.addConstraint(Q2);
// now nest it
comp.addConstraint(comp2);
final SingleFieldConstraint Z = new SingleFieldConstraint();
Z.setFieldName("goo3");
Z.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
Z.setValue("foo");
Z.setOperator("==");
p.addConstraint(Z);
ActionInsertFact ass = new ActionInsertFact("Whee");
m.addRhsItem(ass);
String drl = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
PackageDataModelOracle dmo = mock(PackageDataModelOracle.class);
RuleModel m2 = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.EMPTY_LIST, dmo);
assertNotNull(m2);
assertEquals("with composite", m2.name);
assertEquals(m2.lhs.length, m.lhs.length);
assertEquals(m2.rhs.length, m.rhs.length);
}
use of org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testCompositeOrConstraints.
@Test
public void testCompositeOrConstraints() {
RuleModel m = new RuleModel();
m.name = "or composite";
FactPattern p = new FactPattern("Goober");
m.addLhsItem(p);
CompositeFieldConstraint comp = new CompositeFieldConstraint();
comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
p.addConstraint(comp);
final SingleFieldConstraint sfc1 = new SingleFieldConstraint();
sfc1.setFactType("Goober");
sfc1.setFieldName("gooField");
sfc1.setFieldType(DataType.TYPE_STRING);
sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
sfc1.setValue("gooValue");
sfc1.setOperator("==");
comp.addConstraint(sfc1);
final SingleFieldConstraint sfc2 = new SingleFieldConstraint();
sfc2.setFactType("Goober");
sfc2.setFieldName("fooField");
sfc2.setFieldType(DataType.TYPE_OBJECT);
sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
sfc2.setOperator("!= null");
comp.addConstraint(sfc2);
final SingleFieldConstraint sfc3 = new SingleFieldConstraint();
sfc3.setFactType("Bar");
sfc3.setFieldName("barField");
sfc3.setParent(sfc2);
sfc3.setFieldType(DataType.TYPE_STRING);
sfc3.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
sfc3.setValue("barValue");
sfc3.setOperator("==");
comp.addConstraint(sfc3);
ActionInsertFact ass = new ActionInsertFact("Whee");
m.addRhsItem(ass);
String actual = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
String expected = "rule \"or composite\"" + "dialect \"mvel\"\n" + "when\n" + "Goober( gooField == \"gooValue\" || fooField != null || fooField.barField == \"barValue\" )\n" + "then\n" + "insert( new Whee() );\n" + "end";
checkMarshalling(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testCompositeOrConstraintsComplex.
@Test
public void testCompositeOrConstraintsComplex() {
RuleModel m = new RuleModel();
m.name = "or composite complex";
FactPattern p = new FactPattern("Goober");
m.addLhsItem(p);
CompositeFieldConstraint comp = new CompositeFieldConstraint();
comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
p.addConstraint(comp);
final SingleFieldConstraint sfc1 = new SingleFieldConstraint();
sfc1.setFactType("Goober");
sfc1.setFieldName("gooField");
sfc1.setFieldType(DataType.TYPE_STRING);
sfc1.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
sfc1.setValue("gooValue");
sfc1.setOperator("==");
comp.addConstraint(sfc1);
final SingleFieldConstraint sfc2 = new SingleFieldConstraint();
sfc2.setFactType("Goober");
sfc2.setFieldName("fooField");
sfc2.setFieldType(DataType.TYPE_OBJECT);
sfc2.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
sfc2.setOperator("!= null");
comp.addConstraint(sfc2);
final SingleFieldConstraint sfc3 = new SingleFieldConstraint();
sfc3.setFactType("Bar");
sfc3.setFieldName("barField");
sfc3.setParent(sfc2);
sfc3.setFieldType(DataType.TYPE_STRING);
sfc3.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
sfc3.setValue("barValue");
sfc3.setOperator("==");
comp.addConstraint(sfc3);
final SingleFieldConstraint sfc4 = new SingleFieldConstraint();
sfc4.setFactType("Goober");
sfc4.setFieldName("zooField");
sfc4.setFieldType(DataType.TYPE_STRING);
sfc4.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
sfc4.setValue("zooValue");
sfc4.setOperator("==");
p.addConstraint(sfc4);
ActionInsertFact ass = new ActionInsertFact("Whee");
m.addRhsItem(ass);
String expected = "rule \"or composite complex\"" + "dialect \"mvel\"\n" + "when\n" + "Goober( gooField == \"gooValue\" || fooField != null || fooField.barField == \"barValue\", zooField == \"zooValue\" )\n" + "then\n" + "insert( new Whee() );\n" + "end";
checkMarshalling(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint in project drools by kiegroup.
the class RuleModelDRLPersistenceTest method testCompositeConstraints.
@Test
public void testCompositeConstraints() {
RuleModel m = new RuleModel();
m.name = "with composite";
FactPattern p1 = new FactPattern("Person");
p1.setBoundName("p1");
m.addLhsItem(p1);
FactPattern p = new FactPattern("Goober");
m.addLhsItem(p);
CompositeFieldConstraint comp = new CompositeFieldConstraint();
comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
p.addConstraint(comp);
final SingleFieldConstraint X = new SingleFieldConstraint();
X.setFieldName("goo");
X.setFieldType(DataType.TYPE_STRING);
X.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
X.setValue("foo");
X.setOperator("==");
X.setConnectives(new ConnectiveConstraint[1]);
X.getConnectives()[0] = new ConnectiveConstraint();
X.getConnectives()[0].setConstraintValueType(ConnectiveConstraint.TYPE_LITERAL);
X.getConnectives()[0].setFieldType(DataType.TYPE_STRING);
X.getConnectives()[0].setOperator("|| ==");
X.getConnectives()[0].setValue("bar");
comp.addConstraint(X);
final SingleFieldConstraint Y = new SingleFieldConstraint();
Y.setFieldName("goo2");
Y.setFieldType(DataType.TYPE_STRING);
Y.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
Y.setValue("foo");
Y.setOperator("==");
comp.addConstraint(Y);
CompositeFieldConstraint comp2 = new CompositeFieldConstraint();
comp2.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_AND);
final SingleFieldConstraint Q1 = new SingleFieldConstraint();
Q1.setFieldType(DataType.TYPE_STRING);
Q1.setFieldName("goo");
Q1.setOperator("==");
Q1.setValue("whee");
Q1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
comp2.addConstraint(Q1);
final SingleFieldConstraint Q2 = new SingleFieldConstraint();
Q2.setFieldType(DataType.TYPE_STRING);
Q2.setFieldName("gabba");
Q2.setOperator("==");
Q2.setValue("whee");
Q2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
comp2.addConstraint(Q2);
// now nest it
comp.addConstraint(comp2);
final SingleFieldConstraint Z = new SingleFieldConstraint();
Z.setFieldName("goo3");
Z.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
Z.setFieldType(DataType.TYPE_STRING);
Z.setValue("foo");
Z.setOperator("==");
p.addConstraint(Z);
ActionInsertFact ass = new ActionInsertFact("Whee");
m.addRhsItem(ass);
String actual = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
String expected = "rule \"with composite\"\n" + "\tdialect \"mvel\"\n" + "\twhen\n" + "\t\tp1 : Person( )\n" + "\t\tGoober( goo == \"foo\" || == \"bar\" || goo2 == \"foo\" || ( goo == \"whee\" && gabba == \"whee\" ), goo3 == \"foo\" )\n" + "\tthen\n" + "\t\tinsert( new Whee() );\n" + "end\n";
assertEqualsIgnoreWhitespace(expected, actual);
checkMarshalling(expected, m);
}
Aggregations