From 12d08bf159b3979c865dec5c4d0cf7d104dca714 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Mon, 25 Jan 2016 17:46:25 +0100 Subject: [PATCH] DATAREST-754 - Polishing. Upgraded to Groovy 2.4.4. Polished sample domain types and repositories. Removed obsolete format registration in test cases for schema creation. Keep inlined null checks to make sure the IDE doesn't create unnecessary can-be-null warnings. Original pull request: #206. --- spring-data-rest-webmvc/pom.xml | 2 +- ...PersistentEntityToJsonSchemaConverter.java | 16 ++++++------- .../alps/AlpsControllerIntegrationTests.java | 6 ++--- .../groovy/SimulatedGroovyDomainClass.java | 24 +++++++------------ .../SimulatedGroovyDomainClassRepository.java | 4 +--- ...tEntityToJsonSchemaConverterUnitTests.java | 1 - .../groovy/SimulatedGroovyDomainClass.java | 16 +++++-------- .../SimulatedGroovyDomainClassRepository.java | 4 +--- 8 files changed, 26 insertions(+), 47 deletions(-) diff --git a/spring-data-rest-webmvc/pom.xml b/spring-data-rest-webmvc/pom.xml index ed5652daa..0845e7712 100644 --- a/spring-data-rest-webmvc/pom.xml +++ b/spring-data-rest-webmvc/pom.xml @@ -20,7 +20,7 @@ 2.0.9 2.0.2.1 4.0.1.RELEASE - 2.3.7 + 2.4.4 diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverter.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverter.java index 613bffb2b..d214d3ee7 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverter.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverter.java @@ -188,25 +188,23 @@ public class PersistentEntityToJsonSchemaConverter implements ConditionalGeneric } } - boolean isPersistentPropertyNull = persistentProperty == null; - AnnotatedMember primaryMember = definition.getPrimaryMember(); - if (primaryMember == null) { // Ignore bean definitions with neither a getter nor a setter + + if (primaryMember == null) { continue; } - TypeInformation propertyType = isPersistentPropertyNull - ? ClassTypeInformation.from(primaryMember.getRawType()) - : persistentProperty.getTypeInformation(); + TypeInformation propertyType = persistentProperty == null + ? ClassTypeInformation.from(primaryMember.getRawType()) : persistentProperty.getTypeInformation(); TypeInformation actualPropertyType = propertyType.getActualType(); Class rawPropertyType = propertyType.getType(); JsonSchemaFormat format = configuration.getMetadataConfiguration().getSchemaFormatFor(rawPropertyType); - ResourceDescription description = isPersistentPropertyNull + ResourceDescription description = persistentProperty == null ? jackson.getFallbackDescription(metadata, definition) : getDescriptionFor(persistentProperty, metadata); JsonSchemaProperty property = getSchemaProperty(definition, propertyType, description); - boolean isSyntheticProperty = isPersistentPropertyNull; + boolean isSyntheticProperty = persistentProperty == null; boolean isNotWritable = !isSyntheticProperty && !persistentProperty.isWritable(); boolean isJacksonReadOnly = !isSyntheticProperty && jackson.isReadOnly(persistentProperty); @@ -233,7 +231,7 @@ public class PersistentEntityToJsonSchemaConverter implements ConditionalGeneric continue; } - if (isPersistentPropertyNull) { + if (persistentProperty == null) { registrar.register(property, actualPropertyType); continue; } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java index c870f6a35..893557025 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/alps/AlpsControllerIntegrationTests.java @@ -17,7 +17,6 @@ package org.springframework.data.rest.webmvc.alps; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import org.junit.After; @@ -209,11 +208,10 @@ public class AlpsControllerIntegrationTests extends AbstractControllerIntegratio Link profileLink = client.discoverUnique("profile"); Link groovyDomainObjectLink = client.discoverUnique(profileLink, "simulatedGroovyDomainClasses"); + client.follow(groovyDomainObjectLink)// .andExpect(jsonPath( "$.alps.descriptors[?(@.id == 'simulatedGroovyDomainClass-representation')][0].descriptors[0].name", - is("name") - )); - + is("name"))); } } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/groovy/SimulatedGroovyDomainClass.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/groovy/SimulatedGroovyDomainClass.java index 2c739f195..05f4a765d 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/groovy/SimulatedGroovyDomainClass.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/groovy/SimulatedGroovyDomainClass.java @@ -15,26 +15,24 @@ */ package org.springframework.data.rest.webmvc.jpa.groovy; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -import org.springframework.data.mongodb.core.mapping.Document; - import groovy.lang.GroovyObject; import groovy.lang.MetaClass; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + /** * Simulates a Groovy domain object by extending {@link GroovyObject}. * * @author Greg Turnquist + * @author Oliver Gierke * @see DATAREST-754 */ @Entity public class SimulatedGroovyDomainClass implements GroovyObject { - @Id @GeneratedValue private Long id; + private @Id @GeneratedValue Long id; private String name; public Long getId() { @@ -53,8 +51,6 @@ public class SimulatedGroovyDomainClass implements GroovyObject { this.name = name; } - protected SimulatedGroovyDomainClass() {} - // // The following fields don't actually have to be implemented since the test cases don't // make any Groovy calls. This just simulates the structure of a Groovy object to @@ -72,9 +68,7 @@ public class SimulatedGroovyDomainClass implements GroovyObject { } @Override - public void setProperty(String s, Object o) { - - } + public void setProperty(String s, Object o) {} @Override public MetaClass getMetaClass() { @@ -82,7 +76,5 @@ public class SimulatedGroovyDomainClass implements GroovyObject { } @Override - public void setMetaClass(MetaClass metaClass) { - - } + public void setMetaClass(MetaClass metaClass) {} } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/groovy/SimulatedGroovyDomainClassRepository.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/groovy/SimulatedGroovyDomainClassRepository.java index 90f7bd8f8..4b3c29fc2 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/groovy/SimulatedGroovyDomainClassRepository.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/jpa/groovy/SimulatedGroovyDomainClassRepository.java @@ -23,6 +23,4 @@ import org.springframework.data.repository.CrudRepository; * @author Greg Turnquist * @see DATAREST-754 */ -public interface SimulatedGroovyDomainClassRepository extends CrudRepository { - -} +public interface SimulatedGroovyDomainClassRepository extends CrudRepository {} diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverterUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverterUnitTests.java index 6b95964a4..73128c568 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverterUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntityToJsonSchemaConverterUnitTests.java @@ -74,7 +74,6 @@ public class PersistentEntityToJsonSchemaConverterUnitTests { config.getMetadataConfiguration().registerJsonSchemaFormat(JsonSchemaFormat.EMAIL, EmailAddress.class); config.getMetadataConfiguration().registerFormattingPatternFor("[A-Z]+", TypeWithPattern.class); - config.getMetadataConfiguration().registerJsonSchemaFormat(JsonSchemaFormat.EMAIL); config.exposeIdsFor(Profile.class); } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/groovy/SimulatedGroovyDomainClass.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/groovy/SimulatedGroovyDomainClass.java index 2701bf6ee..f01b65d8e 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/groovy/SimulatedGroovyDomainClass.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/groovy/SimulatedGroovyDomainClass.java @@ -15,22 +15,22 @@ */ package org.springframework.data.rest.webmvc.mongodb.groovy; -import org.springframework.data.mongodb.core.mapping.Document; - import groovy.lang.GroovyObject; import groovy.lang.MetaClass; +import org.springframework.data.mongodb.core.mapping.Document; + /** * Simulates a Groovy domain object by extending {@link GroovyObject}. * * @author Greg Turnquist + * @author Oliver Gierke * @see DATAREST-754 */ @Document public class SimulatedGroovyDomainClass implements GroovyObject { - private String id; - private String name; + private String id, name; public String getId() { return id; @@ -65,9 +65,7 @@ public class SimulatedGroovyDomainClass implements GroovyObject { } @Override - public void setProperty(String s, Object o) { - - } + public void setProperty(String s, Object o) {} @Override public MetaClass getMetaClass() { @@ -75,7 +73,5 @@ public class SimulatedGroovyDomainClass implements GroovyObject { } @Override - public void setMetaClass(MetaClass metaClass) { - - } + public void setMetaClass(MetaClass metaClass) {} } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/groovy/SimulatedGroovyDomainClassRepository.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/groovy/SimulatedGroovyDomainClassRepository.java index b11e50699..f25dacf64 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/groovy/SimulatedGroovyDomainClassRepository.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mongodb/groovy/SimulatedGroovyDomainClassRepository.java @@ -23,6 +23,4 @@ import org.springframework.data.repository.CrudRepository; * @author Greg Turnquist * @see DATAREST-754 */ -public interface SimulatedGroovyDomainClassRepository extends CrudRepository { - -} +public interface SimulatedGroovyDomainClassRepository extends CrudRepository {}