Search in sources :

Example 16 with TypeNode

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);
}
Also used : TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) GuidedDecisionTree(org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) AmbiguousRootParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.AmbiguousRootParserMessage) Test(org.junit.Test)

Example 17 with TypeNode

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);
}
Also used : TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) BigInteger(java.math.BigInteger) DataTypeConversionErrorParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.DataTypeConversionErrorParserMessage) GuidedDecisionTree(org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Test(org.junit.Test)

Example 18 with TypeNode

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);
}
Also used : ConstraintNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) GuidedDecisionTree(org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) StringValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue) Test(org.junit.Test)

Example 19 with TypeNode

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);
}
Also used : ConstraintNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) IntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue) BigIntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue) GuidedDecisionTree(org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) StringValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue) Test(org.junit.Test)

Example 20 with TypeNode

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);
}
Also used : ConstraintNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) IntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue) BigIntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue) GuidedDecisionTree(org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) StringValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue) Test(org.junit.Test)

Aggregations

TypeNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)125 TypeNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl)109 GuidedDecisionTree (org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree)106 Test (org.junit.Test)105 ConstraintNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode)61 ConstraintNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl)53 ActionUpdateNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode)34 BigIntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue)33 IntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue)31 ActionFieldValueImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionFieldValueImpl)30 ActionUpdateNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionUpdateNodeImpl)26 StringValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue)24 BigInteger (java.math.BigInteger)23 ActionRetractNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode)17 ActionInsertNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode)16 Node (org.drools.workbench.models.guided.dtree.shared.model.nodes.Node)11 DataTypeConversionErrorParserMessage (org.drools.workbench.models.guided.dtree.shared.model.parser.messages.DataTypeConversionErrorParserMessage)11 DateValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue)11 ActionInsertNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl)9 ActionRetractNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionRetractNodeImpl)9