Search in sources :

Example 71 with GuidedDecisionTree

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

the class GuidedDecisionTreeDRLPersistenceUnmarshallingTest method testValue_Boolean.

@Test
public void testValue_Boolean() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  Person( booleanField == true )\n" + "then \n" + "end";
    final GuidedDecisionTree expected = new GuidedDecisionTree();
    expected.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    final ConstraintNode c1 = new ConstraintNodeImpl("Person", "booleanField", "==", new BooleanValue(true));
    expected.setRoot(type);
    type.addChild(c1);
    addModelField("Person", "this", "Person", DataType.TYPE_THIS);
    addModelField("Person", "booleanField", Boolean.class.getName(), DataType.TYPE_BOOLEAN);
    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) TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) BooleanValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BooleanValue) 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 72 with GuidedDecisionTree

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

the class GuidedDecisionTreeDRLPersistenceUnmarshallingTest method testSingleRule_ActionInsertDateFieldValue.

@Test
public void testSingleRule_ActionInsertDateFieldValue() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  Person( )\n" + "then \n" + "  java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"dd-MMM-yyyy\");\n" + "  Person $var0 = new Person();\n" + "  $var0.setDateOfBirth( sdf.parse(\"15-Jul-1985\") );\n" + "  insert( $var0 );\n" + "end";
    final GuidedDecisionTree expected = new GuidedDecisionTree();
    expected.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    expected.setRoot(type);
    final ActionInsertNode action = new ActionInsertNodeImpl("Person");
    action.setLogicalInsertion(false);
    final Calendar dob = Calendar.getInstance();
    dob.set(Calendar.YEAR, 1985);
    dob.set(Calendar.MONTH, 6);
    dob.set(Calendar.DATE, 15);
    dob.set(Calendar.HOUR_OF_DAY, 0);
    dob.set(Calendar.MINUTE, 0);
    dob.set(Calendar.SECOND, 0);
    action.getFieldValues().add(new ActionFieldValueImpl("dateOfBirth", new DateValue(dob.getTime())));
    type.addChild(action);
    addModelField("Person", "this", "Person", DataType.TYPE_THIS);
    addModelField("Person", "dateOfBirth", Date.class.getName(), DataType.TYPE_DATE);
    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 ActionInsertNode);
    final ActionInsertNode _action = (ActionInsertNode) model.getRoot().getChildren().get(0);
    assertEquals(action.getClassName(), _action.getClassName());
    assertEquals(action.isLogicalInsertion(), _action.isLogicalInsertion());
    assertEquals(action.getFieldValues().size(), _action.getFieldValues().size());
    assertEquals(1, _action.getFieldValues().size());
    assertEquals(action.getFieldValues().get(0).getFieldName(), _action.getFieldValues().get(0).getFieldName());
    assertEquals(action.getFieldValues().get(0).getValue().getValue().toString(), _action.getFieldValues().get(0).getValue().getValue().toString());
    assertEquals(0, _action.getChildren().size());
}
Also used : ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) DateValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue) Calendar(java.util.Calendar) ActionInsertNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionInsertNodeImpl) 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) Date(java.util.Date) Test(org.junit.Test)

Example 73 with GuidedDecisionTree

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

the class GuidedDecisionTreeDRLPersistenceUnmarshallingTest method testValue_BigInteger.

@Test
public void testValue_BigInteger() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  Person( bigIntegerField == 1000000I )\n" + "then \n" + "end";
    final GuidedDecisionTree expected = new GuidedDecisionTree();
    expected.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    final ConstraintNode c1 = new ConstraintNodeImpl("Person", "bigIntegerField", "==", new BigIntegerValue(new BigInteger("1000000")));
    expected.setRoot(type);
    type.addChild(c1);
    addModelField("Person", "this", "Person", DataType.TYPE_THIS);
    addModelField("Person", "bigIntegerField", BigInteger.class.getName(), DataType.TYPE_NUMERIC_BIGINTEGER);
    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) TypeNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.TypeNodeImpl) BigIntegerValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.BigIntegerValue) BigInteger(java.math.BigInteger) 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 74 with GuidedDecisionTree

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

the class GuidedDecisionTreeDRLPersistenceUnmarshallingTest method testValue_Float.

@Test
public void testValue_Float() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  Person( floatField == 1000.56 )\n" + "then \n" + "end";
    final GuidedDecisionTree expected = new GuidedDecisionTree();
    expected.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    final ConstraintNode c1 = new ConstraintNodeImpl("Person", "floatField", "==", new FloatValue(1000.56f));
    expected.setRoot(type);
    type.addChild(c1);
    addModelField("Person", "this", "Person", DataType.TYPE_THIS);
    addModelField("Person", "floatField", Float.class.getName(), DataType.TYPE_NUMERIC_FLOAT);
    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) 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 75 with GuidedDecisionTree

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

the class GuidedDecisionTreeDRLPersistenceUnmarshallingTest method testSingleRule_ActionSetActionRetract.

@Test
public void testSingleRule_ActionSetActionRetract() throws Exception {
    final String drl = "rule \"test_0\"\n" + "when \n" + "  $p : Person( )\n" + "then \n" + "  $p.setAge( 25 );\n" + "  retract( $p );\n" + "end";
    final GuidedDecisionTree expected = new GuidedDecisionTree();
    expected.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    type.setBinding("$p");
    expected.setRoot(type);
    final ActionUpdateNode action1 = new ActionUpdateNodeImpl(type);
    action1.setModify(false);
    action1.getFieldValues().add(new ActionFieldValueImpl("age", new IntegerValue(25)));
    type.addChild(action1);
    final ActionRetractNode action2 = new ActionRetractNodeImpl(type);
    action1.addChild(action2);
    addModelField("Person", "this", "Person", DataType.TYPE_THIS);
    addModelField("Person", "age", Integer.class.getName(), DataType.TYPE_NUMERIC_INTEGER);
    final GuidedDecisionTree model = getAndTestUnmarshalledModel(drl, "test", 0);
    assertEquals(expected.getTreeName(), model.getTreeName());
    assertNotNull(model.getRoot());
    assertEquals(type.getClassName(), model.getRoot().getClassName());
    assertTrue(model.getRoot().isBound());
    assertEquals(type.getBinding(), model.getRoot().getBinding());
    assertEquals(1, model.getRoot().getChildren().size());
    assertNotNull(model.getRoot().getChildren().get(0));
    assertTrue(model.getRoot().getChildren().get(0) instanceof ActionUpdateNode);
    final ActionUpdateNode _action1 = (ActionUpdateNode) model.getRoot().getChildren().get(0);
    assertEquals(action1.getBoundNode().getBinding(), _action1.getBoundNode().getBinding());
    assertEquals(action1.isModify(), _action1.isModify());
    assertEquals(action1.getFieldValues().size(), _action1.getFieldValues().size());
    assertEquals(1, _action1.getFieldValues().size());
    assertEquals(action1.getFieldValues().get(0).getFieldName(), _action1.getFieldValues().get(0).getFieldName());
    assertEquals(action1.getFieldValues().get(0).getValue().getValue().toString(), _action1.getFieldValues().get(0).getValue().getValue().toString());
    assertEquals(1, _action1.getChildren().size());
    assertNotNull(_action1.getChildren().get(0));
    assertTrue(_action1.getChildren().get(0) instanceof ActionRetractNode);
    final ActionRetractNode _action2 = (ActionRetractNode) _action1.getChildren().get(0);
    assertEquals(action2.getBoundNode().getBinding(), _action2.getBoundNode().getBinding());
}
Also used : BigInteger(java.math.BigInteger) 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) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) ActionUpdateNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionUpdateNodeImpl) ActionRetractNodeImpl(org.drools.workbench.models.guided.dtree.shared.model.nodes.impl.ActionRetractNodeImpl) 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) 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