Browse Source

DATAMONGO-793 - Adapt test cases to new initialization model of repositories.

Moved tests for nested repositories to a separate package to prevent initialization of repositories that are not meant to be instantiated actually.
pull/93/merge
Oliver Gierke 12 years ago
parent
commit
39ee9b56e2
  1. 6
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/config/lazy/AllowNestedMongoRepositoriesRepositoryConfigTests.java
  2. 7
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/config/lazy/ClassWithNestedRepository.java
  3. 8
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/config/lazy/NestedMongoRepositoriesJavaConfigTests.java
  4. 15
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/support/MongoRepositoryFactoryBeanUnitTests.java
  5. 3
      spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/config/lazy/AllowNestedMongoRepositoriesRepositoryConfigTests-context.xml

6
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/config/AllowNestedMongoRepositoriesRepositoryConfigTests.java → spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/config/lazy/AllowNestedMongoRepositoriesRepositoryConfigTests.java

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.data.mongodb.repository.config; package org.springframework.data.mongodb.repository.config.lazy;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -21,7 +21,7 @@ import static org.junit.Assert.*;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.repository.ClassWithNestedRepository.NestedUserRepository; import org.springframework.data.mongodb.repository.config.lazy.ClassWithNestedRepository.NestedUserRepository;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -31,7 +31,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Thomas Darimont * @author Thomas Darimont
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "AllowNestedMongoRepositoriesRepositoryConfigTests-context.xml") @ContextConfiguration("AllowNestedMongoRepositoriesRepositoryConfigTests-context.xml")
public class AllowNestedMongoRepositoriesRepositoryConfigTests { public class AllowNestedMongoRepositoriesRepositoryConfigTests {
@Autowired NestedUserRepository fooRepository; @Autowired NestedUserRepository fooRepository;

7
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/ClassWithNestedRepository.java → spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/config/lazy/ClassWithNestedRepository.java

@ -13,7 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.data.mongodb.repository; package org.springframework.data.mongodb.repository.config.lazy;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.User;
/** /**
* @see DATAMONGO-780 * @see DATAMONGO-780
@ -21,5 +24,5 @@ package org.springframework.data.mongodb.repository;
*/ */
public class ClassWithNestedRepository { public class ClassWithNestedRepository {
public static interface NestedUserRepository extends MongoRepository<User, Integer> {} interface NestedUserRepository extends MongoRepository<User, Integer> {}
} }

8
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/config/NestedMongoRepositoriesJavaConfigTests.java → spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/config/lazy/NestedMongoRepositoriesJavaConfigTests.java

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.data.mongodb.repository.config; package org.springframework.data.mongodb.repository.config.lazy;
import static org.hamcrest.CoreMatchers.*; import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -23,8 +23,8 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource; import org.springframework.context.annotation.ImportResource;
import org.springframework.data.mongodb.repository.ClassWithNestedRepository.NestedUserRepository; import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.data.mongodb.repository.PersonRepository; import org.springframework.data.mongodb.repository.config.lazy.ClassWithNestedRepository.NestedUserRepository;
import org.springframework.data.repository.support.Repositories; import org.springframework.data.repository.support.Repositories;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -39,7 +39,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public class NestedMongoRepositoriesJavaConfigTests { public class NestedMongoRepositoriesJavaConfigTests {
@Configuration @Configuration
@EnableMongoRepositories(basePackageClasses = PersonRepository.class, considerNestedRepositories = true) @EnableMongoRepositories(considerNestedRepositories = true)
@ImportResource("classpath:infrastructure.xml") @ImportResource("classpath:infrastructure.xml")
static class Config {} static class Config {}

15
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/support/MongoRepositoryFactoryBeanUnitTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2011-2012 the original author or authors. * Copyright 2011-2013 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -39,15 +39,9 @@ import org.springframework.test.util.ReflectionTestUtils;
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class MongoRepositoryFactoryBeanUnitTests { public class MongoRepositoryFactoryBeanUnitTests {
@Mock @Mock MongoOperations operations;
MongoOperations operations; @Mock MongoConverter converter;
@Mock @SuppressWarnings("rawtypes") MappingContext context;
@Mock
MongoConverter converter;
@Mock
@SuppressWarnings("rawtypes")
MappingContext context;
@Test @Test
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@ -75,6 +69,7 @@ public class MongoRepositoryFactoryBeanUnitTests {
when(operations.getConverter()).thenReturn(converter); when(operations.getConverter()).thenReturn(converter);
when(converter.getMappingContext()).thenReturn(context); when(converter.getMappingContext()).thenReturn(context);
factoryBean.setLazyInit(true);
factoryBean.setMongoOperations(operations); factoryBean.setMongoOperations(operations);
factoryBean.afterPropertiesSet(); factoryBean.afterPropertiesSet();

3
spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/config/AllowNestedMongoRepositoriesRepositoryConfigTests-context.xml → spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/config/lazy/AllowNestedMongoRepositoriesRepositoryConfigTests-context.xml

@ -11,5 +11,6 @@
<import resource="classpath:infrastructure.xml"/> <import resource="classpath:infrastructure.xml"/>
<mongo:repositories base-package="org.springframework.data.mongodb.repository" consider-nested-repositories="true"/> <mongo:repositories base-package="org.springframework.data.mongodb.repository.config.lazy"
consider-nested-repositories="true"/>
</beans> </beans>
Loading…
Cancel
Save