Search in sources :

Example 1 with BeanModelType

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());
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) BasicModelType(com.vaadin.flow.templatemodel.BasicModelType) ListModelType(com.vaadin.flow.template.angular.model.ListModelType) ModelType(com.vaadin.flow.templatemodel.ModelType) BeanModelType(com.vaadin.flow.template.angular.model.BeanModelType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ListModelType(com.vaadin.flow.template.angular.model.ListModelType) BeanModelType(com.vaadin.flow.template.angular.model.BeanModelType) Test(org.junit.Test)

Example 2 with BeanModelType

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());
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) BasicModelType(com.vaadin.flow.templatemodel.BasicModelType) ListModelType(com.vaadin.flow.template.angular.model.ListModelType) ModelType(com.vaadin.flow.templatemodel.ModelType) BeanModelType(com.vaadin.flow.template.angular.model.BeanModelType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ListModelType(com.vaadin.flow.template.angular.model.ListModelType) BeanModelType(com.vaadin.flow.template.angular.model.BeanModelType) Test(org.junit.Test)

Example 3 with BeanModelType

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));
}
Also used : TemplateModel(com.vaadin.flow.template.angular.model.TemplateModel) EmptyModelTemplate(com.vaadin.flow.template.angular.model.TemplateModelTest.EmptyModelTemplate) EmptyModel(com.vaadin.flow.template.angular.model.TemplateModelTest.EmptyModel) BeanModelType(com.vaadin.flow.template.angular.model.BeanModelType) Test(org.junit.Test)

Example 4 with BeanModelType

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));
}
Also used : TemplateMap(com.vaadin.flow.internal.nodefeature.TemplateMap) ModelMap(com.vaadin.flow.internal.nodefeature.ModelMap) StateNode(com.vaadin.flow.internal.StateNode) JsExpressionBindingProvider(com.vaadin.flow.template.angular.JsExpressionBindingProvider) BasicModelType(com.vaadin.flow.templatemodel.BasicModelType) ModelType(com.vaadin.flow.templatemodel.ModelType) BeanModelType(com.vaadin.flow.template.angular.model.BeanModelType) TestModelDescriptor(com.vaadin.flow.template.angular.model.TestModelDescriptor) Test(org.junit.Test)

Aggregations

BeanModelType (com.vaadin.flow.template.angular.model.BeanModelType)4 Test (org.junit.Test)4 BasicModelType (com.vaadin.flow.templatemodel.BasicModelType)3 ModelType (com.vaadin.flow.templatemodel.ModelType)3 ListModelType (com.vaadin.flow.template.angular.model.ListModelType)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 StateNode (com.vaadin.flow.internal.StateNode)1 ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)1 TemplateMap (com.vaadin.flow.internal.nodefeature.TemplateMap)1 JsExpressionBindingProvider (com.vaadin.flow.template.angular.JsExpressionBindingProvider)1 TemplateModel (com.vaadin.flow.template.angular.model.TemplateModel)1 EmptyModel (com.vaadin.flow.template.angular.model.TemplateModelTest.EmptyModel)1 EmptyModelTemplate (com.vaadin.flow.template.angular.model.TemplateModelTest.EmptyModelTemplate)1 TestModelDescriptor (com.vaadin.flow.template.angular.model.TestModelDescriptor)1