DATAREST-184 - Upgraded to Spring Data Neo4j 2.3.3.

The upgrade is necessary to benefit from a fix for DATAGRAPH-409 which transitively fixes this ticket.

Added integration tests for Neo4j repositories.
This commit is contained in:
Oliver Gierke
2013-11-13 15:26:24 +00:00
parent 9b4b111d23
commit 8e29f9bcff
8 changed files with 374 additions and 4 deletions

View File

@@ -17,7 +17,7 @@ ext {
sdJpaVersion = "1.5.0.BUILD-SNAPSHOT"
sdMongoVersion = "1.4.0.BUILD-SNAPSHOT"
sdGemfireVersion = "1.3.3.BUILD-SNAPSHOT"
sdNeo4jVersion = "2.3.2.RELEASE"
sdNeo4jVersion = "2.3.3.BUILD-SNAPSHOT"
// Libraries
jacksonVersion = "2.2.2"
@@ -168,14 +168,12 @@ project("spring-data-rest-core") {
// JPA
testRuntime("org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final", optional)
testRuntime("org.springframework:spring-orm:$springVersion", optional)
}
}
project("spring-data-rest-webmvc") {
apply plugin: "maven"
description = "Spring Data REST MVC components."
@@ -209,6 +207,7 @@ project("spring-data-rest-webmvc") {
testCompile "org.springframework.data:spring-data-jpa:$sdJpaVersion"
testCompile "org.springframework.data:spring-data-mongodb:$sdMongoVersion"
testCompile "org.springframework.data:spring-data-gemfire:$sdGemfireVersion"
testCompile "org.springframework.data:spring-data-neo4j:$sdNeo4jVersion"
// JODA
testCompile "joda-time:joda-time:$jodaVersion"

View File

@@ -0,0 +1,47 @@
/*
* Copyright 2012-2013 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.neo4j;
import org.springframework.data.neo4j.annotation.GraphId;
public abstract class AbstractEntity {
@GraphId//
private Long id;
public Long getId() {
return id;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (id == null || obj == null || !getClass().equals(obj.getClass())) {
return false;
}
return id.equals(((AbstractEntity) obj).id);
}
@Override
public int hashCode() {
return id == null ? 0 : id.hashCode();
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2012-2013 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.neo4j;
import org.springframework.data.neo4j.annotation.NodeEntity;
@NodeEntity
public class Address extends AbstractEntity {
private String street, city;
private Country country;
public Address(String street, String city, Country country) {
this.street = street;
this.city = city;
this.country = country;
}
public Address() {
}
public String getStreet() {
return street;
}
public String getCity() {
return city;
}
public Country getCountry() {
return country;
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright 2012-2013 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.neo4j;
import org.springframework.data.neo4j.annotation.Indexed;
import org.springframework.data.neo4j.annotation.NodeEntity;
@NodeEntity
public class Country extends AbstractEntity {
@Indexed(unique = true) String code;
String name;
public Country(String code, String name) {
this.code = code;
this.name = name;
}
public Country() {}
}

View File

@@ -0,0 +1,88 @@
/*
* Copyright 2012-2013 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.neo4j;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.springframework.data.neo4j.annotation.Indexed;
import org.springframework.data.neo4j.annotation.NodeEntity;
import org.springframework.data.neo4j.annotation.RelatedTo;
import org.springframework.util.Assert;
@NodeEntity
public class Customer extends AbstractEntity {
private String firstName, lastName;
@Indexed(unique = true)//
private String emailAddress;
@RelatedTo(type = "ADDRESS")//
private Set<Address> addresses = new HashSet<Address>();
public Customer(String firstName, String lastName, String emailAddress) {
Assert.hasText(firstName);
Assert.hasText(lastName);
Assert.hasText(emailAddress);
this.firstName = firstName;
this.lastName = lastName;
this.emailAddress = emailAddress;
}
protected Customer() {
}
public void add(Address address) {
this.addresses.add(address);
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public Set<Address> getAddresses() {
return Collections.unmodifiableSet(addresses);
}
public boolean hasAddress(Address address) {
return addresses.contains(address);
}
@Override
public String toString() {
return String.format("%s %s <%s>", firstName, lastName, emailAddress);
}
}

View File

@@ -0,0 +1,23 @@
/*
* Copyright 2012-2013 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.neo4j;
import org.springframework.data.neo4j.repository.GraphRepository;
public interface CustomerRepository extends GraphRepository<Customer> {
Customer findByEmailAddress(String emailAddress);
}

View File

@@ -0,0 +1,91 @@
/*
* Copyright 2013 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.neo4j;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import java.util.Arrays;
import org.junit.Before;
import org.junit.Test;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.config.Neo4jConfiguration;
import org.springframework.data.rest.webmvc.AbstractWebIntegrationTests;
import org.springframework.hateoas.Link;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* Integration tests for exposed Neo4j repositories.
*
* @author Oliver Gierke
*/
@ContextConfiguration
public class Neo4jWebTests extends AbstractWebIntegrationTests {
@Configuration
@ComponentScan
@EnableNeo4jRepositories
@EnableTransactionManagement
static class TestConfig extends Neo4jConfiguration {
@Bean(destroyMethod = "shutdown")
public GraphDatabaseService graphDatabaseService() {
return new EmbeddedGraphDatabase("build/graph.db");
}
}
@Autowired TestDataPopulator populator;
@Before
@Override
public void setUp() {
this.populator.populate();
super.setUp();
}
/*
* (non-Javadoc)
* @see org.springframework.data.rest.webmvc.AbstractWebIntegrationTests#expectedRootLinkRels()
*/
@Override
protected Iterable<String> expectedRootLinkRels() {
return Arrays.asList("customers");
}
/**
* @see DATAREST-184
*/
@Test
public void deletesCustomer() throws Exception {
// Lookup customer
Link customers = discoverUnique("customers");
Link customerLink = assertHasContentLinkWithRel("self", request(customers));
// Delete customer
mvc.perform(delete(customerLink.getHref()));
// Assert no customers anymore
assertDoesNotHaveLinkWithRel("self", request(customers));
}
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright 2013 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.neo4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
/**
* Simple component to populate the Neo4j repositories with sample data.
*
* @author Oliver Gierke
*/
@Component
public class TestDataPopulator {
@Autowired CustomerRepository repository;
@Transactional
public void populate() {
if (repository.count() > 0) {
return;
}
repository.save(new Customer("Oliver", "Gierke", "ogierke@gopivotal.com"));
}
}