mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-21 13:31:46 +00:00
Provide AOT support for @Nested classes in a @ParameterizedClass
This commit adds AOT support for discovering @Nested test classes within a @ClassTemplate test class, which includes @ParameterizedClass test classes. Closes gh-35744
This commit is contained in:
+62
-28
@@ -30,61 +30,95 @@ import java.util.stream.Stream;
|
||||
abstract class AbstractAotTests {
|
||||
|
||||
static final String[] expectedSourceFilesForBasicSpringTests = {
|
||||
|
||||
// BasicSpringJupiterSharedConfigTests -- not generated b/c already generated for AbstractSpringJupiterParameterizedClassTests.InheritedNestedTests.
|
||||
// BasicSpringJupiterTests -- not generated b/c already generated for AbstractSpringJupiterParameterizedClassTests.InheritedNestedTests.
|
||||
// BasicSpringJupiterTests.NestedTests -- not generated b/c already generated for BasicSpringJupiterParameterizedClassTests.NestedTests.
|
||||
|
||||
// Global
|
||||
"org/springframework/test/context/aot/AotTestContextInitializers__Generated.java",
|
||||
"org/springframework/test/context/aot/AotTestAttributes__Generated.java",
|
||||
// BasicSpringJupiterImportedConfigTests
|
||||
|
||||
// AbstractSpringJupiterParameterizedClassTests.InheritedNestedTests
|
||||
"org/springframework/context/event/DefaultEventListenerFactory__TestContext001_BeanDefinitions.java",
|
||||
"org/springframework/context/event/EventListenerMethodProcessor__TestContext001_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterImportedConfigTests__TestContext001_ApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterImportedConfigTests__TestContext001_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterImportedConfigTests__TestContext001_BeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/AbstractSpringJupiterParameterizedClassTests_InheritedNestedTests__TestContext001_ApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/AbstractSpringJupiterParameterizedClassTests_InheritedNestedTests__TestContext001_BeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/AbstractSpringJupiterParameterizedClassTests_InheritedNestedTests__TestContext001_ManagementApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/AbstractSpringJupiterParameterizedClassTests_InheritedNestedTests__TestContext001_ManagementBeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicTestConfiguration__TestContext001_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/management/ManagementConfiguration__TestContext001_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/management/ManagementMessageService__TestContext001_ManagementBeanDefinitions.java",
|
||||
"org/springframework/test/context/support/DynamicPropertyRegistrarBeanInitializer__TestContext001_BeanDefinitions.java",
|
||||
// BasicSpringJupiterSharedConfigTests
|
||||
|
||||
// AbstractSpringJupiterParameterizedClassTests.InheritedNestedTests.InheritedDoublyNestedTests
|
||||
"org/springframework/context/event/DefaultEventListenerFactory__TestContext002_BeanDefinitions.java",
|
||||
"org/springframework/context/event/EventListenerMethodProcessor__TestContext002_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterSharedConfigTests__TestContext002_ApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterSharedConfigTests__TestContext002_BeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterSharedConfigTests__TestContext002_ManagementApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterSharedConfigTests__TestContext002_ManagementBeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/AbstractSpringJupiterParameterizedClassTests_InheritedNestedTests_InheritedDoublyNestedTests__TestContext002_ApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/AbstractSpringJupiterParameterizedClassTests_InheritedNestedTests_InheritedDoublyNestedTests__TestContext002_BeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/AbstractSpringJupiterParameterizedClassTests_InheritedNestedTests_InheritedDoublyNestedTests__TestContext002_ManagementApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/AbstractSpringJupiterParameterizedClassTests_InheritedNestedTests_InheritedDoublyNestedTests__TestContext002_ManagementBeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicTestConfiguration__TestContext002_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/management/ManagementConfiguration__TestContext002_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/management/ManagementMessageService__TestContext002_ManagementBeanDefinitions.java",
|
||||
"org/springframework/test/context/support/DynamicPropertyRegistrarBeanInitializer__TestContext002_BeanDefinitions.java",
|
||||
// BasicSpringJupiterTests -- not generated b/c already generated for BasicSpringJupiterSharedConfigTests.
|
||||
// BasicSpringJupiterTests.NestedTests
|
||||
|
||||
// BasicSpringJupiterImportedConfigTests
|
||||
"org/springframework/context/event/DefaultEventListenerFactory__TestContext003_BeanDefinitions.java",
|
||||
"org/springframework/context/event/EventListenerMethodProcessor__TestContext003_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests_NestedTests__TestContext003_ApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests_NestedTests__TestContext003_BeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests_NestedTests__TestContext003_ManagementApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterTests_NestedTests__TestContext003_ManagementBeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterImportedConfigTests__TestContext003_ApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterImportedConfigTests__TestContext003_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterImportedConfigTests__TestContext003_BeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicTestConfiguration__TestContext003_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/management/ManagementConfiguration__TestContext003_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/management/ManagementMessageService__TestContext003_ManagementBeanDefinitions.java",
|
||||
"org/springframework/test/context/support/DynamicPropertyRegistrarBeanInitializer__TestContext003_BeanDefinitions.java",
|
||||
// BasicSpringTestNGTests
|
||||
|
||||
// BasicSpringJupiterParameterizedClassTests.NestedTests
|
||||
"org/springframework/context/event/DefaultEventListenerFactory__TestContext004_BeanDefinitions.java",
|
||||
"org/springframework/context/event/EventListenerMethodProcessor__TestContext004_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringTestNGTests__TestContext004_ApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringTestNGTests__TestContext004_BeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterParameterizedClassTests_NestedTests__TestContext004_ApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterParameterizedClassTests_NestedTests__TestContext004_BeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterParameterizedClassTests_NestedTests__TestContext004_ManagementApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterParameterizedClassTests_NestedTests__TestContext004_ManagementBeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicTestConfiguration__TestContext004_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/management/ManagementConfiguration__TestContext004_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/management/ManagementMessageService__TestContext004_ManagementBeanDefinitions.java",
|
||||
"org/springframework/test/context/support/DynamicPropertyRegistrarBeanInitializer__TestContext004_BeanDefinitions.java",
|
||||
// BasicSpringVintageTests
|
||||
|
||||
// BasicSpringJupiterParameterizedClassTests.NestedTests.DoublyNestedTests
|
||||
"org/springframework/context/event/DefaultEventListenerFactory__TestContext005_BeanDefinitions.java",
|
||||
"org/springframework/context/event/EventListenerMethodProcessor__TestContext005_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests__TestContext005_ApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests__TestContext005_BeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterParameterizedClassTests_NestedTests_DoublyNestedTests__TestContext005_ApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterParameterizedClassTests_NestedTests_DoublyNestedTests__TestContext005_BeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterParameterizedClassTests_NestedTests_DoublyNestedTests__TestContext005_ManagementApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringJupiterParameterizedClassTests_NestedTests_DoublyNestedTests__TestContext005_ManagementBeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicTestConfiguration__TestContext005_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/management/ManagementConfiguration__TestContext005_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/management/ManagementMessageService__TestContext005_ManagementBeanDefinitions.java",
|
||||
"org/springframework/test/context/support/DynamicPropertyRegistrarBeanInitializer__TestContext005_BeanDefinitions.java",
|
||||
// DisabledInAotRuntimeMethodLevelTests
|
||||
|
||||
// BasicSpringTestNGTests
|
||||
"org/springframework/context/event/DefaultEventListenerFactory__TestContext006_BeanDefinitions.java",
|
||||
"org/springframework/context/event/EventListenerMethodProcessor__TestContext006_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/basic/DisabledInAotRuntimeMethodLevelTests__TestContext006_ApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/DisabledInAotRuntimeMethodLevelTests__TestContext006_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/basic/DisabledInAotRuntimeMethodLevelTests__TestContext006_BeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/support/DynamicPropertyRegistrarBeanInitializer__TestContext006_BeanDefinitions.java"
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringTestNGTests__TestContext006_ApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringTestNGTests__TestContext006_BeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicTestConfiguration__TestContext006_BeanDefinitions.java",
|
||||
"org/springframework/test/context/support/DynamicPropertyRegistrarBeanInitializer__TestContext006_BeanDefinitions.java",
|
||||
|
||||
// BasicSpringVintageTests
|
||||
"org/springframework/context/event/DefaultEventListenerFactory__TestContext007_BeanDefinitions.java",
|
||||
"org/springframework/context/event/EventListenerMethodProcessor__TestContext007_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests__TestContext007_ApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests__TestContext007_BeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/basic/BasicTestConfiguration__TestContext007_BeanDefinitions.java",
|
||||
"org/springframework/test/context/support/DynamicPropertyRegistrarBeanInitializer__TestContext007_BeanDefinitions.java",
|
||||
|
||||
// DisabledInAotRuntimeMethodLevelTests
|
||||
"org/springframework/context/event/DefaultEventListenerFactory__TestContext008_BeanDefinitions.java",
|
||||
"org/springframework/context/event/EventListenerMethodProcessor__TestContext008_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/basic/DisabledInAotRuntimeMethodLevelTests__TestContext008_ApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/basic/DisabledInAotRuntimeMethodLevelTests__TestContext008_BeanDefinitions.java",
|
||||
"org/springframework/test/context/aot/samples/basic/DisabledInAotRuntimeMethodLevelTests__TestContext008_BeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/support/DynamicPropertyRegistrarBeanInitializer__TestContext008_BeanDefinitions.java"
|
||||
};
|
||||
|
||||
Stream<Class<?>> scan() {
|
||||
|
||||
+6
-1
@@ -46,6 +46,7 @@ import org.springframework.context.aot.AbstractAotProcessor;
|
||||
import org.springframework.core.test.tools.CompileWithForkedClassLoader;
|
||||
import org.springframework.core.test.tools.TestCompiler;
|
||||
import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterImportedConfigTests;
|
||||
import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterParameterizedClassTests;
|
||||
import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterSharedConfigTests;
|
||||
import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterTests;
|
||||
import org.springframework.test.context.aot.samples.basic.BasicSpringTestNGTests;
|
||||
@@ -116,11 +117,12 @@ class AotIntegrationTests extends AbstractAotTests {
|
||||
// .printFiles(System.out)
|
||||
.compile(compiled ->
|
||||
// AOT RUN-TIME: EXECUTION
|
||||
runTestsInAotMode(7, List.of(
|
||||
runTestsInAotMode(17, List.of(
|
||||
// The #s represent how many tests should run from each test class, which
|
||||
// must add up to the expectedNumTests above.
|
||||
/* 1 */ BasicSpringJupiterSharedConfigTests.class,
|
||||
/* 2 */ BasicSpringJupiterTests.class, // NestedTests get executed automatically
|
||||
/* 2 * 5 */ BasicSpringJupiterParameterizedClassTests.class, // NestedTests get executed automatically
|
||||
// Run @Import tests AFTER the tests with otherwise identical config
|
||||
// in order to ensure that the other test classes are not accidentally
|
||||
// using the config for the @Import tests.
|
||||
@@ -147,6 +149,9 @@ class AotIntegrationTests extends AbstractAotTests {
|
||||
.filter(clazz -> clazz.getSimpleName().endsWith("Tests"))
|
||||
// TestNG EJB tests use @PersistenceContext which is not yet supported in tests in AOT mode.
|
||||
.filter(clazz -> !clazz.getPackageName().contains("testng.transaction.ejb"))
|
||||
// AOT processing works for ParameterizedDependencyInjectionTests by itself
|
||||
// but fails for an unknown reason within the entire spring-test module.
|
||||
.filter(clazz -> !clazz.getName().equals("org.springframework.test.context.junit4.ParameterizedDependencyInjectionTests"))
|
||||
.toList();
|
||||
|
||||
// Optionally set failOnError flag to true to halt processing at the first failure.
|
||||
|
||||
+2
-1
@@ -30,6 +30,7 @@ import org.junit.jupiter.api.io.CleanupMode;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterImportedConfigTests;
|
||||
import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterParameterizedClassTests;
|
||||
import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterSharedConfigTests;
|
||||
import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterTests;
|
||||
import org.springframework.test.context.aot.samples.basic.BasicSpringTestNGTests;
|
||||
@@ -55,9 +56,9 @@ class TestAotProcessorTests extends AbstractAotTests {
|
||||
Path classpathRoot = Files.createDirectories(tempDir.resolve("build/classes"));
|
||||
Stream.of(
|
||||
BasicSpringJupiterImportedConfigTests.class,
|
||||
BasicSpringJupiterParameterizedClassTests.class,
|
||||
BasicSpringJupiterSharedConfigTests.class,
|
||||
BasicSpringJupiterTests.class,
|
||||
BasicSpringJupiterTests.NestedTests.class,
|
||||
BasicSpringTestNGTests.class,
|
||||
BasicSpringVintageTests.class,
|
||||
DisabledInAotProcessingTests.class,
|
||||
|
||||
+22
@@ -18,7 +18,9 @@ package org.springframework.test.context.aot;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.test.context.aot.samples.basic.AbstractSpringJupiterParameterizedClassTests;
|
||||
import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterImportedConfigTests;
|
||||
import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterParameterizedClassTests;
|
||||
import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterSharedConfigTests;
|
||||
import org.springframework.test.context.aot.samples.basic.BasicSpringJupiterTests;
|
||||
import org.springframework.test.context.aot.samples.basic.BasicSpringTestNGTests;
|
||||
@@ -45,6 +47,11 @@ class TestClassScannerTests extends AbstractAotTests {
|
||||
BasicSpringJupiterSharedConfigTests.class,
|
||||
BasicSpringJupiterTests.class,
|
||||
BasicSpringJupiterTests.NestedTests.class,
|
||||
BasicSpringJupiterParameterizedClassTests.class,
|
||||
AbstractSpringJupiterParameterizedClassTests.InheritedNestedTests.class,
|
||||
AbstractSpringJupiterParameterizedClassTests.InheritedNestedTests.InheritedDoublyNestedTests.class,
|
||||
BasicSpringJupiterParameterizedClassTests.NestedTests.class,
|
||||
BasicSpringJupiterParameterizedClassTests.NestedTests.DoublyNestedTests.class,
|
||||
BasicSpringTestNGTests.class,
|
||||
BasicSpringVintageTests.class,
|
||||
DisabledInAotProcessingTests.class,
|
||||
@@ -61,6 +68,11 @@ class TestClassScannerTests extends AbstractAotTests {
|
||||
BasicSpringJupiterSharedConfigTests.class,
|
||||
BasicSpringJupiterTests.class,
|
||||
BasicSpringJupiterTests.NestedTests.class,
|
||||
BasicSpringJupiterParameterizedClassTests.class,
|
||||
AbstractSpringJupiterParameterizedClassTests.InheritedNestedTests.class,
|
||||
AbstractSpringJupiterParameterizedClassTests.InheritedNestedTests.InheritedDoublyNestedTests.class,
|
||||
BasicSpringJupiterParameterizedClassTests.NestedTests.class,
|
||||
BasicSpringJupiterParameterizedClassTests.NestedTests.DoublyNestedTests.class,
|
||||
DisabledInAotProcessingTests.class,
|
||||
DisabledInAotRuntimeClassLevelTests.class,
|
||||
DisabledInAotRuntimeMethodLevelTests.class
|
||||
@@ -87,6 +99,11 @@ class TestClassScannerTests extends AbstractAotTests {
|
||||
BasicSpringJupiterSharedConfigTests.class,
|
||||
BasicSpringJupiterTests.class,
|
||||
BasicSpringJupiterTests.NestedTests.class,
|
||||
BasicSpringJupiterParameterizedClassTests.class,
|
||||
AbstractSpringJupiterParameterizedClassTests.InheritedNestedTests.class,
|
||||
AbstractSpringJupiterParameterizedClassTests.InheritedNestedTests.InheritedDoublyNestedTests.class,
|
||||
BasicSpringJupiterParameterizedClassTests.NestedTests.class,
|
||||
BasicSpringJupiterParameterizedClassTests.NestedTests.DoublyNestedTests.class,
|
||||
BasicSpringVintageTests.class,
|
||||
BasicSpringTestNGTests.class,
|
||||
DisabledInAotProcessingTests.class,
|
||||
@@ -103,6 +120,11 @@ class TestClassScannerTests extends AbstractAotTests {
|
||||
BasicSpringJupiterSharedConfigTests.class,
|
||||
BasicSpringJupiterTests.class,
|
||||
BasicSpringJupiterTests.NestedTests.class,
|
||||
BasicSpringJupiterParameterizedClassTests.class,
|
||||
AbstractSpringJupiterParameterizedClassTests.InheritedNestedTests.class,
|
||||
AbstractSpringJupiterParameterizedClassTests.InheritedNestedTests.InheritedDoublyNestedTests.class,
|
||||
BasicSpringJupiterParameterizedClassTests.NestedTests.class,
|
||||
BasicSpringJupiterParameterizedClassTests.NestedTests.DoublyNestedTests.class,
|
||||
BasicSpringVintageTests.class,
|
||||
DisabledInAotProcessingTests.class,
|
||||
DisabledInAotRuntimeClassLevelTests.class,
|
||||
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright 2002-present 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.test.context.aot.samples.basic;
|
||||
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.aot.samples.common.MessageService;
|
||||
import org.springframework.test.context.aot.samples.management.ManagementConfiguration;
|
||||
import org.springframework.test.context.env.YamlTestProperties;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Abstract base test class which declares {@link Nested @Nested} test classes
|
||||
* that will be inherited by concrete subclasses.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 7.0
|
||||
*/
|
||||
@SpringJUnitConfig({BasicTestConfiguration.class, ManagementConfiguration.class})
|
||||
@TestPropertySource(properties = "test.engine = jupiter")
|
||||
@YamlTestProperties({
|
||||
"classpath:org/springframework/test/context/aot/samples/basic/test1.yaml",
|
||||
"classpath:org/springframework/test/context/aot/samples/basic/test2.yaml"
|
||||
})
|
||||
public abstract class AbstractSpringJupiterParameterizedClassTests {
|
||||
|
||||
@Nested
|
||||
public class InheritedNestedTests {
|
||||
|
||||
@Test
|
||||
void test(@Autowired ApplicationContext context, @Autowired MessageService messageService,
|
||||
@Value("${test.engine}") String testEngine, @Value("${foo}") String foo) {
|
||||
|
||||
assertThat(messageService.generateMessage()).isEqualTo("Hello, AOT!");
|
||||
assertThat(foo).isEqualTo("${foo}");
|
||||
assertThat(testEngine).isEqualTo("jupiter");
|
||||
BasicSpringJupiterTests.assertEnvProperties(context);
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestPropertySource(properties = "foo=quux")
|
||||
public class InheritedDoublyNestedTests {
|
||||
|
||||
@Test
|
||||
void test(@Autowired ApplicationContext context, @Autowired MessageService messageService,
|
||||
@Value("${test.engine}") String testEngine, @Value("${foo}") String foo) {
|
||||
|
||||
assertThat(messageService.generateMessage()).isEqualTo("Hello, AOT!");
|
||||
assertThat(foo).isEqualTo("quux");
|
||||
assertThat(testEngine).isEqualTo("jupiter");
|
||||
BasicSpringJupiterTests.assertEnvProperties(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This is here to ensure that an inner class is only considered a nested test
|
||||
// class if it's annotated with @Nested.
|
||||
public class InheritedNotReallyNestedTests {
|
||||
}
|
||||
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright 2002-present 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.test.context.aot.samples.basic;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedClass;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.aot.samples.common.MessageService;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* {@link ParameterizedClass @ParameterizedClass} variant of {@link BasicSpringJupiterTests}.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 7.0
|
||||
*/
|
||||
@ParameterizedClass
|
||||
@ValueSource(strings = {"foo", "bar"})
|
||||
public class BasicSpringJupiterParameterizedClassTests extends AbstractSpringJupiterParameterizedClassTests {
|
||||
|
||||
private final String parameterizedString;
|
||||
|
||||
@Resource
|
||||
Integer magicNumber;
|
||||
|
||||
|
||||
BasicSpringJupiterParameterizedClassTests(String parameterizedString) {
|
||||
this.parameterizedString = parameterizedString;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void test(@Autowired ApplicationContext context, @Autowired MessageService messageService,
|
||||
@Value("${test.engine}") String testEngine) {
|
||||
assertThat("foo".equals(parameterizedString) || "bar".equals(parameterizedString)).isTrue();
|
||||
assertThat(messageService.generateMessage()).isEqualTo("Hello, AOT!");
|
||||
assertThat(testEngine).isEqualTo("jupiter");
|
||||
assertThat(magicNumber).isEqualTo(42);
|
||||
BasicSpringJupiterTests.assertEnvProperties(context);
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestPropertySource(properties = "foo=bar")
|
||||
@ActiveProfiles(resolver = SpanishActiveProfilesResolver.class)
|
||||
public class NestedTests {
|
||||
|
||||
@Test
|
||||
void test(@Autowired ApplicationContext context, @Autowired MessageService messageService,
|
||||
@Value("${test.engine}") String testEngine, @Value("${foo}") String foo) {
|
||||
assertThat("foo".equals(parameterizedString) || "bar".equals(parameterizedString)).isTrue();
|
||||
assertThat(messageService.generateMessage()).isEqualTo("¡Hola, AOT!");
|
||||
assertThat(foo).isEqualTo("bar");
|
||||
assertThat(testEngine).isEqualTo("jupiter");
|
||||
BasicSpringJupiterTests.assertEnvProperties(context);
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestPropertySource(properties = "foo=quux")
|
||||
public class DoublyNestedTests {
|
||||
|
||||
@Test
|
||||
void test(@Autowired ApplicationContext context, @Autowired MessageService messageService,
|
||||
@Value("${test.engine}") String testEngine, @Value("${foo}") String foo) {
|
||||
assertThat("foo".equals(parameterizedString) || "bar".equals(parameterizedString)).isTrue();
|
||||
assertThat(messageService.generateMessage()).isEqualTo("¡Hola, AOT!");
|
||||
assertThat(foo).isEqualTo("quux");
|
||||
assertThat(testEngine).isEqualTo("jupiter");
|
||||
BasicSpringJupiterTests.assertEnvProperties(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This is here to ensure that an inner class is only considered a nested test
|
||||
// class if it's annotated with @Nested.
|
||||
public class NotReallyNestedTests {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user