use of com.vaadin.flow.template.angular.model.BeanModelType in project flow by vaadin.
the class ModelDescriptorTest method listInsideList.
@Test
public void listInsideList() {
ModelDescriptor<?> descriptor = ModelDescriptor.get(ListInsideListBeanModel.class);
Assert.assertEquals(1, descriptor.getPropertyNames().count());
ListModelType<?> listPropertyType = (ListModelType<?>) descriptor.getPropertyType("beans");
Type javaType = listPropertyType.getJavaType();
Assert.assertTrue("Expected instanceof ParameterizedType for List", javaType instanceof ParameterizedType);
javaType = ((ParameterizedType) javaType).getActualTypeArguments()[0];
Assert.assertTrue("Expected instanceof ParameterizedType for List in List", javaType instanceof ParameterizedType);
Assert.assertEquals(Bean.class, ((ParameterizedType) javaType).getActualTypeArguments()[0]);
Assert.assertTrue(listPropertyType.getItemType() instanceof ListModelType<?>);
ListModelType<?> type = (ListModelType<?>) listPropertyType.getItemType();
Assert.assertTrue(type.getItemType() instanceof BeanModelType<?>);
BeanModelType<?> modelType = (BeanModelType<?>) type.getItemType();
Assert.assertSame(Bean.class, modelType.getProxyType());
}
use of com.vaadin.flow.template.angular.model.BeanModelType in project flow by vaadin.
the class ModelDescriptorTest method listInsideListInsideList.
@Test
public void listInsideListInsideList() {
ModelDescriptor<?> descriptor = ModelDescriptor.get(ListInsideListInsideList.class);
Assert.assertEquals(1, descriptor.getPropertyNames().count());
ListModelType<?> listPropertyType = (ListModelType<?>) descriptor.getPropertyType("beans");
Type javaType = listPropertyType.getJavaType();
Assert.assertTrue("Expected instanceof ParameterizedType for List", javaType instanceof ParameterizedType);
javaType = ((ParameterizedType) javaType).getActualTypeArguments()[0];
Assert.assertTrue("Expected instanceof ParameterizedType for List in List", javaType instanceof ParameterizedType);
javaType = ((ParameterizedType) javaType).getActualTypeArguments()[0];
Assert.assertTrue("Expected instanceof ParameterizedType for List in List in List", javaType instanceof ParameterizedType);
Assert.assertEquals(Bean.class, ((ParameterizedType) javaType).getActualTypeArguments()[0]);
Assert.assertTrue(listPropertyType.getItemType() instanceof ListModelType<?>);
ListModelType<?> type = (ListModelType<?>) listPropertyType.getItemType();
Assert.assertTrue(type.getItemType() instanceof ListModelType<?>);
type = (ListModelType<?>) type.getItemType();
Assert.assertTrue(type.getItemType() instanceof BeanModelType<?>);
BeanModelType<?> modelType = (BeanModelType<?>) type.getItemType();
Assert.assertSame(Bean.class, modelType.getProxyType());
}
use of com.vaadin.flow.template.angular.model.BeanModelType in project flow by vaadin.
the class TemplateModelProxyHandlerTest method testEquals.
@Test
public void testEquals() {
EmptyModelTemplate emptyModelTemplate1 = new EmptyModelTemplate();
EmptyModelTemplate emptyModelTemplate2 = new EmptyModelTemplate();
TemplateModel m1 = emptyModelTemplate1.getModel();
TemplateModel m2 = emptyModelTemplate2.getModel();
Assert.assertSame(m1.getClass(), m2.getClass());
Assert.assertFalse(m1.equals(null));
Assert.assertFalse(m1.equals("foobar"));
Assert.assertFalse(m1.equals(m2));
ModelDescriptor<EmptyModel> realModelType = ModelDescriptor.get(EmptyModel.class);
Assert.assertTrue(m1.equals(TemplateModelProxyHandler.createModelProxy(emptyModelTemplate1.getElement().getNode(), realModelType)));
BeanModelType<TemplateModel> wrongModelType = new BeanModelType<>(TemplateModel.class, PropertyFilter.ACCEPT_ALL);
Assert.assertFalse(m1.equals(TemplateModelProxyHandler.createModelProxy(emptyModelTemplate1.getElement().getNode(), wrongModelType)));
Assert.assertTrue(m2.equals(m2));
}
use of com.vaadin.flow.template.angular.model.BeanModelType in project flow by vaadin.
the class JsExpressionBindingProviderTest method jsExpressionWithSubProperty.
@Test
public void jsExpressionWithSubProperty() {
JsExpressionBindingProvider binding = new JsExpressionBindingProvider("bean.property");
StateNode beanNode = new StateNode(ModelMap.class);
ModelMap beanModel = ModelMap.get(beanNode);
beanModel.setValue("property", "foo");
StateNode rootNode = new StateNode(TemplateMap.class, ModelMap.class);
Map<String, ModelType> beanProperties = Collections.singletonMap("property", BasicModelType.get(String.class).get());
Map<String, ModelType> modelProperties = Collections.singletonMap("bean", new BeanModelType<>(Object.class, beanProperties));
rootNode.getFeature(TemplateMap.class).setModelDescriptor(new TestModelDescriptor(modelProperties));
ModelMap.get(rootNode).setValue("bean", beanNode);
Assert.assertEquals("foo", binding.getValue(rootNode));
}
Aggregations