use of org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern in project drools-wb by kiegroup.
the class GuidedRuleEditorValidatorTest method testMissingValueInFrom.
@Test
public void testMissingValueInFrom() throws Exception {
FactPattern boundPattern = new FactPattern("Person");
boundPattern.setBoundName("person");
boundPattern.addConstraint(new SingleFieldConstraint("addresses"));
FactPattern pattern = new FactPattern("Address");
SingleFieldConstraint constraint = new SingleFieldConstraint("street");
constraint.setOperator("!=");
pattern.addConstraint(constraint);
FromCompositeFactPattern fromCompositeFactPattern = new FromCompositeFactPattern();
fromCompositeFactPattern.setFactPattern(pattern);
ExpressionFormLine expression = new ExpressionFormLine();
expression.setBinding("person.addresses");
fromCompositeFactPattern.setExpression(expression);
model.lhs = new IPattern[] { boundPattern, fromCompositeFactPattern };
assertFalse(validator.isValid());
assertEquals(1, validator.getErrors().size());
assertEquals(MISSING_VALUE_WHEN_OPERATOR_IS_SET, validator.getErrors().get(0));
verify(constants).FactType0HasAField1ThatHasAnOperatorSetButNoValuePleaseAddAValueOrRemoveTheOperator("Address", "street");
}
use of org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern in project drools-wb by kiegroup.
the class GuidedRuleEditorValidatorTest method testMissingFactTypeInFromCollect.
@Test
public void testMissingFactTypeInFromCollect() throws Exception {
FromCollectCompositeFactPattern fromCompositeFactPattern = new FromCollectCompositeFactPattern();
fromCompositeFactPattern.setRightPattern(new FactPattern("Person"));
model.lhs = new IPattern[] { fromCompositeFactPattern };
assertFalse(validator.isValid());
assertEquals(1, validator.getErrors().size());
assertEquals(MISSING_FACT_PATTERN, validator.getErrors().get(0));
verify(constants).AreasMarkedWithRedAreMandatoryPleaseSetAValueBeforeSaving();
}
use of org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern in project drools-wb by kiegroup.
the class GuidedRuleEditorValidatorTest method testWorkingFrom.
@Test
public void testWorkingFrom() throws Exception {
FactPattern boundPattern = new FactPattern("Person");
boundPattern.setBoundName("person");
boundPattern.addConstraint(new SingleFieldConstraint("addresses"));
FactPattern pattern = new FactPattern("Address");
SingleFieldConstraint constraint = new SingleFieldConstraint("street");
pattern.addConstraint(constraint);
FromCompositeFactPattern fromCompositeFactPattern = new FromCompositeFactPattern();
fromCompositeFactPattern.setFactPattern(pattern);
ExpressionFormLine expression = new ExpressionFormLine();
expression.setBinding("person.addresses");
fromCompositeFactPattern.setExpression(expression);
model.lhs = new IPattern[] { boundPattern, fromCompositeFactPattern };
assertTrue(validator.isValid());
}
use of org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern in project drools-wb by kiegroup.
the class FromAccumulateCompositeFactPatternWidget method showSourcePatternSelector.
/**
* Pops up the fact selector.
*/
protected void showSourcePatternSelector() {
final ListBox box = new ListBox();
AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
String[] facts = oracle.getFactTypes();
box.addItem(GuidedRuleEditorResources.CONSTANTS.Choose());
for (int i = 0; i < facts.length; i++) {
box.addItem(facts[i]);
}
box.setSelectedIndex(0);
final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorResources.CONSTANTS.NewFactPattern());
popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.chooseFactType(), box);
box.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
getFromAccumulatePattern().setSourcePattern(new FactPattern(box.getItemText(box.getSelectedIndex())));
setModified(true);
getModeller().refreshWidget();
popup.hide();
}
});
final Button fromBtn = new Button(HumanReadableConstants.INSTANCE.From());
final Button fromAccumulateBtn = new Button(HumanReadableConstants.INSTANCE.FromAccumulate());
final Button fromCollectBtn = new Button(HumanReadableConstants.INSTANCE.FromCollect());
final Button fromEntryPointBtn = new Button(HumanReadableConstants.INSTANCE.FromEntryPoint());
ClickHandler btnsClickHandler = new ClickHandler() {
public void onClick(ClickEvent event) {
Widget sender = (Widget) event.getSource();
if (sender == fromBtn) {
getFromAccumulatePattern().setSourcePattern(new FromCompositeFactPattern());
} else if (sender == fromAccumulateBtn) {
getFromAccumulatePattern().setSourcePattern(new FromAccumulateCompositeFactPattern());
} else if (sender == fromCollectBtn) {
getFromAccumulatePattern().setSourcePattern(new FromCollectCompositeFactPattern());
} else if (sender == fromEntryPointBtn) {
getFromAccumulatePattern().setSourcePattern(new FromEntryPointFactPattern());
} else {
throw new IllegalArgumentException("Unknown sender: " + sender);
}
setModified(true);
getModeller().refreshWidget();
popup.hide();
}
};
fromBtn.addClickHandler(btnsClickHandler);
fromAccumulateBtn.addClickHandler(btnsClickHandler);
fromCollectBtn.addClickHandler(btnsClickHandler);
fromEntryPointBtn.addClickHandler(btnsClickHandler);
popup.addAttribute("", fromBtn);
popup.addAttribute("", fromAccumulateBtn);
popup.addAttribute("", fromCollectBtn);
popup.addAttribute("", fromEntryPointBtn);
popup.show();
}
use of org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern in project drools-wb by kiegroup.
the class GuidedRuleEditorValidatorTest method testValidFromCompositeFactPattern.
@Test
public void testValidFromCompositeFactPattern() throws Exception {
FactPattern factPattern = new FactPattern("SomeList");
factPattern.setBoundName("list");
FromCompositeFactPattern fromCompositeFactPattern = new FromCompositeFactPattern();
fromCompositeFactPattern.setFactPattern(new FactPattern("Person"));
ExpressionFormLine expression = new ExpressionFormLine();
expression.appendPart(new ExpressionVariable("list", "SomeList", "SomeList"));
fromCompositeFactPattern.setExpression(expression);
model.lhs = new IPattern[] { fromCompositeFactPattern };
assertTrue(validator.isValid());
}
Aggregations