Search in sources :

Example 81 with GuidedDecisionTree

use of org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree in project drools by kiegroup.

the class GuidedDecisionTreeDRLPersistenceUnmarshallingTest method testValue_BigDecimal.

@Test
public void testValue_BigDecimal() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  Person( bigDecimalField == 1000000B )\n" + "then \n" + "end";
    final GuidedDecisionTree expected = new GuidedDecisionTree();
    expected.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    final ConstraintNode c1 = new ConstraintNodeImpl("Person", "bigDecimalField", "==", new BigDecimalValue(new BigDecimal(1000000)));
    expected.setRoot(type);
    type.addChild(c1);
    addModelField("Person", "this", "Person", DataType.TYPE_THIS);
    addModelField("Person", "bigDecimalField", BigDecimal.class.getName(), DataType.TYPE_NUMERIC_BIGDECIMAL);
    final GuidedDecisionTree model = getAndTestUnmarshalledModel(drl, "test", 0);
    assertEquals(expected.getTreeName(), model.getTreeName());
    assertNotNull(model.getRoot());
    assertEquals(type.getClassName(), model.getRoot().getClassName());
    assertFalse(model.getRoot().isBound());
    assertEquals(1, model.getRoot().getChildren().size());
    assertNotNull(model.getRoot().getChildren().get(0));
    assertTrue(model.getRoot().getChildren().get(0) instanceof ConstraintNode);
    final ConstraintNode _c1 = (ConstraintNode) model.getRoot().getChildren().get(0);
    assertEquals(c1.getClassName(), _c1.getClassName());
    assertEquals(c1.getFieldName(), _c1.getFieldName());
    assertEquals(c1.getOperator(), _c1.getOperator());
    assertEquals(c1.getValue().getValue().toString(), _c1.getValue().getValue().toString());
}
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) BigDecimalValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigDecimalValue) 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) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 82 with GuidedDecisionTree

use of org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree in project drools by kiegroup.

the class GuidedDecisionTreeDRLPersistenceUnmarshallingMessagesTest method testValue_Float.

@Test
public void testValue_Float() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  Person( floatField == \"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", "floatField", Float.class.getName(), DataType.TYPE_NUMERIC_FLOAT);
    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) 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 83 with GuidedDecisionTree

use of org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree in project drools by kiegroup.

the class GuidedDecisionTreeDRLPersistenceUnmarshallingMessagesTest method testValue_Double.

@Test
public void testValue_Double() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  Person( doubleField == \"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", "doubleField", Double.class.getName(), DataType.TYPE_NUMERIC_DOUBLE);
    final GuidedDecisionTree model = getAndTestUnmarshalledModel(drl, "test", 1);
    assertNotNull(model);
    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) 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 84 with GuidedDecisionTree

use of org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree in project drools by kiegroup.

the class GuidedDecisionTreeDRLPersistenceUnmarshallingMessagesTest method testValue_Boolean.

@Test
public void testValue_Boolean() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  Person( booleanField == \"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", "booleanField", Boolean.class.getName(), DataType.TYPE_BOOLEAN);
    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) 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 85 with GuidedDecisionTree

use of org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree in project drools by kiegroup.

the class GuidedDecisionTreeDRLPersistenceUnmarshallingMessagesTest method testValue_Byte.

@Test
public void testValue_Byte() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  Person( byteField == \"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", "byteField", Byte.class.getName(), DataType.TYPE_NUMERIC_BYTE);
    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) 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)

Aggregations

GuidedDecisionTree (org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree)114 TypeNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)106 Test (org.junit.Test)106 TypeNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl)105 ConstraintNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode)53 ConstraintNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl)52 BigIntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue)32 IntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue)30 ActionFieldValueImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionFieldValueImpl)29 ActionUpdateNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode)26 ActionUpdateNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionUpdateNodeImpl)25 BigInteger (java.math.BigInteger)23 StringValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue)22 DataTypeConversionErrorParserMessage (org.drools.workbench.models.guided.dtree.shared.model.parser.messages.DataTypeConversionErrorParserMessage)10 DateValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue)10 ActionInsertNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode)9 ActionRetractNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode)9 Calendar (java.util.Calendar)8 ActionInsertNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl)8 ActionRetractNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionRetractNodeImpl)8