DATAREST-740 - Removed Cassandra integration tests.

This commit is contained in:
Oliver Gierke
2016-01-05 12:42:41 +01:00
parent 482c78c925
commit 000f645543
7 changed files with 0 additions and 595 deletions

View File

@@ -162,92 +162,6 @@
</dependencies>
</profile>
<profile>
<id>cassandra</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-cassandra</artifactId>
<version>${springdata.cassandra}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>${cassandra.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.cassandraunit</groupId>
<artifactId>cassandra-unit-spring</artifactId>
<version>${cassandraunit.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
</exclusion>
<exclusion>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
<version>1.1.0.1</version>
<scope>test</scope>
</dependency>
<!-- Declare Antlr locally to favor this one as Solr pulls in 3.5 which breaks Cassandra -->
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr-runtime</artifactId>
<version>3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.concurrentlinkedhashmap</groupId>
<artifactId>concurrentlinkedhashmap-lru</artifactId>
<version>1.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>solr</id>

View File

@@ -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);
}
}
}

View File

@@ -1,7 +0,0 @@
package org.springframework.data.rest.webmvc.cassandra;
class CassandraProperties {
static final String HOSTNAME = "localhost";
static final int PORT = 9142;
}

View File

@@ -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<CreateKeyspaceSpecification> getKeyspaceCreations() {
return Arrays.asList(createKeyspace().name(getKeyspaceName()).withSimpleReplication());
}
}

View File

@@ -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<String> 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()));
}
}

View File

@@ -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;
}
}

View File

@@ -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<Employee, String> {
}