EntityModelFactoryImpl implements EntityModelFactory, EntityModelConstruct { @Override public <T> EntityModel<T> getModel(Class<T> entityClass) { return getModel(entityClass.getSimpleName(), entityClass); } EntityModelFactoryImpl();  EntityModelFactoryImpl(EntityModelFactory... delegatedModelFactories); @Override boolean canProvideModel(String reference, Class<T> entityClass); @Override EntityModel<?> constructNestedEntityModel(EntityModelFactory master, Class<?> type, String reference); MessageService getMessageService(); @Override EntityModel<T> getModel(Class<T> entityClass); @Override @SuppressWarnings({ "unchecked" }) EntityModel<T> getModel(String reference, Class<T> entityClass); boolean hasModel(String reference);  }
@Test public void testPropertyOrder() { EntityModel<Entity2> model = factory.getModel(Entity2.class); assertNotNull(model); AttributeModel nameModel = model.getAttributeModel("name"); assertEquals(0, nameModel.getOrder().intValue()); AttributeModel birthDateModel = model.getAttributeModel("birthDate"); assertEquals(1, birthDateModel.getOrder().intValue()); AttributeModel age = model.getAttributeModel("age"); assertEquals(2, age.getOrder().intValue()); }
@Test public void testAttributeGroups() { EntityModel<Entity3> model = factory.getModel(Entity3.class); assertNotNull(model); assertEquals(3, model.getAttributeGroups().size()); String group1 = model.getAttributeGroups().get(0); assertEquals("group1.key", group1); List<AttributeModel> models = model.getAttributeModelsForGroup(group1); assertEquals("name", models.get(0).getName()); assertEquals(SearchMode.ALWAYS, models.get(0).getSearchMode()); String group2 = model.getAttributeGroups().get(1); assertEquals("group2.key", group2); List<AttributeModel> models2 = model.getAttributeModelsForGroup(group2); assertEquals("age", models2.get(0).getName()); assertTrue(models2.get(0).isRequiredForSearching()); assertEquals(1, model.getRequiredForSearchingAttributeModels().size()); List<AttributeModel> models3 = model.getAttributeModelsForGroup(EntityModel.DEFAULT_GROUP); assertEquals("advancedAge", models3.get(0).getName()); assertTrue(model.isAttributeGroupVisible(EntityModel.DEFAULT_GROUP, true)); assertTrue(model.isAttributeGroupVisible(EntityModel.DEFAULT_GROUP, false)); AttributeModel advancedAgeModel = model.getAttributeModel("advancedAge"); assertEquals(SearchMode.ADVANCED, advancedAgeModel.getSearchMode()); }
@Test public void testAnnotationOverrides() { EntityModel<Entity3> model = factory.getModel(Entity3.class); assertNotNull(model); assertEquals("dis", model.getDisplayName(locale)); assertEquals("diss", model.getDisplayNamePlural(locale)); assertEquals("desc", model.getDescription(locale)); assertEquals("prop", model.getDisplayProperty()); AttributeModel nameModel = model.getAttributeModel("name"); assertNotNull(nameModel); assertEquals("Bas", nameModel.getDefaultValue()); assertEquals("Naampje", nameModel.getDisplayName(locale)); assertEquals("Test", nameModel.getDescription(locale)); assertEquals("Prompt", nameModel.getPrompt(locale)); assertEquals("myStyle", nameModel.getStyles()); assertEquals(String.class, nameModel.getType()); assertNull(nameModel.getDisplayFormat()); assertEquals(AttributeType.BASIC, nameModel.getAttributeType()); assertFalse(nameModel.isSearchCaseSensitive()); assertFalse(nameModel.isSearchPrefixOnly()); assertFalse(nameModel.isSortable()); assertTrue(nameModel.isSearchable()); assertTrue(nameModel.isMainAttribute()); assertEquals(EditableType.READ_ONLY, nameModel.getEditableType()); AttributeModel ageModel = model.getAttributeModel("age"); assertNotNull(ageModel); assertTrue(ageModel.isSearchCaseSensitive()); assertTrue(ageModel.isSearchPrefixOnly()); assertFalse(ageModel.isThousandsGrouping()); AttributeModel entityModel = model.getAttributeModel("entity2"); assertEquals(AttributeType.MASTER, entityModel.getAttributeType()); assertTrue(entityModel.isComplexEditable()); assertTrue(entityModel.isNavigable()); AttributeModel entityListModel = model.getAttributeModel("entityList"); assertEquals(AttributeType.DETAIL, entityListModel.getAttributeType()); AttributeModel birthDateModel = model.getAttributeModel("birthDate"); assertEquals("dd/MM/yyyy", birthDateModel.getDisplayFormat()); AttributeModel derivedModel = model.getAttributeModel("derived"); assertNotNull(derivedModel); assertEquals("deri", derivedModel.getDisplayName(locale)); AttributeModel weightModel = model.getAttributeModel("weight"); assertNotNull(weightModel); assertEquals(4, weightModel.getPrecision()); assertTrue(weightModel.isCurrency()); }
@Test public void testReference() { EntityModel<Entity6> model = factory.getModel("Special", Entity6.class); assertEquals("Special", model.getDisplayName(locale)); assertEquals("SpecialPlural", model.getDisplayNamePlural(locale)); }
@Test public void testMessageOverrides() { EntityModel<Entity6> model = factory.getModel(Entity6.class); assertNotNull(model); assertEquals("Override", model.getDisplayName(locale)); assertEquals("Overrides", model.getDisplayNamePlural(locale)); assertEquals("Description override", model.getDescription(locale)); assertEquals("Prop", model.getDisplayProperty()); AttributeModel nameModel = model.getAttributeModel("name"); assertNotNull(nameModel); assertTrue(nameModel.isSearchCaseSensitive()); assertTrue(nameModel.isSearchPrefixOnly()); assertEquals("customValue", nameModel.getCustomSetting("custom")); assertEquals(4, nameModel.getCustomSetting("custom2")); assertEquals(true, nameModel.getCustomSetting("custom3")); assertEquals("Override", nameModel.getDisplayName(locale)); assertEquals("Prompt override", nameModel.getPrompt(locale)); assertEquals("Style override", nameModel.getStyles()); assertEquals(EditableType.CREATE_ONLY, nameModel.getEditableType()); assertEquals("Style override", nameModel.getStyles()); assertFalse(model.usesDefaultGroupOnly()); String group1 = model.getAttributeGroups().get(0); assertEquals("group1", model.getAttributeGroups().get(0)); String group2 = model.getAttributeGroups().get(1); assertEquals("group2", group2); assertEquals("age", model.getAttributeModelsForGroup(group2).get(0).getName()); assertEquals("birthDate", model.getAttributeModelsForGroup(group2).get(1).getName()); String group3 = model.getAttributeGroups().get(2); assertEquals(EntityModel.DEFAULT_GROUP, group3); }
@Test public void testLob() { EntityModel<Entity5> model = factory.getModel(Entity5.class); AttributeModel attributeModel = model.getAttributeModel("logo"); assertEquals(AttributeType.LOB, attributeModel.getAttributeType()); assertTrue(attributeModel.isImage()); assertTrue(attributeModel.getAllowedExtensions().contains("gif")); assertTrue(attributeModel.getAllowedExtensions().contains("bmp")); }
@Test public void testAssertTrueIgnored() { EntityModel<Entity5> model = factory.getModel(Entity5.class); AttributeModel attributeModel = model.getAttributeModel("someValidation"); assertNull(attributeModel); }
@Test public void testId() { EntityModel<EntityParent> model = factory.getModel(EntityParent.class); AttributeModel attributeModel = model.getIdAttributeModel(); assertNotNull(attributeModel); }
@Test public void testGetAttributeModelsForType() { EntityModel<EntityChild> model = factory.getModel(EntityChild.class); List<AttributeModel> models = model.getAttributeModelsForType(AttributeType.MASTER, EntityParent.class); assertNotNull(models); assertEquals(2, models.size()); assertEquals("parent", models.get(0).getName()); model = factory.getModel(EntityChild.class); models = model.getAttributeModelsForType(AttributeType.MASTER, null); assertNotNull(models); assertEquals(2, models.size()); assertEquals("parent", models.get(0).getName()); EntityModel<EntityParent> pmodel = factory.getModel(EntityParent.class); models = pmodel.getAttributeModelsForType(null, EntityChild.class); assertNotNull(models); assertEquals(1, models.size()); assertEquals("children", models.get(0).getName()); }
@Test public void testNestedAttributes() { EntityModel<EntityParent> parentModel = factory.getModel(EntityParent.class); AttributeModel pm = parentModel.getAttributeModel("name"); assertNotNull(pm); assertEquals("name", pm.getName()); assertTrue(pm.isVisibleInGrid()); EntityModel<EntityChild> model = factory.getModel(EntityChild.class); AttributeModel am = model.getAttributeModel("parent.name"); assertNotNull(am); assertEquals("name", am.getName()); assertEquals(EntityParent.class, am.getEntityModel().getEntityClass()); assertFalse(am.isVisibleInGrid()); }
@Test public void testSortOrder() { EntityModel<EntityParent> model = factory.getModel(EntityParent.class); assertNotNull(model.getSortOrder()); assertEquals(2, model.getSortOrder().size()); AttributeModel amName = model.getAttributeModel("name"); AttributeModel amId = model.getAttributeModel("id"); assertEquals(false, model.getSortOrder().get(amName)); assertEquals(true, model.getSortOrder().get(amId)); EntityModel<EntitySortError> semodel = factory.getModel(EntitySortError.class); assertNotNull(semodel.getSortOrder()); assertEquals(1, semodel.getSortOrder().size()); amName = semodel.getAttributeModel("code"); assertEquals(true, semodel.getSortOrder().get(amName)); }
@Test public void testSelectMode() { EntityModel<Entity7> model = factory.getModel(Entity7.class); AttributeModel am = model.getAttributeModel("entity6"); assertEquals(AttributeSelectMode.LOOKUP, am.getSelectMode()); assertEquals(AttributeSelectMode.LOOKUP, am.getSearchSelectMode()); assertEquals(AttributeSelectMode.LOOKUP, am.getGridSelectMode()); AttributeModel am2 = model.getAttributeModel("entity5"); assertEquals(AttributeSelectMode.COMBO, am2.getSelectMode()); assertEquals(AttributeSelectMode.LOOKUP, am2.getSearchSelectMode()); assertEquals(AttributeSelectMode.COMBO, am2.getGridSelectMode()); AttributeModel am3 = model.getAttributeModel("entity52"); assertEquals(AttributeSelectMode.COMBO, am3.getSelectMode()); assertEquals(AttributeSelectMode.TOKEN, am3.getSearchSelectMode()); assertEquals(AttributeSelectMode.LIST, am3.getGridSelectMode()); }
@Test public void testDateType() { EntityModel<Entity8> model = factory.getModel(Entity8.class); AttributeModel am = model.getAttributeModel("date1"); assertEquals(AttributeDateType.DATE, am.getDateType()); assertEquals("dd-MM-yyyy", am.getDisplayFormat()); am = model.getAttributeModel("date2"); assertEquals(AttributeDateType.TIMESTAMP, am.getDateType()); assertEquals("dd-MM-yyyy HH:mm:ss", am.getDisplayFormat()); am = model.getAttributeModel("date3"); assertEquals(AttributeDateType.TIME, am.getDateType()); assertEquals("HH:mm:ss", am.getDisplayFormat()); am = model.getAttributeModel("date4"); assertEquals(AttributeDateType.TIME, am.getDateType()); assertEquals("ss:mm:HH", am.getDisplayFormat()); am = model.getAttributeModel("date5"); assertEquals(AttributeDateType.DATE, am.getDateType()); assertEquals("yyyy-dd-MM ss:mm:HH", am.getDisplayFormat()); am = model.getAttributeModel("date6"); assertEquals(AttributeDateType.DATE, am.getDateType()); assertEquals("dd-MM-yyyy", am.getDisplayFormat()); }
@Test public void testElementCollection() { EntityModel<Entity9> model = factory.getModel(Entity9.class); AttributeModel am = model.getAttributeModel("elements"); assertEquals(AttributeType.ELEMENT_COLLECTION, am.getAttributeType()); assertEquals("element_table", am.getCollectionTableName()); assertEquals("element", am.getCollectionTableFieldName()); AttributeModel am2 = model.getAttributeModel("longElements"); assertEquals(AttributeType.ELEMENT_COLLECTION, am2.getAttributeType()); assertEquals(100L, am2.getMinValue().longValue()); assertEquals(500L, am2.getMaxValue().longValue()); }
@Test public void testGroupTogetherWith() { EntityModel<Entity10> model = factory.getModel(Entity10.class); AttributeModel am = model.getAttributeModel("attribute1"); assertEquals(1, am.getGroupTogetherWith().size()); assertEquals("attribute2", am.getGroupTogetherWith().get(0)); }
@Test public void testGroupTogetherWithWrongOrder() { EntityModel<Entity11> model = factory.getModel(Entity11.class); AttributeModel am = model.getAttributeModel("attribute2"); assertEquals(1, am.getGroupTogetherWith().size()); assertEquals("attribute1", am.getGroupTogetherWith().get(0)); AttributeModel am1 = model.getAttributeModel("attribute1"); assertTrue(am1.isAlreadyGrouped()); }
@Test public void testCascade() { EntityModel<Entity12> model = factory.getModel(Entity12.class); AttributeModel am = model.getAttributeModel("attribute1"); assertTrue(am.getCascadeAttributes().contains("attribute2")); assertEquals("somePath", am.getCascadeFilterPath("attribute2")); assertEquals(CascadeMode.BOTH, am.getCascadeMode("attribute2")); assertEquals(1, model.getCascadeAttributeModels().size()); assertEquals("attribute1", model.getCascadeAttributeModels().iterator().next().getPath()); }
@Test public void testCascadeMessageBundle() { EntityModel<Entity13> model = factory.getModel(Entity13.class); AttributeModel am = model.getAttributeModel("attribute1"); assertTrue(am.getCascadeAttributes().contains("attribute2")); assertEquals("somePath", am.getCascadeFilterPath("attribute2")); assertEquals(CascadeMode.EDIT, am.getCascadeMode("attribute2")); }
@Test public void testJava8DateTypes() { EntityModel<Entity14> model = factory.getModel(Entity14.class); AttributeModel am1 = model.getAttributeModel("localDate"); assertNotNull(am1); assertEquals("dd/MM/yyyy", am1.getDisplayFormat()); assertEquals(AttributeDateType.DATE, am1.getDateType()); assertEquals(DateUtils.createLocalDate("01011980"), am1.getDefaultValue()); AttributeModel am2 = model.getAttributeModel("localTime"); assertNotNull(am2); assertEquals("HH-mm-ss", am2.getDisplayFormat()); assertEquals(AttributeDateType.TIME, am2.getDateType()); assertEquals(DateUtils.createLocalTime("121314"), am2.getDefaultValue()); AttributeModel am3 = model.getAttributeModel("localDateTime"); assertNotNull(am3); assertEquals("dd/MM/yyyy HH-mm-ss", am3.getDisplayFormat()); assertEquals(AttributeDateType.TIMESTAMP, am3.getDateType()); assertEquals(DateUtils.createLocalDateTime("01011980 121314"), am3.getDefaultValue()); AttributeModel am4 = model.getAttributeModel("zonedDateTime"); assertNotNull(am4); assertEquals("dd-MM-yyyy HH:mm:ssZ", am4.getDisplayFormat()); assertEquals(AttributeDateType.TIMESTAMP, am4.getDateType()); assertEquals(DateUtils.createZonedDateTime("01-01-2017 12:00:00+0100"), am4.getDefaultValue()); }