Skip to content

Commit d9899c4

Browse files
committed
Add AOT Integration test variant for PersonRepositoryIntegrationTests.
Add verification to ensure the same behavior of reflectively and AOT implemented query methods. See #4961
1 parent 8c94f3b commit d9899c4

File tree

3 files changed

+92
-18
lines changed

3 files changed

+92
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.mongodb.repository;
17+
18+
import org.junit.jupiter.api.Disabled;
19+
20+
import org.springframework.context.ApplicationContext;
21+
import org.springframework.context.annotation.Bean;
22+
import org.springframework.context.annotation.Configuration;
23+
import org.springframework.context.annotation.ImportResource;
24+
import org.springframework.data.mongodb.core.MongoOperations;
25+
import org.springframework.data.mongodb.core.TestMongoConfiguration;
26+
import org.springframework.data.mongodb.repository.aot.AotFragmentTestConfigurationSupport;
27+
import org.springframework.data.mongodb.repository.support.MongoRepositoryFactory;
28+
import org.springframework.data.repository.core.support.RepositoryComposition;
29+
import org.springframework.test.context.ContextConfiguration;
30+
31+
/**
32+
* Integration tests for {@link PersonRepository} with mounted AOT-generated repository methods.
33+
*
34+
* @author Mark Paluch
35+
*/
36+
@ContextConfiguration(classes = AotPersonRepositoryIntegrationTests.Config.class)
37+
@Disabled("Several mismatches, some class-loader visibility issues and some behavioral differences remain to be fixed")
38+
class AotPersonRepositoryIntegrationTests extends AbstractPersonRepositoryIntegrationTests {
39+
40+
@Configuration
41+
@ImportResource("classpath:/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-infrastructure.xml")
42+
static class Config extends TestMongoConfiguration {
43+
44+
@Bean
45+
static AotFragmentTestConfigurationSupport aot() {
46+
return new AotFragmentTestConfigurationSupport(PersonRepository.class, false);
47+
}
48+
49+
@Bean
50+
PersonRepository personRepository(MongoOperations mongoOperations, ApplicationContext context) {
51+
52+
MongoRepositoryFactory factory = new MongoRepositoryFactory(mongoOperations);
53+
factory.setBeanFactory(context);
54+
factory.setBeanClassLoader(context.getClassLoader());
55+
factory.setEnvironment(context.getEnvironment());
56+
57+
Object aotFragment = context.getBean("fragment");
58+
59+
return factory.getRepository(PersonRepository.class, RepositoryComposition.RepositoryFragments.just(aotFragment));
60+
}
61+
62+
}
63+
64+
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans xmlns="http://www.springframework.org/schema/beans"
3-
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
4-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xmlns:util="http://www.springframework.org/schema/util"
6-
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd
7-
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:util="http://www.springframework.org/schema/util"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
86
http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
97

10-
<mongo:db-factory dbname="repositories" />
11-
12-
<mongo:mapping-converter auto-index-creation="true" />
13-
14-
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
15-
<constructor-arg ref="mongoDbFactory" />
16-
<constructor-arg ref="mappingConverter" />
17-
<property name="writeConcern">
18-
<util:constant static-field="com.mongodb.WriteConcern.JOURNALED" />
19-
</property>
20-
</bean>
8+
<import resource="PersonRepositoryIntegrationTests-infrastructure.xml"/>
219

2210
<bean class="org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean">
2311
<constructor-arg value="org.springframework.data.mongodb.repository.PersonRepository"/>
@@ -31,6 +19,4 @@
3119
</property>
3220
</bean>
3321

34-
<bean class="org.springframework.data.mongodb.repository.SampleEvaluationContextExtension" />
35-
3622
</beans>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:util="http://www.springframework.org/schema/util"
6+
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd
7+
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
8+
http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
9+
10+
<mongo:db-factory dbname="repositories"/>
11+
12+
<mongo:mapping-converter auto-index-creation="true"/>
13+
14+
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
15+
<constructor-arg ref="mongoDbFactory"/>
16+
<constructor-arg ref="mappingConverter"/>
17+
<property name="writeConcern">
18+
<util:constant static-field="com.mongodb.WriteConcern.JOURNALED"/>
19+
</property>
20+
</bean>
21+
22+
<bean class="org.springframework.data.mongodb.repository.SampleEvaluationContextExtension"/>
23+
24+
</beans>

0 commit comments

Comments
 (0)