DATAGRAPH-1098 - Cleanup and consolidate tests related to configuration of repositories.

This commit is contained in:
Michael Simons
2020-08-28 18:11:39 +02:00
parent 0954cf7684
commit 57552fb3be
25 changed files with 103 additions and 188 deletions

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repositories.domain;
package org.springframework.data.neo4j.domain.sample;
/**
* @author Michal Bachman

View File

@@ -15,9 +15,11 @@
*/
package org.springframework.data.neo4j.domain.sample;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.neo4j.ogm.annotation.GeneratedValue;
@@ -28,8 +30,9 @@ import org.neo4j.ogm.annotation.Version;
import org.neo4j.ogm.annotation.typeconversion.DateString;
/**
* Domain class representing a person emphasizing the use of {@code AbstractEntity}. No declaration of an id is
* required. The id is typed by the parameterizable superclass.
* @author Mark Angrish
* @author Gerrit Meier
* @author Michael Simons
*/
@NodeEntity
public class User {
@@ -64,6 +67,8 @@ public class User {
@DateString private Date dateOfBirth;
private List<User> friends = new ArrayList<>();
/**
* Creates a new empty instance of {@code User}.
*/
@@ -71,6 +76,10 @@ public class User {
this(null, null, null);
}
public User(String lastname) {
this(null, lastname, null);
}
/**
* Creates a new instance of {@code User} with preinitialized values for firstname, lastname, email address and roles.
*
@@ -364,4 +373,8 @@ public class User {
return "User: " + getId() + ", " + getFirstname() + " " + getLastname() + ", " + getEmailAddress();
}
public List<User> getFriends() {
return friends;
}
}

View File

@@ -1,58 +0,0 @@
/*
* Copyright 2011-2020 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
*
* https://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.neo4j.repositories.domain;
import java.util.ArrayList;
import java.util.List;
/**
* @author Michal Bachman
* @author Vince Bickers
*/
public class User {
private Long id;
private String name;
private List<User> friends = new ArrayList<>();
public User() {}
public Long getId() {
return this.id;
}
public User(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<User> getFriends() {
return friends;
}
public void setFriends(List<User> friends) {
this.friends = friends;
}
}

View File

@@ -1,46 +0,0 @@
/*
* Copyright 2011-2020 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
*
* https://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.neo4j.repositories.repo;
import java.util.List;
import org.springframework.data.neo4j.repositories.domain.User;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.stereotype.Repository;
/**
* @author Michal Bachman
* @author Vince Bickers
*/
@Repository
public interface UserRepository extends Neo4jRepository<User, Long> {
/*
* @see DATAGRAPH-813
*/
Long deleteByName(String name); // return a count of deleted objects by name
/*
* @see DATAGRAPH-813
*/
List<Long> removeByName(String name); // remove users by name and return an iterable of the removed users' ids
/*
* @see DATAGRAPH-813
*/
Long countByName(String name); // return a count of objects with name
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repository.relcentric;
package org.springframework.data.neo4j.repository;
import static org.assertj.core.api.Assertions.assertThat;
@@ -27,12 +27,12 @@ import org.junit.runner.RunWith;
import org.neo4j.ogm.session.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.repository.relcentric.app.Actor;
import org.springframework.data.neo4j.repository.relcentric.app.Country;
import org.springframework.data.neo4j.repository.relcentric.app.Genre;
import org.springframework.data.neo4j.repository.relcentric.app.Movie;
import org.springframework.data.neo4j.repository.relcentric.app.Role;
import org.springframework.data.neo4j.repository.relcentric.app.RoleRepository;
import org.springframework.data.neo4j.repository.sample.relcentric.Actor;
import org.springframework.data.neo4j.repository.sample.relcentric.Country;
import org.springframework.data.neo4j.repository.sample.relcentric.Genre;
import org.springframework.data.neo4j.repository.sample.relcentric.Movie;
import org.springframework.data.neo4j.repository.sample.relcentric.Role;
import org.springframework.data.neo4j.repository.sample.relcentric.RoleRepository;
import org.springframework.data.neo4j.test.Neo4jIntegrationTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -118,7 +118,7 @@ public class MinimalRelationshipEntityMappingTests {
}
@Configuration
@Neo4jIntegrationTest(domainPackages = "org.springframework.data.neo4j.repository.relcentric.app")
@Neo4jIntegrationTest(domainPackages = "org.springframework.data.neo4j.repository.sample.relcentric")
static class Config {
}
}

View File

@@ -93,13 +93,13 @@ public class Neo4jRepositoryTests {
}
@Configuration
@Neo4jIntegrationTest(domainPackages = "org.springframework.data.neo4j.domain.sample")
@Neo4jIntegrationTest(domainPackages = "org.springframework.data.neo4j.domain.sample", considerNestedRepositories = true)
static class Config {}
}
interface SampleEntityRepository extends Neo4jRepository<SampleEntity, Long> {}
interface NodeWithUUIDAsIdRepository extends Neo4jRepository<NodeWithUUIDAsId, UUID> {
Optional<NodeWithUUIDAsId> findOneByMyNiceIdAndSomeProperty(UUID id, String someProperty);
interface SampleEntityRepository extends Neo4jRepository<SampleEntity, Long> {}
interface NodeWithUUIDAsIdRepository extends Neo4jRepository<NodeWithUUIDAsId, UUID> {
Optional<NodeWithUUIDAsId> findOneByMyNiceIdAndSomeProperty(UUID id, String someProperty);
}
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repositories;
package org.springframework.data.neo4j.repository;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.data.neo4j.test.GraphDatabaseServiceAssert.assertThat;
@@ -33,10 +33,10 @@ import org.neo4j.harness.TestServerBuilders;
import org.neo4j.ogm.config.Configuration;
import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;
import org.springframework.data.neo4j.repositories.domain.Movie;
import org.springframework.data.neo4j.repositories.domain.User;
import org.springframework.data.neo4j.repositories.repo.MovieRepository;
import org.springframework.data.neo4j.repositories.repo.UserRepository;
import org.springframework.data.neo4j.domain.sample.User;
import org.springframework.data.neo4j.domain.sample.Movie;
import org.springframework.data.neo4j.repository.sample.repo.MovieRepository;
import org.springframework.data.neo4j.repository.sample.repo.UserRepository;
import org.springframework.data.neo4j.repository.support.Neo4jRepositoryFactory;
import org.springframework.data.neo4j.transaction.Neo4jTransactionManager;
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
@@ -68,7 +68,7 @@ public class ProgrammaticRepositoryTests {
Configuration configuration = new Configuration.Builder() //
.uri(serverControls.boltURI().toString()) //
.build();
sessionFactory = new SessionFactory(configuration, "org.springframework.data.neo4j.repositories.domain");
sessionFactory = new SessionFactory(configuration, "org.springframework.data.neo4j.domain.sample");
PlatformTransactionManager platformTransactionManager = new Neo4jTransactionManager(sessionFactory);
transactionTemplate = new TransactionTemplate(platformTransactionManager);
@@ -143,12 +143,11 @@ public class ProgrammaticRepositoryTests {
UserRepository userRepository = factory.getRepository(UserRepository.class);
User userA = new User("A");
userA.setName("A");
userRepository.save(userA);
assertThat(userRepository.count()).isEqualTo(1);
assertThat(userRepository.deleteByName("A")).isEqualTo(new Long(1));
assertThat(userRepository.deleteByLastname("A")).isEqualTo(new Long(1));
assertThat(userRepository.count()).isEqualTo(0);
}
@@ -167,7 +166,7 @@ public class ProgrammaticRepositoryTests {
assertThat(userRepository.count()).isEqualTo(2);
List<Long> deletedUserIds = userRepository.removeByName("A");
List<Long> deletedUserIds = userRepository.removeByLastname("A");
assertThat(deletedUserIds.size()).isEqualTo(2);
Assertions.assertThat(deletedUserIds).containsExactlyInAnyOrder(userA.getId(), userAClone.getId());
@@ -192,7 +191,7 @@ public class ProgrammaticRepositoryTests {
assertThat(userRepository.count()).isEqualTo(2);
userRepository.deleteByName("A");
userRepository.deleteByLastname("A");
assertThat(userRepository.count()).isEqualTo(1);
}
@@ -205,10 +204,9 @@ public class ProgrammaticRepositoryTests {
UserRepository userRepository = factory.getRepository(UserRepository.class);
User userA = new User("A");
userA.setName("A");
userRepository.save(userA);
assertThat(userRepository.countByName("A")).isEqualTo(new Long(1));
assertThat(userRepository.countByLastname("A")).isEqualTo(new Long(1));
}
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repositories;
package org.springframework.data.neo4j.repository;
import static org.springframework.data.neo4j.test.GraphDatabaseServiceAssert.*;
@@ -26,8 +26,8 @@ import org.junit.runner.RunWith;
import org.neo4j.graphdb.GraphDatabaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.repositories.domain.User;
import org.springframework.data.neo4j.repositories.repo.UserRepository;
import org.springframework.data.neo4j.domain.sample.User;
import org.springframework.data.neo4j.repository.sample.repo.UserRepository;
import org.springframework.data.neo4j.test.Neo4jIntegrationTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@@ -57,15 +57,15 @@ public class RepoScanningTests {
userRepository.save(user);
Map<String, Object> params = new HashMap<>();
params.put("name", user.getName());
params.put("name", user.getLastname());
assertThat(graphDatabaseService)
.containsNode("MATCH (n:User {name: $name}) RETURN n", params)
.containsNode("MATCH (n:User {lastname: $name}) RETURN n", params)
.withId(user.getId());
}
@Configuration
@Neo4jIntegrationTest(domainPackages = "org.springframework.data.neo4j.repositories.domain")
@Neo4jIntegrationTest(domainPackages = "org.springframework.data.neo4j.domain.sample")
static class PersistenceContextInTheSamePackage {}
}

View File

@@ -13,10 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repositories;
package org.springframework.data.neo4j.repository;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.data.neo4j.test.GraphDatabaseServiceAssert.*;
import java.util.HashMap;
import java.util.Map;
@@ -28,8 +27,8 @@ import org.junit.runner.RunWith;
import org.neo4j.graphdb.GraphDatabaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.repositories.domain.Movie;
import org.springframework.data.neo4j.repositories.repo.MovieRepository;
import org.springframework.data.neo4j.domain.sample.Movie;
import org.springframework.data.neo4j.repository.sample.repo.MovieRepository;
import org.springframework.data.neo4j.test.GraphDatabaseServiceAssert;
import org.springframework.data.neo4j.test.Neo4jIntegrationTest;
import org.springframework.test.context.ContextConfiguration;
@@ -80,8 +79,8 @@ public class RepositoryDefinitionTests {
}
@Configuration
@Neo4jIntegrationTest(domainPackages = "org.springframework.data.neo4j.repositories.domain",
repositoryPackages = "org.springframework.data.neo4j.repositories.repo")
@Neo4jIntegrationTest(domainPackages = "org.springframework.data.neo4j.domain.sample",
repositoryPackages = "org.springframework.data.neo4j.repository.sample.repo")
static class RepositoriesTestContext {}
}

View File

@@ -21,11 +21,11 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.ConfigurationClassPostProcessor;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.StandardAnnotationMetadata;
import org.springframework.data.neo4j.repository.sample.UserRepository;
import org.springframework.data.neo4j.repository.sample.repo.UserRepository;
import static org.assertj.core.api.Assertions.assertThat;
@@ -42,7 +42,7 @@ public class Neo4jRepositoriesRegistrarTests {
@Before
public void setUp() {
metadata = new StandardAnnotationMetadata(Config.class, true);
metadata = AnnotationMetadata.introspect(Config.class);
registry = new DefaultListableBeanFactory();
}
@@ -52,7 +52,7 @@ public class Neo4jRepositoriesRegistrarTests {
Neo4jRepositoriesRegistrar registrar = new Neo4jRepositoriesRegistrar();
registrar.setResourceLoader(new DefaultResourceLoader());
registrar.setEnvironment(new StandardEnvironment());
registrar.registerBeanDefinitions(metadata, registry);
registrar.registerBeanDefinitions(metadata, registry, ConfigurationClassPostProcessor.IMPORT_BEAN_NAME_GENERATOR);
Iterable<String> names = Arrays.asList(registry.getBeanDefinitionNames());
assertThat(names).contains("userRepository");

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repository;
package org.springframework.data.neo4j.repository.sample.domain;
import java.util.UUID;
@@ -23,7 +23,7 @@ import org.neo4j.ogm.annotation.Index;
import org.neo4j.ogm.annotation.NodeEntity;
/**
* Created by markangrish on 24/03/2017.
* @author Mark Angrish
*/
@NodeEntity
public abstract class Contact {

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repository.relcentric.app;
package org.springframework.data.neo4j.repository.sample.relcentric;
import java.util.ArrayList;
import java.util.List;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repository.relcentric.app;
package org.springframework.data.neo4j.repository.sample.relcentric;
/**
* @author Michael J. Simons

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repository.relcentric.app;
package org.springframework.data.neo4j.repository.sample.relcentric;
/**
* @author Michael J. Simons

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repository.relcentric.app;
package org.springframework.data.neo4j.repository.sample.relcentric;
import org.neo4j.ogm.annotation.Relationship;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repository.relcentric.app;
package org.springframework.data.neo4j.repository.sample.relcentric;
import org.neo4j.ogm.annotation.EndNode;
import org.neo4j.ogm.annotation.RelationshipEntity;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repository.relcentric.app;
package org.springframework.data.neo4j.repository.sample.relcentric;
import java.util.List;

View File

@@ -13,11 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repository;
package org.springframework.data.neo4j.repository.sample.repo;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.sample.domain.Contact;
/**
* Created by markangrish on 24/03/2017.
* @author Mark Angrish
*/
public interface ContactRepository extends Neo4jRepository<Contact, String> {
}

View File

@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repositories.repo;
package org.springframework.data.neo4j.repository.sample.repo;
import org.springframework.data.neo4j.repositories.domain.Movie;
import org.springframework.data.neo4j.domain.sample.Movie;
import org.springframework.data.repository.RepositoryDefinition;
/**

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repository.sample;
package org.springframework.data.neo4j.repository.sample.repo;
import java.util.List;
import java.util.Optional;
@@ -23,17 +23,25 @@ import org.springframework.data.neo4j.domain.sample.User;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
/**
* Repository interface for {@code User}s.
*
* @author Mark Angrish
* @author Mark Paluch
* @author Jens Schauder
* @author Michal Bachman
* @author Vince Bickers
*/
@Repository
public interface UserRepository extends Neo4jRepository<User, Long> {
// DATAGRAPH-813
Long deleteByLastname(String name); // return a count of deleted objects by name
// DATAGRAPH-813
List<Long> removeByLastname(String name); // remove users by name and return an iterable of the removed users' ids
// DATAGRAPH-813
Long countByLastname(String name); // return a count of objects with name
/**
* Retrieve users by their lastname. The finder {@literal User.findByLastname} is declared in
* {@literal META-INF/orm.xml} .
@@ -44,14 +52,14 @@ public interface UserRepository extends Neo4jRepository<User, Long> {
List<User> findByLastname(String lastname);
/**
* Redeclaration of {@link CrudRepository#findOne(java.io.Serializable)} to change transaction configuration.
* Redeclaration of {@link CrudRepository#findById(Object)} (java.io.Serializable)} to change transaction configuration.
*/
@Override
@Transactional
Optional<User> findById(Long primaryKey);
/**
* Redeclaration of {@link CrudRepository#delete(java.io.Serializable)}. to make sure the transaction configuration of
* Redeclaration of {@link CrudRepository#deleteById(Object)} (java.io.Serializable)}. to make sure the transaction configuration of
* the original method is considered if the redeclaration does not carry a {@link Transactional} annotation.
*/
@Override

View File

@@ -23,7 +23,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.neo4j.domain.sample.User;
import org.springframework.data.neo4j.repository.sample.UserRepository;
import org.springframework.data.neo4j.repository.sample.repo.UserRepository;
import org.springframework.data.neo4j.test.Neo4jIntegrationTest;
import org.springframework.data.neo4j.transaction.Neo4jTransactionManager;
import org.springframework.test.context.ContextConfiguration;

View File

@@ -28,7 +28,7 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.neo4j.mapping.MetaDataProvider;
import org.springframework.data.neo4j.repository.ContactRepository;
import org.springframework.data.neo4j.repository.sample.repo.ContactRepository;
/**
* @author Mark Angrish
@@ -58,11 +58,9 @@ public class Neo4jRepositoryFactoryBeanTests {
/**
* Assert that the instance created for the standard configuration is a valid {@code UserRepository}.
*
* @throws Exception
*/
@Test
public void setsUpBasicInstanceCorrectly() throws Exception {
public void setsUpBasicInstanceCorrectly() {
factoryBean.setBeanFactory(beanFactory);
factoryBean.afterPropertiesSet();
@@ -71,7 +69,7 @@ public class Neo4jRepositoryFactoryBeanTests {
}
@Test(expected = IllegalArgumentException.class)
public void requiresListableBeanFactory() throws Exception {
public void requiresListableBeanFactory() {
factoryBean.setBeanFactory(mock(BeanFactory.class));
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.neo4j.repositories.support;
package org.springframework.data.neo4j.repository.support;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
@@ -42,7 +42,7 @@ import org.springframework.transaction.annotation.Transactional;
* @author Jens Schauder
* @author Michael J. Simons
*/
public class GraphRepositoryFactoryTests {
public class Neo4jRepositoryFactoryTests {
Neo4jRepositoryFactory factory;

View File

@@ -24,7 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.domain.sample.User;
import org.springframework.data.neo4j.repository.sample.UserRepository;
import org.springframework.data.neo4j.repository.sample.repo.UserRepository;
import org.springframework.data.neo4j.test.Neo4jIntegrationTest;
import org.springframework.data.neo4j.transaction.Neo4jTransactionManager;
import org.springframework.test.context.ContextConfiguration;

View File

@@ -20,7 +20,8 @@ public class Cinema {
@Relationship(type = "BLOCKBUSTER", direction = Relationship.OUTGOING)
private Movie blockbusterOfTheWeek;
// …
}
----
@@ -53,10 +54,10 @@ There are several ways to avoid that :
====
[source,java]
----
public interface CinemaNameAndBlockbuster { <1>
public interface CinemaNameAndBlockbuster { // <1>
public String getName(); <2>
public Movie getBlockbusterOfTheWeek();
String getName(); // <2>
Movie getBlockbusterOfTheWeek();
}
----
This projection has the following details:
@@ -99,13 +100,13 @@ Look at the following projection interface:
====
[source,java]
----
interface RenamedProperty { <1>
interface RenamedProperty { // <1>
@Value("#{target.name}")
String getCinemaName(); <2>
String getCinemaName(); // <2>
@Value("#{target.blockbusterOfTheWeek.name}")
String getBlockbusterOfTheWeekName(); <3>
String getBlockbusterOfTheWeekName(); // <3>
}
----
This projection has the following details: