use of com.vaadin.flow.component.Component in project flow by vaadin.
the class PolymerTemplateTest method assertTemplateInitialization.
private void assertTemplateInitialization(TemplateInitialization template) {
VirtualChildrenList feature = template.getStateNode().getFeature(VirtualChildrenList.class);
assertEquals(2, feature.size());
Optional<Component> child = com.vaadin.flow.dom.Element.get(feature.get(0)).getComponent();
Assert.assertTrue(child.isPresent());
Assert.assertEquals(TestPolymerTemplate.class, child.get().getClass());
child = com.vaadin.flow.dom.Element.get(feature.get(1)).getComponent();
Assert.assertTrue(child.isPresent());
Assert.assertEquals(TemplateChild.class, child.get().getClass());
}
use of com.vaadin.flow.component.Component in project flow by vaadin.
the class ComponentTest method setup.
@Before
public void setup() throws IntrospectionException, InstantiationException, IllegalAccessException, ClassNotFoundException {
component = createComponent();
WHITE_LIST.add("visible");
addProperties();
BeanInfo componentInfo = Introspector.getBeanInfo(component.getClass());
Stream.of(componentInfo.getPropertyDescriptors()).filter(descriptor -> !WHITE_LIST.contains(descriptor.getName())).forEach(this::assertProperty);
}
use of com.vaadin.flow.component.Component in project flow by vaadin.
the class ElementUtilTest method attachToComponent.
@Test
public void attachToComponent() {
Element e = ElementFactory.createDiv();
Component c = Mockito.mock(Component.class);
ElementUtil.setComponent(e, c);
Assert.assertEquals(c, e.getComponent().get());
}
use of com.vaadin.flow.component.Component in project flow by vaadin.
the class ElementUtilTest method attachTwiceToComponent.
@Test(expected = IllegalStateException.class)
public void attachTwiceToComponent() {
Element e = ElementFactory.createDiv();
Component c = Mockito.mock(Component.class);
ElementUtil.setComponent(e, c);
ElementUtil.setComponent(e, c);
}
use of com.vaadin.flow.component.Component in project flow by vaadin.
the class TemplateInitializer method injectTemplateElement.
@SuppressWarnings("unchecked")
private void injectTemplateElement(Element element, Field field) {
Class<?> fieldType = field.getType();
if (Component.class.isAssignableFrom(fieldType)) {
CustomElementRegistry.getInstance().wrapElementIfNeeded(element);
Component component;
Optional<Component> wrappedComponent = element.getComponent();
if (wrappedComponent.isPresent()) {
component = wrappedComponent.get();
} else {
Class<? extends Component> componentType = (Class<? extends Component>) fieldType;
component = Component.from(element, componentType);
}
ReflectTools.setJavaFieldValue(template, field, component);
} else if (Element.class.isAssignableFrom(fieldType)) {
ReflectTools.setJavaFieldValue(template, field, element);
} else {
String msg = String.format("The field '%s' in '%s' has an @'%s' " + "annotation but the field type '%s' " + "does not extend neither '%s' nor '%s'", field.getName(), templateClass.getName(), Id.class.getSimpleName(), fieldType.getName(), Component.class.getSimpleName(), Element.class.getSimpleName());
throw new IllegalArgumentException(msg);
}
}
Aggregations