use of org.drools.workbench.models.datamodel.rule.ConnectiveConstraint in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testConnectiveConstraintSecondValue.
@Test
public void testConnectiveConstraintSecondValue() {
TemplateModel m = new TemplateModel();
m.name = "t1";
FactPattern p1 = new FactPattern("Person");
m.addLhsItem(p1);
final SingleFieldConstraint X = new SingleFieldConstraint();
X.setFieldName("field1");
X.setFieldType(DataType.TYPE_STRING);
X.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
X.setValue("$f1");
X.setOperator("==");
p1.addConstraint(X);
ConnectiveConstraint connective = new ConnectiveConstraint();
connective.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
connective.setFieldType(DataType.TYPE_STRING);
connective.setOperator("|| ==");
connective.setValue("$f2");
X.setConnectives(new ConnectiveConstraint[1]);
X.getConnectives()[0] = connective;
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"bar\" )\n" + "then\n" + "end\n";
m.addRow(new String[] { null, "bar" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.ConnectiveConstraint in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testCompositeConstraintWithConnectiveConstraintBothValues.
@Test
public void testCompositeConstraintWithConnectiveConstraintBothValues() {
TemplateModel m = new TemplateModel();
m.name = "t1";
FactPattern p1 = new FactPattern("Person");
m.addLhsItem(p1);
CompositeFieldConstraint comp = new CompositeFieldConstraint();
comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
p1.addConstraint(comp);
final SingleFieldConstraint X = new SingleFieldConstraint();
X.setFieldName("field1");
X.setFieldType(DataType.TYPE_STRING);
X.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
X.setValue("$f1");
X.setOperator("==");
comp.addConstraint(X);
ConnectiveConstraint connective = new ConnectiveConstraint();
connective.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
connective.setFieldType(DataType.TYPE_STRING);
connective.setOperator("|| ==");
connective.setValue("goo");
X.setConnectives(new ConnectiveConstraint[1]);
X.getConnectives()[0] = connective;
final SingleFieldConstraint Y = new SingleFieldConstraint();
Y.setFieldName("field2");
Y.setFieldType(DataType.TYPE_STRING);
Y.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
Y.setValue("$f2");
Y.setOperator("==");
comp.addConstraint(Y);
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"foo\" || == \"goo\" || field2 == \"bar\" )\n" + "then\n" + "end\n";
m.addRow(new String[] { "foo", "bar" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.ConnectiveConstraint in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testConnectiveConstraintFirstValue.
@Test
public void testConnectiveConstraintFirstValue() {
TemplateModel m = new TemplateModel();
m.name = "t1";
FactPattern p1 = new FactPattern("Person");
m.addLhsItem(p1);
final SingleFieldConstraint X = new SingleFieldConstraint();
X.setFieldName("field1");
X.setFieldType(DataType.TYPE_STRING);
X.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
X.setValue("$f1");
X.setOperator("==");
p1.addConstraint(X);
ConnectiveConstraint connective = new ConnectiveConstraint();
connective.setConstraintValueType(BaseSingleFieldConstraint.TYPE_TEMPLATE);
connective.setFieldType(DataType.TYPE_STRING);
connective.setOperator("|| ==");
connective.setValue("$f2");
X.setConnectives(new ConnectiveConstraint[1]);
X.getConnectives()[0] = connective;
String expected = "rule \"t1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == \"foo\" )\n" + "then\n" + "end\n";
m.addRow(new String[] { "foo", null });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.ConnectiveConstraint in project drools-wb by kiegroup.
the class RuleModelCloneVisitor method visitConnectiveConstraint.
private ConnectiveConstraint visitConnectiveConstraint(ConnectiveConstraint cc) {
ConnectiveConstraint clone = new ConnectiveConstraint();
clone.setConstraintValueType(cc.getConstraintValueType());
clone.setExpressionValue((ExpressionFormLine) visit(cc.getExpressionValue()));
clone.setFactType(cc.getFactType());
clone.setFieldName(cc.getFieldName());
clone.setFieldType(cc.getFieldType());
clone.setOperator(cc.getOperator());
for (Map.Entry<String, String> entry : cc.getParameters().entrySet()) {
clone.setParameter(entry.getKey(), entry.getValue());
}
clone.setValue(cc.getValue());
return clone;
}
use of org.drools.workbench.models.datamodel.rule.ConnectiveConstraint in project drools-wb by kiegroup.
the class GuidedRuleEditorServiceImplCDITest method testAbbreviatedCondition.
@Test
public void testAbbreviatedCondition() throws Exception {
final String resourcePath = RULES_ROOT + "matchPeopleAbbreviatedCondition.rdrl";
final GuidedEditorContent content = guidedRuleService.loadContent(getPath(resourcePath));
final RuleModel model = content.getModel();
Assertions.assertThat(model.lhs.length).isEqualTo(1);
final FactPattern pattern = (FactPattern) model.lhs[0];
final SingleFieldConstraint fieldConstraintOne = (SingleFieldConstraint) pattern.getConstraint(0);
Assertions.assertThat(fieldConstraintOne.getConnectives()).hasSize(2);
final ConnectiveConstraint fieldConstraintTwo = fieldConstraintOne.getConnectives()[0];
final ConnectiveConstraint fieldConstraintThree = fieldConstraintOne.getConnectives()[1];
Assertions.assertThat(fieldConstraintOne.getFieldName()).isEqualTo("age");
Assertions.assertThat(fieldConstraintOne.getOperator()).isEqualTo(Operator.NOT_EQUAL.getOperatorString());
Assertions.assertThat(fieldConstraintOne.getValue()).isEqualTo("18");
Assertions.assertThat(fieldConstraintTwo.getFieldName()).isEqualTo("age");
Assertions.assertThat(fieldConstraintTwo.getOperator()).isEqualTo("&& " + Operator.LESS.getOperatorString());
Assertions.assertThat(fieldConstraintTwo.getValue()).isEqualTo("25");
Assertions.assertThat(fieldConstraintThree.getFieldName()).isEqualTo("age");
Assertions.assertThat(fieldConstraintThree.getOperator()).isEqualTo("&& " + Operator.GREATER.getOperatorString());
Assertions.assertThat(fieldConstraintThree.getValue()).isEqualTo("15");
final List<ValidationMessage> messages = validateResource(resourcePath);
Assertions.assertThat(messages).isEmpty();
}
Aggregations