use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceUnmarshallingMessagesTest method testAmbiguousRoot.
@Test
public void testAmbiguousRoot() throws Exception {
final String drl1 = "rule \"test_0\"\n" + "when \n" + " Person( )\n" + "then \n" + "end \n";
final String drl2 = "rule \"test_1\"\n" + "when \n" + " Cheese( )\n" + "then \n" + "end \n";
final GuidedDecisionTree expected = new GuidedDecisionTree();
expected.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
expected.setRoot(type);
addModelField("Person", "this", "Person", DataType.TYPE_THIS);
addModelField("Cheese", "this", "Cheese", DataType.TYPE_THIS);
final GuidedDecisionTree model = getAndTestUnmarshalledModel(drl1 + drl2, "test", 1);
assertEquals(expected.getTreeName(), model.getTreeName());
assertNotNull(model.getRoot());
assertEquals(type.getClassName(), model.getRoot().getClassName());
assertFalse(model.getRoot().isBound());
assertEquals(0, model.getRoot().getChildren().size());
assertEquals("test_1", model.getParserErrors().get(0).getOriginalRuleName());
assertEqualsIgnoreWhitespace(drl2, model.getParserErrors().get(0).getOriginalDrl());
assertNotNull(model.getParserErrors().get(0).getMessages());
assertEquals(1, model.getParserErrors().get(0).getMessages().size());
assertTrue(model.getParserErrors().get(0).getMessages().get(0) instanceof AmbiguousRootParserMessage);
final String drl3 = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(drl1 + drl2, drl3);
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceUnmarshallingMessagesTest method testValue_BigInteger.
@Test
public void testValue_BigInteger() throws Exception {
final String drl = "rule \"test_0\"\n" + "when \n" + " Person( bigIntegerField == \"abc\" )\n" + "then \n" + "end";
final GuidedDecisionTree expected = new GuidedDecisionTree();
expected.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
expected.setRoot(type);
addModelField("Person", "this", "Person", DataType.TYPE_THIS);
addModelField("Person", "bigIntegerField", BigInteger.class.getName(), DataType.TYPE_NUMERIC_BIGINTEGER);
final GuidedDecisionTree model = getAndTestUnmarshalledModel(drl, "test", 1);
assertEquals(expected.getTreeName(), model.getTreeName());
assertNull(model.getRoot());
assertEquals("test_0", model.getParserErrors().get(0).getOriginalRuleName());
assertEqualsIgnoreWhitespace(drl, model.getParserErrors().get(0).getOriginalDrl());
assertNotNull(model.getParserErrors().get(0).getMessages());
assertEquals(1, model.getParserErrors().get(0).getMessages().size());
assertTrue(model.getParserErrors().get(0).getMessages().get(0) instanceof DataTypeConversionErrorParserMessage);
final String drl2 = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(drl, drl2);
}
use of org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode 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.nodes.TypeNode 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.nodes.TypeNode 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