diff --git a/spring-data-rest-webmvc/pom.xml b/spring-data-rest-webmvc/pom.xml index 5cb7edf45..38975c161 100644 --- a/spring-data-rest-webmvc/pom.xml +++ b/spring-data-rest-webmvc/pom.xml @@ -162,92 +162,6 @@ - - cassandra - - - true - - - - - - org.springframework.data - spring-data-cassandra - ${springdata.cassandra} - test - - - - org.apache.cassandra - cassandra-all - ${cassandra.version} - test - - - org.slf4j - slf4j-log4j12 - - - - - - org.cassandraunit - cassandra-unit-spring - ${cassandraunit.version} - test - - - org.hamcrest - hamcrest-all - - - org.apache.cassandra - cassandra-all - - - com.datastax.cassandra - cassandra-driver-core - - - org.slf4j - slf4j-log4j12 - - - - - - org.xerial.snappy - snappy-java - 1.1.0.1 - test - - - - - org.antlr - antlr-runtime - 3.2 - test - - - - com.google.guava - guava - ${guava} - test - - - - com.googlecode.concurrentlinkedhashmap - concurrentlinkedhashmap-lru - 1.3.1 - test - - - - - solr 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 deleted file mode 100644 index e39aa0bc7..000000000 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/AbstractCassandraIntegrationTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.rest.webmvc.cassandra; - -import java.io.IOException; - -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; -import com.datastax.driver.core.exceptions.NoHostAvailableException; - -/** - * Base class for testing with an embedded cassandra database - * - * @author Greg Turnquist - */ -public abstract class AbstractCassandraIntegrationTest extends CommonWebTests { - - /** - * The session connected to the system keyspace. - */ - Session systemSession; - - /** - * The {@link com.datastax.driver.core.Cluster} that's connected to Cassandra. - */ - Cluster cluster; - - /** - * Launch an embedded Cassandra instance - * - * @throws ConfigurationException - * @throws IOException - * @throws TTransportException - */ - @BeforeClass - public static void startDatabase() throws ConfigurationException, IOException, TTransportException { - EmbeddedCassandraServerHelper.startEmbeddedCassandra("cassandra.yaml"); - } - - public AbstractCassandraIntegrationTest() { - - // check cluster - if (cluster == null) { - cluster = Cluster.builder()// - .addContactPoint(CassandraProperties.HOSTNAME)// - .withPort(CassandraProperties.PORT)// - .build(); - } - - // check system session connected - if (systemSession == null) { - systemSession = tryToConnect(cluster, 3); - } - } - - private static Session tryToConnect(Cluster cluster, int attempts) { - - try { - return cluster.connect(); - } catch (NoHostAvailableException o_O) { - - if (attempts == 0) { - throw o_O; - } - - try { - Thread.sleep(200); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - - return tryToConnect(cluster, --attempts); - } - } -} 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 deleted file mode 100644 index cb62c8f75..000000000 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/CassandraProperties.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.springframework.data.rest.webmvc.cassandra; - -class CassandraProperties { - - 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/CassandraRepoConfig.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/CassandraRepoConfig.java deleted file mode 100644 index 318aa2562..000000000 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/CassandraRepoConfig.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.springframework.data.rest.webmvc.cassandra; - -import static org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification.*; - -import java.util.Arrays; -import java.util.List; - -import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.cassandra.config.SchemaAction; -import org.springframework.data.cassandra.config.java.AbstractCassandraConfiguration; -import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories; - -/** - * Basic configuration for a Cassandra set up. - * - * @author Greg Turnquist - */ -@Configuration -@EnableCassandraRepositories -public class CassandraRepoConfig extends AbstractCassandraConfiguration { - - @Override - protected String getKeyspaceName() { - return "SpringDataRestCassandra"; - } - - @Override - public SchemaAction getSchemaAction() { - return SchemaAction.RECREATE_DROP_UNUSED; - } - - @Override - protected int getPort() { - return CassandraProperties.PORT; - } - - @Override - public String[] getEntityBasePackages() { - return new String[] {this.getClass().getPackage().getName()}; - } - - /** - * When retrieving the keyspaces, create one for testing. - * - * @return - */ - @Override - protected List getKeyspaceCreations() { - return Arrays.asList(createKeyspace().name(getKeyspaceName()).withSimpleReplication()); - } -} 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 deleted file mode 100644 index 0f6e3651a..000000000 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/CassandraWebTests.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.rest.webmvc.cassandra; - -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -import java.io.IOException; -import java.util.Arrays; - -import org.apache.cassandra.exceptions.ConfigurationException; -import org.apache.thrift.transport.TTransportException; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.hateoas.Link; -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 EmployeeRepository repository; - ObjectMapper mapper; - - @Override - protected Iterable expectedRootLinkRels() { - return Arrays.asList("employees"); - } - - /** - * 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 { - - 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"); - - 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); - - assertJsonPathEquals("$.firstName", "Bilbo", response); - assertJsonPathEquals("$.lastName", "Baggins", response); - assertJsonPathEquals("$.title", "burgler", response); - } - - /** - * 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 { - - Employee employee1 = new Employee(); - employee1.setId("123"); - employee1.setFirstName("Frodo"); - employee1.setLastName("Baggins"); - employee1.setTitle("ring bearer"); - - repository.save(employee1); - - Employee employee2 = new Employee(); - employee2.setId("789"); - employee2.setFirstName("Samwise"); - employee2.setLastName("Gamgee"); - employee2.setTitle("ring bearer"); - - repository.save(employee2); - - Link employeesLink = client.discoverUnique("employees"); - - 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. - * - * @throws Exception - * @see DATAREST-414 - */ - @Test - @Ignore - public void createAnEmployee() throws Exception { - - Employee employee = new Employee(); - employee.setId("123"); - employee.setFirstName("Frodo"); - employee.setLastName("Baggins"); - employee.setTitle("ring bearer"); - - String employeeString = mapper.writeValueAsString(employee); - - Link employeeLink = client.discoverUnique("employees"); - - MockHttpServletResponse response = postAndGet(employeeLink, employeeString, MediaType.APPLICATION_JSON); - - Link newlyMintedEmployeeLink = client.assertHasLinkWithRel("self", response); - Employee newlyMintedEmployee = mapper.readValue(response.getContentAsString(), Employee.class); - - assertThat(newlyMintedEmployee.getFirstName(), equalTo(employee.getFirstName())); - assertThat(newlyMintedEmployee.getLastName(), equalTo(employee.getLastName())); - assertThat(newlyMintedEmployee.getTitle(), equalTo(employee.getTitle())); - - MockHttpServletResponse response2 = patchAndGet(newlyMintedEmployeeLink, "{\"firstName\": \"Bilbo\"}", - MediaType.APPLICATION_JSON); - - Link refurbishedEmployeeLink = client.assertHasLinkWithRel("self", response2); - Employee refurbishedEmployee = mapper.readValue(response2.getContentAsString(), Employee.class); - - assertThat(refurbishedEmployee.getFirstName(), equalTo("Bilbo")); - assertThat(refurbishedEmployee.getLastName(), equalTo(employee.getLastName())); - assertThat(refurbishedEmployee.getTitle(), equalTo(employee.getTitle())); - - MockHttpServletResponse response3 = putAndGet(refurbishedEmployeeLink, "{\"lastName\": \"Jr.\"}", - MediaType.APPLICATION_JSON); - - Employee lastEmployee = mapper.readValue(response3.getContentAsString(), Employee.class); - - assertThat(lastEmployee.getFirstName(), equalTo("Bilbo")); - assertThat(lastEmployee.getLastName(), equalTo("Jr.")); - assertThat(lastEmployee.getTitle(), equalTo(employee.getTitle())); - } - - /** - * 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 { - - Employee employee = new Employee(); - employee.setId("123"); - employee.setFirstName("Frodo"); - employee.setLastName("Baggins"); - employee.setTitle("ring bearer"); - - String employeeString = mapper.writeValueAsString(employee); - - Link employeeLink = client.discoverUnique("employees"); - - MockHttpServletResponse response1 = postAndGet(employeeLink, employeeString, MediaType.APPLICATION_JSON); - - Link newlyMintedEmployeeLink = client.assertHasLinkWithRel("self", response1); - Employee newlyMintedEmployee = mapper.readValue(response1.getContentAsString(), Employee.class); - - assertThat(newlyMintedEmployee.getFirstName(), equalTo(employee.getFirstName())); - assertThat(newlyMintedEmployee.getLastName(), equalTo(employee.getLastName())); - assertThat(newlyMintedEmployee.getTitle(), equalTo(employee.getTitle())); - - MockHttpServletResponse response2 = patchAndGet(newlyMintedEmployeeLink, "{\"firstName\": \"Bilbo\"}", - MediaType.APPLICATION_JSON); - - Employee refurbishedEmployee = mapper.readValue(response2.getContentAsString(), Employee.class); - - // That's actually incorrect, isn't it? - assertThat(refurbishedEmployee.getFirstName(), equalTo("Bilbo")); - assertThat(refurbishedEmployee.getLastName(), equalTo(employee.getLastName())); - assertThat(refurbishedEmployee.getTitle(), equalTo(employee.getTitle())); - } - - /** - * 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 - @Ignore - public void createThenPut() throws Exception { - - Employee employee = new Employee(); - employee.setId("123"); - employee.setFirstName("Frodo"); - employee.setLastName("Baggins"); - employee.setTitle("ring bearer"); - - String employeeString = mapper.writeValueAsString(employee); - - Link employeeLink = client.discoverUnique("employees"); - - MockHttpServletResponse response1 = postAndGet(employeeLink, employeeString, MediaType.APPLICATION_JSON); - - Link newlyMintedEmployeeLink = client.assertHasLinkWithRel("self", response1); - Employee newlyMintedEmployee = mapper.readValue(response1.getContentAsString(), Employee.class); - - assertThat(newlyMintedEmployee.getFirstName(), equalTo(employee.getFirstName())); - assertThat(newlyMintedEmployee.getLastName(), equalTo(employee.getLastName())); - assertThat(newlyMintedEmployee.getTitle(), equalTo(employee.getTitle())); - - MockHttpServletResponse response2 = putAndGet(newlyMintedEmployeeLink, "{\"firstName\": \"Bilbo\"}", - MediaType.APPLICATION_JSON); - - Employee refurbishedEmployee = mapper.readValue(response2.getContentAsString(), Employee.class); - - assertThat(refurbishedEmployee.getFirstName(), equalTo("Bilbo")); - - // Spring Data Cassandra doesn't apply null field values, hence these attributes won't change from - // the original POST. - 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 deleted file mode 100644 index 46c7e9faf..000000000 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/Employee.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.rest.webmvc.cassandra; - -import org.springframework.data.cassandra.mapping.PrimaryKey; -import org.springframework.data.cassandra.mapping.Table; - -/** - * Simple domain object - * - * @author Greg Turnquist - * @author Oliver Gierke - */ -@Table -public class Employee { - - private @PrimaryKey String id; - private String firstName; - private String lastName; - private String title; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - @Override - public String toString() { - return "Id: " + id + " First: " + firstName + " Last: " + lastName + " Title: " + 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 deleted file mode 100644 index a1f698c8a..000000000 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/cassandra/EmployeeRepository.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.data.rest.webmvc.cassandra; - -import org.springframework.data.repository.CrudRepository; - -/** - * Simple repository definition - * - * @author Greg Turnquist - */ -public interface EmployeeRepository extends CrudRepository { - -}