SourceDao { public BeanDescription processJavaInput(InputStream in) throws ParseException { final BeanDescription descriptionToFill = new BeanDescription(); CompilationUnit cu = JavaParser.parse(in, "UTF-8"); (new VoidVisitorAdapter<Object>() { @Override public void visit(MethodDeclaration m, Object arg) { if (m.getAnnotations() != null) { log.debug(m.getName() + ":"); String methodName = m.getName(); if (methodName != null && methodName.length() >= 4 && (methodName.startsWith("set") || methodName.startsWith("get"))) { String propName = methodName.substring(3, 4).toLowerCase() + methodName.substring(4); for (AnnotationExpr an : m.getAnnotations()) { log.debug(" " + an); String annoName = an.getName().toString(); PropertyDescription newProp = descriptionToFill.getProperty(propName); if (newProp == null) { newProp = new PropertyDescription(descriptionToFill, propName, m.getType().toString()); descriptionToFill.addProperty(newProp); } if (MapProperty.class.getSimpleName().equals(annoName)) { processMapPropertyAnnotation(descriptionToFill, newProp, an); } if (DisplayProperty.class.getSimpleName().equals(annoName)) { processDisplayPropertyAnnotation(descriptionToFill, newProp, an); } } } } if (m.getName().startsWith("get")) { descriptionToFill.addGetter(m.getName()); } if (m.getName().startsWith("set")) { descriptionToFill.addSetter(m.getName()); } super.visit(m, arg); } @Override public void visit(FieldDeclaration f, Object arg) { if (f.getVariables().size() > 0 && f.getAnnotations() != null) { log.debug(f.getVariables().get(0).toString() + ":"); String fieldName = f.getVariables().get(0).getId().toString(); if (fieldName != null && fieldName.length() >= 1) { for (AnnotationExpr an : f.getAnnotations()) { log.debug(" " + an); String annoName = an.getName().toString(); if (MapProperty.class.getSimpleName().equals(annoName)) { PropertyDescription newProp = descriptionToFill.getProperty(fieldName); if (newProp == null) { newProp = new PropertyDescription(descriptionToFill, fieldName, f.getType().toString()); descriptionToFill.addProperty(newProp); } processMapPropertyAnnotation(descriptionToFill, newProp, an); } if (DisplayProperty.class.getSimpleName().equals(annoName)) { PropertyDescription newProp = descriptionToFill.getProperty(fieldName); if (newProp == null) { newProp = new PropertyDescription(descriptionToFill, fieldName, f.getType().toString()); descriptionToFill.addProperty(newProp); } processDisplayPropertyAnnotation(descriptionToFill, newProp, an); } } } } super.visit(f, arg); } private void processMapPropertyAnnotation(final BeanDescription descriptionToFill, PropertyDescription newProp, AnnotationExpr an) { newProp.setMapped(true); if (an instanceof NormalAnnotationExpr) { for (MemberValuePair pair : ((NormalAnnotationExpr) an).getPairs()) { if ("profileSettings".equals(pair.getName())) { if (pair.getValue() instanceof ArrayInitializerExpr) { ArrayInitializerExpr array = (ArrayInitializerExpr) pair.getValue(); for (Expression arrayexp : array.getValues()) { processMapPropertyProfileAnnotation(newProp, arrayexp); } } else { processMapPropertyProfileAnnotation(newProp, pair.getValue()); } } else if ("ignore".equals(pair.getName())) { newProp.setMapped(!Boolean.valueOf(pair.getValue().toString())); } } } } private void processMapPropertyProfileAnnotation(PropertyDescription newProp, Expression arrayexp) { log.debug(" " + arrayexp); String profileName = null; for (MemberValuePair innerpair : ((NormalAnnotationExpr) arrayexp).getPairs()) { if ("profileName".equals(innerpair.getName())) { profileName = ((StringLiteralExpr) innerpair.getValue()).getValue(); } } MapPropertyProfileDescription newProfile = newProp.getMapPropertyProfile(profileName); for (MemberValuePair innerpair : ((NormalAnnotationExpr) arrayexp).getPairs()) { if ("deep".equals(innerpair.getName())) { newProfile.setDeep(Boolean.valueOf(innerpair.getValue().toString())); } else if ("exclude".equals(innerpair.getName())) { newProfile.setExcluded(Boolean.valueOf(innerpair.getValue().toString())); } else if ("include".equals(innerpair.getName())) { newProfile.setIncluded(Boolean.valueOf(innerpair.getValue().toString())); } else if ("mandatory".equals(innerpair.getName())) { newProfile.setMandatory(Boolean.valueOf(innerpair.getValue().toString())); } else if ("profileName".equals(innerpair.getName())) { } else if ("readonly".equals(innerpair.getName())) { newProfile.setReadonly(Boolean.valueOf(innerpair.getValue().toString())); } else if ("targetPropertyName".equals(innerpair.getName())) { newProfile.setTargetPropertyName(((StringLiteralExpr) innerpair.getValue()).getValue()); } else if ("targetPropertyClassName".equals(innerpair.getName())) { newProfile.setTargetPropertyClassName(((StringLiteralExpr) innerpair.getValue()).getValue()); } } } private void processDisplayPropertyAnnotation(final BeanDescription descriptionToFill, PropertyDescription newProp, AnnotationExpr an) { newProp.setDisplayed(true); if (an instanceof NormalAnnotationExpr) { for (MemberValuePair pair : ((NormalAnnotationExpr) an).getPairs()) { if ("captionProp".equals(pair.getName())) { newProp.setCaptionProp(((StringLiteralExpr) pair.getValue()).getValue()); } else if ("converterClassName".equals(pair.getName())) { newProp.setConverterClassName(((StringLiteralExpr) pair.getValue()).getValue()); descriptionToFill.addImport(createConverterImportString(newProp.getConverterClassName())); } else if ("captionText".equals(pair.getName())) { newProp.setCaptionText(((StringLiteralExpr) pair.getValue()).getValue()); } else if ("profileSettings".equals(pair.getName())) { if (pair.getValue() instanceof ArrayInitializerExpr) { ArrayInitializerExpr array = (ArrayInitializerExpr) pair.getValue(); for (Expression arrayexp : array.getValues()) { processDisplayPropertyProfileAnnotation(newProp, arrayexp); } } else { processDisplayPropertyProfileAnnotation(newProp, pair.getValue()); } } else if ("ignore".equals(pair.getName())) { newProp.setDisplayed(!Boolean.valueOf(pair.getValue().toString())); } else if ("sortable".equals(pair.getName())) { newProp.setSortable(Boolean.valueOf(pair.getValue().toString())); } } } } private void processDisplayPropertyProfileAnnotation(PropertyDescription newProp, Expression arrayexp) { log.debug(" " + arrayexp); String profileName = Constants.DEFAULT_DISPLAY_PROFILE; for (MemberValuePair innerpair : ((NormalAnnotationExpr) arrayexp).getPairs()) { if ("profileName".equals(innerpair.getName())) { profileName = ((StringLiteralExpr) innerpair.getValue()).getValue(); } } DisplayPropertyProfileDescription newProfile = newProp.getDisplayPropertyProfile(profileName); for (MemberValuePair innerpair : ((NormalAnnotationExpr) arrayexp).getPairs()) { if ("customClassName".equals(innerpair.getName())) { newProfile.setCustomClassName(((StringLiteralExpr) innerpair.getValue()).getValue()); } else if ("customAuswahlAusListe".equals(innerpair.getName())) { newProfile.setCustomAuswahlAusListe(Boolean.valueOf(innerpair.getValue().toString())); } else if ("customMultiAuswahlAusListe".equals(innerpair.getName())) { newProfile.setCustomMultiAuswahlAusListe(Boolean.valueOf(innerpair.getValue().toString())); } else if ("customUnboxed".equals(innerpair.getName())) { newProfile.setCustomUnboxed(Boolean.valueOf(innerpair.getValue().toString())); } else if ("exclude".equals(innerpair.getName())) { newProfile.setExcluded(Boolean.valueOf(innerpair.getValue().toString())); } else if ("fieldType".equals(innerpair.getName())) { newProfile.setFieldType(FieldType.valueOf(innerpair.getValue().toString().replace("FieldType.", ""))); } else if ("include".equals(innerpair.getName())) { newProfile.setIncluded(Boolean.valueOf(innerpair.getValue().toString())); } else if ("order".equals(innerpair.getName())) { newProfile.setOrder(Integer.parseInt(innerpair.getValue().toString())); } else if ("profileName".equals(innerpair.getName())) { } else if ("readOnly".equals(innerpair.getName())) { newProfile.setReadOnly(Boolean.valueOf(innerpair.getValue().toString())); } else if ("required".equals(innerpair.getName())) { newProfile.setRequired(Boolean.valueOf(innerpair.getValue().toString())); } else if ("sectionName".equals(innerpair.getName())) { newProfile.setSectionName(((StringLiteralExpr) innerpair.getValue()).getValue()); } else if ("showInDetail".equals(innerpair.getName())) { newProfile.setShowInDetail(Boolean.valueOf(innerpair.getValue().toString())); } else if ("showInTable".equals(innerpair.getName())) { newProfile.setShowInTable(Boolean.valueOf(innerpair.getValue().toString())); } else if ("tableExpandRatio".equals(innerpair.getName())) { newProfile.setTableExpandRatio(Float.parseFloat(innerpair.getValue().toString())); } else if ("allowTextInput".equals(innerpair.getName())) { newProfile.setAllowTextInput(Boolean.valueOf(innerpair.getValue().toString())); } else if ("useAsSummary".equals(innerpair.getName())) { newProfile.setUseAsSummary(Boolean.valueOf(innerpair.getValue().toString())); } } } @Override public void visit(EnumConstantDeclaration c, Object arg) { log.debug(c.toString() + ":"); String fieldName = c.getName(); if (fieldName != null && fieldName.length() >= 1) { EnumValueDescription newVal = descriptionToFill.getEnumValue(fieldName); if (newVal == null) { newVal = new EnumValueDescription(descriptionToFill, fieldName); descriptionToFill.addEnumValue(newVal); } if (c.getAnnotations() != null) { for (AnnotationExpr an : c.getAnnotations()) { log.debug(" " + an); String annoName = an.getName().toString(); if (DisplayEnum.class.getSimpleName().equals(annoName)) { processDisplayEnumAnnotation(descriptionToFill, newVal, an); } } } } } private void processDisplayEnumAnnotation(final BeanDescription descriptionToFill, EnumValueDescription newVal, AnnotationExpr an) { if (an instanceof NormalAnnotationExpr) { for (MemberValuePair pair : ((NormalAnnotationExpr) an).getPairs()) { if ("captionProp".equals(pair.getName())) { newVal.setCaptionProp(((StringLiteralExpr) pair.getValue()).getValue()); } else if ("captionText".equals(pair.getName())) { newVal.setCaptionText(((StringLiteralExpr) pair.getValue()).getValue()); } } } } @Override public void visit(ClassOrInterfaceDeclaration cls, Object arg) { if (!cls.isInterface()) { if (cls.getAnnotations() != null) { log.debug("(class):"); descriptionToFill.setClassName(cls.getName()); for (AnnotationExpr an : cls.getAnnotations()) { log.debug(" " + an); String annoName = an.getName().toString(); if (MapBean.class.getSimpleName().equals(annoName)) { processMapBeanAnnotation(descriptionToFill, an); } if (DisplayBean.class.getSimpleName().equals(annoName)) { processDisplayBeanAnnotation(descriptionToFill, an); } if (ServiceBean.class.getSimpleName().equals(annoName)) { processServiceBeanAnnotation(descriptionToFill, an); } if (WrappedBean.class.getSimpleName().equals(annoName)) { processWrappedBeanAnnotation(descriptionToFill, an); } } } } super.visit(cls, arg); } private void processMapBeanAnnotation(final BeanDescription descriptionToFill, AnnotationExpr an) { descriptionToFill.setMapped(true); for (MemberValuePair pair : ((NormalAnnotationExpr) an).getPairs()) { if (an instanceof NormalAnnotationExpr) { if ("ignore".equals(pair.getName())) { descriptionToFill.setMapped(!Boolean.valueOf(pair.getValue().toString())); } else if ("profiles".equals(pair.getName())) { if (pair.getValue() instanceof ArrayInitializerExpr) { ArrayInitializerExpr array = (ArrayInitializerExpr) pair.getValue(); for (Expression arrayexp : array.getValues()) { processMapBeanProfileAnnotation(descriptionToFill, arrayexp); } } else { processMapBeanProfileAnnotation(descriptionToFill, pair.getValue()); } } } } } private void processMapBeanProfileAnnotation(final BeanDescription descriptionToFill, Expression arrayexp) { log.debug(" " + arrayexp); String profileName = null; for (MemberValuePair innerpair : ((NormalAnnotationExpr) arrayexp).getPairs()) { if ("profileName".equals(innerpair.getName())) { profileName = ((StringLiteralExpr) innerpair.getValue()).getValue(); } } MapProfileDescription newProfile = descriptionToFill.getMapProfile(profileName); for (MemberValuePair innerpair : ((NormalAnnotationExpr) arrayexp).getPairs()) { if ("bidirectional".equals(innerpair.getName())) { newProfile.setBidirectional(Boolean.valueOf(innerpair.getValue().toString())); } else if ("profileName".equals(innerpair.getName())) { } else if ("target".equals(innerpair.getName())) { newProfile.setTargetClassName(((ClassExpr) innerpair.getValue()).getType().toString()); } } } private void processDisplayBeanAnnotation(final BeanDescription descriptionToFill, AnnotationExpr an) { descriptionToFill.setDisplayed(true); if (an instanceof NormalAnnotationExpr) { descriptionToFill.getDisplayProfile(Constants.DEFAULT_DISPLAY_PROFILE); for (MemberValuePair pair : ((NormalAnnotationExpr) an).getPairs()) { if ("ignore".equals(pair.getName())) { descriptionToFill.setDisplayed(!Boolean.valueOf(pair.getValue().toString())); } else if ("captionProp".equals(pair.getName())) { descriptionToFill.setCaptionProp(((StringLiteralExpr) pair.getValue()).getValue()); } else if ("captionText".equals(pair.getName())) { descriptionToFill.setCaptionText(((StringLiteralExpr) pair.getValue()).getValue()); } else if ("beanValidation".equals(pair.getName())) { descriptionToFill.setBeanValidation(((BooleanLiteralExpr) pair.getValue()).getValue()); } else if ("profiles".equals(pair.getName())) { if (pair.getValue() instanceof ArrayInitializerExpr) { ArrayInitializerExpr array = (ArrayInitializerExpr) pair.getValue(); for (Expression arrayexp : array.getValues()) { processDisplayBeanProfileAnnotation(descriptionToFill, arrayexp); } } else { processDisplayBeanProfileAnnotation(descriptionToFill, pair.getValue()); } } } } } private void processDisplayBeanProfileAnnotation(final BeanDescription descriptionToFill, Expression arrayexp) { log.debug(" " + arrayexp); String profileName = null; for (MemberValuePair innerpair : ((NormalAnnotationExpr) arrayexp).getPairs()) { if ("profileName".equals(innerpair.getName())) { profileName = ((StringLiteralExpr) innerpair.getValue()).getValue(); } } DisplayProfileDescription newProfile = descriptionToFill.getDisplayProfile(profileName); for (MemberValuePair innerpair : ((NormalAnnotationExpr) arrayexp).getPairs()) { if ("profileCaptionText".equals(innerpair.getName())) { newProfile.setProfileCaptionText(((StringLiteralExpr) innerpair.getValue()).getValue()); } else if ("profileCaptionProp".equals(innerpair.getName())) { newProfile.setProfileCaptionProp(((StringLiteralExpr) innerpair.getValue()).getValue()); } else if ("order".equals(innerpair.getName())) { newProfile.setOrder(Integer.parseInt(innerpair.getValue().toString())); } else if ("profileName".equals(innerpair.getName())) { } else if ("showOnFirstPage".equals(innerpair.getName())) { newProfile.setShowOnFirstPage(Boolean.valueOf(innerpair.getValue().toString())); } } } private void processServiceBeanAnnotation(final BeanDescription descriptionToFill, AnnotationExpr an) { descriptionToFill.setService(true); if (an instanceof NormalAnnotationExpr) { for (MemberValuePair pair : ((NormalAnnotationExpr) an).getPairs()) { if ("ignore".equals(pair.getName())) { descriptionToFill.setService(!Boolean.valueOf(pair.getValue().toString())); } } } } private void processWrappedBeanAnnotation(final BeanDescription descriptionToFill, AnnotationExpr an) { descriptionToFill.setWrapped(true); if (an instanceof NormalAnnotationExpr) { for (MemberValuePair pair : ((NormalAnnotationExpr) an).getPairs()) { if ("ignore".equals(pair.getName())) { descriptionToFill.setWrapped(!Boolean.valueOf(pair.getValue().toString())); } } } } @Override public void visit(ImportDeclaration imp, Object arg) { if (!imp.toString().contains("de.akquinet.engineering.vaadinator.annotations.")) { descriptionToFill.addImport(imp.toString().trim()); } super.visit(imp, arg); } @Override public void visit(ConstructorDeclaration n, Object arg) { ConstructorDescription newCons = new ConstructorDescription(descriptionToFill); if (n.getParameters() != null) { for (Parameter p : n.getParameters()) { newCons.addParam(new ConstructorParamDescription(newCons, p.getId().getName(), p.getType().toString())); } } descriptionToFill.addConstructor(newCons); super.visit(n, arg); } @Override public void visit(EnumDeclaration n, Object arg) { log.debug("(enum):"); descriptionToFill.setClassName(n.getName()); descriptionToFill.setEnumeration(true); super.visit(n, arg); } }).visit(cu, null); return descriptionToFill; } SourceDao(Log log); BeanDescription processJavaInput(InputStream in);  }
@Test public void testGeneral() throws ParseException { BeanDescription desc = daoUnderTest.processJavaInput(getClass().getResourceAsStream("Address.javainput")); desc.setPckg("de.akquinet.engineering.vaadinator.example.address.model"); assertEquals("Address", desc.getClassName()); assertEquals("Addresses", desc.getClassNameMultiple()); assertEquals("address", desc.getClassNamePass()); assertEquals("de.akquinet.engineering.vaadinator.example.address.model", desc.getPckg()); assertEquals("de.akquinet.engineering.vaadinator.example.address", desc.getBasePckg()); assertEquals("de.akquinet.engineering.vaadinator.example.address.ui.std.presenter", desc.getPresenterPckg("std")); assertEquals("de.akquinet.engineering.vaadinator.example.address.ui.std.view", desc.getViewPckg("std")); assertNull(desc.getSuperClassName()); assertFalse(desc.hasSuperClass()); assertFalse(desc.isEnumeration()); assertTrue(desc.isMapped()); assertTrue(desc.isDisplayed()); assertFalse(desc.isWrapped()); assertEquals("Adresse", desc.getCaptionText()); assertEquals("Adresse", desc.getEffectiveCaption()); assertEquals("Adressen", desc.getEffectiveCaptionPlural()); assertNull(desc.getCaptionProp()); assertEquals(8, desc.getImports().size()); assertTrue(desc.getImports().toString().contains("java.io.Serializable")); assertTrue(desc.getImports().toString().contains("java.util.Date")); assertFalse(desc.getImports().toString().contains("java.util.List")); assertEquals(2, desc.getConstructors().size()); boolean hasZeroCon = false; boolean hasFourCon = false; for (ConstructorDescription cdesc : desc.getConstructors()) { if (cdesc.getParams().size() > 0) { hasFourCon = true; assertEquals(4, cdesc.getParams().size()); assertEquals("anrede, vorname, nachname, email", cdesc.getConstructorParamPassStr()); assertEquals("anrede", cdesc.getParams().get(0).getParamName()); assertEquals("Anreden", cdesc.getParams().get(0).getParamClassName()); } else { hasZeroCon = true; } } assertTrue(hasZeroCon); assertTrue(hasFourCon); assertEquals(3, desc.getMapProfiles().size()); assertNotNull(desc.getMapProfile("gibtesnicht")); assertNotNull(desc.getMapProfile("full")); assertEquals("mapFull", desc.getMapProfile("full").getProfileMapperName()); assertEquals(6, desc.getMapProfile("full").getPropertiesInProfile().size()); assertEquals("Address", desc.getMapProfile("full").getTargetClassName()); assertNotNull(desc.getMapProfile("restricted")); assertEquals("mapRestricted", desc.getMapProfile("restricted").getProfileMapperName()); assertEquals(4, desc.getMapProfile("restricted").getPropertiesInProfile().size()); assertEquals("Address", desc.getMapProfile("restricted").getTargetClassName()); assertNotNull(desc.getMapProfile("mini")); assertEquals("mapMini", desc.getMapProfile("mini").getProfileMapperName()); assertEquals(1, desc.getMapProfile("mini").getPropertiesInProfile().size()); assertEquals("Address", desc.getMapProfile("mini").getTargetClassName()); assertNotNull(desc.getMapProfile("dto")); assertEquals(2, desc.getSectionNames().size()); assertTrue(desc.getSectionNames().toString().contains("Basisdaten")); assertTrue(desc.getSectionNames().toString().contains("Mehr Infos")); assertEquals(1, desc.getDisplayProfiles().size()); assertNotNull(desc.getDisplayProfile("gibtesnicht")); assertNotNull(desc.getDisplayProfile("std")); assertEquals("\"anrede\", \"vorname\", \"nachname\", \"email\", \"geburtsdatum\"", desc.getDisplayProfile("std") .getSortedPropertiesInProfileForDetailStr()); assertEquals("\"name\", \"email\"", desc.getDisplayProfile("std").getSortedPropertiesInProfileForTableStr()); assertTrue(desc.getDisplayProfile("std").isShowOnFirstPage()); assertEquals(0, desc.getDisplayProfile("std").getOrder()); assertEquals(2, desc.getDisplayProfile("std").getSectionsInProfile().size()); assertTrue(desc.getDisplayProfile("std").getSectionsInProfile().toString().contains("Basisdaten")); assertTrue(desc.getDisplayProfile("std").getSectionsInProfile().toString().contains("Mehr Infos")); assertEquals(7, desc.getProperties().size()); assertNull(desc.getProperty("gibtesnicht")); assertNotNull(desc.getProperty("id")); assertEquals("long", desc.getProperty("id").getPropertyClassName()); assertEquals("Long", desc.getProperty("id").getPropertyClassNameBoxed()); assertTrue(desc.getProperty("id").isPropertyClassRange()); assertTrue(desc.getProperty("id").isMapped()); assertFalse(desc.getProperty("id").isDisplayed()); assertEquals("getId", desc.getProperty("id").getPropertyGetterName()); assertEquals("setId", desc.getProperty("id").getPropertySetterName()); assertNotNull(desc.getProperty("anrede")); assertEquals("Anreden", desc.getProperty("anrede").getPropertyClassName()); assertEquals("Anreden", desc.getProperty("anrede").getPropertyClassNameBoxed()); assertFalse(desc.getProperty("anrede").isPropertyClassRange()); assertTrue(desc.getProperty("anrede").isMapped()); assertTrue(desc.getProperty("anrede").isDisplayed()); assertEquals("Anrede", desc.getProperty("anrede").getCaptionText()); assertNull(desc.getProperty("anrede").getCaptionProp()); assertEquals("getAnrede", desc.getProperty("anrede").getPropertyGetterName()); assertEquals("setAnrede", desc.getProperty("anrede").getPropertySetterName()); assertEquals("Anrede", desc.getProperty("anrede").getEffectiveCaption()); assertNotNull(desc.getProperty("anrede").getEnumClass(Collections.singletonList(new BeanDescription("Anreden", true)))); assertNotNull(desc.getProperty("anrede").getMapPropertyProfile("full")); assertFalse(desc.getProperty("anrede").getMapPropertyProfile("full").isExcluded()); assertFalse(desc.getProperty("anrede").getMapPropertyProfile("full").isIncluded()); assertEquals("anrede", desc.getProperty("anrede").getMapPropertyProfile("full").getTargetPropertyName()); assertEquals("getAnrede", desc.getProperty("anrede").getMapPropertyProfile("full").getTargetPropertyGetterName()); assertEquals("setAnrede", desc.getProperty("anrede").getMapPropertyProfile("full").getTargetPropertySetterName()); assertNull(desc.getProperty("anrede").getMapPropertyProfile("full").getTargetPropertyClassName()); assertNotNull(desc.getProperty("anrede").getMapPropertyProfile("restricted")); assertFalse(desc.getProperty("anrede").getMapPropertyProfile("restricted").isExcluded()); assertFalse(desc.getProperty("anrede").getMapPropertyProfile("restricted").isIncluded()); assertNotNull(desc.getProperty("anrede").getDisplayPropertyProfile("std")); assertEquals(FieldType.DROPDOWN, desc.getProperty("anrede").getDisplayPropertyProfile("std").getFieldType()); assertTrue(desc.getProperty("anrede").getDisplayPropertyProfile("std").isFieldTypeAuswahlAusListe()); assertEquals("Basisdaten", desc.getProperty("anrede").getDisplayPropertyProfile("std").getSectionName()); assertFalse(desc.getProperty("anrede").getDisplayPropertyProfile("std").isShowInTable()); assertTrue(desc.getProperty("anrede").getDisplayPropertyProfile("std").isShowInDetail()); assertNotNull(desc.getProperty("vorname")); assertEquals("String", desc.getProperty("vorname").getPropertyClassName()); assertEquals("String", desc.getProperty("vorname").getPropertyClassNameBoxed()); assertFalse(desc.getProperty("vorname").isPropertyClassRange()); assertTrue(desc.getProperty("vorname").isMapped()); assertTrue(desc.getProperty("vorname").isDisplayed()); assertNull(desc.getProperty("vorname").getCaptionText()); assertNull(desc.getProperty("vorname").getCaptionProp()); assertEquals("getVorname", desc.getProperty("vorname").getPropertyGetterName()); assertEquals("setVorname", desc.getProperty("vorname").getPropertySetterName()); assertEquals("Vorname", desc.getProperty("vorname").getEffectiveCaption()); assertNotNull(desc.getProperty("vorname").getMapPropertyProfile("full")); assertFalse(desc.getProperty("vorname").getMapPropertyProfile("full").isExcluded()); assertFalse(desc.getProperty("vorname").getMapPropertyProfile("full").isIncluded()); assertNotNull(desc.getProperty("vorname").getMapPropertyProfile("restricted")); assertFalse(desc.getProperty("vorname").getMapPropertyProfile("restricted").isExcluded()); assertFalse(desc.getProperty("vorname").getMapPropertyProfile("restricted").isIncluded()); assertNotNull(desc.getProperty("vorname").getDisplayPropertyProfile("std")); assertEquals(FieldType.TEXTFIELD, desc.getProperty("vorname").getDisplayPropertyProfile("std").getFieldType()); assertFalse(desc.getProperty("vorname").getDisplayPropertyProfile("std").isFieldTypeAuswahlAusListe()); assertEquals("Basisdaten", desc.getProperty("vorname").getDisplayPropertyProfile("std").getSectionName()); assertFalse(desc.getProperty("vorname").getDisplayPropertyProfile("std").isShowInTable()); assertTrue(desc.getProperty("vorname").getDisplayPropertyProfile("std").isShowInDetail()); assertNotNull(desc.getProperty("nachname")); assertEquals("String", desc.getProperty("nachname").getPropertyClassName()); assertEquals("String", desc.getProperty("vorname").getPropertyClassNameBoxed()); assertFalse(desc.getProperty("vorname").isPropertyClassRange()); assertTrue(desc.getProperty("nachname").isMapped()); assertTrue(desc.getProperty("nachname").isDisplayed()); assertNull(desc.getProperty("nachname").getCaptionText()); assertNull(desc.getProperty("nachname").getCaptionProp()); assertEquals("getNachname", desc.getProperty("nachname").getPropertyGetterName()); assertEquals("setNachname", desc.getProperty("nachname").getPropertySetterName()); assertEquals("Nachname", desc.getProperty("nachname").getEffectiveCaption()); assertNotNull(desc.getProperty("nachname").getMapPropertyProfile("full")); assertFalse(desc.getProperty("nachname").getMapPropertyProfile("full").isExcluded()); assertFalse(desc.getProperty("nachname").getMapPropertyProfile("full").isIncluded()); assertNotNull(desc.getProperty("nachname").getMapPropertyProfile("restricted")); assertFalse(desc.getProperty("nachname").getMapPropertyProfile("restricted").isExcluded()); assertFalse(desc.getProperty("nachname").getMapPropertyProfile("restricted").isIncluded()); assertNotNull(desc.getProperty("nachname").getDisplayPropertyProfile("std")); assertEquals(FieldType.TEXTFIELD, desc.getProperty("nachname").getDisplayPropertyProfile("std").getFieldType()); assertFalse(desc.getProperty("nachname").getDisplayPropertyProfile("std").isFieldTypeAuswahlAusListe()); assertEquals("Basisdaten", desc.getProperty("nachname").getDisplayPropertyProfile("std").getSectionName()); assertFalse(desc.getProperty("nachname").getDisplayPropertyProfile("std").isShowInTable()); assertTrue(desc.getProperty("nachname").getDisplayPropertyProfile("std").isShowInDetail()); assertNotNull(desc.getProperty("name")); assertEquals("String", desc.getProperty("name").getPropertyClassName()); assertEquals("String", desc.getProperty("name").getPropertyClassNameBoxed()); assertFalse(desc.getProperty("name").isPropertyClassRange()); assertFalse(desc.getProperty("name").isMapped()); assertTrue(desc.getProperty("name").isDisplayed()); assertNull(desc.getProperty("name").getCaptionText()); assertNull(desc.getProperty("name").getCaptionProp()); assertEquals("getName", desc.getProperty("name").getPropertyGetterName()); assertEquals("setName", desc.getProperty("name").getPropertySetterName()); assertEquals("Name", desc.getProperty("name").getEffectiveCaption()); assertNotNull(desc.getProperty("name").getDisplayPropertyProfile("std")); assertEquals(FieldType.TEXTFIELD, desc.getProperty("name").getDisplayPropertyProfile("std").getFieldType()); assertFalse(desc.getProperty("name").getDisplayPropertyProfile("std").isFieldTypeAuswahlAusListe()); assertEquals("Basisdaten", desc.getProperty("name").getDisplayPropertyProfile("std").getSectionName()); assertTrue(desc.getProperty("name").getDisplayPropertyProfile("std").isShowInTable()); assertFalse(desc.getProperty("name").getDisplayPropertyProfile("std").isShowInDetail()); assertNotNull(desc.getProperty("email")); assertEquals("String", desc.getProperty("email").getPropertyClassName()); assertEquals("String", desc.getProperty("email").getPropertyClassNameBoxed()); assertFalse(desc.getProperty("email").isPropertyClassRange()); assertTrue(desc.getProperty("email").isMapped()); assertTrue(desc.getProperty("email").isDisplayed()); assertEquals("E-Mail", desc.getProperty("email").getCaptionText()); assertNull(desc.getProperty("email").getCaptionProp()); assertEquals("getEmail", desc.getProperty("email").getPropertyGetterName()); assertEquals("setEmail", desc.getProperty("email").getPropertySetterName()); assertEquals("E-Mail", desc.getProperty("email").getEffectiveCaption()); assertNotNull(desc.getProperty("email").getMapPropertyProfile("full")); assertFalse(desc.getProperty("email").getMapPropertyProfile("full").isExcluded()); assertFalse(desc.getProperty("email").getMapPropertyProfile("full").isIncluded()); assertNotNull(desc.getProperty("email").getMapPropertyProfile("restricted")); assertTrue(desc.getProperty("email").getMapPropertyProfile("restricted").isExcluded()); assertFalse(desc.getProperty("email").getMapPropertyProfile("restricted").isIncluded()); assertNotNull(desc.getProperty("email").getDisplayPropertyProfile("std")); assertEquals(FieldType.TEXTFIELD, desc.getProperty("email").getDisplayPropertyProfile("std").getFieldType()); assertFalse(desc.getProperty("email").getDisplayPropertyProfile("std").isFieldTypeAuswahlAusListe()); assertEquals("Basisdaten", desc.getProperty("email").getDisplayPropertyProfile("std").getSectionName()); assertTrue(desc.getProperty("email").getDisplayPropertyProfile("std").isShowInTable()); assertTrue(desc.getProperty("email").getDisplayPropertyProfile("std").isShowInDetail()); assertNotNull(desc.getProperty("geburtsdatum")); assertEquals("Date", desc.getProperty("geburtsdatum").getPropertyClassName()); assertEquals("Date", desc.getProperty("geburtsdatum").getPropertyClassNameBoxed()); assertTrue(desc.getProperty("geburtsdatum").isPropertyClassRange()); assertTrue(desc.getProperty("geburtsdatum").isMapped()); assertTrue(desc.getProperty("geburtsdatum").isDisplayed()); assertNull(desc.getProperty("geburtsdatum").getCaptionText()); assertNull(desc.getProperty("geburtsdatum").getCaptionProp()); assertEquals("getGeburtsdatum", desc.getProperty("geburtsdatum").getPropertyGetterName()); assertEquals("setGeburtsdatum", desc.getProperty("geburtsdatum").getPropertySetterName()); assertEquals("Geburtsdatum", desc.getProperty("geburtsdatum").getEffectiveCaption()); assertNotNull(desc.getProperty("geburtsdatum").getMapPropertyProfile("full")); assertFalse(desc.getProperty("geburtsdatum").getMapPropertyProfile("full").isExcluded()); assertFalse(desc.getProperty("geburtsdatum").getMapPropertyProfile("full").isIncluded()); assertNotNull(desc.getProperty("geburtsdatum").getMapPropertyProfile("restricted")); assertTrue(desc.getProperty("geburtsdatum").getMapPropertyProfile("restricted").isExcluded()); assertFalse(desc.getProperty("geburtsdatum").getMapPropertyProfile("restricted").isIncluded()); assertNotNull(desc.getProperty("geburtsdatum").getDisplayPropertyProfile("std")); assertEquals(FieldType.DATEPICKER, desc.getProperty("geburtsdatum").getDisplayPropertyProfile("std").getFieldType()); assertFalse(desc.getProperty("geburtsdatum").getDisplayPropertyProfile("std").isFieldTypeAuswahlAusListe()); assertEquals("Mehr Infos", desc.getProperty("geburtsdatum").getDisplayPropertyProfile("std").getSectionName()); assertFalse(desc.getProperty("geburtsdatum").getDisplayPropertyProfile("std").isShowInTable()); assertTrue(desc.getProperty("geburtsdatum").getDisplayPropertyProfile("std").isShowInDetail()); assertTrue(desc.hasGetter("getAnrede")); assertTrue(desc.hasSetter("setAnrede")); assertTrue(desc.hasGetter("getName")); assertFalse(desc.hasSetter("setName")); assertFalse(desc.isBeanValidation()); outputDesc(desc); }
@Test public void testEnumeration() throws ParseException { BeanDescription desc = daoUnderTest.processJavaInput(getClass().getResourceAsStream("Anreden.javainput")); assertEquals("Anreden", desc.getClassName()); assertTrue(desc.isEnumeration()); assertEquals(3, desc.getEnumValues().size()); assertNull(desc.getEnumValue("gibtesnicht")); assertNotNull(desc.getEnumValue("HERR")); assertEquals("HERR", desc.getEnumValue("HERR").getValue()); assertEquals("Herr", desc.getEnumValue("HERR").getEffectiveCaption()); assertNotNull(desc.getEnumValue("FRAU")); assertEquals("FRAU", desc.getEnumValue("FRAU").getValue()); assertEquals("Frau", desc.getEnumValue("FRAU").getEffectiveCaption()); assertNotNull(desc.getEnumValue("FROLLEIN")); assertEquals("FROLLEIN", desc.getEnumValue("FROLLEIN").getValue()); assertEquals("Fräulein", desc.getEnumValue("FROLLEIN").getCaptionText()); assertEquals("Fräulein", desc.getEnumValue("FROLLEIN").getEffectiveCaption()); assertFalse(desc.isDisplayed()); assertFalse(desc.isMapped()); assertFalse(desc.isWrapped()); }
@Test public void testMinimalJSR303() throws ParseException { BeanDescription desc = daoUnderTest.processJavaInput(getClass().getResourceAsStream("AddressMinimalJSR-303.javainput")); assertTrue(desc.isBeanValidation()); }
@Test public void testNoSummaryMethod () throws ParseException { BeanDescription desc = daoUnderTest.processJavaInput(getClass().getResourceAsStream("AddressMinimal.javainput")); assertEquals("toString", desc.getDisplayProfile(Constants.DEFAULT_DISPLAY_PROFILE).getSummaryMethod()); }
@Test public void testSummaryMethod () throws ParseException { BeanDescription desc = daoUnderTest.processJavaInput(getClass().getResourceAsStream("Address.javainput")); assertEquals("getName", desc.getDisplayProfile(Constants.DEFAULT_DISPLAY_PROFILE).getSummaryMethod()); }
@Test public void testSummaryProperty () throws ParseException { BeanDescription desc = daoUnderTest.processJavaInput(getClass().getResourceAsStream("AddressMinimalCaptionProperty.javainput")); assertEquals("getName", desc.getDisplayProfile(Constants.DEFAULT_DISPLAY_PROFILE).getSummaryMethod()); }
@Test public void testMinimal() throws ParseException { BeanDescription desc = daoUnderTest.processJavaInput(getClass().getResourceAsStream("AddressMinimal.javainput")); desc.setPckg("de.akquinet.engineering.vaadinator.example.address.model"); assertEquals("Address", desc.getClassName()); assertTrue(desc.isDisplayed()); assertEquals("Address", desc.getEffectiveCaption()); assertEquals(1, desc.getSectionNames().size()); assertTrue(desc.getSectionNames().toString().contains("Basisdaten")); assertEquals(1, desc.getDisplayProfiles().size()); assertNotNull(desc.getDisplayProfile("std")); assertNull(desc.getProperty("gibtesnicht")); assertNotNull(desc.getProperty("anrede")); assertEquals("Anreden", desc.getProperty("anrede").getPropertyClassName()); assertTrue(desc.getProperty("anrede").isDisplayed()); assertEquals("Anrede", desc.getProperty("anrede").getEffectiveCaption()); assertNotNull(desc.getProperty("anrede").getEnumClass(Collections.singletonList(new BeanDescription("Anreden", true)))); assertNotNull(desc.getProperty("vorname")); assertEquals("String", desc.getProperty("vorname").getPropertyClassName()); assertTrue(desc.getProperty("vorname").isDisplayed()); assertEquals("Vorname", desc.getProperty("vorname").getEffectiveCaption()); assertEquals(FieldType.TEXTFIELD, desc.getProperty("vorname").getDisplayPropertyProfile("std").getFieldType()); assertNotNull(desc.getProperty("nachname")); assertEquals("String", desc.getProperty("nachname").getPropertyClassName()); assertTrue(desc.getProperty("nachname").isDisplayed()); assertEquals("Nachname", desc.getProperty("nachname").getEffectiveCaption()); assertEquals(FieldType.TEXTFIELD, desc.getProperty("nachname").getDisplayPropertyProfile("std").getFieldType()); assertNotNull(desc.getProperty("name")); assertEquals("String", desc.getProperty("name").getPropertyClassName()); assertTrue(desc.getProperty("name").isDisplayed()); assertEquals("Name", desc.getProperty("name").getEffectiveCaption()); assertEquals(FieldType.TEXTFIELD, desc.getProperty("name").getDisplayPropertyProfile("std").getFieldType()); assertNotNull(desc.getProperty("email")); assertNotNull(desc.getProperty("geburtsdatum")); outputDesc(desc); }