use of org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceUnmarshallingTest method testSingleRule_ActionSetDateFieldValue.
@Test
public void testSingleRule_ActionSetDateFieldValue() throws Exception {
final String drl = "rule \"test_0\"\n" + "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 expected = new GuidedDecisionTree();
expected.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
type.setBinding("$p");
expected.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);
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());
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 _action = (ActionUpdateNode) model.getRoot().getChildren().get(0);
assertEquals(action.getBoundNode().getBinding(), _action.getBoundNode().getBinding());
assertEquals(action.isModify(), _action.isModify());
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());
}
use of org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_ActionModifyDateFieldValue.
@Test
public void testSingleRule_ActionModifyDateFieldValue() 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" + " modify( $p ) {\n" + " setDateOfBirth( sdf.parse(\"15-Jul-1985\") )\n" + " }\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(true);
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);
}
use of org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_ActionInsertLogicalDateFieldValue.
@Test
public void testSingleRule_ActionInsertLogicalDateFieldValue() throws Exception {
final String expected = "rule \"test_0\"" + "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" + " insertLogical( $var0 );\n" + "end";
final GuidedDecisionTree model = new GuidedDecisionTree();
model.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
model.setRoot(type);
final ActionInsertNode action = new ActionInsertNodeImpl("Person");
action.setLogicalInsertion(true);
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);
}
use of org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testSingleRule_ActionInsertDateFieldValue.
@Test
public void testSingleRule_ActionInsertDateFieldValue() throws Exception {
final String expected = "rule \"test_0\"" + "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 model = new GuidedDecisionTree();
model.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
model.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);
action.getFieldValues().add(new ActionFieldValueImpl("dateOfBirth", new DateValue(dob.getTime())));
type.addChild(action);
final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(expected, drl);
}
use of org.drools.workbench.models.guided.dtree.shared.model.values.impl.DateValue in project drools by kiegroup.
the class GuidedDecisionTreeDRLPersistenceMarshallingTest method testValue_Date.
@Test
public void testValue_Date() throws Exception {
final String expected = "rule \"test_0\"" + "when\n" + " Person( dateField == \"15-Jul-1984\" )\n" + "then\n" + "end";
final GuidedDecisionTree model = new GuidedDecisionTree();
model.setTreeName("test");
final TypeNode type = new TypeNodeImpl("Person");
final ConstraintNode c1 = new ConstraintNodeImpl("Person", "dateField", "==", new DateValue(new Date(84, 6, 15)));
model.setRoot(type);
type.addChild(c1);
final String drl = GuidedDecisionTreeDRLPersistence.getInstance().marshal(model);
assertEqualsIgnoreWhitespace(expected, drl);
}
Aggregations