use of org.guvnor.common.services.shared.validation.model.ValidationMessage in project drools-wb by kiegroup.
the class BaseGuidedDecisionTableEditorPresenterTest method checkOnValidateWithErrors.
@Test
@SuppressWarnings("unchecked")
public void checkOnValidateWithErrors() {
final ObservablePath path = mock(ObservablePath.class);
final PlaceRequest placeRequest = mock(PlaceRequest.class);
final GuidedDecisionTableEditorContent content = makeDecisionTableContent();
final GuidedDecisionTableView.Presenter dtPresenter = makeDecisionTable(path, path, placeRequest, content);
final List<ValidationMessage> validationMessages = new ArrayList<ValidationMessage>() {
{
add(new ValidationMessage());
}
};
when(dtService.validate(any(Path.class), any(GuidedDecisionTable52.class))).thenReturn(validationMessages);
doNothing().when(presenter).showValidationPopup(any(List.class));
presenter.onValidate(dtPresenter);
final ArgumentCaptor<GuidedDecisionTable52> modelCaptor = ArgumentCaptor.forClass(GuidedDecisionTable52.class);
verify(dtService, times(1)).validate(eq(path), modelCaptor.capture());
assertNotNull(modelCaptor.getValue());
assertEquals(dtPresenter.getModel(), modelCaptor.getValue());
verify(notification, never()).fire(any(NotificationEvent.class));
verify(presenter, times(1)).showValidationPopup(eq(validationMessages));
}
use of org.guvnor.common.services.shared.validation.model.ValidationMessage in project drools-wb by kiegroup.
the class GuidedRuleEditorServiceImplCDITest method testAbbreviatedCondition.
@Test
public void testAbbreviatedCondition() throws Exception {
final String resourcePath = RULES_ROOT + "matchPeopleAbbreviatedCondition.rdrl";
final GuidedEditorContent content = guidedRuleService.loadContent(getPath(resourcePath));
final RuleModel model = content.getModel();
Assertions.assertThat(model.lhs.length).isEqualTo(1);
final FactPattern pattern = (FactPattern) model.lhs[0];
final SingleFieldConstraint fieldConstraintOne = (SingleFieldConstraint) pattern.getConstraint(0);
Assertions.assertThat(fieldConstraintOne.getConnectives()).hasSize(2);
final ConnectiveConstraint fieldConstraintTwo = fieldConstraintOne.getConnectives()[0];
final ConnectiveConstraint fieldConstraintThree = fieldConstraintOne.getConnectives()[1];
Assertions.assertThat(fieldConstraintOne.getFieldName()).isEqualTo("age");
Assertions.assertThat(fieldConstraintOne.getOperator()).isEqualTo(Operator.NOT_EQUAL.getOperatorString());
Assertions.assertThat(fieldConstraintOne.getValue()).isEqualTo("18");
Assertions.assertThat(fieldConstraintTwo.getFieldName()).isEqualTo("age");
Assertions.assertThat(fieldConstraintTwo.getOperator()).isEqualTo("&& " + Operator.LESS.getOperatorString());
Assertions.assertThat(fieldConstraintTwo.getValue()).isEqualTo("25");
Assertions.assertThat(fieldConstraintThree.getFieldName()).isEqualTo("age");
Assertions.assertThat(fieldConstraintThree.getOperator()).isEqualTo("&& " + Operator.GREATER.getOperatorString());
Assertions.assertThat(fieldConstraintThree.getValue()).isEqualTo("15");
final List<ValidationMessage> messages = validateResource(resourcePath);
Assertions.assertThat(messages).isEmpty();
}
use of org.guvnor.common.services.shared.validation.model.ValidationMessage in project drools-wb by kiegroup.
the class GuidedScoreCardEditorServiceImpl method makeValidationMessages.
private ValidationMessage makeValidationMessages(final String message) {
final ValidationMessage msg = new ValidationMessage();
msg.setText(message);
msg.setLevel(Level.ERROR);
return msg;
}
use of org.guvnor.common.services.shared.validation.model.ValidationMessage in project drools-wb by kiegroup.
the class GuidedScoreCardEditorServiceImpl method doValidation.
private List<ValidationMessage> doValidation(final ScoreCardModel model) {
final List<ValidationMessage> results = new ArrayList<ValidationMessage>();
if (isBlank(model.getFactName())) {
results.add(makeValidationMessages("Fact Name is empty."));
}
if (isBlank(model.getFieldName())) {
results.add(makeValidationMessages("Resultant Score Field is empty."));
}
if (model.getCharacteristics().size() == 0) {
results.add(makeValidationMessages("No Characteristics Found."));
}
int ctr = 1;
for (final Characteristic c : model.getCharacteristics()) {
String characteristicName = "Characteristic ('#" + ctr + "')";
if (isBlank(c.getName())) {
results.add(makeValidationMessages("Characteristic Name '" + characteristicName + "' is empty."));
} else {
characteristicName = "Characteristic ('" + c.getName() + "')";
}
if (isBlank(c.getFact())) {
results.add(makeValidationMessages("Characteristic Name '" + characteristicName + "'. Fact is empty."));
}
if (isBlank(c.getField())) {
results.add(makeValidationMessages("Characteristic Name '" + characteristicName + "'. Characteristic Field is empty."));
} else if (isBlank(c.getDataType())) {
results.add(makeValidationMessages("Characteristic Name '" + characteristicName + "'. Internal Error (missing datatype)."));
}
if (c.getAttributes().size() == 0) {
results.add(makeValidationMessages("Characteristic Name '" + characteristicName + "'. No Attributes Found."));
}
if (model.isUseReasonCodes()) {
if (isBlank(model.getReasonCodeField())) {
results.add(makeValidationMessages("Characteristic Name '" + characteristicName + "'. Resultant Reason Codes Field is empty."));
}
if (!"none".equalsIgnoreCase(model.getReasonCodesAlgorithm())) {
results.add(makeValidationMessages("Characteristic Name '" + characteristicName + "'. Baseline Score is not specified."));
}
}
int attrCtr = 1;
for (final Attribute attribute : c.getAttributes()) {
final String attributeName = "Attribute ('#" + attrCtr + "')";
if (isBlank(attribute.getOperator())) {
results.add(makeValidationMessages("Attribute Name '" + attributeName + "'. Attribute Operator is empty."));
}
if (isBlank(attribute.getValue())) {
results.add(makeValidationMessages("Attribute Name '" + attributeName + "'. Attribute Value is empty."));
}
if (model.isUseReasonCodes()) {
if (isBlank(c.getReasonCode())) {
if (isBlank(attribute.getReasonCode())) {
results.add(makeValidationMessages("Attribute Name '" + attributeName + "'. Reason Code must be set at either attribute or characteristic."));
}
}
}
attrCtr++;
}
ctr++;
}
return results;
}
use of org.guvnor.common.services.shared.validation.model.ValidationMessage in project drools-wb by kiegroup.
the class GuidedDecisionTableEditorServiceImplCDITest method testUndeclaredFunction.
@Test
@Ignore("RHDM-329")
public void testUndeclaredFunction() throws Exception {
final Path path = getPath("rhba370/src/main/resources/com/sample/dtissuesampleproject/UseUndeclaredFunction.gdst");
final List<ValidationMessage> validationMessages = testedService.validate(path, testedService.load(path));
Assertions.assertThat(validationMessages).hasSize(1);
Assertions.assertThat(validationMessages).extracting("text", String.class).allMatch(text -> text.contains("[KBase: defaultKieBase]: Unable to Analyse Expression isNotEmptyUndeclaredFunction(userCode)"));
}
Aggregations