Search in sources :

Example 36 with IAction

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

the class RuleModelDRLPersistenceExtensionsTest method unmarshalWithoutExtensions.

@Test
public void unmarshalWithoutExtensions() {
    RuleModel ruleModel = RuleModelDRLPersistenceImpl.getInstance().unmarshal(DRL_RULE, Collections.emptyList(), new PackageDataModelOracleImpl());
    assertEquals(1, ruleModel.rhs.length);
    IAction iAction = ruleModel.rhs[0];
    assertTrue(iAction instanceof FreeFormLine);
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) TestIAction(org.drools.workbench.models.commons.backend.rule.actions.TestIAction) IAction(org.drools.workbench.models.datamodel.rule.IAction) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) PackageDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.PackageDataModelOracleImpl) Test(org.junit.Test)

Example 37 with IAction

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

the class RuleModelDRLPersistenceExtensionsTest method unmarshalDSLWithExtensions.

@Test
public void unmarshalDSLWithExtensions() {
    RuleModel ruleModel = RuleModelDRLPersistenceImpl.getInstance().unmarshalUsingDSL(DSL_RULE, Collections.emptyList(), new PackageDataModelOracleImpl(), Arrays.asList(new TestIActionPersistenceExtension()));
    assertEquals(1, ruleModel.rhs.length);
    IAction iAction = ruleModel.rhs[0];
    assertTrue(iAction instanceof TestIAction);
}
Also used : TestIActionPersistenceExtension(org.drools.workbench.models.commons.backend.rule.extensions.TestIActionPersistenceExtension) TestIAction(org.drools.workbench.models.commons.backend.rule.actions.TestIAction) IAction(org.drools.workbench.models.datamodel.rule.IAction) TestIAction(org.drools.workbench.models.commons.backend.rule.actions.TestIAction) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) PackageDataModelOracleImpl(org.kie.soup.project.datamodel.commons.oracle.PackageDataModelOracleImpl) Test(org.junit.Test)

Example 38 with IAction

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

the class RuleModelDRLPersistenceUnmarshallingTest method testRHSInsertFactWithFieldAsLiteralSamePackage.

@Test
public void testRHSInsertFactWithFieldAsLiteralSamePackage() {
    String drl = "package org.test\n" + "rule \"variable\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( field1 == 44 )\n" + "then\n" + "Person fact0 = new Person();\n" + "fact0.setField1( 55 );\n" + "insert( fact0 );\n" + "end";
    addModelField("org.test.Person", "field1", "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("field1", sfp.getFieldName());
    assertEquals("==", sfp.getOperator());
    assertEquals("44", sfp.getValue());
    assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, sfp.getConstraintValueType());
    assertEquals(1, m.rhs.length);
    IAction a = m.rhs[0];
    assertTrue(a instanceof ActionInsertFact);
    ActionInsertFact ap = (ActionInsertFact) a;
    assertEquals("Person", ap.getFactType());
    assertEquals("fact0", ap.getBoundName());
    assertEquals(1, ap.getFieldValues().length);
    ActionFieldValue afv = ap.getFieldValues()[0];
    assertEquals("field1", afv.getField());
    assertEquals(FieldNatureType.TYPE_LITERAL, afv.getNature());
    assertEquals("55", afv.getValue());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, afv.getType());
}
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) 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) Test(org.junit.Test)

Example 39 with IAction

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

the class RuleModelDRLPersistenceUnmarshallingTest method testRHSUpdateFactWithFieldAsVariableSamePackage.

@Test
public void testRHSUpdateFactWithFieldAsVariableSamePackage() {
    // https://bugzilla.redhat.com/show_bug.cgi?id=1077212
    String drl = "package org.test\n" + "rule \"variable\"\n" + "dialect \"mvel\"\n" + "when\n" + "$p : Person( $f : field1 == 44 )\n" + "then\n" + "$p.setField1( $f );\n" + "update( $p );\n" + "end";
    addModelField("org.test.Person", "field1", "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("$p", fp.getBoundName());
    assertEquals(1, fp.getConstraintList().getConstraints().length);
    assertTrue(fp.getConstraint(0) instanceof SingleFieldConstraint);
    SingleFieldConstraint sfp = (SingleFieldConstraint) fp.getConstraint(0);
    assertEquals("Person", sfp.getFactType());
    assertEquals("field1", sfp.getFieldName());
    assertEquals("==", sfp.getOperator());
    assertEquals("44", sfp.getValue());
    assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, sfp.getConstraintValueType());
    assertEquals("$f", sfp.getFieldBinding());
    assertEquals(1, m.rhs.length);
    IAction a = m.rhs[0];
    assertTrue(a instanceof ActionUpdateField);
    ActionUpdateField ap = (ActionUpdateField) a;
    assertEquals("$p", ap.getVariable());
    assertEquals(1, ap.getFieldValues().length);
    ActionFieldValue afv = ap.getFieldValues()[0];
    assertEquals("field1", afv.getField());
    assertEquals(FieldNatureType.TYPE_VARIABLE, afv.getNature());
    assertEquals("=$f", afv.getValue());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, afv.getType());
}
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) ActionUpdateField(org.drools.workbench.models.datamodel.rule.ActionUpdateField) IAction(org.drools.workbench.models.datamodel.rule.IAction) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) 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 IAction

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

the class RuleModelDRLPersistenceUnmarshallingTest method testRHSInsertFactWithFieldAsVariable.

@Test
public void testRHSInsertFactWithFieldAsVariable() {
    // https://bugzilla.redhat.com/show_bug.cgi?id=1077212
    String drl = "package org.mortgages\n" + "import org.test.Person\n" + "rule \"variable\"\n" + "dialect \"mvel\"\n" + "when\n" + "Person( $f : field1 == 44 )\n" + "then\n" + "Person fact0 = new Person();\n" + "fact0.setField1( $f );\n" + "insert( fact0 );\n" + "end";
    addModelField("org.test.Person", "field1", "java.lang.Integer", DataType.TYPE_NUMERIC_INTEGER);
    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("field1", sfp.getFieldName());
    assertEquals("==", sfp.getOperator());
    assertEquals("44", sfp.getValue());
    assertEquals(BaseSingleFieldConstraint.TYPE_LITERAL, sfp.getConstraintValueType());
    assertEquals("$f", sfp.getFieldBinding());
    assertEquals(1, m.rhs.length);
    IAction a = m.rhs[0];
    assertTrue(a instanceof ActionInsertFact);
    ActionInsertFact ap = (ActionInsertFact) a;
    assertEquals("Person", ap.getFactType());
    assertEquals("fact0", ap.getBoundName());
    assertEquals(1, ap.getFieldValues().length);
    ActionFieldValue afv = ap.getFieldValues()[0];
    assertEquals("field1", afv.getField());
    assertEquals(FieldNatureType.TYPE_VARIABLE, afv.getNature());
    assertEquals("=$f", afv.getValue());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, afv.getType());
}
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) 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) 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