From a2ba4224fb92e1084c8e47a71b12946715ab1891 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Sun, 11 Jan 2015 17:50:00 +0100 Subject: [PATCH] DATAREST-414 - Polishing. Extracted groups of dependencies into auto-activated profiles to make more visible which dependencies belong to which store. Simplified dependency setup where possible. General polishing in the test cases added. --- pom.xml | 111 +++++++++--------- spring-data-rest-webmvc/pom.xml | 72 +++++++++--- .../AbstractCassandraIntegrationTest.java | 12 +- .../webmvc/cassandra/CassandraProperties.java | 6 +- .../webmvc/cassandra/CassandraWebTests.java | 73 ++++++------ .../data/rest/webmvc/cassandra/Employee.java | 5 +- .../webmvc/cassandra/EmployeeRepository.java | 2 +- 7 files changed, 160 insertions(+), 121 deletions(-) diff --git a/pom.xml b/pom.xml index e9c469c66..f5fb08ca8 100644 --- a/pom.xml +++ b/pom.xml @@ -65,6 +65,59 @@ + + + + jpa + + + true + + + + + + org.springframework.data + spring-data-jpa + ${springdata.jpa} + test + + + + org.hibernate + hibernate-entitymanager + ${hibernate.version} + test + + + + org.hsqldb + hsqldb + 2.3.2 + test + + + + + + mongodb + + + true + + + + + org.springframework.data + spring-data-mongodb + ${springdata.mongodb} + test + + + + + + @@ -74,64 +127,6 @@ true - - - - org.hibernate - hibernate-entitymanager - ${hibernate.version} - test - - - - org.springframework.data - spring-data-jpa - ${springdata.jpa} - test - - - - org.springframework.data - spring-data-mongodb - ${springdata.mongodb} - test - - - - org.springframework.data - spring-data-neo4j - ${springdata.neo4j} - test - - - - org.springframework.data - spring-data-gemfire - ${springdata.gemfire} - test - - - - org.springframework.data - spring-data-solr - ${springdata.solr} - test - - - - org.springframework.data - spring-data-cassandra - ${springdata.cassandra} - test - - - - org.hsqldb - hsqldb - 2.3.2 - test - - diff --git a/spring-data-rest-webmvc/pom.xml b/spring-data-rest-webmvc/pom.xml index 92700b31b..11063ce98 100644 --- a/spring-data-rest-webmvc/pom.xml +++ b/spring-data-rest-webmvc/pom.xml @@ -83,9 +83,9 @@ - com.github.fge - json-patch - 1.7 + com.github.fge + json-patch + 1.7 @@ -116,6 +116,41 @@ + + neo4j + + + true + + + + + org.springframework.data + spring-data-neo4j + ${springdata.neo4j} + test + + + + + + + gemfire + + + true + + + + + org.springframework.data + spring-data-gemfire + ${springdata.gemfire} + test + + + + cassandra @@ -125,6 +160,13 @@ + + org.springframework.data + spring-data-cassandra + ${springdata.cassandra} + test + + org.apache.cassandra cassandra-all @@ -148,14 +190,6 @@ org.hamcrest hamcrest-all - - org.springframework - spring-context - - - org.springframework - spring-test - org.apache.cassandra cassandra-all @@ -178,7 +212,7 @@ test - + org.antlr antlr-runtime @@ -193,12 +227,6 @@ test - - com.googlecode.concurrentlinkedhashmap - concurrentlinkedhashmap-lru - 1.3.1 - test - @@ -210,6 +238,14 @@ + + + org.springframework.data + spring-data-solr + ${springdata.solr} + test + + org.apache.solr solr-core diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/AbstractCassandraIntegrationTest.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/AbstractCassandraIntegrationTest.java index 2063c2791..de9b4fdc5 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/AbstractCassandraIntegrationTest.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/AbstractCassandraIntegrationTest.java @@ -17,14 +17,15 @@ package org.springframework.data.rest.webmvc.cassandra; import java.io.IOException; -import com.datastax.driver.core.Cluster; -import com.datastax.driver.core.Session; import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.thrift.transport.TTransportException; import org.cassandraunit.utils.EmbeddedCassandraServerHelper; import org.junit.BeforeClass; import org.springframework.data.rest.webmvc.CommonWebTests; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Session; + /** * Base class for testing with an embedded cassandra database * @@ -35,11 +36,12 @@ public abstract class AbstractCassandraIntegrationTest extends CommonWebTests { /** * The session connected to the system keyspace. */ - protected Session systemSession; + Session systemSession; + /** * The {@link com.datastax.driver.core.Cluster} that's connected to Cassandra. */ - protected Cluster cluster; + Cluster cluster; /** * Launch an embedded Cassandra instance @@ -54,6 +56,7 @@ public abstract class AbstractCassandraIntegrationTest extends CommonWebTests { } public AbstractCassandraIntegrationTest() { + // check cluster if (cluster == null) { cluster = Cluster.builder()// @@ -67,5 +70,4 @@ public abstract class AbstractCassandraIntegrationTest extends CommonWebTests { systemSession = cluster.connect(); } } - } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/CassandraProperties.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/CassandraProperties.java index 674b1c163..cb62c8f75 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/CassandraProperties.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/CassandraProperties.java @@ -1,7 +1,7 @@ package org.springframework.data.rest.webmvc.cassandra; -public class CassandraProperties { +class CassandraProperties { - public static final String HOSTNAME = "localhost"; - public static final int PORT = 9142; + static final String HOSTNAME = "localhost"; + static final int PORT = 9142; } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/CassandraWebTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/CassandraWebTests.java index 9e6d6b3a6..cc9dc19f8 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/CassandraWebTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/CassandraWebTests.java @@ -32,17 +32,20 @@ import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ContextConfiguration; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; /** * Integration tests for Cassandra repositories * * @author Greg Turnquist + * @author Oliver Gierke */ @ContextConfiguration(classes = CassandraRepoConfig.class) public class CassandraWebTests extends AbstractCassandraIntegrationTest { - @Autowired private EmployeeRepository repository; + @Autowired EmployeeRepository repository; + ObjectMapper mapper; @Override protected Iterable expectedRootLinkRels() { @@ -50,30 +53,32 @@ public class CassandraWebTests extends AbstractCassandraIntegrationTest { } /** - * Given that Spring Data Cassandra can leave behind persistent artifacts, need to clean out ALL entities - * before launching a given test case. - * - * @throws ConfigurationException - * @throws IOException - * @throws TTransportException - * @throws InterruptedException + * Given that Spring Data Cassandra can leave behind persistent artifacts, need to clean out ALL entities before + * launching a given test case. */ @Before public void cleanoutDatabase() throws ConfigurationException, IOException, TTransportException, InterruptedException { - repository.deleteAll(); + this.repository.deleteAll(); + + this.mapper = new ObjectMapper(); + this.mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); } + /** + * @see DATAREST-414 + */ @Test public void create() throws Exception { Link employeeLink = client.discoverUnique("employees"); - ObjectMapper mapper = new ObjectMapper(); + Employee employee = new Employee(); employee.setId("789"); employee.setFirstName("Bilbo"); employee.setLastName("Baggins"); employee.setTitle("burgler"); + String bilboString = mapper.writeValueAsString(employee); MockHttpServletResponse response = postAndGet(employeeLink, bilboString, MediaType.APPLICATION_JSON); @@ -84,10 +89,11 @@ public class CassandraWebTests extends AbstractCassandraIntegrationTest { } /** - * After inserting data directly through a Spring Data Cassandra repository, verify Spring Data REST can - * fetch the resources through hypermedia. + * After inserting data directly through a Spring Data Cassandra repository, verify Spring Data REST can fetch the + * resources through hypermedia. * * @throws Exception + * @see DATAREST-414 */ @Test public void findAllEmployees() throws Exception { @@ -97,6 +103,7 @@ public class CassandraWebTests extends AbstractCassandraIntegrationTest { employee1.setFirstName("Frodo"); employee1.setLastName("Baggins"); employee1.setTitle("ring bearer"); + repository.save(employee1); Employee employee2 = new Employee(); @@ -104,22 +111,23 @@ public class CassandraWebTests extends AbstractCassandraIntegrationTest { employee2.setFirstName("Samwise"); employee2.setLastName("Gamgee"); employee2.setTitle("ring bearer"); + repository.save(employee2); Link employeesLink = client.discoverUnique("employees"); - client.follow(employeesLink) - .andExpect(status().isOk()) + client.follow(employeesLink).andExpect(status().isOk()) .andExpect(jsonPath("$._embedded.employees[*].firstName", hasItems("Samwise", "Frodo"))) .andExpect(jsonPath("$._embedded.employees[*].lastName", hasItems("Gamgee", "Baggins"))) .andExpect(jsonPath("$._embedded.employees[*].title", hasItems("ring bearer", "ring bearer"))); } /** - * Verify some basic creation (POST), updating (PATH) and replacing (PUT) functionality of Spring - * Data Cassandra through Spring Data REST. + * Verify some basic creation (POST), updating (PATH) and replacing (PUT) functionality of Spring Data Cassandra + * through Spring Data REST. * * @throws Exception + * @see DATAREST-414 */ @Test public void createAnEmployee() throws Exception { @@ -129,7 +137,7 @@ public class CassandraWebTests extends AbstractCassandraIntegrationTest { employee.setFirstName("Frodo"); employee.setLastName("Baggins"); employee.setTitle("ring bearer"); - ObjectMapper mapper = new ObjectMapper(); + String employeeString = mapper.writeValueAsString(employee); Link employeeLink = client.discoverUnique("employees"); @@ -143,8 +151,8 @@ public class CassandraWebTests extends AbstractCassandraIntegrationTest { assertThat(newlyMintedEmployee.getLastName(), equalTo(employee.getLastName())); assertThat(newlyMintedEmployee.getTitle(), equalTo(employee.getTitle())); - MockHttpServletResponse response2 = patchAndGet( - newlyMintedEmployeeLink, "{\"firstName\": \"Bilbo\"}", MediaType.APPLICATION_JSON); + MockHttpServletResponse response2 = patchAndGet(newlyMintedEmployeeLink, "{\"firstName\": \"Bilbo\"}", + MediaType.APPLICATION_JSON); Link refurbishedEmployeeLink = client.assertHasLinkWithRel("self", response2); Employee refurbishedEmployee = mapper.readValue(response2.getContentAsString(), Employee.class); @@ -153,8 +161,8 @@ public class CassandraWebTests extends AbstractCassandraIntegrationTest { assertThat(refurbishedEmployee.getLastName(), equalTo(employee.getLastName())); assertThat(refurbishedEmployee.getTitle(), equalTo(employee.getTitle())); - MockHttpServletResponse response3 = putAndGet( - refurbishedEmployeeLink, "{\"lastName\": \"Jr.\"}", MediaType.APPLICATION_JSON); + MockHttpServletResponse response3 = putAndGet(refurbishedEmployeeLink, "{\"lastName\": \"Jr.\"}", + MediaType.APPLICATION_JSON); Employee lastEmployee = mapper.readValue(response3.getContentAsString(), Employee.class); @@ -167,6 +175,7 @@ public class CassandraWebTests extends AbstractCassandraIntegrationTest { * Verify that creating (POST) and then updating (PATCH) a resource only updates the sub-set of fields. * * @throws Exception + * @see DATAREST-414 */ @Test public void createThenPatch() throws Exception { @@ -176,7 +185,7 @@ public class CassandraWebTests extends AbstractCassandraIntegrationTest { employee.setFirstName("Frodo"); employee.setLastName("Baggins"); employee.setTitle("ring bearer"); - ObjectMapper mapper = new ObjectMapper(); + String employeeString = mapper.writeValueAsString(employee); Link employeeLink = client.discoverUnique("employees"); @@ -190,8 +199,8 @@ public class CassandraWebTests extends AbstractCassandraIntegrationTest { assertThat(newlyMintedEmployee.getLastName(), equalTo(employee.getLastName())); assertThat(newlyMintedEmployee.getTitle(), equalTo(employee.getTitle())); - MockHttpServletResponse response2 = patchAndGet( - newlyMintedEmployeeLink, "{\"firstName\": \"Bilbo\"}", MediaType.APPLICATION_JSON); + MockHttpServletResponse response2 = patchAndGet(newlyMintedEmployeeLink, "{\"firstName\": \"Bilbo\"}", + MediaType.APPLICATION_JSON); Employee refurbishedEmployee = mapper.readValue(response2.getContentAsString(), Employee.class); @@ -201,13 +210,12 @@ public class CassandraWebTests extends AbstractCassandraIntegrationTest { } /** - * Verify that first creating (POST) and then replacing (PUT) a resource with a subset of fields only causes - * the subset of fields to be changed inside Cassandra. - * - * NOTE: Cassandra doesn't handle nulls like traditional databases and Spring Data Cassandra ignores - * null fields. + * Verify that first creating (POST) and then replacing (PUT) a resource with a subset of fields only causes the + * subset of fields to be changed inside Cassandra. NOTE: Cassandra doesn't handle nulls like traditional databases + * and Spring Data Cassandra ignores {@literal null} fields. * * @throws Exception + * @see DATAREST-414 */ @Test public void createThenPut() throws Exception { @@ -217,7 +225,7 @@ public class CassandraWebTests extends AbstractCassandraIntegrationTest { employee.setFirstName("Frodo"); employee.setLastName("Baggins"); employee.setTitle("ring bearer"); - ObjectMapper mapper = new ObjectMapper(); + String employeeString = mapper.writeValueAsString(employee); Link employeeLink = client.discoverUnique("employees"); @@ -231,8 +239,8 @@ public class CassandraWebTests extends AbstractCassandraIntegrationTest { assertThat(newlyMintedEmployee.getLastName(), equalTo(employee.getLastName())); assertThat(newlyMintedEmployee.getTitle(), equalTo(employee.getTitle())); - MockHttpServletResponse response2 = putAndGet( - newlyMintedEmployeeLink, "{\"firstName\": \"Bilbo\"}", MediaType.APPLICATION_JSON); + MockHttpServletResponse response2 = putAndGet(newlyMintedEmployeeLink, "{\"firstName\": \"Bilbo\"}", + MediaType.APPLICATION_JSON); Employee refurbishedEmployee = mapper.readValue(response2.getContentAsString(), Employee.class); @@ -243,5 +251,4 @@ public class CassandraWebTests extends AbstractCassandraIntegrationTest { assertThat(refurbishedEmployee.getLastName(), equalTo(employee.getLastName())); assertThat(refurbishedEmployee.getTitle(), equalTo(employee.getTitle())); } - } diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/Employee.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/Employee.java index 2052c0eac..46c7e9faf 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/Employee.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/Employee.java @@ -15,7 +15,6 @@ */ package org.springframework.data.rest.webmvc.cassandra; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.springframework.data.cassandra.mapping.PrimaryKey; import org.springframework.data.cassandra.mapping.Table; @@ -23,12 +22,12 @@ import org.springframework.data.cassandra.mapping.Table; * Simple domain object * * @author Greg Turnquist + * @author Oliver Gierke */ @Table -@JsonIgnoreProperties(ignoreUnknown = true) public class Employee { - @PrimaryKey private String id; + private @PrimaryKey String id; private String firstName; private String lastName; private String title; diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/EmployeeRepository.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/EmployeeRepository.java index 2bd085b61..a1f698c8a 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/EmployeeRepository.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/EmployeeRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.