From eaa70cdc774bf8ce0436ff0d2703098e4e5a165f Mon Sep 17 00:00:00 2001 From: Greg Turnquist Date: Mon, 20 Apr 2020 10:19:47 -0500 Subject: [PATCH] DATAREST-1509 - Test against all ISO-8601 TZ formats. Verify that Jackson properly serializes to ISO-8601 format, which includes three potential timezone endings. Expand CI testing against both Jackson 2.10 and 2.11. Also test these profiles against JDK 8, 11, and 14. Related: spring-projects/spring-data-build#1075 Original pull request: #374. --- Jenkinsfile | 57 +++++++++++++++++++ ...ryRestMvConfigurationIntegrationTests.java | 20 ++++--- .../data/rest/webmvc/util/AssertionUtils.java | 22 +++++++ 3 files changed, 92 insertions(+), 7 deletions(-) create mode 100644 spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/util/AssertionUtils.java diff --git a/Jenkinsfile b/Jenkinsfile index dee966413..08b6c4876 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -85,6 +85,63 @@ pipeline { sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pjava11 clean dependency:list test -Dsort -U -B -Pit' } } + stage("test: spring52/jackson-next (jdk8)") { + agent { + docker { + image 'springci/spring-data-openjdk8-with-mongodb-4.2.0:latest' + label 'data' + args '-v $HOME:/tmp/jenkins-home' + } + } + options { timeout(time: 30, unit: 'MINUTES') } + steps { + sh 'rm -rf ?' + sh 'mkdir -p /tmp/mongodb/db /tmp/mongodb/log' + sh 'mongod --dbpath /tmp/mongodb/db --replSet rs0 --fork --logpath /tmp/mongodb/log/mongod.log &' + sh 'sleep 10' + sh 'mongo --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"' + sh 'sleep 15' + sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pjava11 clean dependency:list test -Dsort -U -B -Pit,spring52-next,jackson-next' + } + } + stage("test: spring52/jackson-next (jdk11)") { + agent { + docker { + image 'springci/spring-data-openjdk11-with-mongodb-4.2.0:latest' + label 'data' + args '-v $HOME:/tmp/jenkins-home' + } + } + options { timeout(time: 30, unit: 'MINUTES') } + steps { + sh 'rm -rf ?' + sh 'mkdir -p /tmp/mongodb/db /tmp/mongodb/log' + sh 'mongod --dbpath /tmp/mongodb/db --replSet rs0 --fork --logpath /tmp/mongodb/log/mongod.log &' + sh 'sleep 10' + sh 'mongo --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"' + sh 'sleep 15' + sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pjava11 clean dependency:list test -Dsort -U -B -Pit,spring52-next,jackson-next' + } + } + stage("test: spring52/jackson-next (jdk14)") { + agent { + docker { + image 'springci/spring-data-openjdk14-with-mongodb-4.2.0:latest' + label 'data' + args '-v $HOME:/tmp/jenkins-home' + } + } + options { timeout(time: 30, unit: 'MINUTES') } + steps { + sh 'rm -rf ?' + sh 'mkdir -p /tmp/mongodb/db /tmp/mongodb/log' + sh 'mongod --dbpath /tmp/mongodb/db --replSet rs0 --fork --logpath /tmp/mongodb/log/mongod.log &' + sh 'sleep 10' + sh 'mongo --eval "rs.initiate({_id: \'rs0\', members:[{_id: 0, host: \'127.0.0.1:27017\'}]});"' + sh 'sleep 15' + sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pjava11 clean dependency:list test -Dsort -U -B -Pit,spring52-next,jenkins-next' + } + } } } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvConfigurationIntegrationTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvConfigurationIntegrationTests.java index c05c06608..de35655be 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvConfigurationIntegrationTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/config/RepositoryRestMvConfigurationIntegrationTests.java @@ -16,16 +16,21 @@ package org.springframework.data.rest.webmvc.config; import static org.assertj.core.api.Assertions.*; +import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*; +import static org.springframework.data.rest.webmvc.util.AssertionUtils.*; +import java.util.Arrays; import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Locale; import java.util.TimeZone; +import java.util.function.Predicate; import javax.naming.Name; import javax.naming.ldap.LdapName; +import org.assertj.core.api.Condition; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -45,6 +50,7 @@ import org.springframework.data.rest.webmvc.RepositoryLinksResource; import org.springframework.data.rest.webmvc.RestMediaTypes; import org.springframework.data.rest.webmvc.alps.AlpsJsonHttpMessageConverter; import org.springframework.data.rest.webmvc.json.PersistentEntityJackson2Module; +import org.springframework.data.rest.webmvc.util.AssertionUtils; import org.springframework.data.web.HateoasPageableHandlerMethodArgumentResolver; import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.format.datetime.DateFormatter; @@ -66,6 +72,7 @@ import com.jayway.jsonpath.JsonPath; * * @author Oliver Gierke * @author Mark Paluch + * @author Greg Turnquist */ public class RepositoryRestMvConfigurationIntegrationTests { @@ -117,7 +124,7 @@ public class RepositoryRestMvConfigurationIntegrationTests { assertThat(params.get("mySize").get(0)).isEqualTo("7000"); } - @Test // DATAREST-336 + @Test // DATAREST-336 DATAREST-1509 public void objectMapperRendersDatesInIsoByDefault() throws Exception { Sample sample = new Sample(); @@ -125,13 +132,12 @@ public class RepositoryRestMvConfigurationIntegrationTests { ObjectMapper mapper = getObjectMapper(); - DateFormatter formatter = new DateFormatter(); - formatter.setPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); - formatter.setTimeZone(TimeZone.getTimeZone("UTC")); + String result = JsonPath.read(mapper.writeValueAsString(sample), "$.date"); - Object result = JsonPath.read(mapper.writeValueAsString(sample), "$.date"); - assertThat(result).isInstanceOf(String.class); - assertThat(result).isEqualTo(formatter.print(sample.date, Locale.US)); + assertThat(result).is(anyOf( // + new Condition<>(endsWith("+00"), "ISO-8601-TZ1"), // + new Condition<>(endsWith("+0000"), "ISO-8601-TZ2"), // + new Condition<>(endsWith("+00:00"), "ISO-8601-TZ3"))); } @Test(expected = NoSuchBeanDefinitionException.class) // DATAREST-362 diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/util/AssertionUtils.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/util/AssertionUtils.java new file mode 100644 index 000000000..470978f07 --- /dev/null +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/util/AssertionUtils.java @@ -0,0 +1,22 @@ +package org.springframework.data.rest.webmvc.util; + +import java.util.function.Predicate; + +/** + * Various extensions of AssertJ to improve testing. + * + * @author Greg Turnquist + */ +public final class AssertionUtils { + + + /** + * {@link Predicate} to verify a given string ends in a certain pattern. + * + * @param pattern + * @return + */ + public static Predicate endsWith(String pattern) { + return s -> s.endsWith(pattern); + } +}