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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations