From d9899c4ebf45b81aa6ed10345120b60fa86772fc Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Thu, 17 Jul 2025 16:44:51 +0200 Subject: [PATCH] Add AOT Integration test variant for PersonRepositoryIntegrationTests. Add verification to ensure the same behavior of reflectively and AOT implemented query methods. See #4961 --- .../AotPersonRepositoryIntegrationTests.java | 64 +++++++++++++++++++ ...rsonRepositoryIntegrationTests-context.xml | 22 ++----- ...ositoryIntegrationTests-infrastructure.xml | 24 +++++++ 3 files changed, 92 insertions(+), 18 deletions(-) create mode 100644 spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AotPersonRepositoryIntegrationTests.java create mode 100644 spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-infrastructure.xml diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AotPersonRepositoryIntegrationTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AotPersonRepositoryIntegrationTests.java new file mode 100644 index 000000000..ce26b11c5 --- /dev/null +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/AotPersonRepositoryIntegrationTests.java @@ -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)); + } + + } + +} diff --git a/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-context.xml b/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-context.xml index 264d474b5..1fc7b9bea 100644 --- a/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-context.xml +++ b/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-context.xml @@ -1,23 +1,11 @@ - - - - - - - - - - - + @@ -31,6 +19,4 @@ - - diff --git a/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-infrastructure.xml b/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-infrastructure.xml new file mode 100644 index 000000000..81a7c261f --- /dev/null +++ b/spring-data-mongodb/src/test/resources/org/springframework/data/mongodb/repository/PersonRepositoryIntegrationTests-infrastructure.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + +