Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DATAMONGO-780 - Add support for nested repositories.
Support for considering nested repository interfaces can now be configured on the EnableMongoRepositories annotation via the considerNestedRepositories property. Original pull request: #87.
- Loading branch information
Showing
5 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
.../src/test/java/org/springframework/data/mongodb/repository/ClassWithNestedRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* 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.mongodb.repository; | ||
|
||
/** | ||
* @see DATAMONGO-780 | ||
* @author Thomas Darimont | ||
*/ | ||
public class ClassWithNestedRepository { | ||
|
||
public static interface NestedUserRepository extends MongoRepository<User, Integer> {} | ||
} |
46 changes: 46 additions & 0 deletions
46
...ork/data/mongodb/repository/config/AllowNestedMongoRepositoriesRepositoryConfigTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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.mongodb.repository.config; | ||
|
||
import static org.hamcrest.CoreMatchers.*; | ||
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.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
/** | ||
* Integration test for repository namespace configuration with nested repositories. | ||
* | ||
* @author Thomas Darimont | ||
*/ | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration(locations = "AllowNestedMongoRepositoriesRepositoryConfigTests-context.xml") | ||
public class AllowNestedMongoRepositoriesRepositoryConfigTests { | ||
|
||
@Autowired NestedUserRepository fooRepository; | ||
|
||
/** | ||
* @see DATAMONGO-780 | ||
*/ | ||
@Test | ||
public void shouldFindNestedRepository() { | ||
assertThat(fooRepository, is(notNullValue())); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...pringframework/data/mongodb/repository/config/NestedMongoRepositoriesJavaConfigTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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.mongodb.repository.config; | ||
|
||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Test; | ||
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.repository.support.Repositories; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
/** | ||
* Integration test for the combination of JavaConfig and an {@link Repositories} wrapper. | ||
* | ||
* @author Thomas Darimont | ||
*/ | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration | ||
public class NestedMongoRepositoriesJavaConfigTests { | ||
|
||
@Configuration | ||
@EnableMongoRepositories(basePackageClasses = PersonRepository.class, considerNestedRepositories = true) | ||
@ImportResource("classpath:infrastructure.xml") | ||
static class Config {} | ||
|
||
@Autowired NestedUserRepository nestedUserRepository; | ||
|
||
/** | ||
* @see DATAMONGO-780 | ||
*/ | ||
@Test | ||
public void shouldSupportNestedRepositories() { | ||
assertThat(nestedUserRepository, is(notNullValue())); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...a/mongodb/repository/config/AllowNestedMongoRepositoriesRepositoryConfigTests-context.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:mongo="http://www.springframework.org/schema/data/mongo" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:repository="http://www.springframework.org/schema/data/repository" | ||
xmlns:util="http://www.springframework.org/schema/util" | ||
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd | ||
http://www.springframework.org/schema/data/repository http://www.springframework.org/schema/data/repository/spring-repository.xsd | ||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> | ||
|
||
<import resource="classpath:infrastructure.xml"/> | ||
|
||
<mongo:repositories base-package="org.springframework.data.mongodb.repository" consider-nested-repositories="true"/> | ||
</beans> |