Search in sources :

Example 41 with FreeFormLine

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

the class RuleModelDRLPersistenceTest method testFreeForm.

@Test
public void testFreeForm() {
    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 = ruleModelPersistence.marshal(m);
    assertNotNull(drl);
    assertTrue(drl.indexOf("Person()") > 0);
    assertTrue(drl.indexOf("fun()") > drl.indexOf("Person()"));
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 42 with FreeFormLine

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

the class RuleModelDRLPersistenceUnmarshallingTest method testVarAssignment.

@Test
public void testVarAssignment() {
    String drl = "rule rule1\n" + "when\n" + " d : Double()\n" + "then\n" + "double test = d.doubleValue();\n" + "end";
    RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals(1, m.rhs.length);
    assertTrue(m.rhs[0] instanceof FreeFormLine);
    assertEquals("double test = d.doubleValue();", ((FreeFormLine) m.rhs[0]).getText());
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 43 with FreeFormLine

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

the class RuleModelDRLPersistenceUnmarshallingTest method testRHSEntryPointInsertion.

@Test
public // https://bugzilla.redhat.com/show_bug.cgi?id=1158176
void testRHSEntryPointInsertion() throws Exception {
    String drl = "package org.test;\n" + "rule \"AgentBooking Rule\"\n" + "dialect \"mvel\"\n" + "  when\n" + "    agent : Agent( )\n" + "    currentDate : TransactionDate( )\n" + "    Number( eval( intValue >=2 )) from accumulate (\n" + "      resEvent : ReservationEvent( agentId == agent.agentId , resdate == currentDate.eventDate ) from entry-point \"reservationEvent\", \n" + "      count(resEvent))\n" + "  then\n" + "    ReservationThresoldEvent thresoldevent = new ReservationThresoldEvent();\n" + "    thresoldevent.setAgentId( agent.getAgentId() );\n" + "    thresoldevent.setTxEventDate( currentDate.getEventDate() );\n" + "    kcontext.getKnowledgeRuntime().getEntryPoint(\"reservationTraceEvent\").insert( thresoldevent );\n" + "end";
    addModelField("org.test.Agent", "this", "org.test.Agent", DataType.TYPE_THIS);
    addModelField("org.test.Agent", "agentId", Integer.class.getName(), DataType.TYPE_NUMERIC_INTEGER);
    addModelField("org.test.TransactionDate", "this", "org.test.TransactionDate", DataType.TYPE_THIS);
    addModelField("org.test.TransactionDate", "eventDate", Date.class.getName(), DataType.TYPE_DATE);
    addModelField("java.lang.Number", "intValue", Integer.class.getName(), DataType.TYPE_NUMERIC_INTEGER);
    addModelField("org.test.ReservationEvent", "this", "org.test.ReservationEvent", DataType.TYPE_THIS);
    addModelField("org.test.ReservationEvent", "agentId", Integer.class.getName(), DataType.TYPE_NUMERIC_INTEGER);
    addModelField("org.test.ReservationEvent", "resdate", Date.class.getName(), DataType.TYPE_DATE);
    when(dmo.getPackageName()).thenReturn("org.test");
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals(3, m.lhs.length);
    assertEquals(3, m.rhs.length);
    assertTrue(m.rhs[0] instanceof FreeFormLine);
    assertTrue(m.rhs[1] instanceof FreeFormLine);
    assertTrue(m.rhs[2] instanceof FreeFormLine);
    assertEqualsIgnoreWhitespace(drl, RuleModelDRLPersistenceImpl.getInstance().marshal(m));
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Date(java.util.Date) Test(org.junit.Test)

Example 44 with FreeFormLine

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

the class RuleModelDRLPersistenceUnmarshallingTest method testLHSFreeFormLine.

@Test
public void testLHSFreeFormLine() {
    String drl = "rule rule1\n" + "when\n" + "//A comment\n" + "then\n" + "end";
    RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals(1, m.lhs.length);
    assertTrue(m.lhs[0] instanceof FreeFormLine);
    assertEquals("//A comment", ((FreeFormLine) m.lhs[0]).getText());
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 45 with FreeFormLine

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

the class RuleModelDRLPersistenceUnmarshallingTest method testRHSOrder.

@Test
public void testRHSOrder() {
    String drl = "rule \"Low Down Payment based on Appraisal\"\n" + "  dialect \"mvel\"\n" + "  ruleflow-group \"apr-calculation\"\n" + "  salience -3\n" + "  no-loop true\n" + " when\n" + "    appraised : Appraisal( )\n" + "    application : Application( mortgageAmount > ( appraised.value * 8 / 10 ) )\n" + " then\n" + "    double ratio = application.getMortgageAmount().doubleValue() / appraised.getValue().doubleValue();\n" + "    int brackets = (int)((ratio - 0.8) / 0.05);\n" + "    brackets++;\n" + "    double aprSurcharge = 0.75 * brackets;\n" + "    System.out.println( \"aprSurcharge added is \" + aprSurcharge );\n" + "    application.setApr(  application.getApr() + aprSurcharge );\n" + "    System.out.println(\"Executed Rule: \" + drools.getRule().getName() );\n" + "end";
    RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals(7, m.rhs.length);
    assertTrue(m.rhs[0] instanceof FreeFormLine);
    assertTrue(m.rhs[1] instanceof FreeFormLine);
    assertTrue(m.rhs[2] instanceof FreeFormLine);
    assertTrue(m.rhs[3] instanceof FreeFormLine);
    assertTrue(m.rhs[4] instanceof FreeFormLine);
    assertTrue(m.rhs[5] instanceof ActionSetField);
    assertTrue(m.rhs[6] instanceof FreeFormLine);
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Aggregations

FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)64 Test (org.junit.Test)49 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)29 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)24 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)22 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)22 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)18 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)18 IAction (org.drools.workbench.models.datamodel.rule.IAction)17 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)14 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)14 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)12 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)11 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)11 ArrayList (java.util.ArrayList)10 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)10 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)10 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)10 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)9 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)9