use of org.drools.workbench.screens.guided.rule.client.editor.util.ConstraintValueEditorHelper in project drools-wb by kiegroup.
the class ConstraintValueEditorHelperTest method testEvents_BoundTypeIsNotEvent.
@Test
public void testEvents_BoundTypeIsNotEvent() throws Exception {
AsyncPackageDataModelOracle oracle = new AsyncPackageDataModelOracleImpl(serviceCaller, validatorInstance);
oracle.setPackageName("org.test");
oracle.addModelFields(new HashMap<String, ModelField[]>() {
{
put("org.test.Event1", new ModelField[] { modelField("this", "org.test.Event1") });
put("org.test.Event2", new ModelField[] { modelField("this", "org.test.Event2") });
}
});
oracle.addEventTypes(new HashMap<String, Boolean>() {
{
put("org.test.Event1", false);
put("org.test.Event2", true);
}
});
oracle.addSuperTypes(new HashMap<String, List<String>>() {
{
put("org.test.Event1", Collections.EMPTY_LIST);
put("org.test.Event2", Collections.EMPTY_LIST);
}
});
oracle.filter();
FactPattern pattern1 = new FactPattern();
pattern1.setFactType("Event1");
pattern1.setBoundName("$e");
SingleFieldConstraint constraint = new SingleFieldConstraint();
constraint.setFactType("Event1");
constraint.setFieldName("this");
constraint.setFieldType("Event1");
constraint.setOperator(OperatorsOracle.SIMPLE_CEP_OPERATORS[0]);
pattern1.addConstraint(constraint);
model.addLhsItem(pattern1);
ConstraintValueEditorHelper helper = new ConstraintValueEditorHelper(model, oracle, "Event2", "this", constraint, "Event2", new DropDownData());
helper.isApplicableBindingsInScope("$e", new Callback<Boolean>() {
@Override
public void callback(Boolean result) {
assertFalse(result);
}
});
}
use of org.drools.workbench.screens.guided.rule.client.editor.util.ConstraintValueEditorHelper in project drools-wb by kiegroup.
the class ConstraintValueEditorHelperTest method testSimplePattern.
@Test
public void testSimplePattern() throws Exception {
AsyncPackageDataModelOracle oracle = mock(AsyncPackageDataModelOracle.class);
FactPattern pattern = new FactPattern();
pattern.setBoundName("pp");
pattern.setFactType("House");
model.addLhsItem(pattern);
FactPattern pattern2 = new FactPattern();
SingleFieldConstraint constraint = new SingleFieldConstraint();
constraint.setFactType("House");
constraint.setFieldName("this");
constraint.setFieldType("org.mortgages.House");
pattern2.addConstraint(constraint);
model.addLhsItem(pattern);
when(oracle.getFieldClassName("House", "this")).thenReturn("org.mortgages.House");
ConstraintValueEditorHelper helper = new ConstraintValueEditorHelper(model, oracle, "House", "this", constraint, "House", new DropDownData());
helper.isApplicableBindingsInScope("pp", new Callback<Boolean>() {
@Override
public void callback(Boolean result) {
assertTrue(result);
}
});
}
use of org.drools.workbench.screens.guided.rule.client.editor.util.ConstraintValueEditorHelper in project drools-wb by kiegroup.
the class ConstraintValueEditorHelperTest method testBoundFieldOfSameType.
@Test
public void testBoundFieldOfSameType() throws Exception {
final AsyncPackageDataModelOracle oracle = mock(AsyncPackageDataModelOracle.class);
final FactPattern pattern = new FactPattern();
final SingleFieldConstraint isFinished = new SingleFieldConstraint();
isFinished.setFieldBinding("$finished");
isFinished.setFactType("House");
isFinished.setFieldName("finished");
isFinished.setFieldType("java.time.LocalDate");
isFinished.setOperator("!= null");
pattern.addConstraint(isFinished);
model.addLhsItem(pattern);
final SingleFieldConstraint isFinishedAfter = new SingleFieldConstraint();
isFinishedAfter.setFactType("House");
isFinishedAfter.setFieldName("bought");
isFinishedAfter.setFieldType("java.time.LocalDate");
isFinishedAfter.setOperator("==");
pattern.addConstraint(isFinishedAfter);
model.addLhsItem(pattern);
when(oracle.getFieldClassName("House", "finished")).thenReturn("java.time.LocalDate");
when(oracle.getFieldClassName("House", "bought")).thenReturn("java.time.LocalDate");
ConstraintValueEditorHelper helper = new ConstraintValueEditorHelper(model, oracle, "House", "bought", isFinished, "LocalDate", new DropDownData());
helper.isApplicableBindingsInScope("$finished", result -> assertTrue(result));
}
use of org.drools.workbench.screens.guided.rule.client.editor.util.ConstraintValueEditorHelper in project drools-wb by kiegroup.
the class ConstraintValueEditorHelperTest method testSimpleField.
@Test
public void testSimpleField() throws Exception {
AsyncPackageDataModelOracle oracle = mock(AsyncPackageDataModelOracle.class);
FactPattern pattern = new FactPattern();
SingleFieldConstraint constraint = new SingleFieldConstraint();
constraint.setFieldBinding("pp");
constraint.setFactType("House");
constraint.setFieldName("parent");
constraint.setFieldType("org.mortgages.Parent");
pattern.addConstraint(constraint);
model.addLhsItem(pattern);
when(oracle.getFieldClassName("House", "parent")).thenReturn("org.mortgages.Parent");
ConstraintValueEditorHelper helper = new ConstraintValueEditorHelper(model, oracle, "House", "parent", constraint, "Parent", new DropDownData());
helper.isApplicableBindingsInScope("pp", new Callback<Boolean>() {
@Override
public void callback(Boolean result) {
assertTrue(result);
}
});
}
use of org.drools.workbench.screens.guided.rule.client.editor.util.ConstraintValueEditorHelper in project drools-wb by kiegroup.
the class ConstraintValueEditorHelperTest method testBoundFieldOfDifferentType.
@Test
public void testBoundFieldOfDifferentType() throws Exception {
final AsyncPackageDataModelOracle oracle = mock(AsyncPackageDataModelOracle.class);
final FactPattern pattern = new FactPattern();
final SingleFieldConstraint isFinished = new SingleFieldConstraint();
isFinished.setFieldBinding("$finished");
isFinished.setFactType("House");
isFinished.setFieldName("finished");
isFinished.setFieldType("java.time.LocalDate");
isFinished.setOperator("!= null");
pattern.addConstraint(isFinished);
model.addLhsItem(pattern);
final SingleFieldConstraint isFinishedAfter = new SingleFieldConstraint();
isFinishedAfter.setFactType("House");
isFinishedAfter.setFieldName("cost");
isFinishedAfter.setFieldType("java.util.BigDecimal");
isFinishedAfter.setOperator("==");
pattern.addConstraint(isFinishedAfter);
model.addLhsItem(pattern);
when(oracle.getFieldClassName("House", "finished")).thenReturn("java.time.LocalDate");
when(oracle.getFieldClassName("House", "cost")).thenReturn("java.util.BigDecimal");
ConstraintValueEditorHelper helper = new ConstraintValueEditorHelper(model, oracle, "House", "cost", isFinished, "LocalDate", new DropDownData());
helper.isApplicableBindingsInScope("$finished", result -> assertFalse(result));
}
Aggregations