From 55c410abec89ac4a7672126a989bda0f32311fb7 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 4 Mar 2025 17:42:42 +0000 Subject: [PATCH] Improve autoconfigure's use of test resources Closes gh-44512 --- .../AutoConfigurationMetadataLoaderTests.java | 14 +- ...tAutoConfigurationImportSelectorTests.java | 17 +- .../amqp/RabbitAutoConfigurationTests.java | 7 +- .../batch/BatchAutoConfigurationTests.java | 9 +- ...BatchAutoConfigurationWithoutJpaTests.java | 7 +- .../cache/CacheAutoConfigurationTests.java | 76 +++++- .../EhCache3CacheAutoConfigurationTests.java | 31 ++- .../CassandraAutoConfigurationTests.java | 4 +- .../condition/ConditionalOnResourceTests.java | 5 +- .../condition/ResourceConditionTests.java | 4 +- .../MessageSourceAutoConfigurationTests.java | 45 +++- .../CouchbaseAutoConfigurationTests.java | 8 +- ...dbcRepositoriesAutoConfigurationTests.java | 18 +- ...dbcRepositoriesAutoConfigurationTests.java | 18 +- .../RedisAutoConfigurationJedisTests.java | 2 + .../redis/RedisAutoConfigurationTests.java | 4 +- ...earchRestClientAutoConfigurationTests.java | 4 +- .../flyway/FlywayAutoConfigurationTests.java | 98 ++++++- ...eImageResourceProviderCustomizerTests.java | 5 +- ...ConfigurationReactiveIntegrationTests.java | 17 +- ...oConfigurationServletIntegrationTests.java | 9 +- .../FreeMarkerAutoConfigurationTests.java | 4 +- ...rkerTemplateAvailabilityProviderTests.java | 8 +- .../DefaultGraphQlSchemaConditionTests.java | 5 +- .../GraphQlAutoConfigurationTests.java | 41 ++- ...lQueryByExampleAutoConfigurationTests.java | 25 +- ...GraphQlQuerydslAutoConfigurationTests.java | 22 +- ...eQueryByExampleAutoConfigurationTests.java | 22 +- ...eactiveQuerydslAutoConfigurationTests.java | 22 +- .../GraphQlWebFluxAutoConfigurationTests.java | 22 +- .../GraphQlRSocketAutoConfigurationTests.java | 22 +- ...WebFluxSecurityAutoConfigurationTests.java | 22 +- ...lWebMvcSecurityAutoConfigurationTests.java | 22 +- .../GraphQlWebMvcAutoConfigurationTests.java | 22 +- .../GroovyTemplateAutoConfigurationTests.java | 19 +- ...oovyTemplateAvailabilityProviderTests.java | 8 +- ...HazelcastAutoConfigurationServerTests.java | 45 +++- .../HazelcastAutoConfigurationTests.java | 37 ++- .../ProjectInfoAutoConfigurationTests.java | 10 +- .../IntegrationAutoConfigurationTests.java | 7 +- ...opertiesEnvironmentPostProcessorTests.java | 7 +- ...iverConfigurationFailureAnalyzerTests.java | 4 +- .../JdbcClientAutoConfigurationTests.java | 38 ++- .../JdbcTemplateAutoConfigurationTests.java | 67 ++++- .../kafka/KafkaAutoConfigurationTests.java | 11 +- .../EmbeddedLdapAutoConfigurationTests.java | 247 +++++++++++++++++- .../Liquibase423AutoConfigurationTests.java | 4 +- .../LiquibaseAutoConfigurationTests.java | 95 ++++++- .../mongo/MongoAutoConfigurationTests.java | 4 +- .../MongoReactiveAutoConfigurationTests.java | 4 +- ...ConfigurationReactiveIntegrationTests.java | 7 +- ...oConfigurationServletIntegrationTests.java | 7 +- .../AbstractJpaAutoConfigurationTests.java | 25 +- ...ibernate2ndLevelCacheIntegrationTests.java | 17 +- .../HibernateJpaAutoConfigurationTests.java | 96 ++++++- .../r2dbc/R2dbcAutoConfigurationTests.java | 7 +- .../RSocketServerAutoConfigurationTests.java | 13 +- ...2ResourceServerAutoConfigurationTests.java | 25 +- ...2ResourceServerAutoConfigurationTests.java | 26 +- ...ml2RelyingPartyAutoConfigurationTests.java | 45 +++- .../SecurityAutoConfigurationTests.java | 23 +- .../SessionAutoConfigurationJdbcTests.java | 30 ++- .../SslPropertiesBundleRegistrarTests.java | 6 +- ...ymeleafReactiveAutoConfigurationTests.java | 10 +- ...hymeleafServletAutoConfigurationTests.java | 23 ++ ...leafTemplateAvailabilityProviderTests.java | 6 +- .../web/WebResourcesRuntimeHintsTests.java | 9 +- .../WebFluxAutoConfigurationTests.java | 4 +- ...WelcomePageRouterFunctionFactoryTests.java | 4 +- ...orWebExceptionHandlerIntegrationTests.java | 23 +- .../DefaultErrorWebExceptionHandlerTests.java | 13 +- ...stractClientHttpConnectorFactoryTests.java | 4 +- ...ttpConnectorFactoryConfigurationTests.java | 4 +- .../JspTemplateAvailabilityProviderTests.java | 8 +- .../servlet/WebMvcAutoConfigurationTests.java | 5 +- .../WelcomePageHandlerMappingTests.java | 7 +- .../servlet/WelcomePageIntegrationTests.java | 9 +- .../BasicErrorControllerIntegrationTests.java | 4 +- .../WebServicesAutoConfigurationTests.java | 77 +++++- ...onfigurationMetadataLoaderTests.properties | 4 - .../resources/META-INF/build-info.properties | 5 - .../META-INF/mappings/non-annotated.xml | 18 -- .../test/resources/META-INF/persistence.xml | 7 - .../META-INF/spring.integration.properties | 1 - ...mportSelectorTests$FromImportsFile.imports | 2 - ...sFileIgnoresMissingOptionalClasses.imports | 3 - .../src/test/resources/application.properties | 1 - .../test/resources/cache/ehcache-override.xml | 10 - .../src/test/resources/city.sql | 1 - .../test/resources/custom-schema-sample.ldif | 7 - .../src/test/resources/custom-schema.ldif | 17 -- .../resources/custom-templates/custom.ftlh | 1 - .../resources/custom-templates/custom.html | 1 - .../resources/custom-templates/custom.tpl | 1 - .../test/resources/custom-templates/custom.vm | 1 - .../resources/custom-templates/suffixed.jsp | 0 .../src/test/resources/data-city-schema.sql | 7 - .../src/test/resources/data.sql | 1 - .../db/changelog/db.changelog-city.yaml | 38 --- .../db/changelog/db.changelog-master.yaml | 20 -- .../db/changelog/db.changelog-override.json | 39 --- .../db/changelog/db.changelog-override.sql | 8 - .../db/changelog/db.changelog-override.xml | 20 -- .../src/test/resources/db/city/V1__init.sql | 9 - .../test/resources/db/migration/V1__init.sql | 1 - .../test/resources/db/non-annotated-data.sql | 1 - .../test/resources/db/vendors/h2/V1__init.sql | 1 - .../src/test/resources/ehcache.xml | 9 - .../src/test/resources/ehcache3.xml | 26 -- .../test/resources/graphql/schema.graphqls | 9 - .../resources/graphql/types/book.graphqls | 6 - .../resources/graphql/types/person.custom | 4 - .../src/test/resources/hazelcast.xml | 12 - .../src/test/resources/hazelcast.yaml | 7 - .../src/test/resources/hazelcast.yml | 7 - .../src/test/resources/infinispan.xml | 13 - .../src/test/resources/ksLoc | 1 - .../src/test/resources/ksLocP | 1 - .../src/test/resources/logging.properties | 5 - .../autoconfigure}/batch/custom-schema.sql | 0 .../boot/autoconfigure/cassandra}/test.jks | Bin .../boot/autoconfigure/couchbase}/test.jks | Bin .../boot/autoconfigure/data/redis/test.jks | Bin 0 -> 1276 bytes .../boot/autoconfigure/elasticsearch/test.jks | Bin 0 -> 1276 bytes .../boot/autoconfigure/mongo/test.jks | Bin 0 -> 1276 bytes .../boot/autoconfigure/mustache}/content.html | 0 .../boot/autoconfigure/mustache}/foo.html | 0 .../boot/autoconfigure/mustache}/foo_de.html | 0 .../boot/autoconfigure/mustache}/home.html | 0 .../boot/autoconfigure/mustache}/layout.html | 0 .../boot/autoconfigure/mustache}/partial.html | 0 .../boot/autoconfigure/rsocket/test.jks | Bin 0 -> 1276 bytes .../security/saml2}/certificate-location | 0 .../security/saml2}/idp-metadata | 0 .../idp-metadata-with-multiple-providers | 0 .../security/saml2}/private-key-location | 0 .../session/custom-schema-h2.sql | 0 .../boot/autoconfigure/ssl/test.jks | Bin 0 -> 1276 bytes .../web/reactive/function/client/test.jks | Bin 0 -> 1276 bytes .../autoconfigure/web/servlet}/index.html | 0 .../web/servlet/static/custom.css} | 0 .../src/test/resources/public-key-location | 6 - .../src/test/resources/public/custom.css | 2 - .../test/resources/schema-multi-basedn.ldif | 114 -------- .../src/test/resources/schema.ldif | 85 ------ .../src/test/resources/schema.sql | 4 - .../resources/templates/data-dialect.html | 1 - .../test/resources/templates/error/507.ftlh | 1 - .../resources/templates/error/error.mustache | 8 - .../src/test/resources/templates/home.ftlh | 1 - .../src/test/resources/templates/home.html | 1 - .../src/test/resources/templates/home.tpl | 1 - .../src/test/resources/templates/home.vm | 1 - .../src/test/resources/templates/included.tpl | 1 - .../test/resources/templates/included_fr.tpl | 1 - .../src/test/resources/templates/includes.tpl | 2 - .../templates/java8time-dialect.html | 1 - .../src/test/resources/templates/layout.html | 14 - .../src/test/resources/templates/message.ftlh | 1 - .../src/test/resources/templates/message.html | 1 - .../src/test/resources/templates/message.tpl | 1 - .../src/test/resources/templates/message.vm | 1 - .../resources/templates/prefix/prefixed.ftlh | 1 - .../resources/templates/prefix/prefixed.tpl | 1 - .../resources/templates/prefix/prefixed.vm | 1 - .../resources/templates/security-dialect.html | 1 - .../resources/templates/suffixed.freemarker | 1 - .../templates/suffixed.groovytemplate | 3 - .../resources/templates/suffixed.thymeleaf | 0 .../test/resources/templates/template.html | 1 - .../src/test/resources/templates/view.html | 10 - .../test/resources/test/messages.properties | 1 - .../test/resources/test/messages2.properties | 1 - .../test/resources/test/swedish.properties | 1 - .../src/test/resources/tsLoc | 1 - .../src/test/resources/tsLocP | 1 - .../test/resources/web/custom-resource.txt | 0 .../test/resources/welcome-page/index.html | 1 - .../src/test/resources/wsdl/service.wsdl | 46 ---- .../src/test/resources/wsdl/types.xsd | 7 - .../test/context/FilteredClassLoader.java | 19 +- 181 files changed, 1655 insertions(+), 820 deletions(-) delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/AutoConfigurationMetadataLoaderTests.properties delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/build-info.properties delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/mappings/non-annotated.xml delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/persistence.xml delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/spring.integration.properties delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/spring/org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$FromImportsFile.imports delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/spring/org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$FromImportsFileIgnoresMissingOptionalClasses.imports delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/application.properties delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/cache/ehcache-override.xml delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/city.sql delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-schema-sample.ldif delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-schema.ldif delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/custom.ftlh delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/custom.html delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/custom.tpl delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/custom.vm delete mode 100755 spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/suffixed.jsp delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/data-city-schema.sql delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/data.sql delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-city.yaml delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-master.yaml delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.json delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.sql delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.xml delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/city/V1__init.sql delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/migration/V1__init.sql delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/non-annotated-data.sql delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/vendors/h2/V1__init.sql delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/ehcache.xml delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/ehcache3.xml delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/graphql/schema.graphqls delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/graphql/types/book.graphqls delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/graphql/types/person.custom delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/hazelcast.xml delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/hazelcast.yaml delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/hazelcast.yml delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/infinispan.xml delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/ksLoc delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/ksLocP delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/logging.properties rename spring-boot-project/spring-boot-autoconfigure/src/test/resources/{ => org/springframework/boot/autoconfigure}/batch/custom-schema.sql (100%) rename spring-boot-project/spring-boot-autoconfigure/src/test/resources/{rsocket => org/springframework/boot/autoconfigure/cassandra}/test.jks (100%) rename spring-boot-project/spring-boot-autoconfigure/src/test/resources/{ => org/springframework/boot/autoconfigure/couchbase}/test.jks (100%) create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/data/redis/test.jks create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/elasticsearch/test.jks create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/mongo/test.jks rename spring-boot-project/spring-boot-autoconfigure/src/test/resources/{mustache-templates => org/springframework/boot/autoconfigure/mustache}/content.html (100%) rename spring-boot-project/spring-boot-autoconfigure/src/test/resources/{mustache-templates => org/springframework/boot/autoconfigure/mustache}/foo.html (100%) rename spring-boot-project/spring-boot-autoconfigure/src/test/resources/{mustache-templates => org/springframework/boot/autoconfigure/mustache}/foo_de.html (100%) rename spring-boot-project/spring-boot-autoconfigure/src/test/resources/{mustache-templates => org/springframework/boot/autoconfigure/mustache}/home.html (100%) rename spring-boot-project/spring-boot-autoconfigure/src/test/resources/{mustache-templates => org/springframework/boot/autoconfigure/mustache}/layout.html (100%) rename spring-boot-project/spring-boot-autoconfigure/src/test/resources/{mustache-templates => org/springframework/boot/autoconfigure/mustache}/partial.html (100%) create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/rsocket/test.jks rename spring-boot-project/spring-boot-autoconfigure/src/test/resources/{saml => org/springframework/boot/autoconfigure/security/saml2}/certificate-location (100%) rename spring-boot-project/spring-boot-autoconfigure/src/test/resources/{saml => org/springframework/boot/autoconfigure/security/saml2}/idp-metadata (100%) rename spring-boot-project/spring-boot-autoconfigure/src/test/resources/{saml => org/springframework/boot/autoconfigure/security/saml2}/idp-metadata-with-multiple-providers (100%) rename spring-boot-project/spring-boot-autoconfigure/src/test/resources/{saml => org/springframework/boot/autoconfigure/security/saml2}/private-key-location (100%) rename spring-boot-project/spring-boot-autoconfigure/src/test/resources/{ => org/springframework/boot/autoconfigure}/session/custom-schema-h2.sql (100%) create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/ssl/test.jks create mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/web/reactive/function/client/test.jks rename spring-boot-project/spring-boot-autoconfigure/src/test/resources/{templates/thymeleaf => org/springframework/boot/autoconfigure/web/servlet}/index.html (100%) rename spring-boot-project/spring-boot-autoconfigure/src/test/resources/{custom-templates/custom.jsp => org/springframework/boot/autoconfigure/web/servlet/static/custom.css} (100%) mode change 100755 => 100644 delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/public-key-location delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/public/custom.css delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/schema-multi-basedn.ldif delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/schema.ldif delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/schema.sql delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/data-dialect.html delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/error/507.ftlh delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/error/error.mustache delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/home.ftlh delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/home.html delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/home.tpl delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/home.vm delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/included.tpl delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/included_fr.tpl delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/includes.tpl delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/java8time-dialect.html delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/layout.html delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/message.ftlh delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/message.html delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/message.tpl delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/message.vm delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/prefix/prefixed.ftlh delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/prefix/prefixed.tpl delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/prefix/prefixed.vm delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/security-dialect.html delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/suffixed.freemarker delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/suffixed.groovytemplate delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/suffixed.thymeleaf delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/template.html delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/view.html delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/test/messages.properties delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/test/messages2.properties delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/test/swedish.properties delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/tsLoc delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/tsLocP delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/web/custom-resource.txt delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/welcome-page/index.html delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/wsdl/service.wsdl delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/wsdl/types.xsd diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationMetadataLoaderTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationMetadataLoaderTests.java index adb83a99bf1..ab919d4ec96 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationMetadataLoaderTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/AutoConfigurationMetadataLoaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-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. @@ -20,6 +20,8 @@ import java.util.Collections; import org.junit.jupiter.api.Test; +import org.springframework.boot.testsupport.classpath.resources.WithResource; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -27,6 +29,12 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Phillip Webb */ +@WithResource(name = "metadata.properties", content = """ + test= + test.string=abc + test.int=123 + test.set=a,b,b,c + """) class AutoConfigurationMetadataLoaderTests { @Test @@ -90,8 +98,8 @@ class AutoConfigurationMetadataLoaderTests { } private AutoConfigurationMetadata load() { - return AutoConfigurationMetadataLoader.loadMetadata(null, - "META-INF/AutoConfigurationMetadataLoaderTests.properties"); + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + return AutoConfigurationMetadataLoader.loadMetadata(classLoader, "metadata.properties"); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java index f63d78964b1..5e6a9feccc9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ImportAutoConfigurationImportSelectorTests.java @@ -28,6 +28,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.core.annotation.AliasFor; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.type.AnnotationMetadata; @@ -74,6 +75,12 @@ class ImportAutoConfigurationImportSelectorTests { } @Test + @WithResource( + name = "META-INF/spring/org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$FromImportsFile.imports", + content = """ + org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$ImportedAutoConfiguration + org.springframework.boot.autoconfigure.missing.MissingAutoConfiguration + """) void importsAreSelectedFromImportsFile() throws Exception { AnnotationMetadata annotationMetadata = getAnnotationMetadata(FromImportsFile.class); String[] imports = this.importSelector.selectImports(annotationMetadata); @@ -83,9 +90,15 @@ class ImportAutoConfigurationImportSelectorTests { } @Test + @WithResource( + name = "META-INF/spring/org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$FromImportsFile.imports", + content = """ + optional:org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$ImportedAutoConfiguration + optional:org.springframework.boot.autoconfigure.missing.MissingAutoConfiguration + org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$AnotherImportedAutoConfiguration + """) void importsSelectedFromImportsFileIgnoreMissingOptionalClasses() throws Exception { - AnnotationMetadata annotationMetadata = getAnnotationMetadata( - FromImportsFileIgnoresMissingOptionalClasses.class); + AnnotationMetadata annotationMetadata = getAnnotationMetadata(FromImportsFile.class); String[] imports = this.importSelector.selectImports(annotationMetadata); assertThat(imports).containsExactly( "org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$ImportedAutoConfiguration", diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java index 1f3e84d18e7..a6bdc9fdfc5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -910,9 +910,8 @@ class RabbitAutoConfigurationTests { void enableSslWithBundle() { this.contextRunner.withUserConfiguration(TestConfiguration.class) .withPropertyValues("spring.rabbitmq.ssl.bundle=test-bundle", - "spring.ssl.bundle.jks.test-bundle.keystore.location=classpath:test.jks", - "spring.ssl.bundle.jks.test-bundle.keystore.password=secret", - "spring.ssl.bundle.jks.test-bundle.key.password=password") + "spring.ssl.bundle.jks.test-bundle.keystore.location=classpath:org/springframework/boot/autoconfigure/amqp/test.jks", + "spring.ssl.bundle.jks.test-bundle.keystore.password=secret") .run((context) -> { com.rabbitmq.client.ConnectionFactory rabbitConnectionFactory = getTargetConnectionFactory(context); assertThat(rabbitConnectionFactory.isSSL()).isTrue(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java index bf8bad0de84..9a0f713e483 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -72,6 +72,8 @@ import org.springframework.boot.sql.init.DatabaseInitializationSettings; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.boot.testsupport.classpath.resources.WithPackageResources; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -284,13 +286,13 @@ class BatchAutoConfigurationTests { } @Test + @WithPackageResources("custom-schema.sql") void testRenamePrefix() { this.contextRunner .withUserConfiguration(TestConfiguration.class, EmbeddedDataSourceConfiguration.class, HibernateJpaAutoConfiguration.class) .withPropertyValues("spring.datasource.generate-unique-name=true", - "spring.batch.jdbc.schema:classpath:batch/custom-schema.sql", - "spring.batch.jdbc.tablePrefix:PREFIX_") + "spring.batch.jdbc.schema:classpath:custom-schema.sql", "spring.batch.jdbc.tablePrefix:PREFIX_") .run((context) -> { assertThat(context).hasSingleBean(JobLauncher.class); assertThat(context.getBean(BatchProperties.class).getJdbc().getInitializeSchema()) @@ -392,6 +394,7 @@ class BatchAutoConfigurationTests { } @Test + @WithResource(name = "db/changelog/db.changelog-master.yaml", content = "databaseChangeLog:") void jobRepositoryBeansDependOnLiquibase() { this.contextRunner.withUserConfiguration(TestConfiguration.class, EmbeddedDataSourceConfiguration.class) .withUserConfiguration(LiquibaseAutoConfiguration.class) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJpaTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJpaTests.java index a907a075b25..3377b5a449a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJpaTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationWithoutJpaTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -34,6 +34,7 @@ import org.springframework.boot.autoconfigure.transaction.TransactionAutoConfigu import org.springframework.boot.sql.init.DatabaseInitializationMode; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.testsupport.classpath.ClassPathExclusions; +import org.springframework.boot.testsupport.classpath.resources.WithPackageResources; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.transaction.annotation.Isolation; @@ -70,11 +71,11 @@ class BatchAutoConfigurationWithoutJpaTests { } @Test + @WithPackageResources("custom-schema.sql") void jdbcWithCustomPrefix() { this.contextRunner.withUserConfiguration(DefaultConfiguration.class, EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.datasource.generate-unique-name=true", - "spring.batch.jdbc.schema:classpath:batch/custom-schema.sql", - "spring.batch.jdbc.tablePrefix:PREFIX_") + "spring.batch.jdbc.schema:classpath:custom-schema.sql", "spring.batch.jdbc.tablePrefix:PREFIX_") .run((context) -> { assertThat(new JdbcTemplate(context.getBean(DataSource.class)) .queryForList("select * from PREFIX_JOB_EXECUTION")).isEmpty(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java index 53a23bdfec8..e33f93cd9d5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -16,6 +16,10 @@ package org.springframework.boot.autoconfigure.cache; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -47,6 +51,7 @@ import org.springframework.boot.autoconfigure.cache.support.MockCachingProvider. import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration; import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.testsupport.classpath.ClassPathExclusions; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.cache.Cache; import org.springframework.cache.Cache.ValueWrapper; import org.springframework.cache.CacheManager; @@ -461,6 +466,7 @@ class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationTests { } @Test + @WithHazelcastXmlResource void hazelcastCacheExplicit() { this.contextRunner.withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class)) .withUserConfiguration(DefaultCacheConfiguration.class) @@ -476,6 +482,7 @@ class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationTests { } @Test + @WithHazelcastXmlResource void hazelcastCacheWithCustomizers() { this.contextRunner.withUserConfiguration(HazelcastCacheAndCustomizersConfiguration.class) .withPropertyValues("spring.cache.type=hazelcast") @@ -528,10 +535,31 @@ class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationTests { } @Test + @WithResource(name = "hazelcast-specific.xml", content = """ + + + + + + 3600 + 600 + + + + + + + + + + + """) void hazelcastAsJCacheWithConfig() { String cachingProviderFqn = HazelcastServerCachingProvider.class.getName(); try { - String configLocation = "org/springframework/boot/autoconfigure/hazelcast/hazelcast-specific.xml"; + String configLocation = "hazelcast-specific.xml"; this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class) .withPropertyValues("spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn, "spring.cache.jcache.config=" + configLocation) @@ -548,6 +576,7 @@ class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationTests { } @Test + @WithHazelcastXmlResource void hazelcastAsJCacheWithExistingHazelcastInstance() { String cachingProviderFqn = HazelcastServerCachingProvider.class.getName(); this.contextRunner.withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class)) @@ -567,6 +596,7 @@ class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationTests { } @Test + @WithInfinispanXmlResource void infinispanCacheWithConfig() { this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class) .withPropertyValues("spring.cache.type=infinispan", "spring.cache.infinispan.config=infinispan.xml") @@ -615,6 +645,7 @@ class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationTests { } @Test + @WithInfinispanXmlResource void infinispanAsJCacheWithConfig() { String cachingProviderClassName = JCachingProvider.class.getName(); String configLocation = "infinispan.xml"; @@ -1058,4 +1089,45 @@ class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationTests { } + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @WithResource(name = "infinispan.xml", content = """ + + + + + + + + + + + + + + """) + @interface WithInfinispanXmlResource { + + } + + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @WithResource(name = "hazelcast.xml", content = """ + + default-instance + + + + + + + + + """) + @interface WithHazelcastXmlResource { + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/EhCache3CacheAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/EhCache3CacheAutoConfigurationTests.java index 3ee060cffee..92f66b9ac9b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/EhCache3CacheAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/EhCache3CacheAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.cache.CacheAutoConfigurationTests.DefaultCacheConfiguration; import org.springframework.boot.testsupport.classpath.ClassPathExclusions; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.cache.jcache.JCacheCacheManager; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; @@ -49,6 +50,34 @@ class EhCache3CacheAutoConfigurationTests extends AbstractCacheAutoConfiguration } @Test + @WithResource(name = "ehcache3.xml", content = """ + + + + 200 + + + + + 600 + + + + + + + 400 + + + + + """) void ehcache3AsJCacheWithConfig() { String cachingProviderFqn = EhcacheCachingProvider.class.getName(); String configLocation = "ehcache3.xml"; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfigurationTests.java index 4a276d96bd1..d7ef91cbe34 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -38,6 +38,7 @@ import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfigurati import org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration; import org.springframework.boot.ssl.NoSuchSslBundleException; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithPackageResources; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -89,6 +90,7 @@ class CassandraAutoConfigurationTests { } @Test + @WithPackageResources("test.jks") void cqlSessionBuilderWithSslBundle() { this.contextRunner .withPropertyValues("spring.cassandra.ssl.bundle=test-bundle", diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnResourceTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnResourceTests.java index e01c32696dd..177603123f3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnResourceTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnResourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-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. @@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.condition; import org.junit.jupiter.api.Test; import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -35,6 +36,7 @@ class ConditionalOnResourceTests { private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); @Test + @WithResource(name = "schema.sql") void testResourceExists() { this.context.register(BasicConfiguration.class); this.context.refresh(); @@ -43,6 +45,7 @@ class ConditionalOnResourceTests { } @Test + @WithResource(name = "schema.sql") void testResourceExistsWithPlaceholder() { TestPropertyValues.of("schema=schema.sql").applyTo(this.context); this.context.register(PlaceholderConfiguration.class); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ResourceConditionTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ResourceConditionTests.java index dfc936fdd84..f1daa8d5c97 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ResourceConditionTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ResourceConditionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-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. @@ -20,6 +20,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -45,6 +46,7 @@ class ResourceConditionTests { } @Test + @WithResource(name = "logging.properties") void defaultResourceAndNoExplicitKey() { load(DefaultLocationConfiguration.class); assertThat(this.context.containsBean("foo")).isTrue(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationTests.java index e3098316413..ddf4aff3280 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/context/MessageSourceAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -16,6 +16,10 @@ package org.springframework.boot.autoconfigure.context; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.Locale; import org.junit.jupiter.api.Disabled; @@ -28,6 +32,7 @@ import org.springframework.boot.autoconfigure.context.MessageSourceAutoConfigura import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ContextConsumer; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.MessageSource; import org.springframework.context.MessageSourceResolvable; import org.springframework.context.annotation.Bean; @@ -57,6 +62,7 @@ class MessageSourceAutoConfigurationTests { } @Test + @WithTestMessagesPropertiesResource void propertiesBundleWithSlashIsDetected() { this.contextRunner.withPropertyValues("spring.messages.basename:test/messages").run((context) -> { assertThat(context).hasSingleBean(MessageSource.class); @@ -65,6 +71,7 @@ class MessageSourceAutoConfigurationTests { } @Test + @WithTestMessagesPropertiesResource void propertiesBundleWithDotIsDetected() { this.contextRunner.withPropertyValues("spring.messages.basename:test.messages").run((context) -> { assertThat(context).hasSingleBean(MessageSource.class); @@ -73,6 +80,7 @@ class MessageSourceAutoConfigurationTests { } @Test + @WithTestSwedishPropertiesResource void testEncodingWorks() { this.contextRunner.withPropertyValues("spring.messages.basename:test/swedish") .run((context) -> assertThat(context.getMessage("foo", null, "Foo message", Locale.UK)) @@ -80,6 +88,7 @@ class MessageSourceAutoConfigurationTests { } @Test + @WithTestMessagesPropertiesResource void testCacheDurationNoUnit() { this.contextRunner .withPropertyValues("spring.messages.basename:test/messages", "spring.messages.cache-duration=10") @@ -87,6 +96,7 @@ class MessageSourceAutoConfigurationTests { } @Test + @WithTestMessagesPropertiesResource void testCacheDurationWithUnit() { this.contextRunner .withPropertyValues("spring.messages.basename:test/messages", "spring.messages.cache-duration=1m") @@ -101,6 +111,8 @@ class MessageSourceAutoConfigurationTests { } @Test + @WithTestMessagesPropertiesResource + @WithTestMessages2PropertiesResource void testMultipleMessageSourceCreated() { this.contextRunner.withPropertyValues("spring.messages.basename:test/messages,test/messages2") .run((context) -> { @@ -110,13 +122,16 @@ class MessageSourceAutoConfigurationTests { } @Test + @WithTestMessagesPropertiesResource @Disabled("Expected to fail per gh-1075") + @WithResource(name = "application-switch-messages.properties", content = "spring.messages.basename:test/messages") void testMessageSourceFromPropertySourceAnnotation() { this.contextRunner.withUserConfiguration(Config.class) .run((context) -> assertThat(context.getMessage("foo", null, "Foo message", Locale.UK)).isEqualTo("bar")); } @Test + @WithTestMessagesPropertiesResource void testFallbackDefault() { this.contextRunner.withPropertyValues("spring.messages.basename:test/messages") .run((context) -> assertThat(context.getBean(MessageSource.class)) @@ -124,6 +139,7 @@ class MessageSourceAutoConfigurationTests { } @Test + @WithTestMessagesPropertiesResource void testFallbackTurnOff() { this.contextRunner .withPropertyValues("spring.messages.basename:test/messages", @@ -133,6 +149,7 @@ class MessageSourceAutoConfigurationTests { } @Test + @WithTestMessagesPropertiesResource void testFormatMessageDefault() { this.contextRunner.withPropertyValues("spring.messages.basename:test/messages") .run((context) -> assertThat(context.getBean(MessageSource.class)) @@ -140,6 +157,7 @@ class MessageSourceAutoConfigurationTests { } @Test + @WithTestMessagesPropertiesResource void testFormatMessageOn() { this.contextRunner .withPropertyValues("spring.messages.basename:test/messages", @@ -149,6 +167,7 @@ class MessageSourceAutoConfigurationTests { } @Test + @WithTestMessagesPropertiesResource void testUseCodeAsDefaultMessageDefault() { this.contextRunner.withPropertyValues("spring.messages.basename:test/messages") .run((context) -> assertThat(context.getBean(MessageSource.class)) @@ -156,6 +175,7 @@ class MessageSourceAutoConfigurationTests { } @Test + @WithTestMessagesPropertiesResource void testUseCodeAsDefaultMessageOn() { this.contextRunner .withPropertyValues("spring.messages.basename:test/messages", @@ -171,6 +191,7 @@ class MessageSourceAutoConfigurationTests { } @Test + @WithTestMessagesPropertiesResource void existingMessageSourceInParentIsIgnored() { this.contextRunner.run((parent) -> this.contextRunner.withParent(parent) .withPropertyValues("spring.messages.basename:test/messages") @@ -178,6 +199,7 @@ class MessageSourceAutoConfigurationTests { } @Test + @WithTestMessagesPropertiesResource void messageSourceWithNonStandardBeanNameIsIgnored() { this.contextRunner.withPropertyValues("spring.messages.basename:test/messages") .withUserConfiguration(CustomBeanNameMessageSourceConfiguration.class) @@ -238,4 +260,25 @@ class MessageSourceAutoConfigurationTests { } + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @WithResource(name = "test/messages.properties", content = "foo=bar") + @interface WithTestMessagesPropertiesResource { + + } + + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @WithResource(name = "test/messages2.properties", content = "foo-foo=bar-bar") + @interface WithTestMessages2PropertiesResource { + + } + + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @WithResource(name = "test/swedish.properties", content = "foo=Some text with some swedish öäå!") + @interface WithTestSwedishPropertiesResource { + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java index 6b38551d5f8..26cc499de7d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/couchbase/CouchbaseAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -39,6 +39,7 @@ import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration; import org.springframework.boot.ssl.NoSuchSslBundleException; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithPackageResources; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -190,13 +191,14 @@ class CouchbaseAutoConfigurationTests { } @Test + @WithPackageResources("test.jks") void enableSslWithBundle() { testClusterEnvironment((env) -> { SecurityConfig securityConfig = env.securityConfig(); assertThat(securityConfig.tlsEnabled()).isTrue(); assertThat(securityConfig.trustManagerFactory()).isNotNull(); - }, "spring.ssl.bundle.jks.test-bundle.keystore.location=classpath:test.jks", - "spring.ssl.bundle.jks.test-bundle.keystore.password=secret", + }, "spring.ssl.bundle.jks.test-bundle.truststore.location=classpath:test.jks", + "spring.ssl.bundle.jks.test-bundle.truststore.password=secret", "spring.couchbase.env.ssl.bundle=test-bundle"); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigurationTests.java index 1b481cb5062..0c251b578ff 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jdbc/JdbcRepositoriesAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -33,6 +33,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerA import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration; import org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.domain.ManagedTypes; @@ -61,6 +62,17 @@ import static org.mockito.Mockito.mock; * @author Mark Paluch * @author Jens Schauder */ +@WithResource(name = "schema.sql", content = """ + CREATE TABLE CITY ( + id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + name VARCHAR(30), + state VARCHAR(30), + country VARCHAR(30), + map VARCHAR(30) + ); + """) +@WithResource(name = "data.sql", + content = "INSERT INTO CITY (ID, NAME, STATE, COUNTRY, MAP) values (2000, 'Washington', 'DC', 'US', 'Google');") class JdbcRepositoriesAutoConfigurationTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() @@ -208,8 +220,8 @@ class JdbcRepositoriesAutoConfigurationTests { return (runner) -> runner .withConfiguration( AutoConfigurations.of(DataSourceAutoConfiguration.class, SqlInitializationAutoConfiguration.class)) - .withPropertyValues("spring.sql.init.schema-locations=classpath:data-city-schema.sql", - "spring.sql.init.data-locations=classpath:city.sql", "spring.datasource.generate-unique-name:true"); + .withPropertyValues("spring.sql.init.schema-locations=classpath:schema.sql", + "spring.sql.init.data-locations=classpath:data.sql", "spring.datasource.generate-unique-name:true"); } @TestAutoConfigurationPackage(City.class) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcRepositoriesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcRepositoriesAutoConfigurationTests.java index b9bea3baf0c..e9c9dd9bf6c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcRepositoriesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/r2dbc/R2dbcRepositoriesAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -31,6 +31,7 @@ import org.springframework.boot.autoconfigure.data.r2dbc.city.CityRepository; import org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; @@ -48,6 +49,17 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Mark Paluch */ +@WithResource(name = "schema.sql", content = """ + CREATE TABLE CITY ( + id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + name VARCHAR(30), + state VARCHAR(30), + country VARCHAR(30), + map VARCHAR(30) + ); + """) +@WithResource(name = "data.sql", + content = "INSERT INTO CITY (ID, NAME, STATE, COUNTRY, MAP) values (2000, 'Washington', 'DC', 'US', 'Google');") class R2dbcRepositoriesAutoConfigurationTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() @@ -117,8 +129,8 @@ class R2dbcRepositoriesAutoConfigurationTests { @Autowired void initializeDatabase(ConnectionFactory connectionFactory) { ResourceLoader resourceLoader = new DefaultResourceLoader(); - Resource[] scripts = new Resource[] { resourceLoader.getResource("classpath:data-city-schema.sql"), - resourceLoader.getResource("classpath:city.sql") }; + Resource[] scripts = new Resource[] { resourceLoader.getResource("classpath:schema.sql"), + resourceLoader.getResource("classpath:data.sql") }; new ResourceDatabasePopulator(scripts).populate(connectionFactory).block(); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java index f66f5fe5af1..bee589fa0ce 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationJedisTests.java @@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.testsupport.assertj.SimpleAsyncTaskExecutorAssert; import org.springframework.boot.testsupport.classpath.ClassPathExclusions; +import org.springframework.boot.testsupport.classpath.resources.WithPackageResources; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.task.SimpleAsyncTaskExecutor; @@ -255,6 +256,7 @@ class RedisAutoConfigurationJedisTests { } @Test + @WithPackageResources("test.jks") void testRedisConfigurationWithSslBundle() { this.contextRunner .withPropertyValues("spring.data.redis.ssl.bundle:test-bundle", diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java index 8e6dc52f51f..98ad5b21f57 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -41,6 +41,7 @@ import org.springframework.boot.test.context.assertj.AssertableApplicationContex import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.testsupport.assertj.SimpleAsyncTaskExecutorAssert; +import org.springframework.boot.testsupport.classpath.resources.WithPackageResources; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.task.SimpleAsyncTaskExecutor; @@ -569,6 +570,7 @@ class RedisAutoConfigurationTests { } @Test + @WithPackageResources("test.jks") void testRedisConfigurationWithSslBundle() { this.contextRunner .withPropertyValues("spring.data.redis.ssl.bundle:test-bundle", diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientAutoConfigurationTests.java index 25b0da05aeb..ffd4acd6cbd 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -41,6 +41,7 @@ import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestCli import org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithPackageResources; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.util.ReflectionTestUtils; @@ -288,6 +289,7 @@ class ElasticsearchRestClientAutoConfigurationTests { } @Test + @WithPackageResources("test.jks") @SuppressWarnings("unchecked") void configureWithSslBundle() { List properties = new ArrayList<>(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java index ba1d009cd3a..13145d406df 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/FlywayAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -16,6 +16,11 @@ package org.springframework.boot.autoconfigure.flyway; +import java.io.Serializable; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.sql.Connection; import java.sql.SQLException; import java.util.Arrays; @@ -25,6 +30,10 @@ import java.util.UUID; import javax.sql.DataSource; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; import org.flywaydb.core.Flyway; import org.flywaydb.core.api.Location; import org.flywaydb.core.api.MigrationVersion; @@ -68,6 +77,8 @@ import org.springframework.boot.test.context.assertj.AssertableApplicationContex import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.boot.testsupport.classpath.resources.ResourcePath; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; @@ -410,7 +421,9 @@ class FlywayAutoConfigurationTests { } @Test - void failOnMissingLocationsAllExist() { + @WithResource(name = "db/changelog/V1.1__refine.sql") + @WithResource(name = "db/migration/V1__init.sql", content = "DROP TABLE IF EXISTS TEST") + void failOnMissingLocationsDoesNotFailWhenAllExist() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.flyway.fail-on-missing-locations=true") .withPropertyValues("spring.flyway.locations:classpath:db/changelog,classpath:db/migration") @@ -418,6 +431,8 @@ class FlywayAutoConfigurationTests { } @Test + @WithResource(name = "db/changelog/V1.1__refine.sql") + @WithResource(name = "db/migration/V1__init.sql", content = "DROP TABLE IF EXISTS TEST") void failOnMissingLocationsAllExistWithImplicitClasspathPrefix() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.flyway.fail-on-missing-locations=true") @@ -426,10 +441,11 @@ class FlywayAutoConfigurationTests { } @Test - void failOnMissingLocationsAllExistWithFilesystemPrefix() { + @WithResource(name = "db/migration/V1__init.sql", content = "DROP TABLE IF EXISTS TEST") + void failOnMissingLocationsFilesystemPrefixDoesNotFailWhenAllExist(@ResourcePath("db/migration") String migration) { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.flyway.fail-on-missing-locations=true") - .withPropertyValues("spring.flyway.locations:filesystem:src/test/resources/db/migration") + .withPropertyValues("spring.flyway.locations:filesystem:" + migration) .run((context) -> assertThat(context).hasNotFailed()); } @@ -465,6 +481,7 @@ class FlywayAutoConfigurationTests { } @Test + @WithMetaInfPersistenceXmlResource void customFlywayWithJpa() { this.contextRunner .withUserConfiguration(EmbeddedDataSourceConfiguration.class, CustomFlywayWithJpaConfiguration.class) @@ -479,6 +496,7 @@ class FlywayAutoConfigurationTests { } @Test + @WithMetaInfPersistenceXmlResource void customFlywayMigrationInitializerWithJpa() { this.contextRunner .withUserConfiguration(EmbeddedDataSourceConfiguration.class, @@ -517,6 +535,7 @@ class FlywayAutoConfigurationTests { } @Test + @WithResource(name = "db/vendors/h2/V1__init.sql", content = "DROP TABLE IF EXISTS TEST;") void useVendorDirectory() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.flyway.locations=classpath:db/vendors/{vendor},classpath:db/changelog") @@ -529,6 +548,7 @@ class FlywayAutoConfigurationTests { } @Test + @WithResource(name = "db/vendors/h2/V1__init.sql", content = "DROP TABLE IF EXISTS TEST;") void useOneLocationWithVendorDirectory() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.flyway.locations=classpath:db/vendors/{vendor}") @@ -1336,4 +1356,74 @@ class FlywayAutoConfigurationTests { } + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @WithResource(name = "META-INF/persistence.xml", + content = """ + + + + org.springframework.boot.autoconfigure.flyway.FlywayAutoConfigurationTests$City + true + + + """) + @interface WithMetaInfPersistenceXmlResource { + + } + + @Entity + public static class City implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue + private Long id; + + @Column(nullable = false) + private String name; + + @Column(nullable = false) + private String state; + + @Column(nullable = false) + private String country; + + @Column(nullable = false) + private String map; + + protected City() { + } + + City(String name, String state, String country, String map) { + this.name = name; + this.state = state; + this.country = country; + this.map = map; + } + + public String getName() { + return this.name; + } + + public String getState() { + return this.state; + } + + public String getCountry() { + return this.country; + } + + public String getMap() { + return this.map; + } + + @Override + public String toString() { + return getName() + "," + getState() + "," + getCountry(); + } + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/NativeImageResourceProviderCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/NativeImageResourceProviderCustomizerTests.java index 6928a3f8945..33b474d8414 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/NativeImageResourceProviderCustomizerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/flyway/NativeImageResourceProviderCustomizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-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. @@ -24,6 +24,8 @@ import org.flywaydb.core.api.resource.LoadableResource; import org.flywaydb.core.internal.resource.NoopResourceProvider; import org.junit.jupiter.api.Test; +import org.springframework.boot.testsupport.classpath.resources.WithResource; + import static org.assertj.core.api.Assertions.assertThat; /** @@ -44,6 +46,7 @@ class NativeImageResourceProviderCustomizerTests { } @Test + @WithResource(name = "db/migration/V1__init.sql") void nativeImageResourceProviderShouldFindMigrations() { FluentConfiguration configuration = new FluentConfiguration(); this.customizer.customize(configuration); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationReactiveIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationReactiveIntegrationTests.java index 3a477755418..14644c63c8b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationReactiveIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationReactiveIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -20,11 +20,15 @@ import java.io.StringWriter; import java.time.Duration; import java.util.Locale; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; +import reactor.core.scheduler.Schedulers; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.ApplicationContext; import org.springframework.http.MediaType; import org.springframework.mock.http.server.reactive.MockServerHttpRequest; @@ -46,6 +50,12 @@ class FreeMarkerAutoConfigurationReactiveIntegrationTests { private final ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner() .withConfiguration(AutoConfigurations.of(FreeMarkerAutoConfiguration.class)); + @BeforeEach + @AfterEach + void clearReactorSchedulers() { + Schedulers.shutdownNow(); + } + @Test void defaultConfiguration() { this.contextRunner.run((context) -> { @@ -57,6 +67,7 @@ class FreeMarkerAutoConfigurationReactiveIntegrationTests { } @Test + @WithResource(name = "templates/home.ftlh", content = "home") void defaultViewResolution() { this.contextRunner.run((context) -> { MockServerWebExchange exchange = render(context, "home"); @@ -67,6 +78,7 @@ class FreeMarkerAutoConfigurationReactiveIntegrationTests { } @Test + @WithResource(name = "templates/prefix/prefixed.ftlh", content = "prefixed") void customPrefix() { this.contextRunner.withPropertyValues("spring.freemarker.prefix:prefix/").run((context) -> { MockServerWebExchange exchange = render(context, "prefixed"); @@ -76,6 +88,7 @@ class FreeMarkerAutoConfigurationReactiveIntegrationTests { } @Test + @WithResource(name = "templates/suffixed.freemarker", content = "suffixed") void customSuffix() { this.contextRunner.withPropertyValues("spring.freemarker.suffix:.freemarker").run((context) -> { MockServerWebExchange exchange = render(context, "suffixed"); @@ -85,6 +98,7 @@ class FreeMarkerAutoConfigurationReactiveIntegrationTests { } @Test + @WithResource(name = "custom-templates/custom.ftlh", content = "custom") void customTemplateLoaderPath() { this.contextRunner.withPropertyValues("spring.freemarker.templateLoaderPath:classpath:/custom-templates/") .run((context) -> { @@ -104,6 +118,7 @@ class FreeMarkerAutoConfigurationReactiveIntegrationTests { } @Test + @WithResource(name = "templates/message.ftlh", content = "Message: ${greeting}") void renderTemplate() { this.contextRunner.withPropertyValues().run((context) -> { FreeMarkerConfigurer freemarker = context.getBean(FreeMarkerConfigurer.class); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationServletIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationServletIntegrationTests.java index 975478d8aea..08068266492 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationServletIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationServletIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -29,6 +29,7 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext; import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter; @@ -75,6 +76,7 @@ class FreeMarkerAutoConfigurationServletIntegrationTests { } @Test + @WithResource(name = "templates/home.ftlh", content = "home") void defaultViewResolution() throws Exception { load(); MockHttpServletResponse response = render("home"); @@ -84,6 +86,7 @@ class FreeMarkerAutoConfigurationServletIntegrationTests { } @Test + @WithResource(name = "templates/home.ftlh", content = "home") void customContentType() throws Exception { load("spring.freemarker.contentType:application/json"); MockHttpServletResponse response = render("home"); @@ -93,6 +96,7 @@ class FreeMarkerAutoConfigurationServletIntegrationTests { } @Test + @WithResource(name = "templates/prefix/prefixed.ftlh", content = "prefixed") void customPrefix() throws Exception { load("spring.freemarker.prefix:prefix/"); MockHttpServletResponse response = render("prefixed"); @@ -101,6 +105,7 @@ class FreeMarkerAutoConfigurationServletIntegrationTests { } @Test + @WithResource(name = "templates/suffixed.freemarker", content = "suffixed") void customSuffix() throws Exception { load("spring.freemarker.suffix:.freemarker"); MockHttpServletResponse response = render("suffixed"); @@ -109,6 +114,7 @@ class FreeMarkerAutoConfigurationServletIntegrationTests { } @Test + @WithResource(name = "custom-templates/custom.ftlh", content = "custom") void customTemplateLoaderPath() throws Exception { load("spring.freemarker.templateLoaderPath:classpath:/custom-templates/"); MockHttpServletResponse response = render("custom"); @@ -138,6 +144,7 @@ class FreeMarkerAutoConfigurationServletIntegrationTests { } @Test + @WithResource(name = "templates/message.ftlh", content = "Message: ${greeting}") void renderTemplate() throws Exception { load(); FreeMarkerConfigurer freemarker = this.context.getBean(FreeMarkerConfigurer.class); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationTests.java index 77658ef5fb0..cafe528c4dd 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -27,6 +27,7 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.system.CapturedOutput; import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.boot.testsupport.BuildOutput; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import static org.assertj.core.api.Assertions.assertThat; @@ -45,6 +46,7 @@ class FreeMarkerAutoConfigurationTests { .withConfiguration(AutoConfigurations.of(FreeMarkerAutoConfiguration.class)); @Test + @WithResource(name = "templates/message.ftlh", content = "Message: ${greeting}") void renderNonWebAppTemplate() { this.contextRunner.run((context) -> { freemarker.template.Configuration freemarker = context.getBean(freemarker.template.Configuration.class); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerTemplateAvailabilityProviderTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerTemplateAvailabilityProviderTests.java index d39f11fb8bb..1c510f5c5be 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerTemplateAvailabilityProviderTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerTemplateAvailabilityProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -25,6 +25,7 @@ import org.springframework.beans.factory.aot.AotServices; import org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider.FreeMarkerTemplateAvailabilityProperties; import org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider.FreeMarkerTemplateAvailabilityRuntimeHints; import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.ResourceLoader; import org.springframework.mock.env.MockEnvironment; @@ -45,6 +46,7 @@ class FreeMarkerTemplateAvailabilityProviderTests { private final MockEnvironment environment = new MockEnvironment(); @Test + @WithResource(name = "templates/home.ftlh") void availabilityOfTemplateInDefaultLocation() { assertThat(this.provider.isTemplateAvailable("home", this.environment, getClass().getClassLoader(), this.resourceLoader)) @@ -59,6 +61,7 @@ class FreeMarkerTemplateAvailabilityProviderTests { } @Test + @WithResource(name = "custom-templates/custom.ftlh") void availabilityOfTemplateWithCustomLoaderPath() { this.environment.setProperty("spring.freemarker.template-loader-path", "classpath:/custom-templates/"); assertThat(this.provider.isTemplateAvailable("custom", this.environment, getClass().getClassLoader(), @@ -67,6 +70,7 @@ class FreeMarkerTemplateAvailabilityProviderTests { } @Test + @WithResource(name = "custom-templates/custom.ftlh") void availabilityOfTemplateWithCustomLoaderPathConfiguredAsAList() { this.environment.setProperty("spring.freemarker.template-loader-path[0]", "classpath:/custom-templates/"); assertThat(this.provider.isTemplateAvailable("custom", this.environment, getClass().getClassLoader(), @@ -75,6 +79,7 @@ class FreeMarkerTemplateAvailabilityProviderTests { } @Test + @WithResource(name = "templates/prefix/prefixed.ftlh") void availabilityOfTemplateWithCustomPrefix() { this.environment.setProperty("spring.freemarker.prefix", "prefix/"); assertThat(this.provider.isTemplateAvailable("prefixed", this.environment, getClass().getClassLoader(), @@ -83,6 +88,7 @@ class FreeMarkerTemplateAvailabilityProviderTests { } @Test + @WithResource(name = "templates/suffixed.freemarker") void availabilityOfTemplateWithCustomSuffix() { this.environment.setProperty("spring.freemarker.suffix", ".freemarker"); assertThat(this.provider.isTemplateAvailable("suffixed", this.environment, getClass().getClassLoader(), diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/DefaultGraphQlSchemaConditionTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/DefaultGraphQlSchemaConditionTests.java index 197eaab69ec..c486ac898a1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/DefaultGraphQlSchemaConditionTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/DefaultGraphQlSchemaConditionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -38,6 +39,8 @@ class DefaultGraphQlSchemaConditionTests { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner(); @Test + @WithResource(name = "graphql/one.graphqls") + @WithResource(name = "graphql/two.graphqls") void matchesWhenSchemaFilesAreDetected() { this.contextRunner.withUserConfiguration(TestingConfiguration.class).run((context) -> { didMatch(context); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfigurationTests.java index a5c68a41411..2efad9321f8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/GraphQlAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -35,10 +35,13 @@ import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.graphql.GraphQlAutoConfiguration.GraphQlResourcesRuntimeHints; +import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener; import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration; +import org.springframework.boot.logging.LogLevel; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.system.CapturedOutput; import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ByteArrayResource; @@ -58,6 +61,25 @@ import static org.mockito.Mockito.mock; /** * Tests for {@link GraphQlAutoConfiguration}. */ +@WithResource(name = "graphql/types/book.graphqls", content = """ + type Book { + id: ID + name: String + pageCount: Int + author: String + } + """) +@WithResource(name = "graphql/schema.graphqls", content = """ + type Query { + greeting(name: String! = "Spring"): String! + bookById(id: ID): Book + books: BookConnection + } + + type Subscription { + booksOnSale(minPages: Int) : Book! + } + """) @ExtendWith(OutputCaptureExtension.class) class GraphQlAutoConfigurationTests { @@ -66,11 +88,12 @@ class GraphQlAutoConfigurationTests { @Test void shouldContributeDefaultBeans() { - this.contextRunner.run((context) -> assertThat(context).hasSingleBean(GraphQlSource.class) - .hasSingleBean(BatchLoaderRegistry.class) - .hasSingleBean(ExecutionGraphQlService.class) - .hasSingleBean(AnnotatedControllerConfigurer.class) - .hasSingleBean(EncodingCursorStrategy.class)); + this.contextRunner.withInitializer(ConditionEvaluationReportLoggingListener.forLogLevel(LogLevel.INFO)) + .run((context) -> assertThat(context).hasSingleBean(GraphQlSource.class) + .hasSingleBean(BatchLoaderRegistry.class) + .hasSingleBean(ExecutionGraphQlService.class) + .hasSingleBean(AnnotatedControllerConfigurer.class) + .hasSingleBean(EncodingCursorStrategy.class)); } @Test @@ -98,6 +121,12 @@ class GraphQlAutoConfigurationTests { } @Test + @WithResource(name = "graphql/types/person.custom", content = """ + type Person { + id: ID + name: String + } + """) void shouldScanLocationsWithCustomExtension() { this.contextRunner.withPropertyValues("spring.graphql.schema.file-extensions:.graphqls,.custom") .run((context) -> { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlQueryByExampleAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlQueryByExampleAutoConfigurationTests.java index 964bf0ebaff..531c66fbac8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlQueryByExampleAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlQueryByExampleAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -18,12 +18,11 @@ package org.springframework.boot.autoconfigure.graphql.data; import java.util.Optional; -import org.junit.jupiter.api.Test; - import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.graphql.Book; import org.springframework.boot.autoconfigure.graphql.GraphQlAutoConfiguration; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.repository.CrudRepository; @@ -41,6 +40,25 @@ import static org.mockito.Mockito.mock; * * @author Brian Clozel */ +@WithResource(name = "graphql/types/book.graphqls", content = """ + type Book { + id: ID + name: String + pageCount: Int + author: String + } + """) +@WithResource(name = "graphql/schema.graphqls", content = """ + type Query { + greeting(name: String! = "Spring"): String! + bookById(id: ID): Book + books: BookConnection + } + + type Subscription { + booksOnSale(minPages: Int) : Book! + } + """) class GraphQlQueryByExampleAutoConfigurationTests { private static final Book book = new Book("42", "Test title", 42, "Test Author"); @@ -51,7 +69,6 @@ class GraphQlQueryByExampleAutoConfigurationTests { .withUserConfiguration(MockRepositoryConfig.class) .withPropertyValues("spring.main.web-application-type=servlet"); - @Test void shouldRegisterDataFetcherForQueryByExampleRepositories() { this.contextRunner.run((context) -> { ExecutionGraphQlService graphQlService = context.getBean(ExecutionGraphQlService.class); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlQuerydslAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlQuerydslAutoConfigurationTests.java index ff2624099b2..4b0c324847f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlQuerydslAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlQuerydslAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -25,6 +25,7 @@ import org.springframework.boot.autoconfigure.graphql.Book; import org.springframework.boot.autoconfigure.graphql.GraphQlAutoConfiguration; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.querydsl.QuerydslPredicateExecutor; @@ -44,6 +45,25 @@ import static org.mockito.Mockito.mock; * * @author Brian Clozel */ +@WithResource(name = "graphql/types/book.graphqls", content = """ + type Book { + id: ID + name: String + pageCount: Int + author: String + } + """) +@WithResource(name = "graphql/schema.graphqls", content = """ + type Query { + greeting(name: String! = "Spring"): String! + bookById(id: ID): Book + books: BookConnection + } + + type Subscription { + booksOnSale(minPages: Int) : Book! + } + """) class GraphQlQuerydslAutoConfigurationTests { private static final Book book = new Book("42", "Test title", 42, "Test Author"); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlReactiveQueryByExampleAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlReactiveQueryByExampleAutoConfigurationTests.java index 8f4a94a4101..834c630f903 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlReactiveQueryByExampleAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlReactiveQueryByExampleAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.graphql.Book; import org.springframework.boot.autoconfigure.graphql.GraphQlAutoConfiguration; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.repository.query.ReactiveQueryByExampleExecutor; @@ -41,6 +42,25 @@ import static org.mockito.Mockito.mock; * * @author Brian Clozel */ +@WithResource(name = "graphql/types/book.graphqls", content = """ + type Book { + id: ID + name: String + pageCount: Int + author: String + } + """) +@WithResource(name = "graphql/schema.graphqls", content = """ + type Query { + greeting(name: String! = "Spring"): String! + bookById(id: ID): Book + books: BookConnection + } + + type Subscription { + booksOnSale(minPages: Int) : Book! + } + """) class GraphQlReactiveQueryByExampleAutoConfigurationTests { private static final Mono bookPublisher = Mono.just(new Book("42", "Test title", 42, "Test Author")); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlReactiveQuerydslAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlReactiveQuerydslAutoConfigurationTests.java index 8c807fe9898..9401bed26e3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlReactiveQuerydslAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/data/GraphQlReactiveQuerydslAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -24,6 +24,7 @@ import org.springframework.boot.autoconfigure.graphql.Book; import org.springframework.boot.autoconfigure.graphql.GraphQlAutoConfiguration; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.querydsl.ReactiveQuerydslPredicateExecutor; @@ -43,6 +44,25 @@ import static org.mockito.Mockito.mock; * * @author Brian Clozel */ +@WithResource(name = "graphql/types/book.graphqls", content = """ + type Book { + id: ID + name: String + pageCount: Int + author: String + } + """) +@WithResource(name = "graphql/schema.graphqls", content = """ + type Query { + greeting(name: String! = "Spring"): String! + bookById(id: ID): Book + books: BookConnection + } + + type Subscription { + booksOnSale(minPages: Int) : Book! + } + """) class GraphQlReactiveQuerydslAutoConfigurationTests { private static final Mono bookPublisher = Mono.just(new Book("42", "Test title", 42, "Test Author")); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/reactive/GraphQlWebFluxAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/reactive/GraphQlWebFluxAutoConfigurationTests.java index bf4dc6695da..a0273406ef0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/reactive/GraphQlWebFluxAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/reactive/GraphQlWebFluxAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -34,6 +34,7 @@ import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration; import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; @@ -57,6 +58,25 @@ import static org.hamcrest.Matchers.containsString; * * @author Brian Clozel */ +@WithResource(name = "graphql/types/book.graphqls", content = """ + type Book { + id: ID + name: String + pageCount: Int + author: String + } + """) +@WithResource(name = "graphql/schema.graphqls", content = """ + type Query { + greeting(name: String! = "Spring"): String! + bookById(id: ID): Book + books: BookConnection + } + + type Subscription { + booksOnSale(minPages: Int) : Book! + } + """) class GraphQlWebFluxAutoConfigurationTests { private static final String BASE_URL = "https://spring.example.org/"; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/rsocket/GraphQlRSocketAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/rsocket/GraphQlRSocketAutoConfigurationTests.java index 69f664ef0e8..bdf39ff98b7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/rsocket/GraphQlRSocketAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/rsocket/GraphQlRSocketAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -36,6 +36,7 @@ import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfigurat import org.springframework.boot.autoconfigure.web.reactive.error.ErrorWebFluxAutoConfiguration; import org.springframework.boot.rsocket.context.RSocketPortInfoApplicationContextInitializer; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer; import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; import org.springframework.boot.web.embedded.netty.NettyRouteProvider; @@ -53,6 +54,25 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Brian Clozel */ +@WithResource(name = "graphql/types/book.graphqls", content = """ + type Book { + id: ID + name: String + pageCount: Int + author: String + } + """) +@WithResource(name = "graphql/schema.graphqls", content = """ + type Query { + greeting(name: String! = "Spring"): String! + bookById(id: ID): Book + books: BookConnection + } + + type Subscription { + booksOnSale(minPages: Int) : Book! + } + """) class GraphQlRSocketAutoConfigurationTests { private final ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner() diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebFluxSecurityAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebFluxSecurityAutoConfigurationTests.java index 3d8fcc9fa67..fc4e623cf7d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebFluxSecurityAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebFluxSecurityAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2024 the original author or authors. + * Copyright 2020-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. @@ -34,6 +34,7 @@ import org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurity import org.springframework.boot.autoconfigure.web.reactive.HttpHandlerAutoConfiguration; import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfiguration; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.graphql.execution.ErrorType; @@ -60,6 +61,25 @@ import static org.springframework.security.config.Customizer.withDefaults; * * @author Brian Clozel */ +@WithResource(name = "graphql/types/book.graphqls", content = """ + type Book { + id: ID + name: String + pageCount: Int + author: String + } + """) +@WithResource(name = "graphql/schema.graphqls", content = """ + type Query { + greeting(name: String! = "Spring"): String! + bookById(id: ID): Book + books: BookConnection + } + + type Subscription { + booksOnSale(minPages: Int) : Book! + } + """) class GraphQlWebFluxSecurityAutoConfigurationTests { private static final String BASE_URL = "https://spring.example.org/graphql"; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebMvcSecurityAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebMvcSecurityAutoConfigurationTests.java index 6a0abd80b98..3073d9bd9d2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebMvcSecurityAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/security/GraphQlWebMvcSecurityAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2024 the original author or authors. + * Copyright 2020-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. @@ -30,6 +30,7 @@ import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfi import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.graphql.execution.ErrorType; @@ -63,6 +64,25 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * * @author Brian Clozel */ +@WithResource(name = "graphql/types/book.graphqls", content = """ + type Book { + id: ID + name: String + pageCount: Int + author: String + } + """) +@WithResource(name = "graphql/schema.graphqls", content = """ + type Query { + greeting(name: String! = "Spring"): String! + bookById(id: ID): Book + books: BookConnection + } + + type Subscription { + booksOnSale(minPages: Int) : Book! + } + """) class GraphQlWebMvcSecurityAutoConfigurationTests { private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfigurationTests.java index 85418adef91..6128a01c7bb 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/graphql/servlet/GraphQlWebMvcAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -33,6 +33,7 @@ import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration; import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; @@ -65,6 +66,25 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * * @author Brian Clozel */ +@WithResource(name = "graphql/types/book.graphqls", content = """ + type Book { + id: ID + name: String + pageCount: Int + author: String + } + """) +@WithResource(name = "graphql/schema.graphqls", content = """ + type Query { + greeting(name: String! = "Spring"): String! + bookById(id: ID): Book + books: BookConnection + } + + type Subscription { + booksOnSale(minPages: Int) : Book! + } + """) class GraphQlWebMvcAutoConfigurationTests { private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfigurationTests.java index 03a0d821181..d2eba9d5fb0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -31,6 +31,7 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.boot.testsupport.BuildOutput; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.core.io.ClassPathResource; @@ -83,6 +84,7 @@ class GroovyTemplateAutoConfigurationTests { } @Test + @WithResource(name = "templates/home.tpl", content = "yield 'home'") void defaultViewResolution() throws Exception { registerAndRefreshContext(); MockHttpServletResponse response = render("home"); @@ -92,6 +94,11 @@ class GroovyTemplateAutoConfigurationTests { } @Test + @WithResource(name = "templates/includes.tpl", content = """ + yield 'include' + include template: 'included.tpl' + """) + @WithResource(name = "templates/included.tpl", content = "yield 'here'") void includesViewResolution() throws Exception { registerAndRefreshContext(); MockHttpServletResponse response = render("includes"); @@ -108,6 +115,11 @@ class GroovyTemplateAutoConfigurationTests { } @Test + @WithResource(name = "templates/includes.tpl", content = """ + yield 'include' + include template: 'included.tpl' + """) + @WithResource(name = "templates/included_fr.tpl", content = "yield 'voila'") void localeViewResolution() throws Exception { registerAndRefreshContext(); MockHttpServletResponse response = render("includes", Locale.FRENCH); @@ -117,6 +129,7 @@ class GroovyTemplateAutoConfigurationTests { } @Test + @WithResource(name = "templates/home.tpl", content = "yield 'home'") void customContentType() throws Exception { registerAndRefreshContext("spring.groovy.template.contentType:application/json"); MockHttpServletResponse response = render("home"); @@ -126,6 +139,7 @@ class GroovyTemplateAutoConfigurationTests { } @Test + @WithResource(name = "templates/prefix/prefixed.tpl", content = "yield \"prefixed\"") void customPrefix() throws Exception { registerAndRefreshContext("spring.groovy.template.prefix:prefix/"); MockHttpServletResponse response = render("prefixed"); @@ -134,6 +148,7 @@ class GroovyTemplateAutoConfigurationTests { } @Test + @WithResource(name = "templates/suffixed.groovytemplate", content = "yield \"suffixed\"") void customSuffix() throws Exception { registerAndRefreshContext("spring.groovy.template.suffix:.groovytemplate"); MockHttpServletResponse response = render("suffixed"); @@ -142,6 +157,7 @@ class GroovyTemplateAutoConfigurationTests { } @Test + @WithResource(name = "custom-templates/custom.tpl", content = "yield \"custom\"") void customTemplateLoaderPath() throws Exception { registerAndRefreshContext("spring.groovy.template.resource-loader-path:classpath:/custom-templates/"); MockHttpServletResponse response = render("custom"); @@ -156,6 +172,7 @@ class GroovyTemplateAutoConfigurationTests { } @Test + @WithResource(name = "templates/message.tpl", content = "yield \"Message: ${greeting}\"") void renderTemplate() throws Exception { registerAndRefreshContext(); GroovyMarkupConfig config = this.context.getBean(GroovyMarkupConfig.class); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAvailabilityProviderTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAvailabilityProviderTests.java index 86c0158471e..e3a3d1f8047 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAvailabilityProviderTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAvailabilityProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -25,6 +25,7 @@ import org.springframework.beans.factory.aot.AotServices; import org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider.GroovyTemplateAvailabilityProperties; import org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider.GroovyTemplateAvailabilityRuntimeHints; import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.ResourceLoader; import org.springframework.mock.env.MockEnvironment; @@ -45,6 +46,7 @@ class GroovyTemplateAvailabilityProviderTests { private final MockEnvironment environment = new MockEnvironment(); @Test + @WithResource(name = "templates/home.tpl") void availabilityOfTemplateInDefaultLocation() { assertThat(this.provider.isTemplateAvailable("home", this.environment, getClass().getClassLoader(), this.resourceLoader)) @@ -59,6 +61,7 @@ class GroovyTemplateAvailabilityProviderTests { } @Test + @WithResource(name = "custom-templates/custom.tpl") void availabilityOfTemplateWithCustomLoaderPath() { this.environment.setProperty("spring.groovy.template.resource-loader-path", "classpath:/custom-templates/"); assertThat(this.provider.isTemplateAvailable("custom", this.environment, getClass().getClassLoader(), @@ -67,6 +70,7 @@ class GroovyTemplateAvailabilityProviderTests { } @Test + @WithResource(name = "custom-templates/custom.tpl") void availabilityOfTemplateWithCustomLoaderPathConfiguredAsAList() { this.environment.setProperty("spring.groovy.template.resource-loader-path[0]", "classpath:/custom-templates/"); assertThat(this.provider.isTemplateAvailable("custom", this.environment, getClass().getClassLoader(), @@ -75,6 +79,7 @@ class GroovyTemplateAvailabilityProviderTests { } @Test + @WithResource(name = "templates/prefix/prefixed.tpl") void availabilityOfTemplateWithCustomPrefix() { this.environment.setProperty("spring.groovy.template.prefix", "prefix/"); assertThat(this.provider.isTemplateAvailable("prefixed", this.environment, getClass().getClassLoader(), @@ -83,6 +88,7 @@ class GroovyTemplateAvailabilityProviderTests { } @Test + @WithResource(name = "templates/suffixed.groovytemplate") void availabilityOfTemplateWithCustomSuffix() { this.environment.setProperty("spring.groovy.template.suffix", ".groovytemplate"); assertThat(this.provider.isTemplateAvailable("suffixed", this.environment, getClass().getClassLoader(), diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationServerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationServerTests.java index 1a578b657b1..4d5e6c478c8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationServerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationServerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -16,6 +16,10 @@ package org.springframework.boot.autoconfigure.hazelcast; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.Map; import com.hazelcast.config.Config; @@ -38,6 +42,7 @@ import org.springframework.boot.test.context.assertj.AssertableApplicationContex import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.testsupport.classpath.ClassPathExclusions; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; @@ -57,6 +62,7 @@ class HazelcastAutoConfigurationServerTests { .withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class)); @Test + @WithHazelcastXmlResource void defaultConfigFile() { // hazelcast.xml present in root classpath this.contextRunner.run((context) -> { @@ -201,6 +207,7 @@ class HazelcastAutoConfigurationServerTests { } @Test + @WithHazelcastXmlResource void autoConfiguredConfigUsesApplicationClassLoader() { this.contextRunner.run((context) -> { Config config = context.getBean(HazelcastInstance.class).getConfig(); @@ -209,6 +216,7 @@ class HazelcastAutoConfigurationServerTests { } @Test + @WithHazelcastXmlResource void autoConfiguredConfigUsesSpringManagedContext() { this.contextRunner.run((context) -> { Config config = context.getBean(HazelcastInstance.class).getConfig(); @@ -217,6 +225,7 @@ class HazelcastAutoConfigurationServerTests { } @Test + @WithHazelcastXmlResource void autoConfiguredConfigCanUseSpringAwareComponent() { this.contextRunner.withPropertyValues("test.hazelcast.key=42").run((context) -> { HazelcastInstance hz = context.getBean(HazelcastInstance.class); @@ -226,14 +235,19 @@ class HazelcastAutoConfigurationServerTests { } @Test + @WithHazelcastXmlResource void autoConfiguredConfigWithoutHazelcastSpringDoesNotUseSpringManagedContext() { - this.contextRunner.withClassLoader(new FilteredClassLoader(SpringManagedContext.class)).run((context) -> { - Config config = context.getBean(HazelcastInstance.class).getConfig(); - assertThat(config.getManagedContext()).isNull(); - }); + this.contextRunner + .withClassLoader( + new FilteredClassLoader(Thread.currentThread().getContextClassLoader(), SpringManagedContext.class)) + .run((context) -> { + Config config = context.getBean(HazelcastInstance.class).getConfig(); + assertThat(config.getManagedContext()).isNull(); + }); } @Test + @WithHazelcastXmlResource void autoConfiguredContextCanOverrideManagementContextUsingCustomizer() { this.contextRunner.withBean(TestHazelcastConfigCustomizer.class).run((context) -> { Config config = context.getBean(HazelcastInstance.class).getConfig(); @@ -242,6 +256,7 @@ class HazelcastAutoConfigurationServerTests { } @Test + @WithHazelcastXmlResource void autoConfiguredConfigSetsHazelcastLoggingToSlf4j() { this.contextRunner.run((context) -> { Config config = context.getBean(HazelcastInstance.class).getConfig(); @@ -322,4 +337,24 @@ class HazelcastAutoConfigurationServerTests { } + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @WithResource(name = "hazelcast.xml", content = """ + + default-instance + + + + + + + + + """) + @interface WithHazelcastXmlResource { + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationTests.java index fdff5e4210b..def1dcb1888 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/hazelcast/HazelcastAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -22,6 +22,7 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.core.io.ClassPathResource; import static org.assertj.core.api.Assertions.assertThat; @@ -37,7 +38,39 @@ class HazelcastAutoConfigurationTests { .withConfiguration(AutoConfigurations.of(HazelcastAutoConfiguration.class)); @Test - void defaultConfigFile() { + @WithResource(name = "hazelcast.xml", content = """ + + default-instance + + + + + + + + + """) + @WithResource(name = "hazelcast.yml", content = """ + hazelcast: + network: + join: + auto-detection: + enabled: false + multicast: + enabled: false + """) + @WithResource(name = "hazelcast.yaml", content = """ + hazelcast: + network: + join: + auto-detection: + enabled: false + multicast: + enabled: false + """) + void defaultConfigFileIsHazelcastXml() { // no hazelcast-client.xml and hazelcast.xml is present in root classpath // this also asserts that XML has priority over YAML // as hazelcast.yaml, hazelcast.yml, and hazelcast.xml are available. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfigurationTests.java index 7a65682b930..38f420f6da6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/info/ProjectInfoAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -25,6 +25,7 @@ import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoCon import org.springframework.boot.info.BuildProperties; import org.springframework.boot.info.GitProperties; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -90,6 +91,13 @@ class ProjectInfoAutoConfigurationTests { } @Test + @WithResource(name = "META-INF/build-info.properties", content = """ + build.group=com.example + build.artifact=demo + build.name=Demo Project + build.version=0.0.1-SNAPSHOT + build.time=2016-03-04T14:16:05.000Z + """) void buildPropertiesDefaultLocation() { this.contextRunner.run((context) -> { BuildProperties buildProperties = context.getBean(BuildProperties.class); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java index f4c7bca9e87..2fdfcdf6f9c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -54,6 +54,7 @@ import org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer; import org.springframework.boot.sql.init.DatabaseInitializationMode; import org.springframework.boot.sql.init.DatabaseInitializationSettings; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; @@ -372,6 +373,8 @@ class IntegrationAutoConfigurationTests { } @Test + @WithResource(name = "META-INF/spring.integration.properties", + content = "spring.integration.endpoints.noAutoStartup=testService*") void integrationGlobalPropertiesFromSpringIntegrationPropertiesFile() { this.contextRunner .withPropertyValues("spring.integration.channel.auto-create=false", @@ -539,7 +542,7 @@ class IntegrationAutoConfigurationTests { } @MessagingGateway - interface TestGateway extends RequestReplyExchanger { + public interface TestGateway extends RequestReplyExchanger { } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationPropertiesEnvironmentPostProcessorTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationPropertiesEnvironmentPostProcessorTests.java index 1b4bbab8844..4cacb3e54df 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationPropertiesEnvironmentPostProcessorTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/integration/IntegrationPropertiesEnvironmentPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -37,6 +37,7 @@ import org.springframework.boot.context.properties.bind.Binder; import org.springframework.boot.origin.Origin; import org.springframework.boot.origin.OriginLookup; import org.springframework.boot.origin.TextResourceOrigin; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.PropertySource; @@ -60,6 +61,8 @@ import static org.mockito.Mockito.mock; class IntegrationPropertiesEnvironmentPostProcessorTests { @Test + @WithResource(name = "META-INF/spring.integration.properties", + content = "spring.integration.endpoints.noAutoStartup=testService*") void postProcessEnvironmentAddPropertySource() { ConfigurableEnvironment environment = new StandardEnvironment(); new IntegrationPropertiesEnvironmentPostProcessor().postProcessEnvironment(environment, @@ -69,6 +72,8 @@ class IntegrationPropertiesEnvironmentPostProcessorTests { } @Test + @WithResource(name = "META-INF/spring.integration.properties", + content = "spring.integration.endpoints.noAutoStartup=testService*") void postProcessEnvironmentAddPropertySourceLast() { ConfigurableEnvironment environment = new StandardEnvironment(); environment.getPropertySources() diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/HikariDriverConfigurationFailureAnalyzerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/HikariDriverConfigurationFailureAnalyzerTests.java index 9dafdc04b7a..c9030edae20 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/HikariDriverConfigurationFailureAnalyzerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/HikariDriverConfigurationFailureAnalyzerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -24,6 +24,7 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration; import org.springframework.boot.diagnostics.FailureAnalysis; import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Configuration; @@ -37,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat; class HikariDriverConfigurationFailureAnalyzerTests { @Test + @WithResource(name = "schema.sql", content = "") void failureAnalysisIsPerformed() { FailureAnalysis failureAnalysis = performAnalysis(TestConfiguration.class); assertThat(failureAnalysis).isNotNull(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcClientAutoConfigurationTests.java index 6c4035dc79e..209f9df0e35 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcClientAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcClientAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -22,6 +22,7 @@ import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.simple.JdbcClient; @@ -68,6 +69,16 @@ class JdbcClientAutoConfigurationTests { } @Test + @WithResource(name = "db/city/V1__init.sql", content = """ + CREATE SEQUENCE city_seq INCREMENT BY 50; + CREATE TABLE CITY ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY, + name VARCHAR(30), + state VARCHAR(30), + country VARCHAR(30), + map VARCHAR(30) + ); + """) void jdbcClientIsOrderedAfterFlywayMigration() { this.contextRunner.withUserConfiguration(JdbcClientDataSourceMigrationValidator.class) .withPropertyValues("spring.flyway.locations:classpath:db/city") @@ -79,6 +90,31 @@ class JdbcClientAutoConfigurationTests { } @Test + @WithResource(name = "db/changelog/db.changelog-city.yaml", content = """ + databaseChangeLog: + - changeSet: + id: 1 + author: dsyer + changes: + - createSequence: + sequenceName: city_seq + incrementBy: 50 + - createTable: + tableName: city + columns: + - column: + name: id + type: bigint + autoIncrement: true + constraints: + primaryKey: true + nullable: false + - column: + name: name + type: varchar(50) + constraints: + nullable: false + """) void jdbcClientIsOrderedAfterLiquibaseMigration() { this.contextRunner.withUserConfiguration(JdbcClientDataSourceMigrationValidator.class) .withPropertyValues("spring.liquibase.change-log:classpath:db/changelog/db.changelog-city.yaml") diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfigurationTests.java index 7154f618dd4..9326b731310 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/JdbcTemplateAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -16,6 +16,10 @@ package org.springframework.boot.autoconfigure.jdbc; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.Collections; import javax.sql.DataSource; @@ -27,6 +31,7 @@ import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration; import org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration; import org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; @@ -149,6 +154,13 @@ class JdbcTemplateAutoConfigurationTests { } @Test + @WithResource(name = "schema.sql", content = """ + CREATE TABLE BAR ( + id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + name VARCHAR(30) + ); + """) + @WithResource(name = "data.sql", content = "INSERT INTO BAR VALUES (1, 'Andy');") void testDependencyToScriptBasedDataSourceInitialization() { this.contextRunner.withConfiguration(AutoConfigurations.of(SqlInitializationAutoConfiguration.class)) .withUserConfiguration(DataSourceInitializationValidator.class) @@ -159,6 +171,16 @@ class JdbcTemplateAutoConfigurationTests { } @Test + @WithResource(name = "db/city/V1__init.sql", content = """ + CREATE SEQUENCE city_seq INCREMENT BY 50; + CREATE TABLE CITY ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY, + name VARCHAR(30), + state VARCHAR(30), + country VARCHAR(30), + map VARCHAR(30) + ); + """) void testDependencyToFlyway() { this.contextRunner.withUserConfiguration(DataSourceMigrationValidator.class) .withPropertyValues("spring.flyway.locations:classpath:db/city") @@ -170,6 +192,16 @@ class JdbcTemplateAutoConfigurationTests { } @Test + @WithResource(name = "db/city/V1__init.sql", content = """ + CREATE SEQUENCE city_seq INCREMENT BY 50; + CREATE TABLE CITY ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY, + name VARCHAR(30), + state VARCHAR(30), + country VARCHAR(30), + map VARCHAR(30) + ); + """) void testDependencyToFlywayWithJdbcTemplateMixed() { this.contextRunner.withUserConfiguration(NamedParameterDataSourceMigrationValidator.class) .withPropertyValues("spring.flyway.locations:classpath:db/city") @@ -182,6 +214,7 @@ class JdbcTemplateAutoConfigurationTests { } @Test + @WithDbChangelogCityYamlResource void testDependencyToLiquibase() { this.contextRunner.withUserConfiguration(DataSourceMigrationValidator.class) .withPropertyValues("spring.liquibase.change-log:classpath:db/changelog/db.changelog-city.yaml") @@ -193,6 +226,7 @@ class JdbcTemplateAutoConfigurationTests { } @Test + @WithDbChangelogCityYamlResource void testDependencyToLiquibaseWithJdbcTemplateMixed() { this.contextRunner.withUserConfiguration(NamedParameterDataSourceMigrationValidator.class) .withPropertyValues("spring.liquibase.change-log:classpath:db/changelog/db.changelog-city.yaml") @@ -291,4 +325,35 @@ class JdbcTemplateAutoConfigurationTests { } + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @WithResource(name = "db/changelog/db.changelog-city.yaml", content = """ + databaseChangeLog: + - changeSet: + id: 1 + author: dsyer + changes: + - createSequence: + sequenceName: city_seq + incrementBy: 50 + - createTable: + tableName: city + columns: + - column: + name: id + type: bigint + autoIncrement: true + constraints: + primaryKey: true + nullable: false + - column: + name: name + type: varchar(50) + constraints: + nullable: false + """) + @interface WithDbChangelogCityYamlResource { + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java index 521297b534b..fdd1cedad32 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java @@ -54,6 +54,7 @@ import org.springframework.boot.test.context.assertj.AssertableApplicationContex import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.testsupport.assertj.SimpleAsyncTaskExecutorAssert; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.task.AsyncTaskExecutor; @@ -119,6 +120,8 @@ class KafkaAutoConfigurationTests { .withConfiguration(AutoConfigurations.of(KafkaAutoConfiguration.class, SslAutoConfiguration.class)); @Test + @WithResource(name = "ksLoc") + @WithResource(name = "tsLoc") void consumerProperties() { this.contextRunner.withPropertyValues("spring.kafka.bootstrap-servers=foo:1234", "spring.kafka.properties.foo=bar", "spring.kafka.properties.baz=qux", @@ -200,6 +203,8 @@ class KafkaAutoConfigurationTests { } @Test + @WithResource(name = "ksLocP") + @WithResource(name = "tsLocP") void producerProperties() { this.contextRunner.withPropertyValues("spring.kafka.clientId=cid", "spring.kafka.properties.foo.bar.baz=qux.fiz.buz", "spring.kafka.producer.acks=all", @@ -270,6 +275,8 @@ class KafkaAutoConfigurationTests { } @Test + @WithResource(name = "ksLocP") + @WithResource(name = "tsLocP") void adminProperties() { this.contextRunner .withPropertyValues("spring.kafka.clientId=cid", "spring.kafka.properties.foo.bar.baz=qux.fiz.buz", @@ -330,8 +337,10 @@ class KafkaAutoConfigurationTests { }); } - @SuppressWarnings("unchecked") @Test + @SuppressWarnings("unchecked") + @WithResource(name = "ksLocP") + @WithResource(name = "tsLocP") void streamsProperties() { this.contextRunner.withUserConfiguration(EnableKafkaStreamsConfiguration.class) .withPropertyValues("spring.kafka.client-id=cid", diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfigurationTests.java index 8833ccd11ba..74249e5d354 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -16,6 +16,11 @@ package org.springframework.boot.autoconfigure.ldap.embedded; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + import com.unboundid.ldap.listener.InMemoryDirectoryServer; import com.unboundid.ldap.sdk.BindResult; import com.unboundid.ldap.sdk.DN; @@ -30,6 +35,7 @@ import org.springframework.boot.autoconfigure.ldap.LdapAutoConfiguration; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -100,6 +106,7 @@ class EmbeddedLdapAutoConfigurationTests { } @Test + @WithSchemaLdifResource void testSetLdifFile() { this.contextRunner.withPropertyValues("spring.ldap.embedded.base-dn:dc=spring,dc=org").run((context) -> { InMemoryDirectoryServer server = context.getBean(InMemoryDirectoryServer.class); @@ -108,6 +115,7 @@ class EmbeddedLdapAutoConfigurationTests { } @Test + @WithSchemaLdifResource void testQueryEmbeddedLdap() { this.contextRunner.withPropertyValues("spring.ldap.embedded.base-dn:dc=spring,dc=org") .withConfiguration(AutoConfigurations.of(LdapAutoConfiguration.class)) @@ -130,6 +138,34 @@ class EmbeddedLdapAutoConfigurationTests { } @Test + @WithResource(name = "custom-schema.ldif", content = """ + dn: cn=schema + attributeTypes: ( 1.3.6.1.4.1.32473.1.1.1 + NAME 'exampleAttributeName' + DESC 'An example attribute type definition' + EQUALITY caseIgnoreMatch + ORDERING caseIgnoreOrderingMatch + SUBSTR caseIgnoreSubstringsMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 + SINGLE-VALUE + X-ORIGIN 'Managing Schema Document' ) + objectClasses: ( 1.3.6.1.4.1.32473.1.2.2 + NAME 'exampleAuxiliaryClass' + DESC 'An example auxiliary object class definition' + SUP top + AUXILIARY + MAY exampleAttributeName + X-ORIGIN 'Managing Schema Document' ) + """) + @WithResource(name = "custom-schema-sample.ldif", content = """ + dn: dc=spring,dc=org + objectclass: top + objectclass: domain + objectclass: extensibleObject + objectClass: exampleAuxiliaryClass + dc: spring + exampleAttributeName: exampleAttributeName + """) void testCustomSchemaValidation() { this.contextRunner .withPropertyValues("spring.ldap.embedded.validation.schema:classpath:custom-schema.ldif", @@ -144,6 +180,122 @@ class EmbeddedLdapAutoConfigurationTests { } @Test + @WithResource(name = "schema-multi-basedn.ldif", content = """ + dn: dc=spring,dc=org + objectclass: top + objectclass: domain + objectclass: extensibleObject + dc: spring + + dn: ou=groups,dc=spring,dc=org + objectclass: top + objectclass: organizationalUnit + ou: groups + + dn: cn=ROLE_USER,ou=groups,dc=spring,dc=org + objectclass: top + objectclass: groupOfUniqueNames + cn: ROLE_USER + uniqueMember: cn=Some Person,ou=company1,c=Sweden,dc=spring,dc=org + uniqueMember: cn=Some Person2,ou=company1,c=Sweden,dc=spring,dc=org + uniqueMember: cn=Some Person,ou=company1,c=Sweden,dc=spring,dc=org + uniqueMember: cn=Some Person3,ou=company1,c=Sweden,dc=spring,dc=org + + dn: cn=ROLE_ADMIN,ou=groups,dc=spring,dc=org + objectclass: top + objectclass: groupOfUniqueNames + cn: ROLE_ADMIN + uniqueMember: cn=Some Person2,ou=company1,c=Sweden,dc=spring,dc=org + + dn: c=Sweden,dc=spring,dc=org + objectclass: top + objectclass: country + c: Sweden + description: The country of Sweden + + dn: ou=company1,c=Sweden,dc=spring,dc=org + objectclass: top + objectclass: organizationalUnit + ou: company1 + description: First company in Sweden + + dn: cn=Some Person,ou=company1,c=Sweden,dc=spring,dc=org + objectclass: top + objectclass: person + objectclass: organizationalPerson + objectclass: inetOrgPerson + uid: some.person + userPassword: password + cn: Some Person + sn: Person + description: Sweden, Company1, Some Person + telephoneNumber: +46 555-123456 + + dn: cn=Some Person2,ou=company1,c=Sweden,dc=spring,dc=org + objectclass: top + objectclass: person + objectclass: organizationalPerson + objectclass: inetOrgPerson + uid: some.person2 + userPassword: password + cn: Some Person2 + sn: Person2 + description: Sweden, Company1, Some Person2 + telephoneNumber: +46 555-654321 + + dn: cn=Some Person3,ou=company1,c=Sweden,dc=spring,dc=org + objectclass: top + objectclass: person + objectclass: organizationalPerson + objectclass: inetOrgPerson + uid: some.person3 + userPassword: password + cn: Some Person3 + sn: Person3 + description: Sweden, Company1, Some Person3 + telephoneNumber: +46 555-123654 + + dn: cn=Some Person4,ou=company1,c=Sweden,dc=spring,dc=org + objectclass: top + objectclass: person + objectclass: organizationalPerson + objectclass: inetOrgPerson + uid: some.person4 + userPassword: password + cn: Some Person + sn: Person + description: Sweden, Company1, Some Person + telephoneNumber: +46 555-456321 + + dn: dc=vmware,dc=com + objectclass: top + objectclass: domain + objectclass: extensibleObject + dc: vmware + + dn: ou=groups,dc=vmware,dc=com + objectclass: top + objectclass: organizationalUnit + ou: groups + + dn: c=Sweden,dc=vmware,dc=com + objectclass: top + objectclass: country + c: Sweden + description:The country of Sweden + + dn: cn=Some Random Person,c=Sweden,dc=vmware,dc=com + objectclass: top + objectclass: person + objectclass: organizationalPerson + objectclass: inetOrgPerson + uid: some.random.person + userPassword: password + cn: Some Random Person + sn: Person + description: Sweden, VMware, Some Random Person + telephoneNumber: +46 555-123456 + """) void testMultiBaseDn() { this.contextRunner.withPropertyValues("spring.ldap.embedded.ldif:classpath:schema-multi-basedn.ldif", "spring.ldap.embedded.base-dn[0]:dc=spring,dc=org", "spring.ldap.embedded.base-dn[1]:dc=vmware,dc=com") @@ -206,4 +358,97 @@ class EmbeddedLdapAutoConfigurationTests { } + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @WithResource(name = "schema.ldif", content = """ + dn: dc=spring,dc=org + objectclass: top + objectclass: domain + objectclass: extensibleObject + dc: spring + + dn: ou=groups,dc=spring,dc=org + objectclass: top + objectclass: organizationalUnit + ou: groups + + dn: cn=ROLE_USER,ou=groups,dc=spring,dc=org + objectclass: top + objectclass: groupOfUniqueNames + cn: ROLE_USER + uniqueMember: cn=Some Person,ou=company1,c=Sweden,dc=spring,dc=org + uniqueMember: cn=Some Person2,ou=company1,c=Sweden,dc=spring,dc=org + uniqueMember: cn=Some Person,ou=company1,c=Sweden,dc=spring,dc=org + uniqueMember: cn=Some Person3,ou=company1,c=Sweden,dc=spring,dc=org + + dn: cn=ROLE_ADMIN,ou=groups,dc=spring,dc=org + objectclass: top + objectclass: groupOfUniqueNames + cn: ROLE_ADMIN + uniqueMember: cn=Some Person2,ou=company1,c=Sweden,dc=spring,dc=org + + dn: c=Sweden,dc=spring,dc=org + objectclass: top + objectclass: country + c: Sweden + description: The country of Sweden + + dn: ou=company1,c=Sweden,dc=spring,dc=org + objectclass: top + objectclass: organizationalUnit + ou: company1 + description: First company in Sweden + + dn: cn=Some Person,ou=company1,c=Sweden,dc=spring,dc=org + objectclass: top + objectclass: person + objectclass: organizationalPerson + objectclass: inetOrgPerson + uid: some.person + userPassword: password + cn: Some Person + sn: Person + description: Sweden, Company1, Some Person + telephoneNumber: +46 555-123456 + + dn: cn=Some Person2,ou=company1,c=Sweden,dc=spring,dc=org + objectclass: top + objectclass: person + objectclass: organizationalPerson + objectclass: inetOrgPerson + uid: some.person2 + userPassword: password + cn: Some Person2 + sn: Person2 + description: Sweden, Company1, Some Person2 + telephoneNumber: +46 555-654321 + + dn: cn=Some Person3,ou=company1,c=Sweden,dc=spring,dc=org + objectclass: top + objectclass: person + objectclass: organizationalPerson + objectclass: inetOrgPerson + uid: some.person3 + userPassword: password + cn: Some Person3 + sn: Person3 + description: Sweden, Company1, Some Person3 + telephoneNumber: +46 555-123654 + + dn: cn=Some Person4,ou=company1,c=Sweden,dc=spring,dc=org + objectclass: top + objectclass: person + objectclass: organizationalPerson + objectclass: inetOrgPerson + uid: some.person4 + userPassword: password + cn: Some Person + sn: Person + description: Sweden, Company1, Some Person + telephoneNumber: +46 555-456321 + """) + @interface WithSchemaLdifResource { + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/Liquibase423AutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/Liquibase423AutoConfigurationTests.java index 850a1e66124..f12d064a24f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/Liquibase423AutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/Liquibase423AutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -27,6 +27,7 @@ import org.springframework.boot.test.context.assertj.AssertableApplicationContex import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.testsupport.classpath.ClassPathOverrides; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import static org.assertj.core.api.Assertions.assertThat; @@ -43,6 +44,7 @@ class Liquibase423AutoConfigurationTests { .withPropertyValues("spring.datasource.generate-unique-name=true"); @Test + @WithResource(name = "db/changelog/db.changelog-master.yaml", content = "databaseChangeLog:") void defaultSpringLiquibase() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .run(assertLiquibase((liquibase) -> { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java index 83d2f7d94aa..ef544656676 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/liquibase/LiquibaseAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -18,6 +18,10 @@ package org.springframework.boot.autoconfigure.liquibase; import java.io.File; import java.io.IOException; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.nio.file.Files; import java.nio.file.Path; import java.sql.Connection; @@ -56,6 +60,7 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.test.system.CapturedOutput; import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; @@ -97,6 +102,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void createsDataSourceWithNoDataSourceBeanAndLiquibaseUrl() { String jdbcUrl = "jdbc:hsqldb:mem:liquibase" + UUID.randomUUID(); this.contextRunner.withPropertyValues("spring.liquibase.url:" + jdbcUrl).run(assertLiquibase((liquibase) -> { @@ -113,6 +119,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void defaultSpringLiquibase() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .run(assertLiquibase((liquibase) -> { @@ -135,6 +142,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void liquibaseDataSourceIsUsedOverJdbcConnectionDetails() { this.contextRunner .withUserConfiguration(LiquibaseDataSourceConfiguration.class, JdbcConnectionDetailsConfiguration.class) @@ -147,6 +155,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void liquibaseDataSourceIsUsedOverLiquibaseConnectionDetails() { this.contextRunner .withUserConfiguration(LiquibaseDataSourceConfiguration.class, @@ -160,6 +169,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void liquibasePropertiesAreUsedOverJdbcConnectionDetails() { this.contextRunner .withPropertyValues("spring.liquibase.url=jdbc:hsqldb:mem:liquibasetest", "spring.liquibase.user=some-user", @@ -190,6 +200,18 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithResource(name = "db/changelog/db.changelog-override.xml", + content = """ + + + + + """) void changelogXml() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.liquibase.change-log:classpath:/db/changelog/db.changelog-override.xml") @@ -198,6 +220,11 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithResource(name = "db/changelog/db.changelog-override.json", content = """ + { + "databaseChangeLog": [] + } + """) void changelogJson() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.liquibase.change-log:classpath:/db/changelog/db.changelog-override.json") @@ -206,6 +233,16 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithResource(name = "db/changelog/db.changelog-override.sql", content = """ + --liquibase formatted sql + + --changeset author:awilkinson + + CREATE TABLE customer ( + id int AUTO_INCREMENT NOT NULL PRIMARY KEY, + name varchar(50) NOT NULL + ); + """) void changelogSql() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.liquibase.change-log:classpath:/db/changelog/db.changelog-override.sql") @@ -214,6 +251,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void defaultValues() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .run(assertLiquibase((liquibase) -> { @@ -232,6 +270,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void overrideContexts() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.liquibase.contexts:test, production") @@ -239,6 +278,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void overrideDefaultSchema() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.liquibase.default-schema:public") @@ -246,6 +286,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void overrideLiquibaseInfrastructure() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.liquibase.liquibase-schema:public", @@ -266,6 +307,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void overrideDropFirst() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.liquibase.drop-first:true") @@ -273,6 +315,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void overrideClearChecksums() { String jdbcUrl = "jdbc:hsqldb:mem:liquibase" + UUID.randomUUID(); this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) @@ -284,6 +327,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void overrideDataSource() { String jdbcUrl = "jdbc:hsqldb:mem:liquibase" + UUID.randomUUID(); this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) @@ -296,6 +340,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void overrideDataSourceAndDriverClassName() { String jdbcUrl = "jdbc:hsqldb:mem:liquibase" + UUID.randomUUID(); String driverClassName = "org.hsqldb.jdbcDriver"; @@ -310,6 +355,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void overrideUser() { String databaseName = "normal" + UUID.randomUUID(); this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) @@ -324,6 +370,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void overrideUserWhenCustom() { this.contextRunner.withUserConfiguration(CustomDataSourceConfiguration.class) .withPropertyValues("spring.liquibase.user:test", "spring.liquibase.password:secret") @@ -337,6 +384,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void createDataSourceDoesNotFallbackToEmbeddedProperties() { String jdbcUrl = "jdbc:hsqldb:mem:liquibase" + UUID.randomUUID(); this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) @@ -349,6 +397,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void overrideUserAndFallbackToEmbeddedProperties() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.liquibase.user:sa") @@ -359,6 +408,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void overrideTestRollbackOnUpdate() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.liquibase.test-rollback-on-update:true") @@ -379,12 +429,14 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void logging(CapturedOutput output) { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .run(assertLiquibase((liquibase) -> assertThat(output).doesNotContain(": liquibase:"))); } @Test + @WithDbChangelogMasterYamlResource void overrideLabelFilter() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.liquibase.label-filter:test, production") @@ -392,6 +444,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void overrideShowSummary() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.liquibase.show-summary=off") @@ -403,6 +456,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void overrideShowSummaryOutput() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.liquibase.show-summary-output=all") @@ -414,6 +468,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void overrideUiService() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.liquibase.ui-service=console") @@ -422,6 +477,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource @SuppressWarnings("unchecked") void testOverrideParameters() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) @@ -435,6 +491,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void rollbackFile(@TempDir Path temp) throws IOException { File file = Files.createTempFile(temp, "rollback-file", "sql").toFile(); this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) @@ -448,6 +505,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void liquibaseDataSource() { this.contextRunner .withUserConfiguration(LiquibaseDataSourceConfiguration.class, EmbeddedDataSourceConfiguration.class) @@ -458,6 +516,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void liquibaseDataSourceWithoutDataSourceAutoConfiguration() { this.contextRunner.withUserConfiguration(LiquibaseDataSourceConfiguration.class).run((context) -> { SpringLiquibase liquibase = context.getBean(SpringLiquibase.class); @@ -466,6 +525,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void userConfigurationBeans() { this.contextRunner .withUserConfiguration(LiquibaseUserConfiguration.class, EmbeddedDataSourceConfiguration.class) @@ -476,6 +536,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void userConfigurationEntityManagerFactoryDependency() { this.contextRunner.withConfiguration(AutoConfigurations.of(HibernateJpaAutoConfiguration.class)) .withUserConfiguration(LiquibaseUserConfiguration.class, EmbeddedDataSourceConfiguration.class) @@ -486,6 +547,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void userConfigurationJdbcTemplateDependency() { this.contextRunner.withConfiguration(AutoConfigurations.of(JdbcTemplateAutoConfiguration.class)) .withUserConfiguration(LiquibaseUserConfiguration.class, EmbeddedDataSourceConfiguration.class) @@ -496,6 +558,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void overrideTag() { this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class) .withPropertyValues("spring.liquibase.tag:1.0.0") @@ -503,6 +566,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void whenLiquibaseIsAutoConfiguredThenJooqDslContextDependsOnSpringLiquibaseBeans() { this.contextRunner.withConfiguration(AutoConfigurations.of(JooqAutoConfiguration.class)) .withUserConfiguration(EmbeddedDataSourceConfiguration.class) @@ -513,6 +577,7 @@ class LiquibaseAutoConfigurationTests { } @Test + @WithDbChangelogMasterYamlResource void whenCustomSpringLiquibaseIsDefinedThenJooqDslContextDependsOnSpringLiquibaseBeans() { this.contextRunner.withConfiguration(AutoConfigurations.of(JooqAutoConfiguration.class)) .withUserConfiguration(LiquibaseUserConfiguration.class, EmbeddedDataSourceConfiguration.class) @@ -672,4 +737,32 @@ class LiquibaseAutoConfigurationTests { } + @WithResource(name = "db/changelog/db.changelog-master.yaml", content = """ + databaseChangeLog: + - changeSet: + id: 1 + author: marceloverdijk + changes: + - createTable: + tableName: customer + columns: + - column: + name: id + type: int + autoIncrement: true + constraints: + primaryKey: true + nullable: false + - column: + name: name + type: varchar(50) + constraints: + nullable: false + """) + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + @interface WithDbChangelogMasterYamlResource { + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfigurationTests.java index b2122ebecc2..4ba66770174 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -31,6 +31,7 @@ import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration; import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithPackageResources; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -85,6 +86,7 @@ class MongoAutoConfigurationTests { } @Test + @WithPackageResources("test.jks") void configuresSslWithBundle() { this.contextRunner .withPropertyValues("spring.data.mongodb.ssl.bundle=test-bundle", diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfigurationTests.java index a3225f4fea0..44ee73001b1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoReactiveAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -34,6 +34,7 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithPackageResources; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -93,6 +94,7 @@ class MongoReactiveAutoConfigurationTests { } @Test + @WithPackageResources("test.jks") void configuresSslWithBundle() { this.contextRunner .withPropertyValues("spring.data.mongodb.ssl.bundle=test-bundle", diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationReactiveIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationReactiveIntegrationTests.java index 9f9524eaa72..0836b7d7176 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationReactiveIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationReactiveIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -105,9 +105,10 @@ class MustacheAutoConfigurationReactiveIntegrationTests { @Bean MustacheViewResolver viewResolver() { Mustache.Compiler compiler = Mustache.compiler() - .withLoader(new MustacheResourceTemplateLoader("classpath:/mustache-templates/", ".html")); + .withLoader(new MustacheResourceTemplateLoader( + "classpath:/org/springframework/boot/autoconfigure/mustache/", ".html")); MustacheViewResolver resolver = new MustacheViewResolver(compiler); - resolver.setPrefix("classpath:/mustache-templates/"); + resolver.setPrefix("classpath:/org/springframework/boot/autoconfigure/mustache/"); resolver.setSuffix(".html"); return resolver; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationServletIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationServletIntegrationTests.java index c6c892e3331..aba169ffc33 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationServletIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mustache/MustacheAutoConfigurationServletIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -115,9 +115,10 @@ class MustacheAutoConfigurationServletIntegrationTests { @Bean MustacheViewResolver viewResolver() { Mustache.Compiler compiler = Mustache.compiler() - .withLoader(new MustacheResourceTemplateLoader("classpath:/mustache-templates/", ".html")); + .withLoader(new MustacheResourceTemplateLoader( + "classpath:/org/springframework/boot/autoconfigure/mustache/", ".html")); MustacheViewResolver resolver = new MustacheViewResolver(compiler); - resolver.setPrefix("classpath:/mustache-templates/"); + resolver.setPrefix("classpath:/org/springframework/boot/autoconfigure/mustache/"); resolver.setSuffix(".html"); return resolver; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java index d5efec995d6..b8c9e4ed9ce 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -17,6 +17,10 @@ package org.springframework.boot.autoconfigure.orm.jpa; import java.io.File; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -46,6 +50,7 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; import org.springframework.boot.testsupport.BuildOutput; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -208,6 +213,7 @@ abstract class AbstractJpaAutoConfigurationTests { } @Test + @WithMetaInfPersistenceXmlResource void usesManuallyDefinedLocalContainerEntityManagerFactoryBeanIfAvailable() { this.contextRunner.withUserConfiguration(TestConfigurationWithLocalContainerEntityManagerFactoryBean.class) .run((context) -> { @@ -219,6 +225,7 @@ abstract class AbstractJpaAutoConfigurationTests { } @Test + @WithMetaInfPersistenceXmlResource void usesManuallyDefinedEntityManagerFactoryIfAvailable() { this.contextRunner.withUserConfiguration(TestConfigurationWithLocalContainerEntityManagerFactoryBean.class) .run((context) -> { @@ -477,4 +484,20 @@ abstract class AbstractJpaAutoConfigurationTests { } + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @WithResource(name = "META-INF/persistence.xml", + content = """ + + + + org.springframework.boot.autoconfigure.orm.jpa.test.City + true + + + """) + @interface WithMetaInfPersistenceXmlResource { + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/Hibernate2ndLevelCacheIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/Hibernate2ndLevelCacheIntegrationTests.java index f3b2ff2521a..274c373e0fc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/Hibernate2ndLevelCacheIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/Hibernate2ndLevelCacheIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -23,6 +23,7 @@ import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Configuration; @@ -41,6 +42,20 @@ class Hibernate2ndLevelCacheIntegrationTests { .withUserConfiguration(TestConfiguration.class); @Test + @WithResource(name = "hazelcast.xml", content = """ + + default-instance + + + + + + + + + """) void hibernate2ndLevelCacheWithJCacheAndHazelcast() { String cachingProviderFqn = HazelcastServerCachingProvider.class.getName(); String configLocation = "classpath:hazelcast.xml"; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java index 3d0d625c33b..e5d5b141dfa 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -72,6 +72,7 @@ import org.springframework.boot.orm.jpa.hibernate.SpringJtaPlatform; import org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitialization; import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.runner.ContextConsumer; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; @@ -129,6 +130,8 @@ class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigurationTes } @Test + @WithResource(name = "city.sql", + content = "INSERT INTO CITY (ID, NAME, STATE, COUNTRY, MAP) values (2000, 'Washington', 'DC', 'US', 'Google')") void testDmlScriptRunsEarly() { contextRunner().withUserConfiguration(TestInitializedJpaConfiguration.class) .withClassLoader(new HideDataScriptClassLoader()) @@ -139,6 +142,16 @@ class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigurationTes } @Test + @WithResource(name = "db/city/V1__init.sql", content = """ + CREATE SEQUENCE city_seq INCREMENT BY 50; + CREATE TABLE CITY ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY, + name VARCHAR(30), + state VARCHAR(30), + country VARCHAR(30), + map VARCHAR(30) + ); + """) void testFlywaySwitchOffDdlAuto() { contextRunner().withPropertyValues("spring.sql.init.mode:never", "spring.flyway.locations:classpath:db/city") .withConfiguration(AutoConfigurations.of(FlywayAutoConfiguration.class)) @@ -146,6 +159,17 @@ class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigurationTes } @Test + @WithResource(name = "db/city/V1__init.sql", content = """ + CREATE SEQUENCE city_seq INCREMENT BY 50; + + CREATE TABLE CITY ( + id BIGINT GENERATED BY DEFAULT AS IDENTITY, + name VARCHAR(30), + state VARCHAR(30), + country VARCHAR(30), + map VARCHAR(30) + ); + """) void testFlywayPlusValidation() { contextRunner() .withPropertyValues("spring.sql.init.mode:never", "spring.flyway.locations:classpath:db/city", @@ -155,6 +179,46 @@ class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigurationTes } @Test + @WithResource(name = "db/changelog/db.changelog-city.yaml", content = """ + databaseChangeLog: + - changeSet: + id: 1 + author: dsyer + changes: + - createSequence: + sequenceName: city_seq + incrementBy: 50 + - createTable: + tableName: city + columns: + - column: + name: id + type: bigint + autoIncrement: true + constraints: + primaryKey: true + nullable: false + - column: + name: name + type: varchar(50) + constraints: + nullable: false + - column: + name: state + type: varchar(50) + constraints: + nullable: false + - column: + name: country + type: varchar(50) + constraints: + nullable: false + - column: + name: map + type: varchar(50) + constraints: + nullable: true + """) void testLiquibasePlusValidation() { contextRunner() .withPropertyValues("spring.liquibase.change-log:classpath:db/changelog/db.changelog-city.yaml", @@ -296,9 +360,32 @@ class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigurationTes } @Test + @WithResource(name = "META-INF/mappings/non-annotated.xml", + content = """ + + + + + + + + + + + + + + + + """) + @WithResource(name = "non-annotated-data.sql", + content = "INSERT INTO NON_ANNOTATED (id, item) values (2000, 'Test');") void customResourceMapping() { contextRunner().withClassLoader(new HideDataScriptClassLoader()) - .withPropertyValues("spring.sql.init.data-locations:classpath:/db/non-annotated-data.sql", + .withPropertyValues("spring.sql.init.data-locations:classpath:non-annotated-data.sql", "spring.jpa.mapping-resources=META-INF/mappings/non-annotated.xml", "spring.jpa.defer-datasource-initialization=true") .run((context) -> { @@ -368,6 +455,8 @@ class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigurationTes } @Test + @WithResource(name = "city.sql", + content = "INSERT INTO CITY (ID, NAME, STATE, COUNTRY, MAP) values (2000, 'Washington', 'DC', 'US', 'Google')") void eventListenerCanBeRegisteredAsBeans() { contextRunner().withUserConfiguration(TestInitializedJpaConfiguration.class) .withClassLoader(new HideDataScriptClassLoader()) @@ -478,6 +567,7 @@ class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigurationTes } @Test + @WithMetaInfPersistenceXmlResource void whenLocalContainerEntityManagerFactoryBeanHasNoJpaVendorAdapterAutoConfigurationSucceeds() { contextRunner() .withUserConfiguration( @@ -698,7 +788,7 @@ class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigurationTes private static final List HIDDEN_RESOURCES = Arrays.asList("schema-all.sql", "schema.sql"); HideDataScriptClassLoader() { - super(new URL[0], HideDataScriptClassLoader.class.getClassLoader()); + super(new URL[0], Thread.currentThread().getContextClassLoader()); } @Override diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/r2dbc/R2dbcAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/r2dbc/R2dbcAutoConfigurationTests.java index 9ef8ee88f39..fb4f3eb4f10 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/r2dbc/R2dbcAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/r2dbc/R2dbcAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -44,6 +44,8 @@ import org.springframework.boot.r2dbc.EmbeddedDatabaseConnection; import org.springframework.boot.r2dbc.OptionsCapableConnectionFactory; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.ForkedClassPath; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.r2dbc.core.DatabaseClient; @@ -237,6 +239,9 @@ class R2dbcAutoConfigurationTests { } @Test + @WithResource(name = "META-INF/services/io.r2dbc.spi.ConnectionFactoryProvider", + content = "org.springframework.boot.autoconfigure.r2dbc.SimpleConnectionFactoryProvider") + @ForkedClassPath void configureWithPoolShouldApplyAdditionalProperties() { this.contextRunner .withPropertyValues("spring.r2dbc.url:r2dbc:simple://foo", "spring.r2dbc.properties.test=value", diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfigurationTests.java index 62569319c38..7362a2aebc6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/rsocket/RSocketServerAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -29,6 +29,7 @@ import org.springframework.boot.ssl.NoSuchSslBundleException; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithPackageResources; import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -126,30 +127,32 @@ class RSocketServerAutoConfigurationTests { } @Test + @WithPackageResources("test.jks") void shouldUseSslWhenRocketServerSslIsConfigured() { reactiveWebContextRunner() - .withPropertyValues("spring.rsocket.server.ssl.keyStore=classpath:rsocket/test.jks", + .withPropertyValues("spring.rsocket.server.ssl.keyStore=classpath:test.jks", "spring.rsocket.server.ssl.keyPassword=password", "spring.rsocket.server.port=0") .run((context) -> assertThat(context).hasSingleBean(RSocketServerFactory.class) .hasSingleBean(RSocketServerBootstrap.class) .hasSingleBean(RSocketServerCustomizer.class) .getBean(RSocketServerFactory.class) - .hasFieldOrPropertyWithValue("ssl.keyStore", "classpath:rsocket/test.jks") + .hasFieldOrPropertyWithValue("ssl.keyStore", "classpath:test.jks") .hasFieldOrPropertyWithValue("ssl.keyPassword", "password")); } @Test @Disabled + @WithPackageResources("test.jks") void shouldUseSslWhenRocketServerSslIsConfiguredWithSslBundle() { reactiveWebContextRunner() .withPropertyValues("spring.rsocket.server.port=0", "spring.rsocket.server.ssl.bundle=test-bundle", - "spring.ssl.bundle.jks.test-bundle.keystore.location=classpath:rsocket/test.jks", + "spring.ssl.bundle.jks.test-bundle.keystore.location=classpath:test.jks", "spring.ssl.bundle.jks.test-bundle.key.password=password") .run((context) -> assertThat(context).hasSingleBean(RSocketServerFactory.class) .hasSingleBean(RSocketServerBootstrap.class) .hasSingleBean(RSocketServerCustomizer.class) .getBean(RSocketServerFactory.class) - .hasFieldOrPropertyWithValue("sslBundle.details.keyStore", "classpath:rsocket/test.jks") + .hasFieldOrPropertyWithValue("sslBundle.details.keyStore", "classpath:test.jks") .hasFieldOrPropertyWithValue("sslBundle.details.keyPassword", "password")); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/reactive/ReactiveOAuth2ResourceServerAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/reactive/ReactiveOAuth2ResourceServerAutoConfigurationTests.java index 771c5cb4b67..3e845727128 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/reactive/ReactiveOAuth2ResourceServerAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/reactive/ReactiveOAuth2ResourceServerAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -17,6 +17,10 @@ package org.springframework.boot.autoconfigure.security.oauth2.resource.reactive; import java.io.IOException; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.net.URI; import java.net.URL; import java.time.Duration; @@ -49,6 +53,7 @@ import org.springframework.boot.autoconfigure.security.oauth2.resource.JwtConver import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; @@ -173,6 +178,7 @@ class ReactiveOAuth2ResourceServerAutoConfigurationTests { } @Test + @WithPublicKeyResource void autoConfigurationUsingPublicKeyValueShouldConfigureResourceServerUsingSingleJwsAlgorithm() { this.contextRunner .withPropertyValues( @@ -186,6 +192,7 @@ class ReactiveOAuth2ResourceServerAutoConfigurationTests { } @Test + @WithPublicKeyResource void autoConfigurationUsingPublicKeyValueWithMultipleJwsAlgorithmsShouldFail() { this.contextRunner .withPropertyValues( @@ -284,6 +291,7 @@ class ReactiveOAuth2ResourceServerAutoConfigurationTests { } @Test + @WithPublicKeyResource void autoConfigurationShouldConfigureResourceServerUsingPublicKeyValue() { this.contextRunner .withPropertyValues( @@ -539,6 +547,7 @@ class ReactiveOAuth2ResourceServerAutoConfigurationTests { } @Test + @WithPublicKeyResource void autoConfigurationShouldConfigureAudienceValidatorIfPropertyProvidedAndPublicKey() throws Exception { this.server = new MockWebServer(); this.server.start(); @@ -891,4 +900,18 @@ class ReactiveOAuth2ResourceServerAutoConfigurationTests { } + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @WithResource(name = "public-key-location", content = """ + -----BEGIN PUBLIC KEY----- + MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdlatRjRjogo3WojgGHFHYLugd + UWAY9iR3fy4arWNA1KoS8kVw33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQs + HUfQrSDv+MuSUMAe8jzKE4qW+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5D + o2kQ+X5xK9cipRgEKwIDAQAB + -----END PUBLIC KEY----- + """) + @interface WithPublicKeyResource { + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/servlet/OAuth2ResourceServerAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/servlet/OAuth2ResourceServerAutoConfigurationTests.java index 9de6d030a84..776615eb2d6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/servlet/OAuth2ResourceServerAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/resource/servlet/OAuth2ResourceServerAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -16,6 +16,10 @@ package org.springframework.boot.autoconfigure.security.oauth2.resource.servlet; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.net.URI; import java.net.URL; import java.time.Instant; @@ -48,6 +52,7 @@ import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguratio import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; @@ -174,6 +179,7 @@ class OAuth2ResourceServerAutoConfigurationTests { } @Test + @WithPublicKeyResource void autoConfigurationUsingPublicKeyValueShouldConfigureResourceServerUsingSingleJwsAlgorithm() { this.contextRunner .withPropertyValues( @@ -187,6 +193,7 @@ class OAuth2ResourceServerAutoConfigurationTests { } @Test + @WithPublicKeyResource void autoConfigurationUsingPublicKeyValueWithMultipleJwsAlgorithmsShouldFail() { this.contextRunner .withPropertyValues( @@ -277,6 +284,7 @@ class OAuth2ResourceServerAutoConfigurationTests { } @Test + @WithPublicKeyResource void autoConfigurationShouldConfigureResourceServerUsingPublicKeyValue() throws Exception { this.server = new MockWebServer(); this.server.start(); @@ -304,6 +312,7 @@ class OAuth2ResourceServerAutoConfigurationTests { } @Test + @WithPublicKeyResource void autoConfigurationShouldFailIfAlgorithmIsInvalid() { this.contextRunner .withPropertyValues( @@ -583,6 +592,7 @@ class OAuth2ResourceServerAutoConfigurationTests { } @Test + @WithPublicKeyResource void autoConfigurationShouldConfigureAudienceValidatorIfPropertyProvidedAndPublicKey() throws Exception { this.server = new MockWebServer(); this.server.start(); @@ -877,4 +887,18 @@ class OAuth2ResourceServerAutoConfigurationTests { } + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @WithResource(name = "public-key-location", content = """ + -----BEGIN PUBLIC KEY----- + MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdlatRjRjogo3WojgGHFHYLugd + UWAY9iR3fy4arWNA1KoS8kVw33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQs + HUfQrSDv+MuSUMAe8jzKE4qW+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5D + o2kQ+X5xK9cipRgEKwIDAQAB + -----END PUBLIC KEY----- + """) + @interface WithPublicKeyResource { + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyAutoConfigurationTests.java index 5c8b4ae27da..ccebaaf2727 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -32,6 +32,7 @@ import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithPackageResources; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; @@ -89,6 +90,7 @@ class Saml2RelyingPartyAutoConfigurationTests { } @Test + @WithPackageResources({ "certificate-location", "private-key-location" }) void relyingPartyRegistrationRepositoryBeanShouldBeCreatedWhenPropertiesPresent() { this.contextRunner.withPropertyValues(getPropertyValues()).run((context) -> { RelyingPartyRegistrationRepository repository = context.getBean(RelyingPartyRegistrationRepository.class); @@ -123,6 +125,7 @@ class Saml2RelyingPartyAutoConfigurationTests { } @Test + @WithPackageResources({ "certificate-location", "private-key-location" }) void autoConfigurationWhenSignRequestsTrueAndNoSigningCredentialsShouldThrowException() { this.contextRunner.withPropertyValues(getPropertyValuesWithoutSigningCredentials(true)).run((context) -> { assertThat(context).hasFailed(); @@ -132,17 +135,19 @@ class Saml2RelyingPartyAutoConfigurationTests { } @Test + @WithPackageResources({ "certificate-location", "private-key-location" }) void autoConfigurationWhenSignRequestsFalseAndNoSigningCredentialsShouldNotThrowException() { this.contextRunner.withPropertyValues(getPropertyValuesWithoutSigningCredentials(false)) .run((context) -> assertThat(context).hasSingleBean(RelyingPartyRegistrationRepository.class)); } @Test + @WithPackageResources("idp-metadata") void autoconfigurationShouldQueryAssertingPartyMetadataWhenMetadataUrlIsPresent() throws Exception { try (MockWebServer server = new MockWebServer()) { server.start(); String metadataUrl = server.url("").toString(); - setupMockResponse(server, new ClassPathResource("saml/idp-metadata")); + setupMockResponse(server, new ClassPathResource("idp-metadata")); this.contextRunner.withPropertyValues(PREFIX + ".foo.assertingparty.metadata-uri=" + metadataUrl) .run((context) -> { assertThat(context).hasSingleBean(RelyingPartyRegistrationRepository.class); @@ -152,11 +157,12 @@ class Saml2RelyingPartyAutoConfigurationTests { } @Test + @WithPackageResources("idp-metadata") void autoconfigurationShouldUseBindingFromMetadataUrlIfPresent() throws Exception { try (MockWebServer server = new MockWebServer()) { server.start(); String metadataUrl = server.url("").toString(); - setupMockResponse(server, new ClassPathResource("saml/idp-metadata")); + setupMockResponse(server, new ClassPathResource("idp-metadata")); this.contextRunner.withPropertyValues(PREFIX + ".foo.assertingparty.metadata-uri=" + metadataUrl) .run((context) -> { RelyingPartyRegistrationRepository repository = context @@ -169,11 +175,12 @@ class Saml2RelyingPartyAutoConfigurationTests { } @Test + @WithPackageResources("idp-metadata") void autoconfigurationWhenMetadataUrlAndPropertyPresentShouldUseBindingFromProperty() throws Exception { try (MockWebServer server = new MockWebServer()) { server.start(); String metadataUrl = server.url("").toString(); - setupMockResponse(server, new ClassPathResource("saml/idp-metadata")); + setupMockResponse(server, new ClassPathResource("idp-metadata")); this.contextRunner .withPropertyValues(PREFIX + ".foo.assertingparty.metadata-uri=" + metadataUrl, PREFIX + ".foo.assertingparty.singlesignon.binding=redirect") @@ -188,6 +195,7 @@ class Saml2RelyingPartyAutoConfigurationTests { } @Test + @WithPackageResources({ "certificate-location", "private-key-location" }) void autoconfigurationWhenNoMetadataUrlOrPropertyPresentShouldUseRedirectBinding() { this.contextRunner.withPropertyValues(getPropertyValuesWithoutSsoBinding()).run((context) -> { RelyingPartyRegistrationRepository repository = context.getBean(RelyingPartyRegistrationRepository.class); @@ -208,12 +216,14 @@ class Saml2RelyingPartyAutoConfigurationTests { } @Test + @WithPackageResources({ "certificate-location", "private-key-location" }) void samlLoginShouldBeConfigured() { this.contextRunner.withPropertyValues(getPropertyValues()) .run((context) -> assertThat(hasSecurityFilter(context, Saml2WebSsoAuthenticationFilter.class)).isTrue()); } @Test + @WithPackageResources({ "private-key-location", "certificate-location" }) void samlLoginShouldBackOffWhenASecurityFilterChainBeanIsPresent() { this.contextRunner.withConfiguration(AutoConfigurations.of(WebMvcAutoConfiguration.class)) .withUserConfiguration(TestSecurityFilterChainConfig.class) @@ -222,13 +232,17 @@ class Saml2RelyingPartyAutoConfigurationTests { } @Test + @WithPackageResources({ "certificate-location", "private-key-location" }) void samlLoginShouldShouldBeConditionalOnSecurityWebFilterClass() { - this.contextRunner.withClassLoader(new FilteredClassLoader(SecurityFilterChain.class)) + this.contextRunner + .withClassLoader( + new FilteredClassLoader(Thread.currentThread().getContextClassLoader(), SecurityFilterChain.class)) .withPropertyValues(getPropertyValues()) .run((context) -> assertThat(context).doesNotHaveBean(SecurityFilterChain.class)); } @Test + @WithPackageResources({ "certificate-location", "private-key-location" }) void samlLogoutShouldBeConfigured() { this.contextRunner.withPropertyValues(getPropertyValues()) .run((context) -> assertThat(hasSecurityFilter(context, Saml2LogoutRequestFilter.class)).isTrue()); @@ -240,26 +254,29 @@ class Saml2RelyingPartyAutoConfigurationTests { PREFIX + ".foo.assertingparty.singlesignon.binding=post", PREFIX + ".foo.assertingparty.singlesignon.sign-request=" + signRequests, PREFIX + ".foo.assertingparty.entity-id=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php", - PREFIX + ".foo.assertingparty.verification.credentials[0].certificate-location=classpath:saml/certificate-location" }; + PREFIX + ".foo.assertingparty.verification.credentials[0].certificate-location=classpath:certificate-location" }; } @Test + @WithPackageResources("idp-metadata-with-multiple-providers") void autoconfigurationWhenMultipleProvidersAndNoSpecifiedEntityId() throws Exception { testMultipleProviders(null, "https://idp.example.com/idp/shibboleth"); } @Test + @WithPackageResources("idp-metadata-with-multiple-providers") void autoconfigurationWhenMultipleProvidersAndSpecifiedEntityId() throws Exception { testMultipleProviders("https://idp.example.com/idp/shibboleth", "https://idp.example.com/idp/shibboleth"); testMultipleProviders("https://idp2.example.com/idp/shibboleth", "https://idp2.example.com/idp/shibboleth"); } @Test + @WithPackageResources("idp-metadata") void signRequestShouldApplyIfMetadataUriIsSet() throws Exception { try (MockWebServer server = new MockWebServer()) { server.start(); String metadataUrl = server.url("").toString(); - setupMockResponse(server, new ClassPathResource("saml/idp-metadata")); + setupMockResponse(server, new ClassPathResource("idp-metadata")); this.contextRunner.withPropertyValues(PREFIX + ".foo.assertingparty.metadata-uri=" + metadataUrl, PREFIX + ".foo.assertingparty.singlesignon.sign-request=true", PREFIX + ".foo.signing.credentials[0].private-key-location=classpath:org/springframework/boot/autoconfigure/security/saml2/rsa.key", @@ -277,7 +294,7 @@ class Saml2RelyingPartyAutoConfigurationTests { try (MockWebServer server = new MockWebServer()) { server.start(); String metadataUrl = server.url("").toString(); - setupMockResponse(server, new ClassPathResource("saml/idp-metadata-with-multiple-providers")); + setupMockResponse(server, new ClassPathResource("idp-metadata-with-multiple-providers")); WebApplicationContextRunner contextRunner = this.contextRunner .withPropertyValues(PREFIX + ".foo.assertingparty.metadata-uri=" + metadataUrl); if (specifiedEntityId != null) { @@ -300,15 +317,15 @@ class Saml2RelyingPartyAutoConfigurationTests { + ".foo.assertingparty.singlesignon.url=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SSOService.php", PREFIX + ".foo.assertingparty.singlesignon.sign-request=false", PREFIX + ".foo.assertingparty.entity-id=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php", - PREFIX + ".foo.assertingparty.verification.credentials[0].certificate-location=classpath:saml/certificate-location" }; + PREFIX + ".foo.assertingparty.verification.credentials[0].certificate-location=classpath:certificate-location" }; } private String[] getPropertyValues() { return new String[] { - PREFIX + ".foo.signing.credentials[0].private-key-location=classpath:saml/private-key-location", - PREFIX + ".foo.signing.credentials[0].certificate-location=classpath:saml/certificate-location", - PREFIX + ".foo.decryption.credentials[0].private-key-location=classpath:saml/private-key-location", - PREFIX + ".foo.decryption.credentials[0].certificate-location=classpath:saml/certificate-location", + PREFIX + ".foo.signing.credentials[0].private-key-location=classpath:private-key-location", + PREFIX + ".foo.signing.credentials[0].certificate-location=classpath:certificate-location", + PREFIX + ".foo.decryption.credentials[0].private-key-location=classpath:private-key-location", + PREFIX + ".foo.decryption.credentials[0].certificate-location=classpath:certificate-location", PREFIX + ".foo.singlelogout.url=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SLOService.php", PREFIX + ".foo.singlelogout.response-url=https://simplesaml-for-spring-saml.cfapps.io/", PREFIX + ".foo.singlelogout.binding=post", @@ -316,7 +333,7 @@ class Saml2RelyingPartyAutoConfigurationTests { PREFIX + ".foo.assertingparty.singlesignon.binding=post", PREFIX + ".foo.assertingparty.singlesignon.sign-request=false", PREFIX + ".foo.assertingparty.entity-id=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/metadata.php", - PREFIX + ".foo.assertingparty.verification.credentials[0].certificate-location=classpath:saml/certificate-location", + PREFIX + ".foo.assertingparty.verification.credentials[0].certificate-location=classpath:certificate-location", PREFIX + ".foo.asserting-party.singlelogout.url=https://simplesaml-for-spring-saml.cfapps.io/saml2/idp/SLOService.php", PREFIX + ".foo.asserting-party.singlelogout.response-url=https://simplesaml-for-spring-saml.cfapps.io/", PREFIX + ".foo.asserting-party.singlelogout.binding=post", diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/servlet/SecurityAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/servlet/SecurityAutoConfigurationTests.java index 3a75d04394b..3a26ce94b7b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/servlet/SecurityAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/servlet/SecurityAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -16,6 +16,10 @@ package org.springframework.boot.autoconfigure.security.servlet; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.security.interfaces.RSAPublicKey; import java.util.EnumSet; @@ -36,6 +40,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.boot.convert.ApplicationConversionService; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.boot.web.servlet.DelegatingFilterProxyRegistrationBean; import org.springframework.boot.web.servlet.filter.OrderedFilter; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -193,6 +198,7 @@ class SecurityAutoConfigurationTests { } @Test + @WithPublicKeyResource void whenAConfigurationPropertyBindingConverterIsDefinedThenBindingToAnRsaKeySucceeds() { this.contextRunner.withUserConfiguration(ConverterConfiguration.class, PropertiesConfiguration.class) .withPropertyValues("jwt.public-key=classpath:public-key-location") @@ -200,6 +206,7 @@ class SecurityAutoConfigurationTests { } @Test + @WithPublicKeyResource void whenTheBeanFactoryHasAConversionServiceAndAConfigurationPropertyBindingConverterIsDefinedThenBindingToAnRsaKeySucceeds() { this.contextRunner .withInitializer( @@ -295,4 +302,18 @@ class SecurityAutoConfigurationTests { } + @Target(ElementType.METHOD) + @Retention(RetentionPolicy.RUNTIME) + @WithResource(name = "public-key-location", content = """ + -----BEGIN PUBLIC KEY----- + MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdlatRjRjogo3WojgGHFHYLugd + UWAY9iR3fy4arWNA1KoS8kVw33cJibXr8bvwUAUparCwlvdbH6dvEOfou0/gCFQs + HUfQrSDv+MuSUMAe8jzKE4qW+jK+xQU9a03GUnKHkkle+Q0pX/g6jXZ7r1/xAK5D + o2kQ+X5xK9cipRgEKwIDAQAB + -----END PUBLIC KEY----- + """) + @interface WithPublicKeyResource { + + } + } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationJdbcTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationJdbcTests.java index 30202631d84..047e06369a5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationJdbcTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/session/SessionAutoConfigurationJdbcTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -21,6 +21,7 @@ import java.time.Duration; import javax.sql.DataSource; import org.apache.commons.dbcp2.BasicDataSource; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -37,6 +38,7 @@ import org.springframework.boot.sql.init.DatabaseInitializationSettings; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.boot.web.servlet.AbstractFilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -63,13 +65,19 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; */ class SessionAutoConfigurationJdbcTests extends AbstractSessionAutoConfigurationTests { - private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() - .withClassLoader(new FilteredClassLoader(HazelcastIndexedSessionRepository.class, - MongoIndexedSessionRepository.class, RedisIndexedSessionRepository.class)) - .withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class, - DataSourceTransactionManagerAutoConfiguration.class, JdbcTemplateAutoConfiguration.class, - SessionAutoConfiguration.class)) - .withPropertyValues("spring.datasource.generate-unique-name=true"); + private WebApplicationContextRunner contextRunner; + + @BeforeEach + void prepareRunner() { + this.contextRunner = new WebApplicationContextRunner() + .withClassLoader(new FilteredClassLoader(Thread.currentThread().getContextClassLoader(), + HazelcastIndexedSessionRepository.class, MongoIndexedSessionRepository.class, + RedisIndexedSessionRepository.class)) + .withConfiguration(AutoConfigurations.of(DataSourceAutoConfiguration.class, + DataSourceTransactionManagerAutoConfiguration.class, JdbcTemplateAutoConfiguration.class, + SessionAutoConfiguration.class)) + .withPropertyValues("spring.datasource.generate-unique-name=true"); + } @Test void defaultConfig() { @@ -127,9 +135,8 @@ class SessionAutoConfigurationJdbcTests extends AbstractSessionAutoConfiguration @Test void customTableName() { - this.contextRunner - .withPropertyValues("spring.session.jdbc.table-name=FOO_BAR", - "spring.session.jdbc.schema=classpath:session/custom-schema-h2.sql") + this.contextRunner.withPropertyValues("spring.session.jdbc.table-name=FOO_BAR", + "spring.session.jdbc.schema=classpath:org/springframework/boot/autoconfigure/session/custom-schema-h2.sql") .run((context) -> { JdbcIndexedSessionRepository repository = validateSessionRepository(context, JdbcIndexedSessionRepository.class); @@ -211,6 +218,7 @@ class SessionAutoConfigurationJdbcTests extends AbstractSessionAutoConfiguration } @Test + @WithResource(name = "db/changelog/db.changelog-master.yaml", content = "databaseChangeLog:") void sessionRepositoryBeansDependOnLiquibase() { this.contextRunner.withConfiguration(AutoConfigurations.of(LiquibaseAutoConfiguration.class)) .withPropertyValues("spring.session.jdbc.initialize-schema=never") diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ssl/SslPropertiesBundleRegistrarTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ssl/SslPropertiesBundleRegistrarTests.java index dafabd8801b..19df0b1f9a4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ssl/SslPropertiesBundleRegistrarTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/ssl/SslPropertiesBundleRegistrarTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -67,9 +67,9 @@ class SslPropertiesBundleRegistrarTests { void shouldWatchJksBundles() { JksSslBundleProperties jks = new JksSslBundleProperties(); jks.setReloadOnUpdate(true); - jks.getKeystore().setLocation("classpath:test.jks"); + jks.getKeystore().setLocation("classpath:org/springframework/boot/autoconfigure/ssl/test.jks"); jks.getKeystore().setPassword("secret"); - jks.getTruststore().setLocation("classpath:test.jks"); + jks.getTruststore().setLocation("classpath:org/springframework/boot/autoconfigure/ssl/test.jks"); jks.getTruststore().setPassword("secret"); this.properties.getBundle().getJks().put("bundle1", jks); this.registrar.registerBundles(this.registry); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveAutoConfigurationTests.java index 6d17a0ef752..af84fb8f713 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafReactiveAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -43,6 +43,7 @@ import org.springframework.boot.test.context.runner.ReactiveWebApplicationContex import org.springframework.boot.test.system.CapturedOutput; import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.boot.testsupport.BuildOutput; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.MediaType; @@ -70,6 +71,7 @@ class ThymeleafReactiveAutoConfigurationTests { .withConfiguration(AutoConfigurations.of(ThymeleafAutoConfiguration.class)); @Test + @WithResource(name = "templates/template.html", content = "foo") void createFromConfigClass() { this.contextRunner.withPropertyValues("spring.thymeleaf.suffix:.html").run((context) -> { TemplateEngine engine = context.getBean(TemplateEngine.class); @@ -188,6 +190,7 @@ class ThymeleafReactiveAutoConfigurationTests { } @Test + @WithResource(name = "templates/data-dialect.html", content = "") void useDataDialect() { this.contextRunner.run((context) -> { ISpringWebFluxTemplateEngine engine = context.getBean(ISpringWebFluxTemplateEngine.class); @@ -198,6 +201,8 @@ class ThymeleafReactiveAutoConfigurationTests { } @Test + @WithResource(name = "templates/java8time-dialect.html", + content = "") void useJava8TimeDialect() { this.contextRunner.run((context) -> { ISpringWebFluxTemplateEngine engine = context.getBean(ISpringWebFluxTemplateEngine.class); @@ -208,6 +213,8 @@ class ThymeleafReactiveAutoConfigurationTests { } @Test + @WithResource(name = "templates/security-dialect.html", + content = "
\n") void useSecurityDialect() { this.contextRunner.run((context) -> { ISpringWebFluxTemplateEngine engine = context.getBean(ISpringWebFluxTemplateEngine.class); @@ -229,6 +236,7 @@ class ThymeleafReactiveAutoConfigurationTests { } @Test + @WithResource(name = "templates/home.html", content = "Home") void renderTemplate() { this.contextRunner.run((context) -> { ISpringWebFluxTemplateEngine engine = context.getBean(ISpringWebFluxTemplateEngine.class); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafServletAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafServletAutoConfigurationTests.java index 9f58eefb4a5..47c53001190 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafServletAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafServletAutoConfigurationTests.java @@ -46,6 +46,7 @@ import org.springframework.boot.test.context.runner.WebApplicationContextRunner; import org.springframework.boot.test.system.CapturedOutput; import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.boot.testsupport.BuildOutput; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter; import org.springframework.context.annotation.Bean; @@ -89,6 +90,7 @@ class ThymeleafServletAutoConfigurationTests { } @Test + @WithResource(name = "templates/template.html", content = "foo") void createFromConfigClass() { this.contextRunner.withPropertyValues("spring.thymeleaf.mode:HTML", "spring.thymeleaf.suffix:") .run((context) -> { @@ -184,6 +186,19 @@ class ThymeleafServletAutoConfigurationTests { } @Test + @WithResource(name = "templates/view.html", + content = """ + + + Content + + +
+ foo +
+ + + """) void createLayoutFromConfigClass() { this.contextRunner.run((context) -> { ThymeleafView view = (ThymeleafView) context.getBean(ThymeleafViewResolver.class) @@ -200,6 +215,7 @@ class ThymeleafServletAutoConfigurationTests { } @Test + @WithResource(name = "templates/data-dialect.html", content = "") void useDataDialect() { this.contextRunner.run((context) -> { TemplateEngine engine = context.getBean(TemplateEngine.class); @@ -210,6 +226,8 @@ class ThymeleafServletAutoConfigurationTests { } @Test + @WithResource(name = "templates/java8time-dialect.html", + content = "") void useJava8TimeDialect() { this.contextRunner.run((context) -> { TemplateEngine engine = context.getBean(TemplateEngine.class); @@ -220,6 +238,8 @@ class ThymeleafServletAutoConfigurationTests { } @Test + @WithResource(name = "templates/security-dialect.html", + content = "
\n") void useSecurityDialect() { this.contextRunner.run((context) -> { TemplateEngine engine = context.getBean(TemplateEngine.class); @@ -246,6 +266,7 @@ class ThymeleafServletAutoConfigurationTests { } @Test + @WithResource(name = "templates/home.html", content = "Home") void renderTemplate() { this.contextRunner.run((context) -> { TemplateEngine engine = context.getBean(TemplateEngine.class); @@ -256,6 +277,8 @@ class ThymeleafServletAutoConfigurationTests { } @Test + @WithResource(name = "templates/message.html", + content = "Message: Hello") void renderNonWebAppTemplate() { new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(ThymeleafAutoConfiguration.class)) .run((context) -> { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafTemplateAvailabilityProviderTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafTemplateAvailabilityProviderTests.java index 7861c74fc12..406dc9b104c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafTemplateAvailabilityProviderTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafTemplateAvailabilityProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.thymeleaf; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.ResourceLoader; import org.springframework.mock.env.MockEnvironment; @@ -39,6 +40,7 @@ class ThymeleafTemplateAvailabilityProviderTests { private final MockEnvironment environment = new MockEnvironment(); @Test + @WithResource(name = "templates/home.html") void availabilityOfTemplateInDefaultLocation() { assertThat(this.provider.isTemplateAvailable("home", this.environment, getClass().getClassLoader(), this.resourceLoader)) @@ -53,6 +55,7 @@ class ThymeleafTemplateAvailabilityProviderTests { } @Test + @WithResource(name = "custom-templates/custom.html") void availabilityOfTemplateWithCustomPrefix() { this.environment.setProperty("spring.thymeleaf.prefix", "classpath:/custom-templates/"); assertThat(this.provider.isTemplateAvailable("custom", this.environment, getClass().getClassLoader(), @@ -61,6 +64,7 @@ class ThymeleafTemplateAvailabilityProviderTests { } @Test + @WithResource(name = "templates/suffixed.thymeleaf") void availabilityOfTemplateWithCustomSuffix() { this.environment.setProperty("spring.thymeleaf.suffix", ".thymeleaf"); assertThat(this.provider.isTemplateAvailable("suffixed", this.environment, getClass().getClassLoader(), diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebResourcesRuntimeHintsTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebResourcesRuntimeHintsTests.java index 9c4f337bab6..29cb54d08c5 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebResourcesRuntimeHintsTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebResourcesRuntimeHintsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -17,7 +17,6 @@ package org.springframework.boot.autoconfigure.web; import java.net.URL; -import java.net.URLClassLoader; import java.util.Collections; import java.util.List; import java.util.function.Consumer; @@ -27,6 +26,7 @@ import org.junit.jupiter.api.Test; import org.springframework.aot.hint.ResourcePatternHint; import org.springframework.aot.hint.ResourcePatternHints; import org.springframework.aot.hint.RuntimeHints; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import static org.assertj.core.api.Assertions.assertThat; @@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Stephane Nicoll */ +@WithResource(name = "web/custom-resource.txt") class WebResourcesRuntimeHintsTests { @Test @@ -71,12 +72,12 @@ class WebResourcesRuntimeHintsTests { }; } - private static class TestClassLoader extends URLClassLoader { + private static class TestClassLoader extends ClassLoader { private final List availableResources; TestClassLoader(List availableResources) { - super(new URL[0], TestClassLoader.class.getClassLoader()); + super(Thread.currentThread().getContextClassLoader()); this.availableResources = availableResources; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java index d6127133dcc..d366fb9deb7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -57,6 +57,7 @@ import org.springframework.boot.autoconfigure.web.reactive.WebFluxAutoConfigurat import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.boot.web.codec.CodecCustomizer; import org.springframework.boot.web.reactive.context.ReactiveWebApplicationContext; import org.springframework.boot.web.reactive.filter.OrderedHiddenHttpMethodFilter; @@ -530,6 +531,7 @@ class WebFluxAutoConfigurationTests { } @Test + @WithResource(name = "welcome-page/index.html", content = "welcome-page-static") void welcomePageHandlerMapping() { this.contextRunner.withPropertyValues("spring.web.resources.static-locations=classpath:/welcome-page/") .run((context) -> { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WelcomePageRouterFunctionFactoryTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WelcomePageRouterFunctionFactoryTests.java index 7a464da43e7..996956eede1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WelcomePageRouterFunctionFactoryTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WelcomePageRouterFunctionFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -27,6 +27,7 @@ import reactor.core.publisher.Mono; import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider; import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProviders; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.context.support.StaticApplicationContext; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; @@ -46,6 +47,7 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Brian Clozel */ +@WithResource(name = "welcome-page/index.html", content = "welcome-page-static") class WelcomePageRouterFunctionFactoryTests { private StaticApplicationContext applicationContext; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java index 838055707b7..01c1481f91c 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -22,9 +22,12 @@ import java.util.LinkedHashMap; import java.util.Map; import jakarta.validation.Valid; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import reactor.core.publisher.Mono; +import reactor.core.scheduler.Schedulers; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -39,6 +42,7 @@ import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplic import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; import org.springframework.boot.test.system.CapturedOutput; import org.springframework.boot.test.system.OutputCaptureExtension; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.boot.web.error.ErrorAttributeOptions; import org.springframework.boot.web.error.ErrorAttributeOptions.Include; import org.springframework.boot.web.reactive.error.DefaultErrorAttributes; @@ -88,6 +92,12 @@ class DefaultErrorWebExceptionHandlerIntegrationTests { .withPropertyValues("spring.main.web-application-type=reactive", "server.port=0") .withUserConfiguration(Application.class); + @BeforeEach + @AfterEach + void clearReactorSchedulers() { + Schedulers.shutdownNow(); + } + @Test void jsonError(CapturedOutput output) { this.contextRunner.run((context) -> { @@ -141,7 +151,18 @@ class DefaultErrorWebExceptionHandlerIntegrationTests { } @Test + @WithResource(name = "templates/error/error.mustache", content = """ + + +
    +
  • status: {{status}}
  • +
  • message: {{message}}
  • +
+ + + """) void htmlError() { + Schedulers.shutdownNow(); this.contextRunner.withPropertyValues("server.error.include-message=always").run((context) -> { WebTestClient client = getWebClient(context); String body = client.get() diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerTests.java index 0d368313947..51970676f01 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -24,6 +24,7 @@ import reactor.core.publisher.Mono; import org.springframework.boot.autoconfigure.web.ErrorProperties; import org.springframework.boot.autoconfigure.web.WebProperties.Resources; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext; import org.springframework.boot.web.reactive.error.ErrorAttributes; import org.springframework.context.ApplicationContext; @@ -52,6 +53,16 @@ import static org.mockito.Mockito.mock; class DefaultErrorWebExceptionHandlerTests { @Test + @WithResource(name = "templates/error/error.mustache", content = """ + + +
    +
  • status: {{status}}
  • +
  • message: {{message}}
  • +
+ + + """) void nonStandardErrorStatusCodeShouldNotFail() { ErrorAttributes errorAttributes = mock(ErrorAttributes.class); given(errorAttributes.getErrorAttributes(any(), any())).willReturn(Collections.singletonMap("status", 498)); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/AbstractClientHttpConnectorFactoryTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/AbstractClientHttpConnectorFactoryTests.java index 5210a610287..44f573b737b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/AbstractClientHttpConnectorFactoryTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/AbstractClientHttpConnectorFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -22,6 +22,7 @@ import org.springframework.boot.ssl.SslBundle; import org.springframework.boot.ssl.SslBundleKey; import org.springframework.boot.ssl.jks.JksSslStoreBundle; import org.springframework.boot.ssl.jks.JksSslStoreDetails; +import org.springframework.boot.testsupport.classpath.resources.WithPackageResources; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.server.Ssl; import org.springframework.boot.web.server.Ssl.ClientAuth; @@ -62,6 +63,7 @@ abstract class AbstractClientHttpConnectorFactoryTests { } @Test + @WithPackageResources("test.jks") void secureConnection() throws Exception { TomcatServletWebServerFactory webServerFactory = new TomcatServletWebServerFactory(0); Ssl ssl = new Ssl(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorFactoryConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorFactoryConfigurationTests.java index 5d7fd0fab66..78b02ef97d9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorFactoryConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/function/client/ClientHttpConnectorFactoryConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -25,6 +25,7 @@ import org.springframework.boot.ssl.jks.JksSslStoreBundle; import org.springframework.boot.ssl.jks.JksSslStoreDetails; import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithPackageResources; import org.springframework.context.annotation.Bean; import org.springframework.http.client.reactive.HttpComponentsClientHttpConnector; @@ -42,6 +43,7 @@ import static org.mockito.Mockito.spy; class ClientHttpConnectorFactoryConfigurationTests { @Test + @WithPackageResources("test.jks") void shouldApplyHttpClientMapper() { JksSslStoreDetails storeDetails = JksSslStoreDetails.forLocation("classpath:test.jks"); JksSslStoreBundle stores = new JksSslStoreBundle(storeDetails, storeDetails); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/JspTemplateAvailabilityProviderTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/JspTemplateAvailabilityProviderTests.java index 01ea06f34de..ccb3b7bca59 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/JspTemplateAvailabilityProviderTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/JspTemplateAvailabilityProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-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. @@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.web.servlet; import org.junit.jupiter.api.Test; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.ResourceLoader; import org.springframework.mock.env.MockEnvironment; @@ -43,15 +44,16 @@ class JspTemplateAvailabilityProviderTests { } @Test + @WithResource(name = "custom-templates/custom.jsp") void availabilityOfTemplateWithCustomPrefix() { this.environment.setProperty("spring.mvc.view.prefix", "classpath:/custom-templates/"); assertThat(isTemplateAvailable("custom.jsp")).isTrue(); } @Test + @WithResource(name = "suffixed.java-server-pages") void availabilityOfTemplateWithCustomSuffix() { - this.environment.setProperty("spring.mvc.view.prefix", "classpath:/custom-templates/"); - this.environment.setProperty("spring.mvc.view.suffix", ".jsp"); + this.environment.setProperty("spring.mvc.view.suffix", ".java-server-pages"); assertThat(isTemplateAvailable("suffixed")).isTrue(); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java index 7ccc5e12bff..ee95541b2e3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -57,6 +57,7 @@ import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguratio import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext; import org.springframework.boot.test.context.runner.ContextConsumer; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; import org.springframework.boot.web.server.WebServerFactoryCustomizerBeanPostProcessor; import org.springframework.boot.web.servlet.FilterRegistrationBean; @@ -656,6 +657,7 @@ class WebMvcAutoConfigurationTests { } @Test + @WithResource(name = "welcome-page/index.html", content = "welcome-page-static") void welcomePageHandlerMappingIsAutoConfigured() { this.contextRunner.withPropertyValues("spring.web.resources.static-locations:classpath:/welcome-page/") .run((context) -> { @@ -666,6 +668,7 @@ class WebMvcAutoConfigurationTests { } @Test + @WithResource(name = "welcome-page/index.html", content = "welcome-page-static") void welcomePageHandlerIncludesCorsConfiguration() { this.contextRunner.withPropertyValues("spring.web.resources.static-locations:classpath:/welcome-page/") .withUserConfiguration(CorsConfigurer.class) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WelcomePageHandlerMappingTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WelcomePageHandlerMappingTests.java index 96462cf037b..796bd2afdaf 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WelcomePageHandlerMappingTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WelcomePageHandlerMappingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -16,6 +16,7 @@ package org.springframework.boot.autoconfigure.web.servlet; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.Map; @@ -36,7 +37,7 @@ import org.springframework.boot.test.system.OutputCaptureExtension; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.FileSystemResource; +import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; @@ -200,7 +201,7 @@ class WelcomePageHandlerMappingTests { @Bean Resource staticIndexPage() { - return new FileSystemResource("src/test/resources/welcome-page/index.html"); + return new ByteArrayResource("welcome-page-static".getBytes(StandardCharsets.UTF_8)); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WelcomePageIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WelcomePageIntegrationTests.java index 14fe3858386..a34b15f8bed 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WelcomePageIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WelcomePageIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -41,9 +41,10 @@ import static org.assertj.core.api.Assertions.assertThat; * * @author Madhura Bhave */ -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - properties = { "spring.web.resources.chain.strategy.content.enabled=true", - "spring.thymeleaf.prefix=classpath:/templates/thymeleaf/" }) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = { + "spring.web.resources.chain.strategy.content.enabled=true", + "spring.thymeleaf.prefix=classpath:/org/springframework/boot/autoconfigure/web/servlet/", + "spring.web.resources.static-locations=classpath:/org/springframework/boot/autoconfigure/web/servlet/static" }) class WelcomePageIntegrationTests { @LocalServerPort diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorControllerIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorControllerIntegrationTests.java index 909e5908703..5baf1f67c34 100755 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorControllerIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorControllerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-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. @@ -46,6 +46,7 @@ import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoC import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.boot.web.error.ErrorAttributeOptions; import org.springframework.boot.web.error.ErrorAttributeOptions.Include; import org.springframework.boot.web.servlet.error.ErrorAttributes; @@ -326,6 +327,7 @@ class BasicErrorControllerIntegrationTests { } @Test + @WithResource(name = "templates/error/507.ftlh", content = "We are out of storage") void testConventionTemplateMapping() { load(); RequestEntity request = RequestEntity.get(URI.create(createUrl("/noStorage"))) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfigurationTests.java index 89aed095a37..d00d451819a 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/webservices/WebServicesAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 the original author or authors. + * Copyright 2012-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. @@ -19,10 +19,13 @@ package org.springframework.boot.autoconfigure.webservices; import java.util.Collection; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.BeanCreationException; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.WebApplicationContextRunner; +import org.springframework.boot.testsupport.classpath.resources.WithResource; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.ApplicationContext; import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition; @@ -87,17 +90,67 @@ class WebServicesAutoConfigurationTests { .containsEntry("key2", "value2")); } - @Test - void withWsdlBeans() { - this.contextRunner.withPropertyValues("spring.webservices.wsdl-locations=classpath:/wsdl").run((context) -> { - assertThat(context.getBeansOfType(SimpleWsdl11Definition.class)).containsOnlyKeys("service"); - assertThat(context.getBeansOfType(SimpleXsdSchema.class)).containsOnlyKeys("types"); - }); - } - - @Test - void withWsdlBeansAsList() { - this.contextRunner.withPropertyValues("spring.webservices.wsdl-locations[0]=classpath:/wsdl").run((context) -> { + @ParameterizedTest + @WithResource(name = "wsdl/service.wsdl", content = """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + """) + @WithResource(name = "wsdl/types.xsd", content = """ + + + + + + """) + @ValueSource(strings = { "spring.webservices.wsdl-locations", "spring.webservices.wsdl-locations[0]" }) + void withWsdlBeans(String propertyName) { + this.contextRunner.withPropertyValues(propertyName + "=classpath:/wsdl").run((context) -> { assertThat(context.getBeansOfType(SimpleWsdl11Definition.class)).containsOnlyKeys("service"); assertThat(context.getBeansOfType(SimpleXsdSchema.class)).containsOnlyKeys("types"); }); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/AutoConfigurationMetadataLoaderTests.properties b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/AutoConfigurationMetadataLoaderTests.properties deleted file mode 100644 index 2dc12708cec..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/AutoConfigurationMetadataLoaderTests.properties +++ /dev/null @@ -1,4 +0,0 @@ -test= -test.string=abc -test.int=123 -test.set=a,b,b,c diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/build-info.properties b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/build-info.properties deleted file mode 100644 index c0ad96bbba8..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/build-info.properties +++ /dev/null @@ -1,5 +0,0 @@ -build.group=com.example -build.artifact=demo -build.name=Demo Project -build.version=0.0.1-SNAPSHOT -build.time=2016-03-04T14:16:05.000Z diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/mappings/non-annotated.xml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/mappings/non-annotated.xml deleted file mode 100644 index 3b33b0dff38..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/mappings/non-annotated.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - -
- - - - - - - - - - - diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/persistence.xml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/persistence.xml deleted file mode 100644 index 439d601d8fa..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/persistence.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - org.springframework.boot.autoconfigure.orm.jpa.test.City - true - - diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/spring.integration.properties b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/spring.integration.properties deleted file mode 100644 index 2b2aca228b9..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/spring.integration.properties +++ /dev/null @@ -1 +0,0 @@ -spring.integration.endpoints.noAutoStartup=testService* diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/spring/org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$FromImportsFile.imports b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/spring/org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$FromImportsFile.imports deleted file mode 100644 index 951bbd8f242..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/spring/org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$FromImportsFile.imports +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$ImportedAutoConfiguration -org.springframework.boot.autoconfigure.missing.MissingAutoConfiguration \ No newline at end of file diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/spring/org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$FromImportsFileIgnoresMissingOptionalClasses.imports b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/spring/org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$FromImportsFileIgnoresMissingOptionalClasses.imports deleted file mode 100644 index c76445a839e..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/spring/org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$FromImportsFileIgnoresMissingOptionalClasses.imports +++ /dev/null @@ -1,3 +0,0 @@ -optional:org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$ImportedAutoConfiguration -optional:org.springframework.boot.autoconfigure.missing.MissingAutoConfiguration -org.springframework.boot.autoconfigure.ImportAutoConfigurationImportSelectorTests$AnotherImportedAutoConfiguration \ No newline at end of file diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/application.properties b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/application.properties deleted file mode 100644 index a8d63792d0b..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -foo: bucket diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/cache/ehcache-override.xml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/cache/ehcache-override.xml deleted file mode 100644 index e902bdeba15..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/cache/ehcache-override.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/city.sql b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/city.sql deleted file mode 100644 index eb08623b4cf..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/city.sql +++ /dev/null @@ -1 +0,0 @@ -INSERT INTO CITY (ID, NAME, STATE, COUNTRY, MAP) values (2000, 'Washington', 'DC', 'US', 'Google'); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-schema-sample.ldif b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-schema-sample.ldif deleted file mode 100644 index 91159a86b0f..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-schema-sample.ldif +++ /dev/null @@ -1,7 +0,0 @@ -dn: dc=spring,dc=org -objectclass: top -objectclass: domain -objectclass: extensibleObject -objectClass: exampleAuxiliaryClass -dc: spring -exampleAttributeName: exampleAttributeName diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-schema.ldif b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-schema.ldif deleted file mode 100644 index ca6a82170d1..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-schema.ldif +++ /dev/null @@ -1,17 +0,0 @@ -dn: cn=schema -attributeTypes: ( 1.3.6.1.4.1.32473.1.1.1 - NAME 'exampleAttributeName' - DESC 'An example attribute type definition' - EQUALITY caseIgnoreMatch - ORDERING caseIgnoreOrderingMatch - SUBSTR caseIgnoreSubstringsMatch - SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 - SINGLE-VALUE - X-ORIGIN 'Managing Schema Document' ) -objectClasses: ( 1.3.6.1.4.1.32473.1.2.2 - NAME 'exampleAuxiliaryClass' - DESC 'An example auxiliary object class definition' - SUP top - AUXILIARY - MAY exampleAttributeName - X-ORIGIN 'Managing Schema Document' ) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/custom.ftlh b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/custom.ftlh deleted file mode 100644 index 0d82d79c85d..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/custom.ftlh +++ /dev/null @@ -1 +0,0 @@ -custom diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/custom.html b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/custom.html deleted file mode 100644 index 8b137891791..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/custom.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/custom.tpl b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/custom.tpl deleted file mode 100644 index cd07d3d3c64..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/custom.tpl +++ /dev/null @@ -1 +0,0 @@ -yield "custom" diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/custom.vm b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/custom.vm deleted file mode 100644 index 0d82d79c85d..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/custom.vm +++ /dev/null @@ -1 +0,0 @@ -custom diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/suffixed.jsp b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/custom-templates/suffixed.jsp deleted file mode 100755 index e69de29bb2d..00000000000 diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/data-city-schema.sql b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/data-city-schema.sql deleted file mode 100644 index b2a4112add9..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/data-city-schema.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE CITY ( - id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, - name VARCHAR(30), - state VARCHAR(30), - country VARCHAR(30), - map VARCHAR(30) -); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/data.sql b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/data.sql deleted file mode 100644 index 487614d4409..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/data.sql +++ /dev/null @@ -1 +0,0 @@ -INSERT INTO BAR VALUES (1, 'Andy'); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-city.yaml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-city.yaml deleted file mode 100644 index c46dc1dacbf..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-city.yaml +++ /dev/null @@ -1,38 +0,0 @@ -databaseChangeLog: - - changeSet: - id: 1 - author: dsyer - changes: - - createSequence: - sequenceName: city_seq - incrementBy: 50 - - createTable: - tableName: city - columns: - - column: - name: id - type: bigint - autoIncrement: true - constraints: - primaryKey: true - nullable: false - - column: - name: name - type: varchar(50) - constraints: - nullable: false - - column: - name: state - type: varchar(50) - constraints: - nullable: false - - column: - name: country - type: varchar(50) - constraints: - nullable: false - - column: - name: map - type: varchar(50) - constraints: - nullable: true diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-master.yaml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-master.yaml deleted file mode 100644 index 134b17b543e..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-master.yaml +++ /dev/null @@ -1,20 +0,0 @@ -databaseChangeLog: - - changeSet: - id: 1 - author: marceloverdijk - changes: - - createTable: - tableName: customer - columns: - - column: - name: id - type: int - autoIncrement: true - constraints: - primaryKey: true - nullable: false - - column: - name: name - type: varchar(50) - constraints: - nullable: false diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.json b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.json deleted file mode 100644 index acaa0e21184..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "databaseChangeLog": [ - { - "changeSet": { - "author": "awilkinson", - "id": "1", - "changes": [ - { - "createTable": { - "tableName": "customer", - "columns": [ - { - "column": { - "name": "id", - "type": "int", - "autoIncrement": true, - "constraints": { - "nullable": false, - "primaryKey": true - } - } - }, - { - "column": { - "name": "name", - "type": "varchar(50)", - "constraints": { - "nullable": false - } - } - } - ] - } - } - ] - } - } - ] -} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.sql b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.sql deleted file mode 100644 index cd68b45850a..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.sql +++ /dev/null @@ -1,8 +0,0 @@ ---liquibase formatted sql - ---changeset author:awilkinson - -CREATE TABLE customer ( - id int AUTO_INCREMENT NOT NULL PRIMARY KEY, - name varchar(50) NOT NULL -); \ No newline at end of file diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.xml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.xml deleted file mode 100644 index 77c318e5823..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/changelog/db.changelog-override.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/city/V1__init.sql b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/city/V1__init.sql deleted file mode 100644 index 571f6fa46eb..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/city/V1__init.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE SEQUENCE city_seq INCREMENT BY 50; - -CREATE TABLE CITY ( - id BIGINT GENERATED BY DEFAULT AS IDENTITY, - name VARCHAR(30), - state VARCHAR(30), - country VARCHAR(30), - map VARCHAR(30) -); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/migration/V1__init.sql b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/migration/V1__init.sql deleted file mode 100644 index 867c7c24f52..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/migration/V1__init.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS TEST; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/non-annotated-data.sql b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/non-annotated-data.sql deleted file mode 100644 index b741d23ccf8..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/non-annotated-data.sql +++ /dev/null @@ -1 +0,0 @@ -INSERT INTO NON_ANNOTATED (id, item) values (2000, 'Test'); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/vendors/h2/V1__init.sql b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/vendors/h2/V1__init.sql deleted file mode 100644 index 867c7c24f52..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/db/vendors/h2/V1__init.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE IF EXISTS TEST; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/ehcache.xml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/ehcache.xml deleted file mode 100644 index f3653ed7891..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/ehcache.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/ehcache3.xml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/ehcache3.xml deleted file mode 100644 index 5f048f21863..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/ehcache3.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - 200 - - - - - 600 - - - - - - - 400 - - - - diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/graphql/schema.graphqls b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/graphql/schema.graphqls deleted file mode 100644 index dc80e899dd8..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/graphql/schema.graphqls +++ /dev/null @@ -1,9 +0,0 @@ -type Query { - greeting(name: String! = "Spring"): String! - bookById(id: ID): Book - books: BookConnection -} - -type Subscription { - booksOnSale(minPages: Int) : Book! -} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/graphql/types/book.graphqls b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/graphql/types/book.graphqls deleted file mode 100644 index 16217d759b1..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/graphql/types/book.graphqls +++ /dev/null @@ -1,6 +0,0 @@ -type Book { - id: ID - name: String - pageCount: Int - author: String -} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/graphql/types/person.custom b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/graphql/types/person.custom deleted file mode 100644 index 8cff728ad18..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/graphql/types/person.custom +++ /dev/null @@ -1,4 +0,0 @@ -type Person { - id: ID - name: String -} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/hazelcast.xml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/hazelcast.xml deleted file mode 100644 index cd699391185..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/hazelcast.xml +++ /dev/null @@ -1,12 +0,0 @@ - - default-instance - - - - - - - - diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/hazelcast.yaml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/hazelcast.yaml deleted file mode 100644 index 686d75638a9..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/hazelcast.yaml +++ /dev/null @@ -1,7 +0,0 @@ -hazelcast: - network: - join: - auto-detection: - enabled: false - multicast: - enabled: false diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/hazelcast.yml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/hazelcast.yml deleted file mode 100644 index 686d75638a9..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/hazelcast.yml +++ /dev/null @@ -1,7 +0,0 @@ -hazelcast: - network: - join: - auto-detection: - enabled: false - multicast: - enabled: false diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/infinispan.xml b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/infinispan.xml deleted file mode 100644 index 55f7b2ec2df..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/infinispan.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/ksLoc b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/ksLoc deleted file mode 100644 index 696f2109e66..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/ksLoc +++ /dev/null @@ -1 +0,0 @@ -Test file for Kafka. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/ksLocP b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/ksLocP deleted file mode 100644 index 696f2109e66..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/ksLocP +++ /dev/null @@ -1 +0,0 @@ -Test file for Kafka. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/logging.properties b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/logging.properties deleted file mode 100644 index b69c75b0382..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/logging.properties +++ /dev/null @@ -1,5 +0,0 @@ -# Enable this by setting -Djava.util.logging.config.file=src/test/resources/logging.properties -handlers = java.util.logging.ConsoleHandler -.level = INFO -java.util.logging.ConsoleHandler.level = FINE -org.springframework.security.level = ALL diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/batch/custom-schema.sql b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/batch/custom-schema.sql similarity index 100% rename from spring-boot-project/spring-boot-autoconfigure/src/test/resources/batch/custom-schema.sql rename to spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/batch/custom-schema.sql diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/rsocket/test.jks b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/cassandra/test.jks similarity index 100% rename from spring-boot-project/spring-boot-autoconfigure/src/test/resources/rsocket/test.jks rename to spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/cassandra/test.jks diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/test.jks b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/couchbase/test.jks similarity index 100% rename from spring-boot-project/spring-boot-autoconfigure/src/test/resources/test.jks rename to spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/couchbase/test.jks diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/data/redis/test.jks b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/data/redis/test.jks new file mode 100644 index 0000000000000000000000000000000000000000..0fc3e802f75461dd074facb9611d350db4d5960f GIT binary patch literal 1276 zcmezO_TO6u1_mZ5W@O+hNi8nXP0YzmEM{O}OjTL=XFE`?-k{cikBv*4jgf^>i%F1? zk(GfZ`?F{4vBFug6<%MmmXJ+)mEgQoslXV6!5_H^yana6V1?kw1w zbE0Bi&GHlLHzfosgjrwL)qKcc5I;l0LF?W2lpQg%-cHp$l(#o)?Jkath1@gQN{hG8 zig@wKv#0R7vd_QC=JG%%Ffy=4=$RT=0v*d`(8R=M(8RcU0W%XL6BCP-)w&Y~JZv0V zZ64=rS(uqv84M~6g$xAPm_u3EggJBalM{0?@{3DgVjNh+*s+LlVG-lTBF2m)W*{fd zYiMC$VQ64zW@K(?5e4L0B5?=MWswHLZ0z7LVq$~_7BeF|vl9agPmO-znfkD()@R+bGrT$(AXmN24#zv*XRX z#$UNu(Lmln78u;Jd@N!tBKmU@J0!OJc3G%!N>OO@P1n+F-CorAVRmOQaA8six!iWP z)M3lXpnJ*TI=kIlH(Yxia-ls?xvctEx&P5B6()tKm`>%bo~@fX9{j%TtMU1G!|pw& zZ6BRjIqQ^`bIxR@OmMno&8^H%tpq36Esh&T(+MJ_la+#pV>+3scS%i%F1? zk(GfZ`?F{4vBFug6<%MmmXJ+)mEgQoslXV6!5_H^yana6V1?kw1w zbE0Bi&GHlLHzfosgjrwL)qKcc5I;l0LF?W2lpQg%-cHp$l(#o)?Jkath1@gQN{hG8 zig@wKv#0R7vd_QC=JG%%Ffy=4=$RT=0v*d`(8R=M(8RcU0W%XL6BCP-)w&Y~JZv0V zZ64=rS(uqv84M~6g$xAPm_u3EggJBalM{0?@{3DgVjNh+*s+LlVG-lTBF2m)W*{fd zYiMC$VQ64zW@K(?5e4L0B5?=MWswHLZ0z7LVq$~_7BeF|vl9agPmO-znfkD()@R+bGrT$(AXmN24#zv*XRX z#$UNu(Lmln78u;Jd@N!tBKmU@J0!OJc3G%!N>OO@P1n+F-CorAVRmOQaA8six!iWP z)M3lXpnJ*TI=kIlH(Yxia-ls?xvctEx&P5B6()tKm`>%bo~@fX9{j%TtMU1G!|pw& zZ6BRjIqQ^`bIxR@OmMno&8^H%tpq36Esh&T(+MJ_la+#pV>+3scS%i%F1? zk(GfZ`?F{4vBFug6<%MmmXJ+)mEgQoslXV6!5_H^yana6V1?kw1w zbE0Bi&GHlLHzfosgjrwL)qKcc5I;l0LF?W2lpQg%-cHp$l(#o)?Jkath1@gQN{hG8 zig@wKv#0R7vd_QC=JG%%Ffy=4=$RT=0v*d`(8R=M(8RcU0W%XL6BCP-)w&Y~JZv0V zZ64=rS(uqv84M~6g$xAPm_u3EggJBalM{0?@{3DgVjNh+*s+LlVG-lTBF2m)W*{fd zYiMC$VQ64zW@K(?5e4L0B5?=MWswHLZ0z7LVq$~_7BeF|vl9agPmO-znfkD()@R+bGrT$(AXmN24#zv*XRX z#$UNu(Lmln78u;Jd@N!tBKmU@J0!OJc3G%!N>OO@P1n+F-CorAVRmOQaA8six!iWP z)M3lXpnJ*TI=kIlH(Yxia-ls?xvctEx&P5B6()tKm`>%bo~@fX9{j%TtMU1G!|pw& zZ6BRjIqQ^`bIxR@OmMno&8^H%tpq36Esh&T(+MJ_la+#pV>+3scS%i%F1? zk(GfZ`?F{4vBFug6<%MmmXJ+)mEgQoslXV6!5_H^yana6V1?kw1w zbE0Bi&GHlLHzfosgjrwL)qKcc5I;l0LF?W2lpQg%-cHp$l(#o)?Jkath1@gQN{hG8 zig@wKv#0R7vd_QC=JG%%Ffy=4=$RT=0v*d`(8R=M(8RcU0W%XL6BCP-)w&Y~JZv0V zZ64=rS(uqv84M~6g$xAPm_u3EggJBalM{0?@{3DgVjNh+*s+LlVG-lTBF2m)W*{fd zYiMC$VQ64zW@K(?5e4L0B5?=MWswHLZ0z7LVq$~_7BeF|vl9agPmO-znfkD()@R+bGrT$(AXmN24#zv*XRX z#$UNu(Lmln78u;Jd@N!tBKmU@J0!OJc3G%!N>OO@P1n+F-CorAVRmOQaA8six!iWP z)M3lXpnJ*TI=kIlH(Yxia-ls?xvctEx&P5B6()tKm`>%bo~@fX9{j%TtMU1G!|pw& zZ6BRjIqQ^`bIxR@OmMno&8^H%tpq36Esh&T(+MJ_la+#pV>+3scS%i%F1? zk(GfZ`?F{4vBFug6<%MmmXJ+)mEgQoslXV6!5_H^yana6V1?kw1w zbE0Bi&GHlLHzfosgjrwL)qKcc5I;l0LF?W2lpQg%-cHp$l(#o)?Jkath1@gQN{hG8 zig@wKv#0R7vd_QC=JG%%Ffy=4=$RT=0v*d`(8R=M(8RcU0W%XL6BCP-)w&Y~JZv0V zZ64=rS(uqv84M~6g$xAPm_u3EggJBalM{0?@{3DgVjNh+*s+LlVG-lTBF2m)W*{fd zYiMC$VQ64zW@K(?5e4L0B5?=MWswHLZ0z7LVq$~_7BeF|vl9agPmO-znfkD()@R+bGrT$(AXmN24#zv*XRX z#$UNu(Lmln78u;Jd@N!tBKmU@J0!OJc3G%!N>OO@P1n+F-CorAVRmOQaA8six!iWP z)M3lXpnJ*TI=kIlH(Yxia-ls?xvctEx&P5B6()tKm`>%bo~@fX9{j%TtMU1G!|pw& zZ6BRjIqQ^`bIxR@OmMno&8^H%tpq36Esh&T(+MJ_la+#pV>+3scS%i%F1? zk(GfZ`?F{4vBFug6<%MmmXJ+)mEgQoslXV6!5_H^yana6V1?kw1w zbE0Bi&GHlLHzfosgjrwL)qKcc5I;l0LF?W2lpQg%-cHp$l(#o)?Jkath1@gQN{hG8 zig@wKv#0R7vd_QC=JG%%Ffy=4=$RT=0v*d`(8R=M(8RcU0W%XL6BCP-)w&Y~JZv0V zZ64=rS(uqv84M~6g$xAPm_u3EggJBalM{0?@{3DgVjNh+*s+LlVG-lTBF2m)W*{fd zYiMC$VQ64zW@K(?5e4L0B5?=MWswHLZ0z7LVq$~_7BeF|vl9agPmO-znfkD()@R+bGrT$(AXmN24#zv*XRX z#$UNu(Lmln78u;Jd@N!tBKmU@J0!OJc3G%!N>OO@P1n+F-CorAVRmOQaA8six!iWP z)M3lXpnJ*TI=kIlH(Yxia-ls?xvctEx&P5B6()tKm`>%bo~@fX9{j%TtMU1G!|pw& zZ6BRjIqQ^`bIxR@OmMno&8^H%tpq36Esh&T(+MJ_la+#pV>+3scS% diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/error/507.ftlh b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/error/507.ftlh deleted file mode 100644 index a562b8fe9cf..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/error/507.ftlh +++ /dev/null @@ -1 +0,0 @@ -We are out of storage diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/error/error.mustache b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/error/error.mustache deleted file mode 100644 index c29c825d826..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/error/error.mustache +++ /dev/null @@ -1,8 +0,0 @@ - - -
    -
  • status: {{status}}
  • -
  • message: {{message}}
  • -
- - diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/home.ftlh b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/home.ftlh deleted file mode 100644 index 5e72f75cb40..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/home.ftlh +++ /dev/null @@ -1 +0,0 @@ -home diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/home.html b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/home.html deleted file mode 100644 index d8a1185cc01..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/home.html +++ /dev/null @@ -1 +0,0 @@ -Home diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/home.tpl b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/home.tpl deleted file mode 100644 index eb07ff6f939..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/home.tpl +++ /dev/null @@ -1 +0,0 @@ -yield "home" \ No newline at end of file diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/home.vm b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/home.vm deleted file mode 100644 index 5e72f75cb40..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/home.vm +++ /dev/null @@ -1 +0,0 @@ -home diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/included.tpl b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/included.tpl deleted file mode 100644 index a1bbaa02e9a..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/included.tpl +++ /dev/null @@ -1 +0,0 @@ -yield "here" \ No newline at end of file diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/included_fr.tpl b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/included_fr.tpl deleted file mode 100644 index 035e2e95759..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/included_fr.tpl +++ /dev/null @@ -1 +0,0 @@ -yield "voila" \ No newline at end of file diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/includes.tpl b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/includes.tpl deleted file mode 100644 index 9ea4039123d..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/includes.tpl +++ /dev/null @@ -1,2 +0,0 @@ -yield "include" -include template: "included.tpl" \ No newline at end of file diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/java8time-dialect.html b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/java8time-dialect.html deleted file mode 100644 index 2c2bce877b2..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/java8time-dialect.html +++ /dev/null @@ -1 +0,0 @@ - diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/layout.html b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/layout.html deleted file mode 100644 index 57add3758e6..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/layout.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - Layout - - -
-

Layout

-
- Fake content -
-
- - diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/message.ftlh b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/message.ftlh deleted file mode 100644 index b3992342b27..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/message.ftlh +++ /dev/null @@ -1 +0,0 @@ -Message: ${greeting} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/message.html b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/message.html deleted file mode 100644 index ba236128ec2..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/message.html +++ /dev/null @@ -1 +0,0 @@ -Message: Hello diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/message.tpl b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/message.tpl deleted file mode 100644 index 6a9df3b50d1..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/message.tpl +++ /dev/null @@ -1 +0,0 @@ -yield "Message: ${greeting}" \ No newline at end of file diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/message.vm b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/message.vm deleted file mode 100644 index b3992342b27..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/message.vm +++ /dev/null @@ -1 +0,0 @@ -Message: ${greeting} diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/prefix/prefixed.ftlh b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/prefix/prefixed.ftlh deleted file mode 100644 index 278ed403330..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/prefix/prefixed.ftlh +++ /dev/null @@ -1 +0,0 @@ -prefixed diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/prefix/prefixed.tpl b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/prefix/prefixed.tpl deleted file mode 100644 index 05426ef6995..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/prefix/prefixed.tpl +++ /dev/null @@ -1 +0,0 @@ -yield "prefixed" diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/prefix/prefixed.vm b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/prefix/prefixed.vm deleted file mode 100644 index 278ed403330..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/prefix/prefixed.vm +++ /dev/null @@ -1 +0,0 @@ -prefixed diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/security-dialect.html b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/security-dialect.html deleted file mode 100644 index a22a79e6073..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/security-dialect.html +++ /dev/null @@ -1 +0,0 @@ -
diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/suffixed.freemarker b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/suffixed.freemarker deleted file mode 100644 index cfe8d439ab1..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/suffixed.freemarker +++ /dev/null @@ -1 +0,0 @@ -suffixed diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/suffixed.groovytemplate b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/suffixed.groovytemplate deleted file mode 100644 index 3539f6d6f4a..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/suffixed.groovytemplate +++ /dev/null @@ -1,3 +0,0 @@ -yield """ -suffixed -""" \ No newline at end of file diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/suffixed.thymeleaf b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/suffixed.thymeleaf deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/template.html b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/template.html deleted file mode 100644 index 123f6966f70..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/template.html +++ /dev/null @@ -1 +0,0 @@ -foo diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/view.html b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/view.html deleted file mode 100644 index 4ff0e133524..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/templates/view.html +++ /dev/null @@ -1,10 +0,0 @@ - - - Content - - -
- foo -
- - diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/test/messages.properties b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/test/messages.properties deleted file mode 100644 index 74d0a43fccf..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/test/messages.properties +++ /dev/null @@ -1 +0,0 @@ -foo=bar diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/test/messages2.properties b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/test/messages2.properties deleted file mode 100644 index 46858857b99..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/test/messages2.properties +++ /dev/null @@ -1 +0,0 @@ -foo-foo=bar-bar diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/test/swedish.properties b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/test/swedish.properties deleted file mode 100644 index 9a876aade96..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/test/swedish.properties +++ /dev/null @@ -1 +0,0 @@ -foo=Some text with some swedish öäå! diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/tsLoc b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/tsLoc deleted file mode 100644 index 696f2109e66..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/tsLoc +++ /dev/null @@ -1 +0,0 @@ -Test file for Kafka. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/tsLocP b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/tsLocP deleted file mode 100644 index 696f2109e66..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/tsLocP +++ /dev/null @@ -1 +0,0 @@ -Test file for Kafka. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/web/custom-resource.txt b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/web/custom-resource.txt deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/welcome-page/index.html b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/welcome-page/index.html deleted file mode 100644 index 10babc65119..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/welcome-page/index.html +++ /dev/null @@ -1 +0,0 @@ -welcome-page-static \ No newline at end of file diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/wsdl/service.wsdl b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/wsdl/service.wsdl deleted file mode 100644 index ec828428ace..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/wsdl/service.wsdl +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/wsdl/types.xsd b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/wsdl/types.xsd deleted file mode 100644 index dc559d26b73..00000000000 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/wsdl/types.xsd +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/FilteredClassLoader.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/FilteredClassLoader.java index 39d498e642c..e92455173ae 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/FilteredClassLoader.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/FilteredClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-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. @@ -53,6 +53,16 @@ public class FilteredClassLoader extends URLClassLoader implements SmartClassLoa this(Collections.singleton(ClassFilter.of(hiddenClasses)), Collections.emptyList()); } + /** + * Create a {@link FilteredClassLoader} with the given {@code parent} that hides the + * given classes. + * @param parent the parent class loader + * @param hiddenClasses the classes to hide + */ + public FilteredClassLoader(ClassLoader parent, Class... hiddenClasses) { + this(parent, Collections.singleton(ClassFilter.of(hiddenClasses)), Collections.emptyList()); + } + /** * Create a {@link FilteredClassLoader} that hides classes from the given packages. * @param hiddenPackages the packages to hide @@ -86,7 +96,12 @@ public class FilteredClassLoader extends URLClassLoader implements SmartClassLoa private FilteredClassLoader(Collection> classesFilters, Collection> resourcesFilters) { - super(new URL[0], FilteredClassLoader.class.getClassLoader()); + this(FilteredClassLoader.class.getClassLoader(), classesFilters, resourcesFilters); + } + + private FilteredClassLoader(ClassLoader parent, Collection> classesFilters, + Collection> resourcesFilters) { + super(new URL[0], parent); this.classesFilters = classesFilters; this.resourcesFilters = resourcesFilters; }