Search in sources :

Example 1 with PackageDataModelOracle

use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testFreeFormLine.

@Test
public void testFreeFormLine() {
    RuleModel m = new RuleModel();
    m.name = "with composite";
    m.lhs = new IPattern[1];
    m.rhs = new IAction[1];
    FreeFormLine fl = new FreeFormLine();
    fl.setText("Person()");
    m.lhs[0] = fl;
    FreeFormLine fr = new FreeFormLine();
    fr.setText("fun()");
    m.rhs[0] = fr;
    String drl = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    assertNotNull(drl);
    PackageDataModelOracle dmo = mock(PackageDataModelOracle.class);
    RuleModel m_ = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.EMPTY_LIST, dmo);
    assertEquals(1, m_.lhs.length);
    assertEquals(1, m_.rhs.length);
    assertEquals("Person", ((FactPattern) m_.lhs[0]).getFactType());
    assertEquals("fun()", ((FreeFormLine) m_.rhs[0]).getText());
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 2 with PackageDataModelOracle

use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testCompositeConstraintsRoundTrip.

@Test
public void testCompositeConstraintsRoundTrip() throws Exception {
    RuleModel m = new RuleModel();
    m.name = "with composite";
    FactPattern p1 = new FactPattern("Person");
    p1.setBoundName("p1");
    m.addLhsItem(p1);
    FactPattern p = new FactPattern("Goober");
    m.addLhsItem(p);
    CompositeFieldConstraint comp = new CompositeFieldConstraint();
    comp.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_OR);
    p.addConstraint(comp);
    final SingleFieldConstraint X = new SingleFieldConstraint();
    X.setFieldName("goo");
    X.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    X.setValue("foo");
    X.setOperator("==");
    X.setConnectives(new ConnectiveConstraint[1]);
    X.getConnectives()[0] = new ConnectiveConstraint();
    X.getConnectives()[0].setConstraintValueType(ConnectiveConstraint.TYPE_LITERAL);
    X.getConnectives()[0].setOperator("|| ==");
    X.getConnectives()[0].setValue("bar");
    comp.addConstraint(X);
    final SingleFieldConstraint Y = new SingleFieldConstraint();
    Y.setFieldName("goo2");
    Y.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    Y.setValue("foo");
    Y.setOperator("==");
    comp.addConstraint(Y);
    CompositeFieldConstraint comp2 = new CompositeFieldConstraint();
    comp2.setCompositeJunctionType(CompositeFieldConstraint.COMPOSITE_TYPE_AND);
    final SingleFieldConstraint Q1 = new SingleFieldConstraint();
    Q1.setFieldName("goo");
    Q1.setOperator("==");
    Q1.setValue("whee");
    Q1.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    comp2.addConstraint(Q1);
    final SingleFieldConstraint Q2 = new SingleFieldConstraint();
    Q2.setFieldName("gabba");
    Q2.setOperator("==");
    Q2.setValue("whee");
    Q2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    comp2.addConstraint(Q2);
    // now nest it
    comp.addConstraint(comp2);
    final SingleFieldConstraint Z = new SingleFieldConstraint();
    Z.setFieldName("goo3");
    Z.setConstraintValueType(SingleFieldConstraint.TYPE_LITERAL);
    Z.setValue("foo");
    Z.setOperator("==");
    p.addConstraint(Z);
    ActionInsertFact ass = new ActionInsertFact("Whee");
    m.addRhsItem(ass);
    String drl = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    PackageDataModelOracle dmo = mock(PackageDataModelOracle.class);
    RuleModel m2 = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.EMPTY_LIST, dmo);
    assertNotNull(m2);
    assertEquals("with composite", m2.name);
    assertEquals(m2.lhs.length, m.lhs.length);
    assertEquals(m2.rhs.length, m.rhs.length);
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) 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) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) Test(org.junit.Test)

Example 3 with PackageDataModelOracle

use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testFreeFormatDRLAction.

@Test
public void testFreeFormatDRLAction() {
    final String drl = "rule \"r0\"\n" + "dialect \"mvel\"\n" + "when\n" + "$a : Applicant( )\n" + "then\n" + "$a.setName( \"Michael\" );\n" + "Here's something typed by the user as free-format DRL\n" + "$a.setAge( 40 );\n" + "end\n";
    PackageDataModelOracle dmo = mock(PackageDataModelOracle.class);
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.EMPTY_LIST, dmo);
    assertNotNull(m);
    // LHS
    assertEquals(1, m.lhs.length);
    assertTrue(m.lhs[0] instanceof FreeFormLine);
    final FreeFormLine ffl1 = (FreeFormLine) m.lhs[0];
    assertEquals("$a : Applicant( )", ffl1.getText());
    // RHS
    assertEquals(1, m.rhs.length);
    assertTrue(m.rhs[0] instanceof FreeFormLine);
    final FreeFormLine ffl2 = (FreeFormLine) m.rhs[0];
    assertEquals("$a.setName( \"Michael\" );\n" + "Here's something typed by the user as free-format DRL\n" + "$a.setAge( 40 );", ffl2.getText());
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 4 with PackageDataModelOracle

use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testActionCallMethod.

@Test
public void testActionCallMethod() {
    final String drl = "rule \"r0\"\n" + "dialect \"mvel\"\n" + "when\n" + "$a : Applicant( )\n" + "then\n" + "$a.addName( \"Michael\" );\n" + "end\n";
    PackageDataModelOracle dmo = mock(PackageDataModelOracle.class);
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.EMPTY_LIST, dmo);
    assertNotNull(m);
    // LHS
    assertEquals(1, m.lhs.length);
    assertTrue(m.lhs[0] instanceof FactPattern);
    final FactPattern p = (FactPattern) m.lhs[0];
    assertEquals("$a", p.getBoundName());
    assertEquals("Applicant", p.getFactType());
    // RHS
    assertEquals(1, m.rhs.length);
    assertTrue(m.rhs[0] instanceof ActionCallMethod);
    final ActionCallMethod a = (ActionCallMethod) m.rhs[0];
    assertEquals("$a", a.getVariable());
    assertEquals("addName", a.getMethodName());
    assertEquals(1, a.getFieldValues().length);
    final ActionFieldValue fv = a.getFieldValue(0);
    assertEquals("Michael", fv.getValue());
}
Also used : ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) 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)

Example 5 with PackageDataModelOracle

use of org.kie.soup.project.datamodel.oracle.PackageDataModelOracle in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testBasics2.

@Test
public void testBasics2() {
    final RuleModelPersistence p = RuleModelDRLPersistenceImpl.getInstance();
    final RuleModel m = new RuleModel();
    m.addLhsItem(new FactPattern("Person"));
    m.addLhsItem(new FactPattern("Accident"));
    m.addAttribute(new RuleAttribute("no-loop", "true"));
    m.addRhsItem(new ActionInsertFact("Report"));
    ActionGlobalCollectionAdd ag = new ActionGlobalCollectionAdd();
    ag.setFactName("x");
    ag.setGlobalName("g");
    m.addRhsItem(ag);
    m.name = "my rule";
    final String drl = p.marshal(m);
    assertTrue(drl.indexOf("Person( )") > -1);
    assertTrue(drl.indexOf("Accident( )") > -1);
    assertTrue(drl.indexOf("no-loop true") > -1);
    assertTrue(drl.indexOf("org.kie") == -1);
    assertTrue(drl.indexOf("g.add( x );") > -1);
    PackageDataModelOracle dmo = mock(PackageDataModelOracle.class);
    RuleModel rm_ = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.EMPTY_LIST, dmo);
    assertEquals(2, rm_.rhs.length);
}
Also used : ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) PackageDataModelOracle(org.kie.soup.project.datamodel.oracle.PackageDataModelOracle) 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) ActionGlobalCollectionAdd(org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd) Test(org.junit.Test)

Aggregations

PackageDataModelOracle (org.kie.soup.project.datamodel.oracle.PackageDataModelOracle)40 Test (org.junit.Test)24 PackageDataModelOracleBaselinePayload (org.kie.workbench.common.services.datamodel.model.PackageDataModelOracleBaselinePayload)19 Path (org.uberfire.backend.vfs.Path)18 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)12 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)12 RawMVELEvaluator (org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator)12 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)11 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)11 AsyncPackageDataModelOracle (org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle)11 ModuleDataModelOracle (org.kie.soup.project.datamodel.oracle.ModuleDataModelOracle)10 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)9 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)9 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)8 ResourceOpenedEvent (org.uberfire.workbench.events.ResourceOpenedEvent)8 ActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionInsertFactCol52)7 ActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionSetFieldCol52)7 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)7 LimitedEntryActionInsertFactCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionInsertFactCol52)6 LimitedEntryActionSetFieldCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryActionSetFieldCol52)6