Search in sources :

Example 1 with IAction

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

the class RuleModelDRLPersistenceUnmarshallingTest method testRHSChainedMethodCalls2.

@Test
public // https://bugzilla.redhat.com/show_bug.cgi?id=1127303
void testRHSChainedMethodCalls2() throws Exception {
    String drl = "package org.test;\n" + "rule \"MyRule\"\n" + "dialect \"mvel\"\n" + "when\n" + "  Person( $n : name )\n" + "then\n" + "  $n.toUpperCase().indexOf(\".\", 1);\n" + "end";
    addModelField("org.test.Person", "this", "org.test.Person", DataType.TYPE_THIS);
    addModelField("org.test.Person", "name", String.class.getName(), DataType.TYPE_STRING);
    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("Person", fp0.getFactType());
    assertEquals(1, fp0.getNumberOfConstraints());
    assertTrue(fp0.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint sfc1 = (SingleFieldConstraint) fp0.getConstraint(0);
    assertEquals("Person", sfc1.getFactType());
    assertEquals("name", sfc1.getFieldName());
    assertEquals(DataType.TYPE_STRING, sfc1.getFieldType());
    assertEquals(1, m.rhs.length);
    final IAction a0 = m.rhs[0];
    assertTrue(a0 instanceof FreeFormLine);
    final FreeFormLine ffl1 = (FreeFormLine) a0;
    assertEquals("$n.toUpperCase().indexOf(\".\", 1);", ffl1.getText());
    // 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) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) IAction(org.drools.workbench.models.datamodel.rule.IAction) 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 2 with IAction

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

the class RuleModelDRLPersistenceUnmarshallingTest method testBigDecimal3.

@Test
public // https://bugzilla.redhat.com/show_bug.cgi?id=1189930
void testBigDecimal3() throws Exception {
    String drl = "package org.test;\n" + "import java.lang.Number;\n" + "import java.math.BigDecimal;\n" + "import java.util.Calendar;\n" + "rule \"BigDecimalRule\"\n" + "  dialect \"java\"\n" + "when\n" + "  $bd : BigDecimal( )\n" + "then\n" + "  LastRunInformation lastRun = new LastRunInformation();\n" + "  lastRun.setLastNumber($bd);\n" + "\n" + "  insert(lastRun);\n" + "end";
    addModelField("org.test.LastRunInformation", "this", "org.test.LastRunInformation", DataType.TYPE_THIS);
    addModelField("org.test.LastRunInformation", "lastNumber", BigDecimal.class.getName(), DataType.TYPE_NUMERIC_BIGDECIMAL);
    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 p = m.lhs[0];
    assertTrue(p instanceof FactPattern);
    final FactPattern fp = (FactPattern) p;
    assertEquals("$bd", fp.getBoundName());
    assertEquals("BigDecimal", fp.getFactType());
    assertEquals(1, m.rhs.length);
    final IAction a = m.rhs[0];
    assertTrue(a instanceof ActionInsertFact);
    final ActionInsertFact aif = (ActionInsertFact) a;
    assertEquals("lastRun", aif.getBoundName());
    assertEquals("LastRunInformation", aif.getFactType());
    assertEquals(1, aif.getFieldValues().length);
    final ActionFieldValue afv0 = aif.getFieldValues()[0];
    assertEquals("lastNumber", afv0.getField());
    assertEquals(FieldNatureType.TYPE_VARIABLE, afv0.getNature());
    assertEquals("=$bd", afv0.getValue());
    // Check round-trip
    assertEqualsIgnoreWhitespace(drl, RuleModelDRLPersistenceImpl.getInstance().marshal(m));
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) IAction(org.drools.workbench.models.datamodel.rule.IAction) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) 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) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with IAction

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

the class RuleModelDRLPersistenceUnmarshallingTest method testBigDecimal1.

@Test
public // Formatted as generated from a Guided Rule in the Workbench
void testBigDecimal1() throws Exception {
    String drl = "package org.test;\n" + "import java.lang.Number;\n" + "import java.math.BigDecimal;\n" + "import java.util.Calendar;\n" + "rule \"BigDecimalRule\"\n" + "  dialect \"java\"\n" + "when\n" + "  $bd : BigDecimal( )\n" + "then\n" + "  LastRunInformation lastRun = new LastRunInformation();\n" + "  lastRun.setLastNumber( $bd );\n" + "  insert( lastRun );\n" + "end";
    addModelField("org.test.LastRunInformation", "this", "org.test.LastRunInformation", DataType.TYPE_THIS);
    addModelField("org.test.LastRunInformation", "lastNumber", BigDecimal.class.getName(), DataType.TYPE_NUMERIC_BIGDECIMAL);
    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 p = m.lhs[0];
    assertTrue(p instanceof FactPattern);
    final FactPattern fp = (FactPattern) p;
    assertEquals("$bd", fp.getBoundName());
    assertEquals("BigDecimal", fp.getFactType());
    assertEquals(1, m.rhs.length);
    final IAction a = m.rhs[0];
    assertTrue(a instanceof ActionInsertFact);
    final ActionInsertFact aif = (ActionInsertFact) a;
    assertEquals("lastRun", aif.getBoundName());
    assertEquals("LastRunInformation", aif.getFactType());
    assertEquals(1, aif.getFieldValues().length);
    final ActionFieldValue afv0 = aif.getFieldValues()[0];
    assertEquals("lastNumber", afv0.getField());
    assertEquals(FieldNatureType.TYPE_VARIABLE, afv0.getNature());
    assertEquals("=$bd", afv0.getValue());
    // Check round-trip
    assertEqualsIgnoreWhitespace(drl, RuleModelDRLPersistenceImpl.getInstance().marshal(m));
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) IAction(org.drools.workbench.models.datamodel.rule.IAction) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) 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) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 4 with IAction

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

the class RuleModelDRLPersistenceUnmarshallingTest method testRHSChainedMethodCalls4.

@Test
public // https://bugzilla.redhat.com/show_bug.cgi?id=1127303
void testRHSChainedMethodCalls4() throws Exception {
    String drl = "package org.test;\n" + "rule \"MyRule\"\n" + "dialect \"mvel\"\n" + "when\n" + "  Person( $n : name )\n" + "then\n" + "  $n.toUpperCase().indexOf(\"\\\").\", 1);\n" + "end";
    addModelField("org.test.Person", "this", "org.test.Person", DataType.TYPE_THIS);
    addModelField("org.test.Person", "name", String.class.getName(), DataType.TYPE_STRING);
    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("Person", fp0.getFactType());
    assertEquals(1, fp0.getNumberOfConstraints());
    assertTrue(fp0.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint sfc1 = (SingleFieldConstraint) fp0.getConstraint(0);
    assertEquals("Person", sfc1.getFactType());
    assertEquals("name", sfc1.getFieldName());
    assertEquals(DataType.TYPE_STRING, sfc1.getFieldType());
    assertEquals(1, m.rhs.length);
    final IAction a0 = m.rhs[0];
    assertTrue(a0 instanceof FreeFormLine);
    final FreeFormLine ffl1 = (FreeFormLine) a0;
    assertEquals("$n.toUpperCase().indexOf(\"\\\").\", 1);", ffl1.getText());
    // 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) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) IAction(org.drools.workbench.models.datamodel.rule.IAction) 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 5 with IAction

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

the class RuleModelDRLPersistenceUnmarshallingTest method testRHSChainedMethodCalls1.

@Test
public // https://bugzilla.redhat.com/show_bug.cgi?id=1127303
void testRHSChainedMethodCalls1() throws Exception {
    String drl = "package org.test;\n" + "rule \"MyRule\"\n" + "dialect \"mvel\"\n" + "when\n" + "  Person( $n : name )\n" + "then\n" + "  $n.toUpperCase().indexOf(\"S\", 1);\n" + "end";
    addModelField("org.test.Person", "this", "org.test.Person", DataType.TYPE_THIS);
    addModelField("org.test.Person", "name", String.class.getName(), DataType.TYPE_STRING);
    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("Person", fp0.getFactType());
    assertEquals(1, fp0.getNumberOfConstraints());
    assertTrue(fp0.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint sfc1 = (SingleFieldConstraint) fp0.getConstraint(0);
    assertEquals("Person", sfc1.getFactType());
    assertEquals("name", sfc1.getFieldName());
    assertEquals(DataType.TYPE_STRING, sfc1.getFieldType());
    assertEquals(1, m.rhs.length);
    final IAction a0 = m.rhs[0];
    assertTrue(a0 instanceof FreeFormLine);
    final FreeFormLine ffl1 = (FreeFormLine) a0;
    assertEquals("$n.toUpperCase().indexOf(\"S\", 1);", ffl1.getText());
    // 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) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) IAction(org.drools.workbench.models.datamodel.rule.IAction) 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

IAction (org.drools.workbench.models.datamodel.rule.IAction)63 Test (org.junit.Test)44 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)35 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)32 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)31 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)30 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)29 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)25 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)21 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)20 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)20 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)20 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)20 ArrayList (java.util.ArrayList)19 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)19 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)17 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)17 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)17 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)15 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)15