Search in sources :

Example 11 with ValidationMessage

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));
}
Also used : PlaceRequest(org.uberfire.mvp.PlaceRequest) ObservablePath(org.uberfire.backend.vfs.ObservablePath) Path(org.uberfire.backend.vfs.Path) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) GuidedDecisionTableEditorContent(org.drools.workbench.screens.guided.dtable.model.GuidedDecisionTableEditorContent) ArrayList(java.util.ArrayList) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) GuidedDecisionTableView(org.drools.workbench.screens.guided.dtable.client.widget.table.GuidedDecisionTableView) List(java.util.List) ArrayList(java.util.ArrayList) ObservablePath(org.uberfire.backend.vfs.ObservablePath) Test(org.junit.Test)

Example 12 with ValidationMessage

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();
}
Also used : SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) GuidedEditorContent(org.drools.workbench.screens.guided.rule.model.GuidedEditorContent) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 13 with ValidationMessage

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;
}
Also used : ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage)

Example 14 with ValidationMessage

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;
}
Also used : ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) Attribute(org.drools.workbench.models.guided.scorecard.shared.Attribute) Characteristic(org.drools.workbench.models.guided.scorecard.shared.Characteristic) ArrayList(java.util.ArrayList)

Example 15 with ValidationMessage

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)"));
}
Also used : Path(org.uberfire.backend.vfs.Path) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ValidationMessage (org.guvnor.common.services.shared.validation.model.ValidationMessage)19 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 Path (org.uberfire.backend.vfs.Path)6 List (java.util.List)3 FileAlreadyExistsException (org.uberfire.java.nio.file.FileAlreadyExistsException)3 IOException (java.io.IOException)2 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)2 ObservablePath (org.uberfire.backend.vfs.ObservablePath)2 NotificationEvent (org.uberfire.workbench.events.NotificationEvent)2 StringReader (java.io.StringReader)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 NotThreadSafe (javax.annotation.concurrent.NotThreadSafe)1 Assertions (org.assertj.core.api.Assertions)1 DSLMappingParseException (org.drools.compiler.lang.dsl.DSLMappingParseException)1 DSLTokenizedMappingFile (org.drools.compiler.lang.dsl.DSLTokenizedMappingFile)1 ConnectiveConstraint (org.drools.workbench.models.datamodel.rule.ConnectiveConstraint)1 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)1 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)1