use of com.vaadin.flow.server.webcomponent.WebComponentBinding in project flow by vaadin.
the class WebComponentUI method createWebComponentWrapper.
private Element createWebComponentWrapper(WebComponentConfiguration<? extends Component> configuration, WebComponentConnectEvent event) {
Element rootElement = new Element(event.getTag());
WebComponentBinding binding = configuration.createWebComponentBinding(Instantiator.get(this), rootElement, event.getAttributeJson());
WebComponentWrapper wrapper = new WebComponentWrapper(rootElement, binding, getConfigurationRegistry().getShadowDomElements());
return wrapper.getElement();
}
use of com.vaadin.flow.server.webcomponent.WebComponentBinding 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.WebComponentBinding 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.WebComponentBinding in project flow by vaadin.
the class WebComponentWrapperTest method constructWrapperAndGetBinding.
/**
* @param exporter
* exporter of the correct type, defines C
* @param element
* nullable root element
* @param ui
* nullable WebComponentUI
* @param <C>
* type of the exported component
* @return web component wrapper
*/
private <C extends Component> WebComponentBinding<C> constructWrapperAndGetBinding(WebComponentExporter<C> exporter, Element element, WebComponentUI ui) {
if (element == null) {
element = new Element("tag");
}
WebComponentBinding<C> binding = (WebComponentBinding<C>) new WebComponentExporter.WebComponentConfigurationFactory().create(exporter).createWebComponentBinding(new MockInstantiator(), element, Json.createObject());
wrapper = new WebComponentWrapper(element, binding) {
@Override
public Optional<UI> getUI() {
return Optional.of(ui);
}
};
return binding;
}
use of com.vaadin.flow.server.webcomponent.WebComponentBinding 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