Search in sources :

Example 56 with GuidedDecisionTree

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

the class GuidedDecisionTreeWidgetTest method setup.

@Before
public void setup() {
    ApplicationPreferences.setUp(Collections.singletonMap(ApplicationPreferences.DATE_FORMAT, "dd/mm/yyyy"));
    this.widget = spy(new GuidedDecisionTreeWidget(clearEvent, shapeSelectedEvent, shapeAddedEvent, shapeDeletedEvent, layoutManager, typeNodeFactory, constraintNodeFactory, actionInsertNodeFactory, actionUpdateNodeFactory, actionRetractNodeFactory));
    // We need to mock these after ApplicationPreferences has been initialised
    uiRootShape = mock(TypeShape.class);
    uiChildShape = mock(ConstraintShape.class);
    doReturn(uiRootNode).when(uiRootShape).getModelNode();
    doReturn(uiChildNode).when(uiChildShape).getModelNode();
    doReturn(uiRootShape).when(uiChildShape).getParentNode();
    widget.init(presenter);
    widget.init();
    uiModel = new GuidedDecisionTree();
    uiModel.setRoot(uiRootNode);
    widget.setModel(uiModel);
    widget.setUiRoot(uiRootShape);
    uiRootNode.addChild(uiChildNode);
}
Also used : ConstraintShape(org.drools.workbench.screens.guided.dtree.client.widget.shapes.ConstraintShape) GuidedDecisionTree(org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree) TypeShape(org.drools.workbench.screens.guided.dtree.client.widget.shapes.TypeShape) Before(org.junit.Before)

Example 57 with GuidedDecisionTree

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

the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_ActionSetDateFieldValue.

@Test
public void testSingleRule_ActionSetDateFieldValue() throws Exception {
    final String expected = "rule \"test_0\"" + "when\n" + "  $p : Person()\n" + "then\n" + "  java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"dd-MMM-yyyy\");\n" + "  $p.setDateOfBirth( sdf.parse(\"15-Jul-1985\") );\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);
    final Calendar dob = Calendar.getInstance();
    dob.set(Calendar.YEAR, 1985);
    dob.set(Calendar.MONTH, 6);
    dob.set(Calendar.DATE, 15);
    action.getFieldValues().add(new ActionFieldValueImpl("dateOfBirth", new DateValue(dob.getTime())));
    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) DateValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue) Calendar(java.util.Calendar) 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) Test(org.junit.Test)

Example 58 with GuidedDecisionTree

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

the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_TypeBinding.

@Test
public void testSingleRule_TypeBinding() throws Exception {
    final String expected = "rule \"test_0\"" + "when\n" + "  $p : Person( )\n" + "then\n" + "end";
    final GuidedDecisionTree model = new GuidedDecisionTree();
    model.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    type.setBinding("$p");
    model.setRoot(type);
    final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
    assertEqualsIgnoreWhitespace(expected, drl);
}
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) Test(org.junit.Test)

Example 59 with GuidedDecisionTree

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

the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testValue_Double.

@Test
public void testValue_Double() throws Exception {
    final String expected = "rule \"test_0\"" + "when\n" + "  Person( doubleField == 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", "doubleField", "==", new DoubleValue(1000.56));
    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) DoubleValue(org.drools.workbench.models.guided.dtree.shared.model.values.impl.DoubleValue) 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) Test(org.junit.Test)

Example 60 with GuidedDecisionTree

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

the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_ActionSetWithConstraint.

@Test
public void testSingleRule_ActionSetWithConstraint() throws Exception {
    final String expected = "rule \"test_0\"" + "when\n" + "  $p : Person( $n : name )\n" + "then\n" + "  $p.setAge( 25 );\n" + "end";
    final GuidedDecisionTree model = new GuidedDecisionTree();
    model.setTreeName("test");
    final TypeNode type = new TypeNodeImpl("Person");
    type.setBinding("$p");
    final ConstraintNode c1 = new ConstraintNodeImpl("Person", "name");
    c1.setBinding("$n");
    model.setRoot(type);
    type.addChild(c1);
    final ActionUpdateNode action = new ActionUpdateNodeImpl(type);
    action.setModify(false);
    action.getFieldValues().add(new ActionFieldValueImpl("age", new IntegerValue(25)));
    c1.addChild(action);
    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) 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) 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