Browse Source

Add AOT Integration test variant for PersonRepositoryIntegrationTests.

Add verification to ensure the same behavior of reflectively and AOT implemented query methods.

See #4961
pull/5026/head
Mark Paluch 5 months ago
parent
commit
d9899c4ebf
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 64
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AotPersonRepositoryIntegrationTests.java
  2. 18
      spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-context.xml
  3. 24
      spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-infrastructure.xml

64
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AotPersonRepositoryIntegrationTests.java

@ -0,0 +1,64 @@ @@ -0,0 +1,64 @@
/*
* Copyright 2025 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
*
* https://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;
import org.junit.jupiter.api.Disabled;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.TestMongoConfiguration;
import org.springframework.data.mongodb.repository.aot.AotFragmentTestConfigurationSupport;
import org.springframework.data.mongodb.repository.support.MongoRepositoryFactory;
import org.springframework.data.repository.core.support.RepositoryComposition;
import org.springframework.test.context.ContextConfiguration;
/**
* Integration tests for {@link PersonRepository} with mounted AOT-generated repository methods.
*
* @author Mark Paluch
*/
@ContextConfiguration(classes = AotPersonRepositoryIntegrationTests.Config.class)
@Disabled("Several mismatches, some class-loader visibility issues and some behavioral differences remain to be fixed")
class AotPersonRepositoryIntegrationTests extends AbstractPersonRepositoryIntegrationTests {
@Configuration
@ImportResource("classpath:/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-infrastructure.xml")
static class Config extends TestMongoConfiguration {
@Bean
static AotFragmentTestConfigurationSupport aot() {
return new AotFragmentTestConfigurationSupport(PersonRepository.class, false);
}
@Bean
PersonRepository personRepository(MongoOperations mongoOperations, ApplicationContext context) {
MongoRepositoryFactory factory = new MongoRepositoryFactory(mongoOperations);
factory.setBeanFactory(context);
factory.setBeanClassLoader(context.getClassLoader());
factory.setEnvironment(context.getEnvironment());
Object aotFragment = context.getBean("fragment");
return factory.getRepository(PersonRepository.class, RepositoryComposition.RepositoryFragments.just(aotFragment));
}
}
}

18
spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-context.xml

@ -1,23 +1,11 @@ @@ -1,23 +1,11 @@
<?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:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<mongo:db-factory dbname="repositories" />
<mongo:mapping-converter auto-index-creation="true" />
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongoDbFactory" />
<constructor-arg ref="mappingConverter" />
<property name="writeConcern">
<util:constant static-field="com.mongodb.WriteConcern.JOURNALED" />
</property>
</bean>
<import resource="PersonRepositoryIntegrationTests-infrastructure.xml"/>
<bean class="org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean">
<constructor-arg value="org.springframework.data.mongodb.repository.PersonRepository"/>
@ -31,6 +19,4 @@ @@ -31,6 +19,4 @@
</property>
</bean>
<bean class="org.springframework.data.mongodb.repository.SampleEvaluationContextExtension" />
</beans>

24
spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-infrastructure.xml

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
<?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:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util https://www.springframework.org/schema/util/spring-util.xsd">
<mongo:db-factory dbname="repositories"/>
<mongo:mapping-converter auto-index-creation="true"/>
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongoDbFactory"/>
<constructor-arg ref="mappingConverter"/>
<property name="writeConcern">
<util:constant static-field="com.mongodb.WriteConcern.JOURNALED"/>
</property>
</bean>
<bean class="org.springframework.data.mongodb.repository.SampleEvaluationContextExtension"/>
</beans>
Loading…
Cancel
Save