Search in sources :

Example 36 with SingleFieldConstraint

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

the class RuleModelDRLPersistenceUnmarshallingTest method testReciprocal_SingleFieldConstraintCEPOperator1Parameter.

@Test
public void testReciprocal_SingleFieldConstraintCEPOperator1Parameter() {
    // This is the inverse of "SingleFieldConstraintCEPOperator1Parameter"
    String drl = "rule \"rule1\"\n" + "dialect \"mvel\"\n" + "when\n" + "$e : Event()\n" + "Event( this after[1d] $e )\n" + "then\n" + "end";
    RuleModel m = new RuleModel();
    m.name = "rule1";
    FactPattern fp1 = new FactPattern();
    fp1.setFactType("Event");
    fp1.setBoundName("$e");
    FactPattern fp2 = new FactPattern();
    fp2.setFactType("Event");
    SingleFieldConstraint sfp = new SingleFieldConstraint();
    sfp.setFactType("Event");
    sfp.setFieldName("this");
    sfp.setOperator("after");
    sfp.setValue("$e");
    sfp.setConstraintValueType(BaseSingleFieldConstraint.TYPE_VARIABLE);
    sfp.getParameters().put("0", "1d");
    sfp.getParameters().put("org.drools.workbench.models.commons.backend.rule.visibleParameterSet", "1");
    sfp.getParameters().put("org.drools.workbench.models.commons.backend.rule.operatorParameterGenerator", "org.drools.workbench.models.commons.backend.rule.CEPOperatorParameterDRLBuilder");
    fp2.addConstraint(sfp);
    m.addLhsItem(fp1);
    m.addLhsItem(fp2);
    String actualDrl = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    assertEqualsIgnoreWhitespace(drl, actualDrl);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 37 with SingleFieldConstraint

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

the class RuleModelDRLPersistenceUnmarshallingTest method testLHSInOperatorFieldNameContainingNotInLiteral.

@Test
public void testLHSInOperatorFieldNameContainingNotInLiteral() {
    String drl = "package org.test\n" + "rule \"in\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( rating not in (1, 2) )\n" + "then\n" + "end";
    addModelField("org.test.Person", "rating", "java.lang.Integer", DataType.TYPE_NUMERIC_INTEGER);
    when(dmo.getPackageName()).thenReturn("org.test");
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals(1, m.lhs.length);
    IPattern p = m.lhs[0];
    assertTrue(p instanceof FactPattern);
    FactPattern fp = (FactPattern) p;
    assertEquals("Person", fp.getFactType());
    assertEquals(1, fp.getConstraintList().getConstraints().length);
    assertTrue(fp.getConstraint(0) instanceof SingleFieldConstraint);
    SingleFieldConstraint sfp = (SingleFieldConstraint) fp.getConstraint(0);
    assertEquals("Person", sfp.getFactType());
    assertEquals("rating", sfp.getFieldName());
    assertEquals("not in", sfp.getOperator());
    assertEquals("1, 2", sfp.getValue());
    assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, sfp.getConstraintValueType());
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 38 with SingleFieldConstraint

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

the class RuleModelDRLPersistenceUnmarshallingTest method testFieldVarsFactTypeInTheSamePackage.

@Test
public void testFieldVarsFactTypeInTheSamePackage() throws Exception {
    String drl = "" + "package org.test\n" + "rule \"Borked\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "    Customer( var:contact )\n" + "  then\n" + "end";
    addModelField("org.test.Customer", "contact", "org.test.Contact", "org.test.Contact");
    RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    FactPattern pattern = (FactPattern) m.lhs[0];
    SingleFieldConstraint constraint = (SingleFieldConstraint) pattern.getFieldConstraints()[0];
    assertEquals("var", constraint.getFieldBinding());
    assertEquals("Customer", constraint.getFactType());
    assertEquals("contact", constraint.getFieldName());
    assertEquals("org.test.Contact", constraint.getFieldType());
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 39 with SingleFieldConstraint

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

the class RuleModelDRLPersistenceUnmarshallingTest method testLHSValidLiteralFieldName.

@Test
public // https://issues.jboss.org/browse/DROOLS-715
void testLHSValidLiteralFieldName() throws Exception {
    String drl = "package org.test;\n" + "rule \"MyRule\"\n" + "dialect \"mvel\"\n" + "when\n" + "  MyClass( valid == true )\n" + "then\n" + "end";
    addModelField("org.test.MyClass", "this", "org.test.MyClass", DataType.TYPE_THIS);
    addModelField("org.test.MyClass", "valid", Boolean.class.getName(), DataType.TYPE_BOOLEAN);
    when(dmo.getPackageName()).thenReturn("org.test");
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals(1, m.lhs.length);
    final IPattern p0 = m.lhs[0];
    assertTrue(p0 instanceof FactPattern);
    final FactPattern fp0 = (FactPattern) p0;
    assertEquals("MyClass", fp0.getFactType());
    assertEquals(1, fp0.getNumberOfConstraints());
    assertTrue(fp0.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint sfc1 = (SingleFieldConstraint) fp0.getConstraint(0);
    assertEquals("MyClass", sfc1.getFactType());
    assertEquals("valid", sfc1.getFieldName());
    assertEquals(DataType.TYPE_BOOLEAN, sfc1.getFieldType());
    assertEquals("==", sfc1.getOperator());
    assertEquals("true", sfc1.getValue());
    assertEquals(BaseSingleFieldConstraint.TYPE_ENUM, sfc1.getConstraintValueType());
    // Check round-trip
    assertEqualsIgnoreWhitespace(drl, RuleModelDRLPersistenceImpl.getInstance().marshal(m));
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 40 with SingleFieldConstraint

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

the class RuleModelDRLPersistenceUnmarshallingTest method testLiteralStrFieldNames.

@Test
public void testLiteralStrFieldNames() throws Exception {
    // The issue is fields that contain the "str" operator literal value
    String drl = "rule \"rule1\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "    Room( decoration == \"tapestry\" , strangeField == 11 )\n" + "  then\n" + "end";
    addModelField("Room", "decoration", "java.lang.String", DataType.TYPE_STRING);
    addModelField("Room", "strangeField", "java.lang.Integer", DataType.TYPE_NUMERIC_INTEGER);
    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("Room", fp.getFactType());
    assertEquals(2, fp.getNumberOfConstraints());
    assertTrue(fp.getConstraint(0) instanceof SingleFieldConstraint);
    SingleFieldConstraint sfp0 = (SingleFieldConstraint) fp.getConstraint(0);
    assertEquals("Room", sfp0.getFactType());
    assertEquals("decoration", sfp0.getFieldName());
    assertEquals("==", sfp0.getOperator());
    assertEquals("tapestry", sfp0.getValue());
    assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, sfp0.getConstraintValueType());
    assertEquals(DataType.TYPE_STRING, sfp0.getFieldType());
    SingleFieldConstraint sfp1 = (SingleFieldConstraint) fp.getConstraint(1);
    assertEquals("Room", sfp1.getFactType());
    assertEquals("strangeField", sfp1.getFieldName());
    assertEquals("==", sfp1.getOperator());
    assertEquals("11", sfp1.getValue());
    assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, sfp1.getConstraintValueType());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, sfp1.getFieldType());
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Aggregations

SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)278 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)250 Test (org.junit.Test)242 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)236 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)218 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)199 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)148 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)142 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)138 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)73 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)65 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)64 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)62 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)28 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)27 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)25 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)23 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)23 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)21 ArrayList (java.util.ArrayList)20