Search in sources :

Example 1 with ValidationMarker

use of org.linkki.util.validation.ValidationMarker in project linkki by linkki-framework.

the class OkCancelDialogTest method testValidate_FiltersMessages.

@Test
public void testValidate_FiltersMessages() {
    ValidationMarker mandatoryFieldMarker = () -> true;
    Message message = Message.builder("error", ErrorLevel.ERROR).markers(mandatoryFieldMarker).create();
    MessageList messages = new MessageList(message);
    ValidationService validationService = ValidationService.of(messages);
    OkCancelDialog dialog = new OkCancelDialog("caption");
    dialog.setValidationService(validationService);
    // mandatory field validations are hidden initially
    assertThat(dialog.getValidationDisplayState(), is(ValidationDisplayState.HIDE_MANDATORY_FIELD_VALIDATIONS));
    MessageList dialogMessage = dialog.validate();
    assertTrue(dialogMessage.isEmpty());
    assertThat(dialog, is(not(displayingMessage())));
    assertThat(dialog, is(showingEnabledOkButton()));
    // mandatory field validations are shown after the first click on the OK button
    getOkButton(dialog).click();
    assertThat(dialog.getValidationDisplayState(), is(ValidationDisplayState.SHOW_ALL));
    dialogMessage = dialog.validate();
    assertThat(dialogMessage, contains(message));
    assertThat(dialog, is(displayingMessage("error")));
    assertThat(dialog, is(showingDisabledOkButton()));
}
Also used : Message(org.linkki.core.message.Message) ValidationMarker(org.linkki.util.validation.ValidationMarker) ValidationService(org.linkki.core.binding.validation.ValidationService) MessageList(org.linkki.core.message.MessageList) Test(org.junit.Test)

Example 2 with ValidationMarker

use of org.linkki.util.validation.ValidationMarker in project linkki by linkki-framework.

the class MessageListTest method testGetMessagesByMarker_withValidationMarker.

@Test
public void testGetMessagesByMarker_withValidationMarker() {
    ValidationMarker marker = () -> false;
    MessageList messages = new MessageList(Message.builder("msg1", ErrorLevel.INFORMATION).create(), Message.builder("msgWithMarker", ErrorLevel.WARNING).markers(marker).create());
    MessageList messagesByMarker = messages.getMessagesByMarker(marker);
    assertThat(messagesByMarker, is(not(sameInstance(messages))));
    assertThat(messagesByMarker, hasSize(1));
    assertThat(messagesByMarker.getMessage(0), is(messages.getMessage(1)));
}
Also used : ValidationMarker(org.linkki.util.validation.ValidationMarker) MessageMatchers.emptyMessageList(org.linkki.core.matcher.MessageMatchers.emptyMessageList) Test(org.junit.Test)

Example 3 with ValidationMarker

use of org.linkki.util.validation.ValidationMarker in project linkki by linkki-framework.

the class MessageListTest method testGetMessagesByMarker_predicate.

@Test
public void testGetMessagesByMarker_predicate() {
    MessageList messages = new MessageList(Message.builder("msgWithoutMarker", ErrorLevel.INFORMATION).create(), Message.builder("msgWithMatchingMarker", ErrorLevel.WARNING).markers(() -> true).create(), Message.builder("msgWithNonMathingMarker", ErrorLevel.ERROR).markers(() -> false).create());
    MessageList messagesByMarker = messages.getMessagesByMarker(ValidationMarker::isRequiredInformationMissing);
    assertThat(messagesByMarker, is(not(sameInstance(messages))));
    assertThat(messagesByMarker, hasSize(1));
    assertThat(messagesByMarker.getMessage(0), is(messages.getMessage(1)));
}
Also used : ValidationMarker(org.linkki.util.validation.ValidationMarker) MessageMatchers.emptyMessageList(org.linkki.core.matcher.MessageMatchers.emptyMessageList) Test(org.junit.Test)

Example 4 with ValidationMarker

use of org.linkki.util.validation.ValidationMarker in project linkki by linkki-framework.

the class MessageTest method testIsMandatoryFieldMessage.

@Test
public void testIsMandatoryFieldMessage() {
    ValidationMarker mandatoryMarker = () -> true;
    ValidationMarker notMandatoryMarker = () -> false;
    assertThat(createMessage().isMandatoryFieldMessage(), is(false));
    assertThat(createMessage(notMandatoryMarker).isMandatoryFieldMessage(), is(false));
    assertThat(createMessage(mandatoryMarker).isMandatoryFieldMessage(), is(true));
    assertThat(createMessage(notMandatoryMarker, mandatoryMarker).isMandatoryFieldMessage(), is(true));
}
Also used : ValidationMarker(org.linkki.util.validation.ValidationMarker) Test(org.junit.Test)

Example 5 with ValidationMarker

use of org.linkki.util.validation.ValidationMarker in project linkki by linkki-framework.

the class ValidationDisplayStateTest method testFilter.

@Test
public void testFilter() {
    ValidationMarker mandatoryFieldMarker = () -> true;
    ValidationMarker nonMandatoryFieldMarker = () -> false;
    Message m1 = Message.builder("m1", ErrorLevel.ERROR).markers(mandatoryFieldMarker).create();
    Message m2 = Message.builder("m2", ErrorLevel.ERROR).markers(nonMandatoryFieldMarker).create();
    Message m3 = Message.builder("m3", ErrorLevel.ERROR).create();
    MessageList messages = new MessageList(m1, m2, m3);
    assertThat(SHOW_ALL.filter(messages), contains(m1, m2, m3));
    assertThat(HIDE_MANDATORY_FIELD_VALIDATIONS.filter(messages), contains(m2, m3));
}
Also used : Message(org.linkki.core.message.Message) ValidationMarker(org.linkki.util.validation.ValidationMarker) MessageList(org.linkki.core.message.MessageList) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 ValidationMarker (org.linkki.util.validation.ValidationMarker)5 MessageMatchers.emptyMessageList (org.linkki.core.matcher.MessageMatchers.emptyMessageList)2 Message (org.linkki.core.message.Message)2 MessageList (org.linkki.core.message.MessageList)2 ValidationService (org.linkki.core.binding.validation.ValidationService)1