Skip to content

Commit 892409d

Browse files
committed
DATAREST-774 - Separated integration tests from core project to avoid classpath overlap.
Extracted store specific tests into separate test modules to prevent classpath overlap between projects. Those tests are now executed in an "it" build profile to prevent the tests being packaged for distribution on release. Use Map-based repositories and mapping contexts for test in the Core and WebMvc module. Slightly changed the configuration API for lookup types on RepositoryRestConfiguration. Related ticket: DATAREST-776.
1 parent 897bc88 commit 892409d

File tree

189 files changed

+1884
-1506
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

189 files changed

+1884
-1506
lines changed

pom.xml

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
<springdata.gemfire>1.8.0.BUILD-SNAPSHOT</springdata.gemfire>
3535
<springdata.solr>2.0.0.BUILD-SNAPSHOT</springdata.solr>
3636
<springdata.cassandra>1.4.0.BUILD-SNAPSHOT</springdata.cassandra>
37+
<springdata.keyvalue>1.1.0.BUILD-SNAPSHOT</springdata.keyvalue>
3738

3839
<hibernate.version>4.3.10.Final</hibernate.version>
40+
<jsonpath>0.9.1</jsonpath>
3941
<bundlor.enabled>false</bundlor.enabled>
4042
</properties>
4143

@@ -67,7 +69,23 @@
6769
<profiles>
6870

6971
<profile>
72+
73+
<id>it</id>
74+
75+
<modules>
76+
<module>spring-data-rest-core</module>
77+
<module>spring-data-rest-webmvc</module>
78+
<module>spring-data-rest-distribution</module>
79+
<module>spring-data-rest-hal-browser</module>
80+
<module>spring-data-rest-tests</module>
81+
</modules>
82+
83+
</profile>
84+
85+
<profile>
86+
7087
<id>release</id>
88+
7189
<build>
7290
<plugins>
7391
<plugin>
@@ -77,6 +95,7 @@
7795
</plugin>
7896
</plugins>
7997
</build>
98+
8099
</profile>
81100

82101
</profiles>
@@ -90,45 +109,6 @@
90109
<optional>true</optional>
91110
</dependency>
92111

93-
<!-- JPA -->
94-
95-
<dependency>
96-
<groupId>org.springframework.data</groupId>
97-
<artifactId>spring-data-jpa</artifactId>
98-
<version>${springdata.jpa}</version>
99-
<scope>test</scope>
100-
</dependency>
101-
102-
<dependency>
103-
<groupId>org.hibernate</groupId>
104-
<artifactId>hibernate-entitymanager</artifactId>
105-
<version>${hibernate.version}</version>
106-
<scope>test</scope>
107-
</dependency>
108-
109-
<dependency>
110-
<groupId>org.hsqldb</groupId>
111-
<artifactId>hsqldb</artifactId>
112-
<version>2.3.2</version>
113-
<scope>test</scope>
114-
</dependency>
115-
116-
<!-- MongoDB -->
117-
118-
<dependency>
119-
<groupId>org.springframework.data</groupId>
120-
<artifactId>spring-data-mongodb</artifactId>
121-
<version>${springdata.mongodb}</version>
122-
<scope>test</scope>
123-
</dependency>
124-
125-
<dependency>
126-
<groupId>com.querydsl</groupId>
127-
<artifactId>querydsl-mongodb</artifactId>
128-
<version>${querydsl}</version>
129-
<scope>test</scope>
130-
</dependency>
131-
132112
</dependencies>
133113

134114
<repositories>

spring-data-rest-core/pom.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@
5151
<version>${evoinflector}</version>
5252
</dependency>
5353

54-
<dependency>
55-
<groupId>joda-time</groupId>
56-
<artifactId>joda-time</artifactId>
57-
<version>${jodatime}</version>
58-
<optional>true</optional>
59-
</dependency>
60-
6154
<dependency>
6255
<groupId>com.fasterxml.jackson.core</groupId>
6356
<artifactId>jackson-annotations</artifactId>
@@ -71,6 +64,13 @@
7164
<optional>true</optional>
7265
</dependency>
7366

67+
<dependency>
68+
<groupId>org.springframework.data</groupId>
69+
<artifactId>spring-data-keyvalue</artifactId>
70+
<version>${springdata.keyvalue}</version>
71+
<scope>test</scope>
72+
</dependency>
73+
7474
</dependencies>
7575

7676
</project>

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/EntityLookupConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -61,7 +61,7 @@ class EntityLookupConfiguration implements EntityLookupRegistrar {
6161
* @see org.springframework.data.rest.core.config.EntityLookupRegistrar#forValueRepository(java.lang.Class)
6262
*/
6363
@Override
64-
public <T, ID extends Serializable, R extends Repository<T, ?>> IdMappingRegistrar<T, R> forValueRepository(
64+
public <T, ID extends Serializable, R extends Repository<T, ?>> IdMappingRegistrar<T, R> forLookupRepository(
6565
Class<R> type) {
6666
this.lookupTypes.add(AbstractRepositoryMetadata.getMetadata(type).getDomainType());
6767
return forRepository(type);

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/EntityLookupRegistrar.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,7 +38,14 @@ public interface EntityLookupRegistrar {
3838
*/
3939
<T, ID extends Serializable, R extends Repository<T, ?>> IdMappingRegistrar<T, R> forRepository(Class<R> type);
4040

41-
<T, ID extends Serializable, R extends Repository<T, ?>> IdMappingRegistrar<T, R> forValueRepository(Class<R> type);
41+
/**
42+
* Starts building a custom {@link EntityLookup} for the given repository type and registers the domain type of the
43+
* given repository as lookup type.
44+
*
45+
* @param type must not be {@literal null}.
46+
* @return
47+
*/
48+
<T, ID extends Serializable, R extends Repository<T, ?>> IdMappingRegistrar<T, R> forLookupRepository(Class<R> type);
4249

4350
interface IdMappingRegistrar<T, R extends Repository<T, ?>> {
4451

@@ -61,6 +68,14 @@ interface IdMappingRegistrar<T, R extends Repository<T, ?>> {
6168
<T, ID extends Serializable, R extends Repository<T, ?>> EntityLookupRegistrar forRepository(Class<R> type,
6269
Converter<T, ID> identifierMapping, Lookup<R, ID> lookup);
6370

71+
/**
72+
* Registers an {@link EntityLookup} for the given repository type, identifier mapping and lookup operation and
73+
* registers the domain type managed by the given repository as lookup type.
74+
*
75+
* @param type must not be {@literal null}.
76+
* @param identifierMapping must not be {@literal null}.
77+
* @param lookup must not be {@literal null}.
78+
*/
6479
<T, ID extends Serializable, R extends Repository<T, ?>> EntityLookupRegistrar forValueRepository(Class<R> type,
6580
Converter<T, ID> identifierMapping, Lookup<R, ID> lookup);
6681

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/event/ValidatingRepositoryEventListener.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
2323
import org.slf4j.Logger;
2424
import org.slf4j.LoggerFactory;
2525
import org.springframework.beans.factory.ObjectFactory;
26-
import org.springframework.data.repository.support.Repositories;
26+
import org.springframework.data.mapping.context.PersistentEntities;
2727
import org.springframework.data.rest.core.RepositoryConstraintViolationException;
2828
import org.springframework.data.rest.core.ValidationErrors;
2929
import org.springframework.util.Assert;
@@ -44,19 +44,19 @@ public class ValidatingRepositoryEventListener extends AbstractRepositoryEventLi
4444

4545
private static final Logger LOGGER = LoggerFactory.getLogger(ValidatingRepositoryEventListener.class);
4646

47-
private final ObjectFactory<Repositories> repositoriesFactory;
47+
private final ObjectFactory<PersistentEntities> persistentEntitiesFactory;
4848
private final MultiValueMap<String, Validator> validators;
4949

5050
/**
5151
* Creates a new {@link ValidatingRepositoryEventListener} using the given repositories.
5252
*
53-
* @param repositoriesFactory must not be {@literal null}.
53+
* @param persistentEntitiesFactory must not be {@literal null}.
5454
*/
55-
public ValidatingRepositoryEventListener(ObjectFactory<Repositories> repositoriesFactory) {
55+
public ValidatingRepositoryEventListener(ObjectFactory<PersistentEntities> persistentEntitiesFactory) {
5656

57-
Assert.notNull(repositoriesFactory, "Repositories must not be null!");
57+
Assert.notNull(persistentEntitiesFactory, "PersistentEntities must not be null!");
5858

59-
this.repositoriesFactory = repositoriesFactory;
59+
this.persistentEntitiesFactory = persistentEntitiesFactory;
6060
this.validators = new LinkedMultiValueMap<String, Validator>();
6161
}
6262

@@ -159,31 +159,34 @@ protected void onAfterDelete(Object entity) {
159159
validate("afterDelete", entity);
160160
}
161161

162-
private Errors validate(String event, Object o) {
162+
private Errors validate(String event, Object entity) {
163163

164-
if (o == null) {
164+
if (entity == null) {
165165
return null;
166166
}
167167

168-
Class<?> domainType = o.getClass();
169-
Repositories repositories = repositoriesFactory.getObject();
170-
Errors errors = new ValidationErrors(domainType.getSimpleName(), o, repositories.getPersistentEntity(domainType));
168+
Class<?> domainType = entity.getClass();
169+
PersistentEntities persistentEntities = persistentEntitiesFactory.getObject();
170+
Errors errors = new ValidationErrors(domainType.getSimpleName(), entity,
171+
persistentEntities.getPersistentEntity(domainType));
171172

172173
for (Validator v : getValidatorsForEvent(event)) {
174+
173175
if (v.supports(domainType)) {
174-
LOGGER.debug("{}: {} with {}", event, o, v);
175-
ValidationUtils.invokeValidator(v, o, errors);
176+
LOGGER.debug("{}: {} with {}", event, entity, v);
177+
ValidationUtils.invokeValidator(v, entity, errors);
176178
}
177179
}
178180

179-
if (errors.getErrorCount() > 0) {
181+
if (errors.hasErrors()) {
180182
throw new RepositoryConstraintViolationException(errors);
181183
}
182184

183185
return errors;
184186
}
185187

186188
private Collection<Validator> getValidatorsForEvent(String event) {
189+
187190
Collection<Validator> validators = this.validators.get(event);
188191
return validators == null ? Collections.<Validator> emptySet() : validators;
189192
}

spring-data-rest-core/src/test/java/org/springframework/data/rest/core/AbstractIntegrationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,8 +18,8 @@
1818
import org.junit.Before;
1919
import org.junit.runner.RunWith;
2020
import org.springframework.beans.factory.annotation.Autowired;
21-
import org.springframework.data.rest.core.domain.jpa.Person;
22-
import org.springframework.data.rest.core.domain.jpa.PersonRepository;
21+
import org.springframework.data.rest.core.domain.Person;
22+
import org.springframework.data.rest.core.domain.PersonRepository;
2323
import org.springframework.test.context.ContextConfiguration;
2424
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2525
import org.springframework.transaction.annotation.Transactional;

spring-data-rest-core/src/test/java/org/springframework/data/rest/core/RepositoryRestConfigurationIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import org.springframework.beans.factory.annotation.Autowired;
88
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
99
import org.springframework.data.rest.core.config.ResourceMapping;
10-
import org.springframework.data.rest.core.domain.jpa.ConfiguredPersonRepository;
10+
import org.springframework.data.rest.core.domain.ConfiguredPersonRepository;
1111

1212
/**
1313
* Tests to check that {@link ResourceMapping}s are handled correctly.

spring-data-rest-core/src/test/java/org/springframework/data/rest/core/RepositoryRestConfigurationUnitTests.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 the original author or authors.
2+
* Copyright 2015-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,6 +25,8 @@
2525
import org.springframework.data.rest.core.config.MetadataConfiguration;
2626
import org.springframework.data.rest.core.config.ProjectionDefinitionConfiguration;
2727
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
28+
import org.springframework.data.rest.core.domain.Profile;
29+
import org.springframework.data.rest.core.domain.ProfileRepository;
2830
import org.springframework.http.MediaType;
2931

3032
/**
@@ -125,4 +127,15 @@ public void returnsBodyForCreateIfExplicitlyActivated() {
125127
assertThat(configuration.returnBodyOnCreate(""), is(true));
126128
assertThat(configuration.returnBodyOnCreate(MediaType.APPLICATION_JSON_VALUE), is(true));
127129
}
130+
131+
/**
132+
* @see DATAREST-776
133+
*/
134+
@Test
135+
public void consideresDomainTypeOfValueRepositoryLookupTypes() {
136+
137+
configuration.withEntityLookup().forLookupRepository(ProfileRepository.class);
138+
139+
assertThat(configuration.isLookupType(Profile.class), is(true));
140+
}
128141
}

spring-data-rest-core/src/test/java/org/springframework/data/rest/core/RepositoryTestsConfig.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,26 +24,25 @@
2424
import org.springframework.context.ApplicationContext;
2525
import org.springframework.context.annotation.Bean;
2626
import org.springframework.context.annotation.Configuration;
27-
import org.springframework.context.annotation.Import;
27+
import org.springframework.data.map.repository.config.EnableMapRepositories;
2828
import org.springframework.data.mapping.context.MappingContext;
2929
import org.springframework.data.mapping.context.PersistentEntities;
3030
import org.springframework.data.repository.support.Repositories;
3131
import org.springframework.data.rest.core.config.EnumTranslationConfiguration;
3232
import org.springframework.data.rest.core.config.MetadataConfiguration;
3333
import org.springframework.data.rest.core.config.ProjectionDefinitionConfiguration;
3434
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
35-
import org.springframework.data.rest.core.domain.jpa.ConfiguredPersonRepository;
36-
import org.springframework.data.rest.core.domain.jpa.JpaRepositoryConfig;
37-
import org.springframework.data.rest.core.domain.jpa.Person;
38-
import org.springframework.data.rest.core.domain.jpa.PersonRepository;
35+
import org.springframework.data.rest.core.domain.ConfiguredPersonRepository;
36+
import org.springframework.data.rest.core.domain.Person;
37+
import org.springframework.data.rest.core.domain.PersonRepository;
3938
import org.springframework.format.support.DefaultFormattingConversionService;
4039

4140
/**
4241
* @author Jon Brisbin
4342
* @author Oliver Gierke
4443
*/
4544
@Configuration
46-
@Import({ JpaRepositoryConfig.class })
45+
@EnableMapRepositories
4746
public class RepositoryTestsConfig {
4847

4948
@Autowired private ApplicationContext context;

spring-data-rest-core/src/test/java/org/springframework/data/rest/core/UriToEntityConverterUnitTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
import org.springframework.core.convert.ConversionFailedException;
3333
import org.springframework.core.convert.TypeDescriptor;
3434
import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair;
35+
import org.springframework.data.annotation.Id;
36+
import org.springframework.data.keyvalue.core.mapping.context.KeyValueMappingContext;
3537
import org.springframework.data.mapping.context.PersistentEntities;
36-
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
3738
import org.springframework.data.repository.core.RepositoryInformation;
3839
import org.springframework.data.repository.support.Repositories;
3940
import org.springframework.data.repository.support.RepositoryInvoker;
@@ -54,14 +55,14 @@ public class UriToEntityConverterUnitTests {
5455
@Mock Repositories repositories;
5556
@Mock RepositoryInvokerFactory invokerFactory;
5657

57-
MongoMappingContext context;
58+
KeyValueMappingContext context;
5859
UriToEntityConverter converter;
5960

6061
@Before
6162
@SuppressWarnings("unchecked")
6263
public void setUp() {
6364

64-
this.context = new MongoMappingContext();
65+
this.context = new KeyValueMappingContext();
6566
this.context.setInitialEntitySet(new HashSet<Class<?>>(Arrays.asList(Entity.class, NonEntity.class)));
6667
this.context.afterPropertiesSet();
6768

@@ -164,7 +165,7 @@ public void rejectsNullRepositories() {
164165
}
165166

166167
static class Entity {
167-
String id;
168+
@Id String id;
168169
}
169170

170171
static class NonEntity {

0 commit comments

Comments
 (0)