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()"));
}
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());
}
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));
}
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());
}
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);
}
Aggregations