Merge branch '6.0.x'
This commit is contained in:
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2023 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;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import org.springframework.aot.generate.InMemoryGeneratedFiles;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.assertj.core.api.Assertions.assertThatNoException;
|
||||
|
||||
/**
|
||||
* Tests for error cases in {@link TestContextAotGenerator}.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 6.0.9
|
||||
*/
|
||||
class TestContextAotGeneratorErrorCaseTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(delimiter = '=', textBlock = """
|
||||
'spring.aot.enabled' = 'true'
|
||||
'org.graalvm.nativeimage.imagecode' = 'buildtime'
|
||||
'org.graalvm.nativeimage.imagecode' = 'runtime'
|
||||
'org.graalvm.nativeimage.imagecode' = 'bogus'
|
||||
""")
|
||||
void attemptToProcessWhileRunningInAotMode(String property, String value) {
|
||||
try {
|
||||
System.setProperty(property, value);
|
||||
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> generator().processAheadOfTime(Stream.empty()))
|
||||
.withMessage("Cannot perform AOT processing during AOT run-time execution");
|
||||
}
|
||||
finally {
|
||||
System.clearProperty(property);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void attemptToProcessWhileRunningInGraalVmNativeBuildToolsAgentMode() {
|
||||
final String IMAGECODE = "org.graalvm.nativeimage.imagecode";
|
||||
try {
|
||||
System.setProperty(IMAGECODE, "AgenT");
|
||||
|
||||
assertThatNoException().isThrownBy(() -> generator().processAheadOfTime(Stream.empty()));
|
||||
}
|
||||
finally {
|
||||
System.clearProperty(IMAGECODE);
|
||||
}
|
||||
}
|
||||
|
||||
private static TestContextAotGenerator generator() {
|
||||
InMemoryGeneratedFiles generatedFiles = new InMemoryGeneratedFiles();
|
||||
return new TestContextAotGenerator(generatedFiles);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ package org.springframework.test.context.aot.samples.basic;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.aot.AotDetector;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -27,7 +28,6 @@ import org.springframework.test.context.ContextLoader;
|
||||
import org.springframework.test.context.MergedContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.aot.AotTestAttributes;
|
||||
import org.springframework.test.context.aot.TestAotDetector;
|
||||
import org.springframework.test.context.aot.samples.basic.BasicSpringVintageTests.CustomXmlBootstrapper;
|
||||
import org.springframework.test.context.aot.samples.common.MessageService;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
@@ -78,7 +78,7 @@ public class BasicSpringVintageTests {
|
||||
String booleanKey1 = "@SpringBootConfiguration-" + mergedConfig.getTestClass().getName() + "-active1";
|
||||
String booleanKey2 = "@SpringBootConfiguration-" + mergedConfig.getTestClass().getName() + "-active2";
|
||||
AotTestAttributes aotAttributes = AotTestAttributes.getInstance();
|
||||
if (TestAotDetector.useGeneratedArtifacts()) {
|
||||
if (AotDetector.useGeneratedArtifacts()) {
|
||||
assertThat(aotAttributes.getString(stringKey))
|
||||
.as("AOT String attribute must already be present during AOT run-time execution")
|
||||
.isEqualTo("org.example.Main");
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.test.context.aot.samples.basic;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.aot.AotDetector;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
|
||||
import org.springframework.context.annotation.Import;
|
||||
@@ -27,7 +28,6 @@ import org.springframework.test.context.ContextConfigurationAttributes;
|
||||
import org.springframework.test.context.ContextCustomizer;
|
||||
import org.springframework.test.context.ContextCustomizerFactory;
|
||||
import org.springframework.test.context.MergedContextConfiguration;
|
||||
import org.springframework.test.context.aot.TestAotDetector;
|
||||
|
||||
/**
|
||||
* Emulates {@code ImportsContextCustomizerFactory} from Spring Boot's testing support.
|
||||
@@ -41,7 +41,7 @@ class ImportsContextCustomizerFactory implements ContextCustomizerFactory {
|
||||
public ContextCustomizer createContextCustomizer(Class<?> testClass,
|
||||
List<ContextConfigurationAttributes> configAttributes) {
|
||||
|
||||
if (TestAotDetector.useGeneratedArtifacts()) {
|
||||
if (AotDetector.useGeneratedArtifacts()) {
|
||||
return null;
|
||||
}
|
||||
if (testClass.getName().startsWith("org.springframework.test.context.aot.samples") &&
|
||||
|
||||
Reference in New Issue
Block a user