Search in sources :

Example 1 with PropertyConfigurationImpl

use of com.vaadin.flow.server.webcomponent.PropertyConfigurationImpl in project flow by vaadin.

the class WebComponentTest method setProperty_throwsWhenGivenWrongPropertyTypeAsParameter.

@Test
public void setProperty_throwsWhenGivenWrongPropertyTypeAsParameter() {
    exception.expect(IllegalArgumentException.class);
    exception.expectMessage("Property 'property' of type " + "'java.lang.Integer' cannot be assigned value of type " + "'java.lang.String'!");
    PropertyConfigurationImpl<Component, Integer> intConfiguration = new PropertyConfigurationImpl<>(Component.class, "property", Integer.class, 0);
    WebComponentBinding<Component> binding = new WebComponentBinding<>(mock(Component.class));
    binding.bindProperty(intConfiguration, false, null);
    WebComponent<Component> webComponent = new WebComponent<>(binding, new Element("tag"));
    PropertyConfigurationImpl<Component, String> stringConfiguration = new PropertyConfigurationImpl<>(Component.class, "property", String.class, "value");
    webComponent.setProperty(stringConfiguration, "newValue");
}
Also used : WebComponentBinding(com.vaadin.flow.server.webcomponent.WebComponentBinding) Element(com.vaadin.flow.dom.Element) PropertyConfigurationImpl(com.vaadin.flow.server.webcomponent.PropertyConfigurationImpl) Component(com.vaadin.flow.component.Component) Test(org.junit.Test)

Example 2 with PropertyConfigurationImpl

use of com.vaadin.flow.server.webcomponent.PropertyConfigurationImpl in project flow by vaadin.

the class WebComponentTest method setProperty_throwsOnUnknownProperty.

@Test
public void setProperty_throwsOnUnknownProperty() {
    exception.expect(IllegalArgumentException.class);
    exception.expectMessage("WebComponent does not have a property identified");
    WebComponentBinding<Component> binding = new WebComponentBinding<>(mock(Component.class));
    WebComponent<Component> webComponent = new WebComponent<>(binding, new Element("tag"));
    PropertyConfigurationImpl<Component, String> configuration = new PropertyConfigurationImpl<>(Component.class, "property", String.class, "value");
    webComponent.setProperty(configuration, "newValue");
}
Also used : WebComponentBinding(com.vaadin.flow.server.webcomponent.WebComponentBinding) Element(com.vaadin.flow.dom.Element) PropertyConfigurationImpl(com.vaadin.flow.server.webcomponent.PropertyConfigurationImpl) Component(com.vaadin.flow.component.Component) Test(org.junit.Test)

Example 3 with PropertyConfigurationImpl

use of com.vaadin.flow.server.webcomponent.PropertyConfigurationImpl in project flow by vaadin.

the class WebComponentTest method setProperty_attemptsToWriteSupportedTypes.

@Test
public void setProperty_attemptsToWriteSupportedTypes() {
    Element element = spy(new Element("tag"));
    // configurations
    PropertyConfigurationImpl<Component, Integer> intConfiguration = new PropertyConfigurationImpl<>(Component.class, "int", Integer.class, 0);
    PropertyConfigurationImpl<Component, Double> doubleConfiguration = new PropertyConfigurationImpl<>(Component.class, "double", Double.class, 0.0);
    PropertyConfigurationImpl<Component, String> stringConfiguration = new PropertyConfigurationImpl<>(Component.class, "string", String.class, "");
    PropertyConfigurationImpl<Component, Boolean> booleanConfiguration = new PropertyConfigurationImpl<>(Component.class, "boolean", Boolean.class, false);
    PropertyConfigurationImpl<Component, JsonValue> jsonConfiguration = new PropertyConfigurationImpl<>(Component.class, "json", JsonValue.class, Json.createNull());
    // binding
    WebComponentBinding<Component> binding = new WebComponentBinding<>(mock(Component.class));
    binding.bindProperty(intConfiguration, false, null);
    binding.bindProperty(doubleConfiguration, false, null);
    binding.bindProperty(stringConfiguration, false, null);
    binding.bindProperty(booleanConfiguration, false, null);
    binding.bindProperty(jsonConfiguration, false, null);
    // test
    WebComponent<Component> webComponent = new WebComponent<>(binding, element);
    webComponent.setProperty(intConfiguration, 1);
    verify(element, Mockito.times(1)).executeJs(ArgumentMatchers.anyString(), ArgumentMatchers.any(), ArgumentMatchers.any());
    webComponent.setProperty(doubleConfiguration, 1.0);
    verify(element, Mockito.times(2)).executeJs(ArgumentMatchers.anyString(), ArgumentMatchers.any(), ArgumentMatchers.any());
    webComponent.setProperty(stringConfiguration, "asd");
    verify(element, Mockito.times(3)).executeJs(ArgumentMatchers.anyString(), ArgumentMatchers.any(), ArgumentMatchers.any());
    webComponent.setProperty(booleanConfiguration, true);
    verify(element, Mockito.times(4)).executeJs(ArgumentMatchers.anyString(), ArgumentMatchers.any(), ArgumentMatchers.any());
    // JsonValue has a different number of arguments
    webComponent.setProperty(jsonConfiguration, Json.create(true));
    verify(element, Mockito.times(5)).executeJs(ArgumentMatchers.anyString(), ArgumentMatchers.any());
}
Also used : Element(com.vaadin.flow.dom.Element) JsonValue(elemental.json.JsonValue) PropertyConfigurationImpl(com.vaadin.flow.server.webcomponent.PropertyConfigurationImpl) WebComponentBinding(com.vaadin.flow.server.webcomponent.WebComponentBinding) Component(com.vaadin.flow.component.Component) Test(org.junit.Test)

Aggregations

Component (com.vaadin.flow.component.Component)3 Element (com.vaadin.flow.dom.Element)3 PropertyConfigurationImpl (com.vaadin.flow.server.webcomponent.PropertyConfigurationImpl)3 WebComponentBinding (com.vaadin.flow.server.webcomponent.WebComponentBinding)3 Test (org.junit.Test)3 JsonValue (elemental.json.JsonValue)1