use of org.drools.workbench.models.datamodel.rule.RuleModel in project drools by kiegroup.
the class RuleModelDRLPersistenceUnmarshallingTest method testLHSFreeFormLineWithDsl.
@Test
public void testLHSFreeFormLineWithDsl() {
String drl = "rule rule1\n" + "when\n" + ">//A comment\n" + "then\n" + "end";
RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshalUsingDSL(drl, Collections.emptyList(), dmo);
assertNotNull(m);
assertEquals(1, m.lhs.length);
assertTrue(m.lhs[0] instanceof FreeFormLine);
assertEquals("//A comment", ((FreeFormLine) m.lhs[0]).getText());
}
use of org.drools.workbench.models.datamodel.rule.RuleModel in project drools by kiegroup.
the class RuleModelDRLPersistenceUnmarshallingTest method testSingleFieldConstraintConnectives4.
@Test
public // https://issues.jboss.org/browse/RHBRMS-2854
void testSingleFieldConstraintConnectives4() {
String drl = "package org.test;\n" + "rule \"rule1\"\n" + "dialect \"mvel\"\n" + "when\n" + " Applicant(age != null && != 1 && < 10 && > 5)\n" + "then\n" + "end";
addModelField("org.test.Applicant", "this", "org.test.Applicant", DataType.TYPE_THIS);
addModelField("org.test.Applicant", "age", Integer.class.getName(), DataType.TYPE_NUMERIC_INTEGER);
when(dmo.getPackageName()).thenReturn("org.test");
RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
assertNotNull(m);
assertEquals("rule1", m.name);
assertEquals(1, m.lhs.length);
IPattern p = m.lhs[0];
assertTrue(p instanceof FactPattern);
FactPattern fp = (FactPattern) p;
assertEquals("Applicant", fp.getFactType());
assertEquals(1, fp.getConstraintList().getConstraints().length);
assertTrue(fp.getConstraint(0) instanceof SingleFieldConstraint);
SingleFieldConstraint sfp = (SingleFieldConstraint) fp.getConstraint(0);
assertEquals("Applicant", sfp.getFactType());
assertEquals("age", sfp.getFieldName());
assertEquals("!= null", sfp.getOperator());
assertNull(sfp.getValue());
assertEquals(BaseSingleFieldConstraint.TYPE_UNDEFINED, sfp.getConstraintValueType());
assertEquals(3, sfp.getConnectives().length);
ConnectiveConstraint cc1 = sfp.getConnectives()[0];
assertEquals("Applicant", cc1.getFactType());
assertEquals("age", cc1.getFieldName());
assertEquals("&& !=", cc1.getOperator());
assertEquals("1", cc1.getValue());
assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, cc1.getConstraintValueType());
ConnectiveConstraint cc2 = sfp.getConnectives()[1];
assertEquals("Applicant", cc2.getFactType());
assertEquals("age", cc2.getFieldName());
assertEquals("&& <", cc2.getOperator());
assertEquals("10", cc2.getValue());
assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, cc2.getConstraintValueType());
ConnectiveConstraint cc3 = sfp.getConnectives()[2];
assertEquals("Applicant", cc3.getFactType());
assertEquals("age", cc3.getFieldName());
assertEquals("&& >", cc3.getOperator());
assertEquals("5", cc3.getValue());
assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, cc3.getConstraintValueType());
assertEqualsIgnoreWhitespace(drl, RuleModelDRLPersistenceImpl.getInstance().marshal(m));
}
use of org.drools.workbench.models.datamodel.rule.RuleModel in project drools by kiegroup.
the class RuleModelDRLPersistenceUnmarshallingTest method testCollectWithFreeFormDRL_MethodsUndefined.
@Test
public void testCollectWithFreeFormDRL_MethodsUndefined() throws Exception {
// https://bugzilla.redhat.com/show_bug.cgi?id=1060816
String drl = "package org.sample.resourceassignment;\n" + "rule \"r1\"\n" + "dialect \"mvel\"\n" + "when\n" + "$trans : Transactions()\n" + "$transactions : java.util.List( eval( size > 0 ) ) from collect ( Transaction() from $trans.getRecCategorization().get(\"APES-01\") )\n" + "then\n" + "end";
addModelField("Transactions", "recCategorization", "java.util.Map", DataType.TYPE_COLLECTION);
addMethodInformation("java.util.Map", "get", new ArrayList<String>() {
{
add("p0");
}
}, "java.lang.String", null, DataType.TYPE_STRING);
final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
assertNotNull(m);
assertEquals(2, m.lhs.length);
IPattern p0 = m.lhs[0];
assertTrue(p0 instanceof FactPattern);
FactPattern fp0 = (FactPattern) p0;
assertEquals("Transactions", fp0.getFactType());
assertEquals("$trans", fp0.getBoundName());
assertEquals(0, fp0.getNumberOfConstraints());
IPattern p1 = m.lhs[1];
assertTrue(p1 instanceof FromCollectCompositeFactPattern);
FromCollectCompositeFactPattern fp1 = (FromCollectCompositeFactPattern) p1;
assertEquals("java.util.List", fp1.getFactPattern().getFactType());
assertEquals("$transactions", fp1.getFactPattern().getBoundName());
assertEquals(1, fp1.getFactPattern().getNumberOfConstraints());
assertTrue(fp1.getFactPattern().getConstraint(0) instanceof SingleFieldConstraint);
SingleFieldConstraint fp1sfc = (SingleFieldConstraint) fp1.getFactPattern().getConstraint(0);
assertEquals("size > 0", fp1sfc.getValue());
assertEquals(BaseSingleFieldConstraint.TYPE_PREDICATE, fp1sfc.getConstraintValueType());
assertTrue(fp1.getRightPattern() instanceof FromCompositeFactPattern);
FromCompositeFactPattern fp2 = (FromCompositeFactPattern) fp1.getRightPattern();
assertNotNull(fp2.getFactPattern());
FactPattern fp3 = fp2.getFactPattern();
assertEquals("Transaction", fp3.getFactType());
assertEquals(0, fp3.getNumberOfConstraints());
assertNotNull(fp2.getExpression());
ExpressionFormLine efl = fp2.getExpression();
assertEquals(3, efl.getParts().size());
assertTrue(efl.getParts().get(0) instanceof ExpressionVariable);
ExpressionVariable ev = (ExpressionVariable) efl.getParts().get(0);
assertEquals("$trans", ev.getName());
assertEquals("Transactions", ev.getClassType());
assertTrue(efl.getParts().get(1) instanceof ExpressionText);
ExpressionText et1 = (ExpressionText) efl.getParts().get(1);
assertEquals("getRecCategorization()", et1.getName());
assertEquals("java.lang.String", et1.getClassType());
assertEquals(DataType.TYPE_STRING, et1.getGenericType());
assertTrue(efl.getParts().get(2) instanceof ExpressionText);
ExpressionText et2 = (ExpressionText) efl.getParts().get(2);
assertEquals("get(\"APES-01\")", et2.getName());
assertEquals("java.lang.String", et2.getClassType());
assertEquals(DataType.TYPE_STRING, et2.getGenericType());
assertEquals(0, m.rhs.length);
}
use of org.drools.workbench.models.datamodel.rule.RuleModel in project drools by kiegroup.
the class RuleModelDRLPersistenceUnmarshallingTest method testRuleNameWithoutTheQuotes.
@Test
public void testRuleNameWithoutTheQuotes() {
String drl = "rule rule1\n" + "when\n" + "then\n" + "end";
RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
assertNotNull(m);
assertEquals("rule1", m.name);
}
use of org.drools.workbench.models.datamodel.rule.RuleModel in project drools by kiegroup.
the class RuleModelDRLPersistenceUnmarshallingTest method testNestedEvalWithDifferentCompositeOperatorsAndTrailingConstraint.
@Test
public // https://issues.jboss.org/browse/RHBPMS-4695
void testNestedEvalWithDifferentCompositeOperatorsAndTrailingConstraint() {
String drl = "rule \"rule1\"\n" + "dialect \"mvel\"\n" + "when\n" + "MyTestDateObject(firstName != null || eval($td.getFirstName().toUpperCase().equals(\"NONAME\") || $td.getFirstName().toUpperCase().equals(\"NAMENOTPROVIDED\")) && firstName != \"\" )\n" + "then\n" + "end";
RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
// Check round-trip
assertEqualsIgnoreWhitespace(drl, RuleModelDRLPersistenceImpl.getInstance().marshal(m));
}
Aggregations