use of org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue 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.values.impl.StringValue in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_ActionSetMultipleFields.
@Test
public void testSingleRule_ActionSetMultipleFields() throws Exception {
final String expected = "rule \"test_0\"" + "when\n" + " $p : Person( )\n" + "then\n" + " $p.setAge( 25 );\n" + " $p.setName( \"Michael\" );\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)));
action.getFieldValues().add(new ActionFieldValueImpl("name", new StringValue("Michael")));
type.addChild(action);
final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(expected, drl);
}
use of org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testMultipleRules_MultiplePatterns.
@Test
public void testMultipleRules_MultiplePatterns() throws Exception {
final String expected = "rule \"test_0\"" + "when\n" + " Person( name == \"Michael\" )\n" + " Address( country == \"England\" )\n" + "then\n" + "end" + "rule \"test_1\"" + "when\n" + " Person( name == \"Michael\" )\n" + " Address( country == \"Norway\" )\n" + "then\n" + "end" + "rule \"test_2\"" + "when\n" + " Person( name == \"Fred\" )\n" + "then\n" + "end";
final GuidedDecisionTree model = new GuidedDecisionTree();
model.setTreeName("test");
final TypeNode type1 = new TypeNodeImpl("Person");
final ConstraintNode c1a = new ConstraintNodeImpl("Person", "name", "==", new StringValue("Michael"));
final ConstraintNode c1b = new ConstraintNodeImpl("Person", "name", "==", new StringValue("Fred"));
final TypeNode type2 = new TypeNodeImpl("Address");
final ConstraintNode c2a = new ConstraintNodeImpl("Address", "country", "==", new StringValue("England"));
final ConstraintNode c2b = new ConstraintNodeImpl("Address", "country", "==", new StringValue("Norway"));
model.setRoot(type1);
type1.addChild(c1a);
type1.addChild(c1b);
c1a.addChild(type2);
type2.addChild(c2a);
type2.addChild(c2b);
final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(expected, drl);
}
use of org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_MultipleConstraints.
@Test
public void testSingleRule_MultipleConstraints() throws Exception {
final String expected = "rule \"test_0\"" + "when\n" + " Person( name == \"Michael\", 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", "age", "==", new IntegerValue(41));
model.setRoot(type);
type.addChild(c1);
c1.addChild(c2);
final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(expected, drl);
}
use of org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testMultipleRules_3Rules.
@Test
public void testMultipleRules_3Rules() throws Exception {
final String expected = "rule \"test_0\"" + "when\n" + " Person( name == \"Michael\" )\n" + "then\n" + "end" + "rule \"test_1\"" + "when\n" + " Person( age == 41 )\n" + "then\n" + "end" + "rule \"test_2\"" + "when\n" + " Person( gender == \"Male\" )\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", "age", "==", new IntegerValue(41));
final ConstraintNode c3 = new ConstraintNodeImpl("Person", "gender", "==", new StringValue("Male"));
model.setRoot(type);
type.addChild(c1);
type.addChild(c2);
type.addChild(c3);
final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(expected, drl);
}
Aggregations