Search in sources :

Example 1 with StringValue

use of org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue in project drools by kiegroup.

the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testMultipleRules_2Rules_1Simple_1Complex.

@Test
public void testMultipleRules_2Rules_1Simple_1Complex() throws Exception {
    final String expected = "rule \"test_0\"" + "when\n" + "  Person( name == \"Michael\" )\n" + "then\n" + "end" + "rule \"test_1\"" + "when\n" + "  Person( name == \"Fred\", 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", "name", "==", new StringValue("Fred"));
    final ConstraintNode c3 = new ConstraintNodeImpl("Person", "age", "==", new IntegerValue(41));
    model.setRoot(type);
    type.addChild(c1);
    type.addChild(c2);
    c2.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)

Example 2 with StringValue

use of org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue 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 3 with StringValue

use of org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue 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 4 with StringValue

use of org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue 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 5 with StringValue

use of org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue 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

StringValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.StringValue)24 TypeNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode)23 TypeNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl)23 Test (org.junit.Test)23 GuidedDecisionTree (org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree)22 ConstraintNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode)19 ConstraintNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ConstraintNodeImpl)19 BigIntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue)12 IntegerValue (org.drools.workbench.models.guided.dtree.shared.model.values.impl.IntegerValue)12 BigInteger (java.math.BigInteger)6 ActionUpdateNode (org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode)4 ActionFieldValueImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionFieldValueImpl)4 ActionUpdateNodeImpl (org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionUpdateNodeImpl)4 ConstraintFactoryHelper (org.drools.workbench.screens.guided.dtree.client.widget.factories.ConstraintFactoryHelper)1 TypeFactoryHelper (org.drools.workbench.screens.guided.dtree.client.widget.factories.TypeFactoryHelper)1 ModelField (org.kie.soup.project.datamodel.oracle.ModelField)1