Search in sources :

Example 1 with Message

use of org.linkki.core.message.Message in project linkki by linkki-framework.

the class OkCancelDialogTest method displayingMessage.

private Matcher<OkCancelDialog> displayingMessage(String text) {
    return new TypeSafeMatcher<OkCancelDialog>() {

        @SuppressWarnings("null")
        @Override
        public void describeTo(Description description) {
            description.appendText("an OkCancelDialog displaying a message with the text '");
            description.appendText(text);
            description.appendText("'");
        }

        @SuppressWarnings("null")
        @Override
        protected boolean matchesSafely(OkCancelDialog dialog) {
            VerticalLayout layout = (VerticalLayout) dialog.getContent();
            VerticalLayout nestedLayout = (VerticalLayout) layout.getComponent(0);
            return components(nestedLayout).filter(MessageRow.class::isInstance).findFirst().map(c -> ((MessageRow) c).getText().equals(text)).orElse(false);
        }
    };
}
Also used : Description(org.hamcrest.Description) ErrorLevel(com.vaadin.server.ErrorMessage.ErrorLevel) VerticalLayout(com.vaadin.ui.VerticalLayout) Matchers.not(org.hamcrest.Matchers.not) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Assert.assertThat(org.junit.Assert.assertThat) Button(com.vaadin.ui.Button) Stream(java.util.stream.Stream) Matchers.contains(org.hamcrest.Matchers.contains) ValidationMarker(org.linkki.util.validation.ValidationMarker) HorizontalLayout(com.vaadin.ui.HorizontalLayout) MessageRow(org.linkki.framework.ui.component.MessageRow) Matcher(org.hamcrest.Matcher) ValidationService(org.linkki.core.binding.validation.ValidationService) Label(com.vaadin.ui.Label) MessageList(org.linkki.core.message.MessageList) Matchers.is(org.hamcrest.Matchers.is) StreamSupport(java.util.stream.StreamSupport) Message(org.linkki.core.message.Message) ValidationDisplayState(org.linkki.core.binding.validation.ValidationDisplayState) Component(com.vaadin.ui.Component) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) VerticalLayout(com.vaadin.ui.VerticalLayout)

Example 2 with Message

use of org.linkki.core.message.Message in project linkki by linkki-framework.

the class BindingManagerTest method testAfterUpdateUi_sortsMessagesByErrorLevel.

@Test
public void testAfterUpdateUi_sortsMessagesByErrorLevel() {
    Message e1 = Message.newError("e1", "E1");
    Message e2 = Message.newError("e2", "E2");
    Message e3 = Message.newError("e3", "E3");
    Message w1 = Message.newWarning("w1", "W1");
    Message w2 = Message.newWarning("w2", "W2");
    Message i1 = Message.newInfo("i1", "I1");
    Message i2 = Message.newInfo("i2", "I2");
    MessageList unsortedMessageList = new MessageList(i2, e1, w1, e3, i1, e2, w2);
    MessageList sortedMessageList = new MessageList(e1, e3, e2, w1, w2, i2, i1);
    validationService = () -> unsortedMessageList;
    TestBindingManager bindingManager = new TestBindingManager(validationService);
    TestBindingContext context = bindingManager.startNewContext("foo");
    bindingManager.afterUpdateUi();
    assertThat(context.messages, is(equalTo(sortedMessageList)));
}
Also used : Message(org.linkki.core.message.Message) MessageList(org.linkki.core.message.MessageList) Test(org.junit.Test)

Example 3 with Message

use of org.linkki.core.message.Message in project linkki by linkki-framework.

the class ReflectionPropertyDispatcherTest method testGetMessages_ShouldReturnMessagesFromPmo.

@Test
public void testGetMessages_ShouldReturnMessagesFromPmo() {
    MessageList messageList = new MessageList();
    Message msg1 = Message.builder(ABC, ErrorLevel.ERROR).invalidObjectWithProperties(testPmo, XYZ).create();
    Message msg2 = Message.builder(ABC, ErrorLevel.ERROR).invalidObjectWithProperties(testPmo, ABC).create();
    Message msg3 = Message.builder(ABC, ErrorLevel.ERROR).invalidObjectWithProperties(testModelObject, XYZ).create();
    messageList.add(msg1);
    messageList.add(msg2);
    messageList.add(msg3);
    assertThat(setupPmoDispatcher(XYZ).getMessages(messageList), hasSize(2));
    assertThat(setupPmoDispatcher(ABC).getMessages(messageList), hasSize(1));
    assertThat(setupPmoDispatcher("invalidProperty").getMessages(messageList), emptyMessageList());
}
Also used : Message(org.linkki.core.message.Message) MessageMatchers.emptyMessageList(org.linkki.core.matcher.MessageMatchers.emptyMessageList) MessageList(org.linkki.core.message.MessageList) Test(org.junit.Test)

Example 4 with Message

use of org.linkki.core.message.Message in project linkki by linkki-framework.

the class ReflectionPropertyDispatcherTest method testGetMessages_ShouldReturnMessagesFromModelObject.

@Test
public void testGetMessages_ShouldReturnMessagesFromModelObject() {
    MessageList messageList = new MessageList();
    Message msg1 = Message.builder(ABC, ErrorLevel.ERROR).invalidObjectWithProperties(testModelObject, XYZ).create();
    Message msg2 = Message.builder(ABC, ErrorLevel.ERROR).invalidObjectWithProperties(testModelObject, ABC).create();
    messageList.add(msg1);
    messageList.add(msg2);
    assertThat(setupPmoDispatcher(XYZ).getMessages(messageList), hasSize(1));
    assertThat(setupPmoDispatcher(ABC).getMessages(messageList), hasSize(1));
    assertThat(setupPmoDispatcher("invalidProperty").getMessages(messageList), emptyMessageList());
}
Also used : Message(org.linkki.core.message.Message) MessageMatchers.emptyMessageList(org.linkki.core.matcher.MessageMatchers.emptyMessageList) MessageList(org.linkki.core.message.MessageList) Test(org.junit.Test)

Example 5 with Message

use of org.linkki.core.message.Message 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)

Aggregations

Message (org.linkki.core.message.Message)8 Test (org.junit.Test)7 MessageList (org.linkki.core.message.MessageList)7 MessageMatchers.emptyMessageList (org.linkki.core.matcher.MessageMatchers.emptyMessageList)3 ValidationMarker (org.linkki.util.validation.ValidationMarker)3 Label (com.vaadin.ui.Label)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 ValidationService (org.linkki.core.binding.validation.ValidationService)2 ErrorLevel (com.vaadin.server.ErrorMessage.ErrorLevel)1 Button (com.vaadin.ui.Button)1 Component (com.vaadin.ui.Component)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Stream (java.util.stream.Stream)1 StreamSupport (java.util.stream.StreamSupport)1 Description (org.hamcrest.Description)1 Matcher (org.hamcrest.Matcher)1 Matchers.contains (org.hamcrest.Matchers.contains)1 Matchers.is (org.hamcrest.Matchers.is)1 Matchers.not (org.hamcrest.Matchers.not)1 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)1