Search in sources :

Example 91 with RuleModel

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

the class PluggableIActionTest method marshalPluggableIAction.

@Test
public void marshalPluggableIAction() {
    RuleModel ruleModel = new RuleModel();
    ruleModel.name = "TestIAction rule";
    ruleModel.addRhsItem(new TestIAction());
    String marshaledString = RuleModelDRLPersistenceImpl.getInstance().marshal(ruleModel);
    assertEquals(DRL_RULE, marshaledString);
}
Also used : TestIAction(org.drools.workbench.models.commons.backend.rule.actions.TestIAction) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 92 with RuleModel

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

the class RuleModelDRLPersistenceExtensionsTest method unmarshalWithExtensions.

@Test
public void unmarshalWithExtensions() {
    RuleModel ruleModel = RuleModelDRLPersistenceImpl.getInstance().unmarshal(DRL_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 93 with RuleModel

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

the class RuleModelDRLPersistenceExtensionsTest method unmarshalDSLWithoutExtensions.

@Test
public void unmarshalDSLWithoutExtensions() {
    RuleModel ruleModel = RuleModelDRLPersistenceImpl.getInstance().unmarshalUsingDSL(DSL_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 94 with RuleModel

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

the class RuleModelDRLPersistenceTest method testNotSoundsLikeAndNotMatchesInDsl.

@Test
public void testNotSoundsLikeAndNotMatchesInDsl() {
    final String dslDefinition = "There is Person that field not matches and not soundslike {name}";
    final String drl = "Person( field not soundslike \"{name}\" && field not matches \"{name}\" )";
    final String dslFile = "[when]" + dslDefinition + "=" + drl;
    final String drlWithDsl = "rule \"with dsl\"\n" + "\tdialect \"mvel\"\n" + " when\n" + dslDefinition.replace("{name}", "John") + "\n" + "then\n" + "end\n";
    final RuleModel model = ruleModelPersistence.unmarshalUsingDSL(drlWithDsl, null, dmo, dslFile);
    final DSLSentence dslSentence = (DSLSentence) model.lhs[0];
    assertEquals(dslDefinition, dslSentence.getDefinition());
    assertEquals(drl, dslSentence.getDrl());
    assertEquals("John", dslSentence.getValues().get(0).getValue());
}
Also used : RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) Test(org.junit.Test)

Example 95 with RuleModel

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

the class RuleModelDRLPersistenceTest method testIncompleteFieldConstraintStringWithNonNull.

@Test
public void testIncompleteFieldConstraintStringWithNonNull() {
    String expected = "" + "rule \"rule\" \n" + "  dialect \"mvel\"\n" + "  when\n" + "    Message( text == \"\" )\n" + "  then\n" + "end\n";
    final RuleModel m = new RuleModel();
    m.name = "rule";
    final FactPattern pat = new FactPattern("Message");
    m.addLhsItem(pat);
    final SingleFieldConstraint con = new SingleFieldConstraint();
    con.setFieldName("text");
    con.setOperator("==");
    con.setValue("");
    con.setFieldType(DataType.TYPE_STRING);
    con.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    pat.addConstraint(con);
    checkMarshalling(expected, m);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) 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

RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)384 Test (org.junit.Test)352 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)223 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)216 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)215 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)201 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)201 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)145 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)134 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)91 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)85 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)63 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)47 ArrayList (java.util.ArrayList)44 IAction (org.drools.workbench.models.datamodel.rule.IAction)31 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)29 SingleFieldConstraintEBLeftSide (org.drools.workbench.models.datamodel.rule.SingleFieldConstraintEBLeftSide)29 ActionUpdateField (org.drools.workbench.models.datamodel.rule.ActionUpdateField)27 RuleAttribute (org.drools.workbench.models.datamodel.rule.RuleAttribute)25 List (java.util.List)24