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.
This commit is contained in:
Oliver Gierke
2013-11-05 17:28:59 +01:00
parent 8fb390ee88
commit 39ee9b56e2
5 changed files with 19 additions and 20 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.mongodb.repository.config;
package org.springframework.data.mongodb.repository.config.lazy;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
@@ -21,7 +21,7 @@ import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
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.junit4.SpringJUnit4ClassRunner;
@@ -31,7 +31,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Thomas Darimont
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "AllowNestedMongoRepositoriesRepositoryConfigTests-context.xml")
@ContextConfiguration("AllowNestedMongoRepositoriesRepositoryConfigTests-context.xml")
public class AllowNestedMongoRepositoriesRepositoryConfigTests {
@Autowired NestedUserRepository fooRepository;

View File

@@ -13,7 +13,10 @@
* See the License for the specific language governing permissions and
* 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
@@ -21,5 +24,5 @@ package org.springframework.data.mongodb.repository;
*/
public class ClassWithNestedRepository {
public static interface NestedUserRepository extends MongoRepository<User, Integer> {}
interface NestedUserRepository extends MongoRepository<User, Integer> {}
}

View File

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

View File

@@ -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");
* 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)
public class MongoRepositoryFactoryBeanUnitTests {
@Mock
MongoOperations operations;
@Mock
MongoConverter converter;
@Mock
@SuppressWarnings("rawtypes")
MappingContext context;
@Mock MongoOperations operations;
@Mock MongoConverter converter;
@Mock @SuppressWarnings("rawtypes") MappingContext context;
@Test
@SuppressWarnings("rawtypes")
@@ -75,6 +69,7 @@ public class MongoRepositoryFactoryBeanUnitTests {
when(operations.getConverter()).thenReturn(converter);
when(converter.getMappingContext()).thenReturn(context);
factoryBean.setLazyInit(true);
factoryBean.setMongoOperations(operations);
factoryBean.afterPropertiesSet();

View File

@@ -11,5 +11,6 @@
<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>