DtoConfig { public List<DtoProperty> getProperties() { if (properties == null) { properties = list(); final List<PropConfig> pcs = getPropertiesConfig(); if (getDomainType() != null) { addPropertiesFromDomainObject(pcs); addChainedPropertiesFromDomainObject(pcs); } addLeftOverExtensionProperties(pcs); sortProperties(pcs, properties); } return properties; } DtoConfig(final TypeOracle oracle, final RootConfig root, final String simpleName, final Object map); List<DtoProperty> getProperties(); List<DtoProperty> getInheritedProperties(); List<DtoProperty> getAllProperties(); String getSimpleName(); String getDtoType(); boolean shouldAddPublicConstructor(); List<String> getAnnotations(); List<String> getInterfaces(); String getBaseDtoSimpleName(); DtoConfig getBaseDto(); List<DtoConfig> getSubClassDtos(); boolean includeBeanMethods(); String getDomainType(); List<String> getEquality(); boolean includeTessellModel(); boolean isEnum(); boolean isAbstract(); List<String> getEnumValues(); boolean isManualDto(); List<String> getForcedMappers(); boolean requiresMapperType(); boolean hasIdProperty(); boolean hasExtensionProperties(); @Override String toString();  }
@Test public void testAllProperties() { oracle.addProperty("com.domain.Foo", "a", "java.lang.String"); oracle.addProperty("com.domain.Foo", "b", "java.lang.String"); addDto("FooDto", domain("Foo"), properties("*")); final DtoConfig dc = rootConfig.getDto("FooDto"); assertThat(dc.getProperties().size(), is(2)); }
@Test public void testMappedPropertiesThatAreAnIdOfAnEntity() { oracle.addProperty("com.domain.Parent", "id", "java.lang.Long"); oracle.addProperty("com.domain.Child", "parent", "com.domain.Parent"); addDto("ParentDto", domain("Parent")); addDto("ChildDto", domain("Child"), properties("parentId")); final DtoConfig dc = rootConfig.getDto("ChildDto"); assertThat(dc.getProperties().size(), is(1)); assertThat(dc.getProperties().get(0).getName(), is("parentId")); assertThat(dc.getProperties().get(0).isChainedId(), is(true)); assertThat(dc.getProperties().get(0).getGetterMethodName(), is("getParent")); assertThat(dc.getProperties().get(0).getSetterMethodName(), is("setParent")); }
@Test public void testMappedPropertiesThatAreAnIdOfNotAnEntity() { oracle.addProperty("com.domain.Parent", "id", "java.lang.Integer"); oracle.addProperty("com.domain.Child", "parent", "com.domain.Parent"); addDto("ParentDto", domain("Parent")); addDto("ChildDto", domain("Child"), properties("parentId Long")); final DtoConfig dc = rootConfig.getDto("ChildDto"); assertThat(dc.getProperties().size(), is(1)); assertThat(dc.getProperties().get(0).getName(), is("parentId")); assertThat(dc.getProperties().get(0).isChainedId(), is(false)); assertThat(dc.getProperties().get(0).isExtension(), is(true)); }
@Test public void testMappedPropertiesThatAreAnIdOfAnEntityWithADifferentType() { oracle.addProperty("com.domain.Parent", "id", "java.lang.Long"); oracle.addProperty("com.domain.Child", "parent", "com.domain.Parent"); addDto("ParentDto", domain("Parent")); addDto("ChildDto", domain("Child"), properties("parentId Integer")); final DtoConfig dc = rootConfig.getDto("ChildDto"); assertThat(dc.getProperties().size(), is(1)); assertThat(dc.getProperties().get(0).getName(), is("parentId")); assertThat(dc.getProperties().get(0).isChainedId(), is(false)); assertThat(dc.getProperties().get(0).isExtension(), is(true)); }
@Test public void testMappedPropertiesThatLookLikeAnIdByAreASeparateProperty() { oracle.addProperty("com.domain.Parent", "id", "java.lang.Long"); oracle.addProperty("com.domain.Child", "parent", "com.domain.Parent"); oracle.addProperty("com.domain.Child", "parentId", "java.lang.String"); addDto("ParentDto", domain("Parent")); addDto("ChildDto", domain("Child"), properties("parentId")); final DtoConfig dc = rootConfig.getDto("ChildDto"); assertThat(dc.getProperties().size(), is(1)); assertThat(dc.getProperties().get(0).getName(), is("parentId")); assertThat(dc.getProperties().get(0).isChainedId(), is(false)); assertThat(dc.getProperties().get(0).isExtension(), is(false)); }
@Test public void testMappedAliasedProperties() { oracle.addProperty("com.domain.Foo", "longPropertyName", "java.lang.String"); addDto("FooDto", domain("Foo"), properties("name(longPropertyName)")); final DtoConfig dc = rootConfig.getDto("FooDto"); assertThat(dc.getProperties().get(0).getName(), is("name")); assertThat(dc.getProperties().get(0).getGetterMethodName(), is("getLongPropertyName")); }
@Test public void testSortedAlphabetically() { oracle.addProperty("com.domain.Foo", "b", "java.lang.String"); oracle.addProperty("com.domain.Foo", "a", "java.lang.String"); oracle.addProperty("com.domain.Foo", "id", "java.lang.Integer"); addDto("FooDto", domain("Foo"), properties("*")); final DtoConfig dc = rootConfig.getDto("FooDto"); assertThat(dc.getProperties().size(), is(3)); assertThat(dc.getProperties().get(0).getName(), is("id")); assertThat(dc.getProperties().get(1).getName(), is("a")); assertThat(dc.getProperties().get(2).getName(), is("b")); }
@Test public void testSortedByConfigFirst() { oracle.addProperty("com.domain.Foo", "d", "java.lang.String"); oracle.addProperty("com.domain.Foo", "c", "java.lang.String"); oracle.addProperty("com.domain.Foo", "b", "java.lang.String"); oracle.addProperty("com.domain.Foo", "a", "java.lang.String"); addDto("FooDto", domain("Foo"), properties("d, c String, b, a")); final DtoConfig dc = rootConfig.getDto("FooDto"); assertThat(dc.getProperties().size(), is(4)); assertThat(dc.getProperties().get(0).getName(), is("d")); assertThat(dc.getProperties().get(1).getName(), is("c")); assertThat(dc.getProperties().get(2).getName(), is("b")); assertThat(dc.getProperties().get(3).getName(), is("a")); }
@Test public void testPropertiesExclusion() { oracle.addProperty("com.domain.Foo", "a", "java.lang.String"); oracle.addProperty("com.domain.Foo", "b", "java.lang.String"); addDto("FooDto", domain("Foo"), properties("-b, *")); final DtoConfig dc = rootConfig.getDto("FooDto"); assertThat(dc.getProperties().size(), is(1)); }
@Test public void testPropertiesInclusion() { oracle.addProperty("com.domain.Foo", "a", "java.lang.String"); oracle.addProperty("com.domain.Foo", "b", "java.lang.String"); final Map<String, Object> map = new HashMap<String, Object>(); map.put("domain", "Foo"); map.put("properties", "a"); final DtoConfig dc = new DtoConfig(oracle, rootConfig, "FooDto", map); assertThat(dc.getProperties().size(), is(1)); }
@Test public void testPropertiesOverrideTypeAndIncludesAll() { oracle.addProperty("com.domain.Foo", "a", "java.util.List"); oracle.addProperty("com.domain.Foo", "b", "java.lang.String"); addDto("FooDto", domain("Foo"), properties("a ArrayList<Integer>, *")); final DtoConfig dc = rootConfig.getDto("FooDto"); assertThat(dc.getProperties().size(), is(2)); assertThat(dc.getProperties().get(0).getName(), is("a")); assertThat(dc.getProperties().get(1).getName(), is("b")); }
@Test public void testMappedPropertiesThatAreEntities() { oracle.addProperty("com.domain.Foo", "bar", "com.domain.Bar"); addDto("FooDto", domain("Foo")); addDto("BarDto"); final DtoConfig dc = rootConfig.getDto("FooDto"); assertThat(dc.getProperties().size(), is(0)); }
@Test public void testMappedPropertiesThatAreReadOnly() { oracle.addProperty("com.domain.Foo", "a", "java.lang.String"); addDto("FooDto", domain("Foo"), properties("~a")); final DtoConfig dc = rootConfig.getDto("FooDto"); assertThat(dc.getProperties().size(), is(1)); assertThat(dc.getProperties().get(0).isReadOnly(), is(true)); }
@Test public void testMappedPropertiesThatAreTheSameType() { oracle.addProperty("com.domain.Foo", "a", "java.lang.Integer"); addDto("FooDto", domain("Foo"), properties("a Integer")); final DtoConfig dc = rootConfig.getDto("FooDto"); assertThat(dc.getProperties().size(), is(1)); assertThat(dc.getProperties().get(0).isExtension(), is(false)); }
@Test public void testMappedPropertiesThatAreADifferentType() { oracle.addProperty("com.domain.Foo", "a", "java.lang.Integer"); addDto("FooDto", domain("Foo"), properties("a Long")); final DtoConfig dc = rootConfig.getDto("FooDto"); assertThat(dc.getProperties().size(), is(1)); assertThat(dc.getProperties().get(0).isExtension(), is(true)); }
@Test public void testExtensionPropertiesThatAreReadOnly() { addDto("FooDto", properties("~a String")); final DtoConfig dc = rootConfig.getDto("FooDto"); assertThat(dc.getProperties().get(0).isReadOnly(), is(true)); }
@Test public void testMappedPropertiesThatAreListsOfEntities() { oracle.addProperty("com.domain.Parent", "name", "java.lang.String"); oracle.addProperty("com.domain.Parent", "children", "java.util.List<com.domain.Child>"); oracle.addProperty("com.domain.Child", "id", "java.lang.Integer"); addDto("ChildDto", properties("*")); addDto("ParentDto", domain("Parent"), properties("*")); final DtoConfig dc = rootConfig.getDto("ParentDto"); assertThat(dc.getProperties().size(), is(1)); assertThat(dc.getProperties().get(0).getName(), is("name")); }