use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_ActionInsertLogicalDateFieldValue.
@Test
public void testSingleRule_ActionInsertLogicalDateFieldValue() throws Exception {
final String expected = "rule \"test_0\"" + "when\n" + " Person( )\n" + "then\n" + " java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"dd-MMM-yyyy\");\n" + " Person $var0 = new Person();\n" + " $var0.setDateOfBirth( sdf.parse(\"15-Jul-1985\") );\n" + " insertLogical( $var0 );\n" + "end";
final GuidedDecisionTree model = new GuidedDecisionTree();
model.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
model.setRoot(type);
final ActionInsertNode action = new ActionInsertNodeImpl("Person");
action.setLogicalInsertion(true);
final Calendar dob = Calendar.getInstance();
dob.set(Calendar.YEAR, 1985);
dob.set(Calendar.MONTH, 6);
dob.set(Calendar.DATE, 15);
action.getFieldValues().add(new ActionFieldValueImpl("dateOfBirth", new DateValue(dob.getTime())));
type.addChild(action);
final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(expected, drl);
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testMultipleRules_2Rules_1Simple_1Complex.
@Test
public void testMultipleRules_2Rules_1Simple_1Complex() throws Exception {
final String expected = "rule \"test_0\"" + "when\n" + " Person( name == \"Michael\" )\n" + "then\n" + "end" + "rule \"test_1\"" + "when\n" + " Person( name == \"Fred\", age == 41 )\n" + "then\n" + "end";
final GuidedDecisionTree model = new GuidedDecisionTree();
model.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
final ConstraintNode c1 = new ConstraintNodeImpl("Person", "name", "==", new StringValue("Michael"));
final ConstraintNode c2 = new ConstraintNodeImpl("Person", "name", "==", new StringValue("Fred"));
final ConstraintNode c3 = new ConstraintNodeImpl("Person", "age", "==", new IntegerValue(41));
model.setRoot(type);
type.addChild(c1);
type.addChild(c2);
c2.addChild(c3);
final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(expected, drl);
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_ActionSet.
@Test
public void testSingleRule_ActionSet() throws Exception {
final String expected = "rule \"test_0\"" + "when\n" + " $p : Person( )\n" + "then\n" + " $p.setAge( 25 );\n" + "end";
final GuidedDecisionTree model = new GuidedDecisionTree();
model.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
type.setBinding("$p");
model.setRoot(type);
final ActionUpdateNode action = new ActionUpdateNodeImpl(type);
action.setModify(false);
action.getFieldValues().add(new ActionFieldValueImpl("age", new IntegerValue(25)));
type.addChild(action);
final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(expected, drl);
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_ActionInsertDateFieldValue.
@Test
public void testSingleRule_ActionInsertDateFieldValue() throws Exception {
final String expected = "rule \"test_0\"" + "when\n" + " Person( )\n" + "then\n" + " java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"dd-MMM-yyyy\");\n" + " Person $var0 = new Person();\n" + " $var0.setDateOfBirth( sdf.parse(\"15-Jul-1985\") );\n" + " insert( $var0 );\n" + "end";
final GuidedDecisionTree model = new GuidedDecisionTree();
model.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
model.setRoot(type);
final ActionInsertNode action = new ActionInsertNodeImpl("Person");
action.setLogicalInsertion(false);
final Calendar dob = Calendar.getInstance();
dob.set(Calendar.YEAR, 1985);
dob.set(Calendar.MONTH, 6);
dob.set(Calendar.DATE, 15);
action.getFieldValues().add(new ActionFieldValueImpl("dateOfBirth", new DateValue(dob.getTime())));
type.addChild(action);
final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(expected, drl);
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testValue_Integer.
@Test
public void testValue_Integer() throws Exception {
final String expected = "rule \"test_0\"" + "when\n" + " Person( integerField == 1000000 )\n" + "then\n" + "end";
final GuidedDecisionTree model = new GuidedDecisionTree();
model.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
final ConstraintNode c1 = new ConstraintNodeImpl("Person", "integerField", "==", new IntegerValue(1000000));
model.setRoot(type);
type.addChild(c1);
final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(expected, drl);
}
Aggregations