Search in sources :

Example 11 with GuidedDecisionTree

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

Example 12 with GuidedDecisionTree

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

the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testValue_Float.

@Test
public void testValue_Float() throws Exception {
    final String expected = "rule \"test_0\"" + "when\n" + "  Person( floatField == 1000.56 )\n" + "then\n" + "end";
    final GuidedDecisionTree model = new GuidedDecisionTree();
    model.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    final ConstraintNode c1 = new ConstraintNodeImpl("Person", "floatField", "==", new FloatValue(1000.56f));
    model.setRoot(type);
    type.addChild(c1);
    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) FloatValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.FloatValue) Test(org.junit.Test)

Example 13 with GuidedDecisionTree

use of org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree 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 14 with GuidedDecisionTree

use of org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree 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 15 with GuidedDecisionTree

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

the class AbstractGuidedDecisionTreeDRLPersistenceUnmarshallingTest method getAndTestUnmarshalledModel.

protected GuidedDecisionTree getAndTestUnmarshalledModel(final String drl, final String baseFileName, final int expectedParseErrorsSize) {
    final GuidedDecisionTree model = GuidedDecisionTreeDRLPersistence.getInstance().unmarshal(drl, baseFileName, dmo);
    assertNotNull(model);
    assertEquals(expectedParseErrorsSize, model.getParserErrors().size());
    return model;
}
Also used : GuidedDecisionTree(org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree)

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