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");
}
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");
}
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());
}
Aggregations