diff --git a/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureRules.java b/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureRules.java index 7630e045a09..9487c293dd4 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureRules.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/architecture/ArchitectureRules.java @@ -80,6 +80,8 @@ final class ArchitectureRules { private static final String AUTOCONFIGURATION_ANNOTATION = "org.springframework.boot.autoconfigure.AutoConfiguration"; + private static final String TEST_AUTOCONFIGURATION_ANNOTATION = "org.springframework.boot.test.autoconfigure.TestAutoConfiguration"; + private ArchitectureRules() { } @@ -112,6 +114,7 @@ final class ArchitectureRules { rules.add(allConfigurationPropertiesBindingBeanMethodsShouldBeStatic()); rules.add(autoConfigurationClassesShouldBePublicAndFinal()); rules.add(autoConfigurationClassesShouldHaveNoPublicMembers()); + rules.add(testAutoConfigurationClassesShouldBePackagePrivateAndFinal()); return List.copyOf(rules); } @@ -358,8 +361,7 @@ final class ArchitectureRules { private static ArchRule autoConfigurationClassesShouldBePublicAndFinal() { return ArchRuleDefinition.classes() - .that() - .areAnnotatedWith(AUTOCONFIGURATION_ANNOTATION) + .that(areRegularAutoConfiguration()) .should() .bePublic() .andShould() @@ -370,8 +372,7 @@ final class ArchitectureRules { private static ArchRule autoConfigurationClassesShouldHaveNoPublicMembers() { return ArchRuleDefinition.members() .that() - .areDeclaredInClassesThat() - .areAnnotatedWith(AUTOCONFIGURATION_ANNOTATION) + .areDeclaredInClassesThat(areRegularAutoConfiguration()) .and(areNotDefaultConstructors()) .and(areNotConstants()) .and(dontOverridePublicMethods()) @@ -380,6 +381,24 @@ final class ArchitectureRules { .allowEmptyShould(true); } + private static ArchRule testAutoConfigurationClassesShouldBePackagePrivateAndFinal() { + return ArchRuleDefinition.classes() + .that() + .areAnnotatedWith(TEST_AUTOCONFIGURATION_ANNOTATION) + .should() + .bePackagePrivate() + .andShould() + .haveModifier(JavaModifier.FINAL) + .allowEmptyShould(true); + } + + private static DescribedPredicate areRegularAutoConfiguration() { + return DescribedPredicate.describe("Regular @AutoConfiguration", + (javaClass) -> javaClass.isMetaAnnotatedWith(AUTOCONFIGURATION_ANNOTATION) + && !javaClass.isMetaAnnotatedWith(TEST_AUTOCONFIGURATION_ANNOTATION) + && !javaClass.isAnnotation()); + } + private static DescribedPredicate dontOverridePublicMethods() { OverridesPublicMethod predicate = new OverridesPublicMethod<>(); return DescribedPredicate.describe("don't override public methods", (member) -> !predicate.test(member)); diff --git a/core/spring-boot-test-autoconfigure/build.gradle b/core/spring-boot-test-autoconfigure/build.gradle index c63889f7526..1fb96603afa 100644 --- a/core/spring-boot-test-autoconfigure/build.gradle +++ b/core/spring-boot-test-autoconfigure/build.gradle @@ -28,6 +28,7 @@ dependencies { compileOnly("org.mockito:mockito-core") optional(project(":core:spring-boot-autoconfigure")) + optional("jakarta.json.bind:jakarta.json.bind-api") optional("org.junit.jupiter:junit-jupiter-api") testImplementation(project(":test-support:spring-boot-test-support")) diff --git a/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/TestAutoConfiguration.java b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/TestAutoConfiguration.java new file mode 100644 index 00000000000..40c9741ff59 --- /dev/null +++ b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/TestAutoConfiguration.java @@ -0,0 +1,80 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.test.autoconfigure; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.AliasFor; + +/** + * Indicates that a class provides configuration that can be automatically applied by + * Spring Boot tests. Test Auto-configuration classes are regular + * {@link AutoConfiguration @AutoConfiguration} classes but may be package-private. + * + * @author Phillip Webb + * @see AutoConfiguration + * @since 4.0.0 + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Configuration(proxyBeanMethods = false) +@AutoConfiguration +public @interface TestAutoConfiguration { + + /** + * Alias for {@link AutoConfiguration#value()}. + * @return the aliased value + */ + @AliasFor(annotation = AutoConfiguration.class) + String value() default ""; + + /** + * Alias for {@link AutoConfiguration#before()}. + * @return the aliased value + */ + @AliasFor(annotation = AutoConfiguration.class) + Class[] before() default {}; + + /** + * Alias for {@link AutoConfiguration#beforeName()}. + * @return the aliased value + */ + @AliasFor(annotation = AutoConfiguration.class) + String[] beforeName() default {}; + + /** + * Alias for {@link AutoConfiguration#after()}. + * @return the aliased value + */ + @AliasFor(annotation = AutoConfiguration.class) + Class[] after() default {}; + + /** + * Alias for {@link AutoConfiguration#afterName()}. + * @return the aliased value + */ + @AliasFor(annotation = AutoConfiguration.class) + String[] afterName() default {}; + +} diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/AutoConfigureJson.java b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/AutoConfigureJson.java similarity index 94% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/AutoConfigureJson.java rename to core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/AutoConfigureJson.java index a573fe70c64..f44347a28a8 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/AutoConfigureJson.java +++ b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/AutoConfigureJson.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test.autoconfigure; +package org.springframework.boot.test.autoconfigure.json; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; @@ -31,7 +31,7 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration; * annotation directly. * * @author Phillip Webb - * @since 4.0.0 + * @since 1.4.0 * @see JsonTest */ @Target(ElementType.TYPE) diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/AutoConfigureJsonTesters.java b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/AutoConfigureJsonTesters.java similarity index 84% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/AutoConfigureJsonTesters.java rename to core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/AutoConfigureJsonTesters.java index 7357f8ae368..aa862df3d82 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/AutoConfigureJsonTesters.java +++ b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/AutoConfigureJsonTesters.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test.autoconfigure; +package org.springframework.boot.test.autoconfigure.json; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; @@ -24,18 +24,18 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.json.test.BasicJsonTester; -import org.springframework.boot.json.test.GsonTester; -import org.springframework.boot.json.test.JacksonTester; -import org.springframework.boot.json.test.JsonbTester; import org.springframework.boot.test.context.PropertyMapping; +import org.springframework.boot.test.json.BasicJsonTester; +import org.springframework.boot.test.json.GsonTester; +import org.springframework.boot.test.json.JacksonTester; +import org.springframework.boot.test.json.JsonbTester; /** * Annotation that can be applied to a test class to enable and configure * auto-configuration of JSON testers. * * @author Phillip Webb - * @since 4.0.0 + * @since 1.4.0 */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) diff --git a/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/ConditionalOnJsonTesters.java b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/ConditionalOnJsonTesters.java new file mode 100644 index 00000000000..2d2381d0a1a --- /dev/null +++ b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/ConditionalOnJsonTesters.java @@ -0,0 +1,42 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.test.autoconfigure.json; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.context.annotation.Conditional; + +/** + * {@link Conditional @Conditional} that checks if JSON testers are enabled. + * + * @author Phillip Webb + * @since 4.0.0 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE, ElementType.METHOD }) +@Documented +@ConditionalOnBooleanProperty("spring.test.jsontesters.enabled") +@ConditionalOnClass(name = "org.assertj.core.api.Assert") +public @interface ConditionalOnJsonTesters { + +} diff --git a/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonMarshalTesterRuntimeHints.java b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonMarshalTesterRuntimeHints.java new file mode 100644 index 00000000000..c2a2bc6b041 --- /dev/null +++ b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonMarshalTesterRuntimeHints.java @@ -0,0 +1,57 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.test.autoconfigure.json; + +import java.lang.reflect.Method; + +import org.jspecify.annotations.Nullable; + +import org.springframework.aot.hint.ExecutableMode; +import org.springframework.aot.hint.MemberCategory; +import org.springframework.aot.hint.ReflectionHints; +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.boot.test.json.AbstractJsonMarshalTester; +import org.springframework.core.ResolvableType; +import org.springframework.util.Assert; +import org.springframework.util.ReflectionUtils; + +/** + * Base class for {@link AbstractJsonMarshalTester} runtime hints. + * + * @author Phillip Webb + * @since 4.0.0 + */ +@SuppressWarnings("rawtypes") +public abstract class JsonMarshalTesterRuntimeHints implements RuntimeHintsRegistrar { + + private final Class tester; + + protected JsonMarshalTesterRuntimeHints(Class tester) { + this.tester = tester; + } + + @Override + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { + ReflectionHints reflection = hints.reflection(); + reflection.registerType(this.tester, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); + Method method = ReflectionUtils.findMethod(this.tester, "initialize", Class.class, ResolvableType.class); + Assert.state(method != null, "'method' must not be null"); + reflection.registerMethod(method, ExecutableMode.INVOKE); + } + +} diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/JsonTest.java b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTest.java similarity index 94% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/JsonTest.java rename to core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTest.java index a03a51ae990..4780ad88f40 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/JsonTest.java +++ b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTest.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test.autoconfigure; +package org.springframework.boot.test.autoconfigure.json; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; @@ -27,11 +27,11 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.json.test.GsonTester; -import org.springframework.boot.json.test.JacksonTester; -import org.springframework.boot.json.test.JsonbTester; import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; import org.springframework.boot.test.context.filter.annotation.TypeExcludeFilters; +import org.springframework.boot.test.json.GsonTester; +import org.springframework.boot.test.json.JacksonTester; +import org.springframework.boot.test.json.JsonbTester; import org.springframework.context.annotation.ComponentScan.Filter; import org.springframework.core.annotation.AliasFor; import org.springframework.core.env.Environment; @@ -64,7 +64,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; * @author Artsiom Yudovin * @see AutoConfigureJson * @see AutoConfigureJsonTesters - * @since 4.0.0 + * @since 1.4.0 */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/JsonTestContextBootstrapper.java b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestContextBootstrapper.java similarity index 94% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/JsonTestContextBootstrapper.java rename to core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestContextBootstrapper.java index 9f059d13006..07680f40079 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/JsonTestContextBootstrapper.java +++ b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestContextBootstrapper.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test.autoconfigure; +package org.springframework.boot.test.autoconfigure.json; import org.springframework.boot.test.autoconfigure.TestSliceTestContextBootstrapper; import org.springframework.test.context.TestContextBootstrapper; diff --git a/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTesterFactoryBean.java b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTesterFactoryBean.java new file mode 100644 index 00000000000..7106f3e9528 --- /dev/null +++ b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTesterFactoryBean.java @@ -0,0 +1,75 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.test.autoconfigure.json; + +import java.lang.reflect.Constructor; + +import org.jspecify.annotations.Nullable; + +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.util.ReflectionUtils; + +/** + * {@link FactoryBean} used to create JSON Tester instances. + * + * @param the object type + * @param the marshaller type + * @author Phillip Webb + * @since 4.0.0 + */ +public final class JsonTesterFactoryBean implements FactoryBean { + + private final Class objectType; + + private final @Nullable M marshaller; + + public JsonTesterFactoryBean(Class objectType, @Nullable M marshaller) { + this.objectType = objectType; + this.marshaller = marshaller; + } + + @Override + public boolean isSingleton() { + return false; + } + + @Override + @SuppressWarnings("unchecked") + public T getObject() throws Exception { + if (this.marshaller == null) { + Constructor constructor = this.objectType.getDeclaredConstructor(); + ReflectionUtils.makeAccessible(constructor); + return (T) BeanUtils.instantiateClass(constructor); + } + Constructor[] constructors = this.objectType.getDeclaredConstructors(); + for (Constructor constructor : constructors) { + if (constructor.getParameterCount() == 1 + && constructor.getParameterTypes()[0].isInstance(this.marshaller)) { + ReflectionUtils.makeAccessible(constructor); + return (T) BeanUtils.instantiateClass(constructor, this.marshaller); + } + } + throw new IllegalStateException(this.objectType + " does not have a usable constructor"); + } + + @Override + public Class getObjectType() { + return this.objectType; + } + +} diff --git a/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestersAutoConfiguration.java b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestersAutoConfiguration.java new file mode 100644 index 00000000000..d038ff9fdfc --- /dev/null +++ b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestersAutoConfiguration.java @@ -0,0 +1,112 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.test.autoconfigure.json; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import org.jspecify.annotations.Nullable; + +import org.springframework.aot.hint.ExecutableMode; +import org.springframework.aot.hint.MemberCategory; +import org.springframework.aot.hint.ReflectionHints; +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.test.json.AbstractJsonMarshalTester; +import org.springframework.boot.test.json.BasicJsonTester; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ImportRuntimeHints; +import org.springframework.context.annotation.Scope; +import org.springframework.core.ResolvableType; +import org.springframework.test.util.ReflectionTestUtils; +import org.springframework.util.Assert; +import org.springframework.util.ReflectionUtils; + +/** + * Auto-configuration for Json testers. + * + * @author Phillip Webb + * @author Eddú Meléndez + * @since 1.4.0 + * @see AutoConfigureJsonTesters + */ +@AutoConfiguration +@ConditionalOnJsonTesters +public final class JsonTestersAutoConfiguration { + + @Bean + static JsonMarshalTestersBeanPostProcessor jsonMarshalTestersBeanPostProcessor() { + return new JsonMarshalTestersBeanPostProcessor(); + } + + @Bean + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + @ImportRuntimeHints(BasicJsonTesterRuntimeHints.class) + FactoryBean basicJsonTesterFactoryBean() { + return new JsonTesterFactoryBean(BasicJsonTester.class, null); + } + + /** + * {@link BeanPostProcessor} used to initialize JSON testers. + */ + static class JsonMarshalTestersBeanPostProcessor implements InstantiationAwareBeanPostProcessor { + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + ReflectionUtils.doWithFields(bean.getClass(), (field) -> processField(bean, field)); + return bean; + } + + private void processField(Object bean, Field field) { + if (AbstractJsonMarshalTester.class.isAssignableFrom(field.getType())) { + initializeTester(bean, field, bean.getClass(), ResolvableType.forField(field).getGeneric()); + } + else if (BasicJsonTester.class.isAssignableFrom(field.getType())) { + initializeTester(bean, field, bean.getClass()); + } + } + + private void initializeTester(Object bean, Field field, Object... args) { + ReflectionUtils.makeAccessible(field); + Object tester = ReflectionUtils.getField(field, bean); + if (tester != null) { + ReflectionTestUtils.invokeMethod(tester, "initialize", args); + } + } + + } + + static class BasicJsonTesterRuntimeHints implements RuntimeHintsRegistrar { + + @Override + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { + ReflectionHints reflection = hints.reflection(); + reflection.registerType(BasicJsonTester.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); + Method method = ReflectionUtils.findMethod(BasicJsonTester.class, "initialize", Class.class); + Assert.state(method != null, "'method' must not be null"); + reflection.registerMethod(method, ExecutableMode.INVOKE); + } + + } + +} diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/JsonTypeExcludeFilter.java b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTypeExcludeFilter.java similarity index 58% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/JsonTypeExcludeFilter.java rename to core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTypeExcludeFilter.java index eeb702a5dbc..693265c22f9 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/JsonTypeExcludeFilter.java +++ b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTypeExcludeFilter.java @@ -14,16 +14,10 @@ * limitations under the License. */ -package org.springframework.boot.json.test.autoconfigure; - -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.Set; +package org.springframework.boot.test.autoconfigure.json; import org.springframework.boot.context.TypeExcludeFilter; -import org.springframework.boot.jackson.JsonComponent; import org.springframework.boot.test.context.filter.annotation.StandardAnnotationCustomizableTypeExcludeFilter; -import org.springframework.util.ClassUtils; /** * {@link TypeExcludeFilter} for {@link JsonTest @JsonTest}. @@ -32,29 +26,8 @@ import org.springframework.util.ClassUtils; */ class JsonTypeExcludeFilter extends StandardAnnotationCustomizableTypeExcludeFilter { - private static final String JACKSON_MODULE = "tools.jackson.databind.JacksonModule"; - - private static final Set> KNOWN_INCLUDES; - - static { - Set> includes = new LinkedHashSet<>(); - try { - includes.add(ClassUtils.forName(JACKSON_MODULE, null)); - } - catch (Exception ex) { - // Ignore - } - includes.add(JsonComponent.class); - KNOWN_INCLUDES = Collections.unmodifiableSet(includes); - } - JsonTypeExcludeFilter(Class testClass) { super(testClass); } - @Override - protected Set> getKnownIncludes() { - return KNOWN_INCLUDES; - } - } diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/package-info.java b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/package-info.java similarity index 92% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/package-info.java rename to core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/package-info.java index 1fe28c1698a..f71c02793d4 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/package-info.java +++ b/core/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/package-info.java @@ -18,6 +18,6 @@ * Auto-configuration for JSON tests. */ @NullMarked -package org.springframework.boot.json.test.autoconfigure; +package org.springframework.boot.test.autoconfigure.json; import org.jspecify.annotations.NullMarked; diff --git a/core/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring-configuration-metadata.json b/core/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring-configuration-metadata.json index c20ecd2b713..7d6486d28e1 100644 --- a/core/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring-configuration-metadata.json +++ b/core/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring-configuration-metadata.json @@ -1,5 +1,11 @@ { "properties": [ + { + "name": "spring.test.jsontesters.enabled", + "type": "java.lang.Boolean", + "description": "Whether auto-configuration of JSON testers is enabled.", + "defaultValue": "true" + }, { "name": "spring.test.print-condition-evaluation-report", "type": "java.lang.Boolean", diff --git a/core/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters.imports b/core/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters.imports new file mode 100644 index 00000000000..851570cf7b6 --- /dev/null +++ b/core/spring-boot-test-autoconfigure/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters.imports @@ -0,0 +1 @@ +org.springframework.boot.test.autoconfigure.json.JsonTestersAutoConfiguration diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleBasicObject.java b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleBasicObject.java similarity index 100% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleBasicObject.java rename to core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleBasicObject.java diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleJsonApplication.java b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleJsonApplication.java similarity index 93% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleJsonApplication.java rename to core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleJsonApplication.java index 0d8fc737504..deb295ac1e2 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleJsonApplication.java +++ b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleJsonApplication.java @@ -17,7 +17,7 @@ package org.springframework.boot.json.test.autoconfigure.app; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.json.test.autoconfigure.JsonTest; +import org.springframework.boot.test.autoconfigure.json.JsonTest; /** * Example {@link SpringBootApplication @SpringBootApplication} for use with diff --git a/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/ExampleJsonApplication.java b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/ExampleJsonApplication.java new file mode 100644 index 00000000000..9c48a963917 --- /dev/null +++ b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/ExampleJsonApplication.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.test.autoconfigure.json; + +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Example {@link SpringBootApplication @SpringBootApplication} for use with + * {@link JsonTest @JsonTest} tests. + * + * @author Phillip Webb + */ +@SpringBootApplication +public class ExampleJsonApplication { + +} diff --git a/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestIntegrationTests.java b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestIntegrationTests.java new file mode 100644 index 00000000000..912c2b5e9eb --- /dev/null +++ b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestIntegrationTests.java @@ -0,0 +1,47 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.test.autoconfigure.json; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.json.test.autoconfigure.app.ExampleJsonApplication; +import org.springframework.boot.test.json.BasicJsonTester; +import org.springframework.test.context.ContextConfiguration; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link JsonTest @JsonTest}. + * + * @author Phillip Webb + * @author Madhura Bhave + * @author Eddú Meléndez + */ +@JsonTest +@ContextConfiguration(classes = ExampleJsonApplication.class) +class JsonTestIntegrationTests { + + @Autowired + private BasicJsonTester basicJson; + + @Test + void basicJson() { + assertThat(this.basicJson.from("{\"a\":\"b\"}")).hasJsonPathStringValue("@.a"); + } + +} diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/JsonTestPropertiesIntegrationTests.java b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestPropertiesIntegrationTests.java similarity index 96% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/JsonTestPropertiesIntegrationTests.java rename to core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestPropertiesIntegrationTests.java index e275a8429ab..55d6509118b 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/JsonTestPropertiesIntegrationTests.java +++ b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestPropertiesIntegrationTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test.autoconfigure; +package org.springframework.boot.test.autoconfigure.json; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/JsonTestWithAutoConfigureJsonTestersTests.java b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestWithAutoConfigureJsonTestersTests.java similarity index 62% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/JsonTestWithAutoConfigureJsonTestersTests.java rename to core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestWithAutoConfigureJsonTestersTests.java index 6b568f85460..2b203860091 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/JsonTestWithAutoConfigureJsonTestersTests.java +++ b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestWithAutoConfigureJsonTestersTests.java @@ -14,17 +14,13 @@ * limitations under the License. */ -package org.springframework.boot.json.test.autoconfigure; +package org.springframework.boot.test.autoconfigure.json; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.json.test.BasicJsonTester; -import org.springframework.boot.json.test.GsonTester; -import org.springframework.boot.json.test.JacksonTester; -import org.springframework.boot.json.test.JsonbTester; -import org.springframework.boot.json.test.autoconfigure.app.ExampleBasicObject; import org.springframework.boot.json.test.autoconfigure.app.ExampleJsonApplication; +import org.springframework.boot.test.json.BasicJsonTester; import org.springframework.test.context.ContextConfiguration; import static org.assertj.core.api.Assertions.assertThat; @@ -43,33 +39,9 @@ class JsonTestWithAutoConfigureJsonTestersTests { @Autowired(required = false) private BasicJsonTester basicJson; - @Autowired(required = false) - private JacksonTester jacksonTester; - - @Autowired(required = false) - private GsonTester gsonTester; - - @Autowired(required = false) - private JsonbTester jsonbTester; - @Test void basicJson() { assertThat(this.basicJson).isNull(); } - @Test - void jackson() { - assertThat(this.jacksonTester).isNull(); - } - - @Test - void gson() { - assertThat(this.gsonTester).isNull(); - } - - @Test - void jsonb() { - assertThat(this.jsonbTester).isNull(); - } - } diff --git a/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestersAutoConfigurationTests.java b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestersAutoConfigurationTests.java new file mode 100644 index 00000000000..8642a1a0b78 --- /dev/null +++ b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/JsonTestersAutoConfigurationTests.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.test.autoconfigure.json; + +import org.junit.jupiter.api.Test; + +import org.springframework.aot.hint.RuntimeHints; +import org.springframework.aot.hint.predicate.ReflectionHintsPredicates; +import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; +import org.springframework.aot.test.generate.TestGenerationContext; +import org.springframework.boot.test.json.BasicJsonTester; +import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.aot.ApplicationContextAotGenerator; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link JsonTestersAutoConfiguration}. + * + * @author Andy Wilkinson + */ +class JsonTestersAutoConfigurationTests { + + @Test + void basicJsonTesterHintsAreContributed() { + try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) { + TestPropertyValues.of("spring.test.jsontesters.enabled=true").applyTo(context); + context.register(JsonTestersAutoConfiguration.class); + TestGenerationContext generationContext = new TestGenerationContext(); + new ApplicationContextAotGenerator().processAheadOfTime(context, generationContext); + RuntimeHints runtimeHints = generationContext.getRuntimeHints(); + ReflectionHintsPredicates reflection = RuntimeHintsPredicates.reflection(); + assertThat(reflection.onType(BasicJsonTester.class)).accepts(runtimeHints); + } + } + +} diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/SpringBootTestWithAutoConfigureJsonTestersTests.java b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/SpringBootTestWithAutoConfigureJsonTestersTests.java similarity index 67% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/SpringBootTestWithAutoConfigureJsonTestersTests.java rename to core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/SpringBootTestWithAutoConfigureJsonTestersTests.java index 32d1820fe1e..117a0461ffd 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/SpringBootTestWithAutoConfigureJsonTestersTests.java +++ b/core/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/json/SpringBootTestWithAutoConfigureJsonTestersTests.java @@ -14,18 +14,14 @@ * limitations under the License. */ -package org.springframework.boot.json.test.autoconfigure; +package org.springframework.boot.test.autoconfigure.json; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.json.test.BasicJsonTester; -import org.springframework.boot.json.test.GsonTester; -import org.springframework.boot.json.test.JacksonTester; -import org.springframework.boot.json.test.JsonbTester; -import org.springframework.boot.json.test.autoconfigure.app.ExampleBasicObject; import org.springframework.boot.json.test.autoconfigure.app.ExampleJsonApplication; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.json.BasicJsonTester; import org.springframework.test.context.ContextConfiguration; import static org.assertj.core.api.Assertions.assertThat; @@ -44,21 +40,9 @@ class SpringBootTestWithAutoConfigureJsonTestersTests { @Autowired private BasicJsonTester basicJson; - @Autowired - private JacksonTester jacksonTester; - - @Autowired - private GsonTester gsonTester; - - @Autowired - private JsonbTester jsonbTester; - @Test void contextLoads() { assertThat(this.basicJson).isNotNull(); - assertThat(this.jacksonTester).isNotNull(); - assertThat(this.jsonbTester).isNotNull(); - assertThat(this.gsonTester).isNotNull(); } } diff --git a/core/spring-boot-test/build.gradle b/core/spring-boot-test/build.gradle index 04b91f1c9e2..b353c3518f3 100644 --- a/core/spring-boot-test/build.gradle +++ b/core/spring-boot-test/build.gradle @@ -27,6 +27,10 @@ dependencies { api(project(":core:spring-boot")) api("org.springframework:spring-test") + optional("tools.jackson.core:jackson-databind") + optional("com.google.code.gson:gson") + optional("com.jayway.jsonpath:json-path") + optional("jakarta.json.bind:jakarta.json.bind-api") optional("jakarta.servlet:jakarta.servlet-api") optional("junit:junit") optional("org.assertj:assertj-core") @@ -34,11 +38,13 @@ dependencies { optional("org.hamcrest:hamcrest-library") optional("org.junit.jupiter:junit-jupiter-api") optional("org.mockito:mockito-core") + optional("org.skyscreamer:jsonassert") optional("org.springframework:spring-web") testImplementation(project(":test-support:spring-boot-test-support")) testImplementation("ch.qos.logback:logback-classic") testImplementation("com.google.code.gson:gson") + testImplementation("org.eclipse:yasson") testImplementation("org.jetbrains.kotlin:kotlin-reflect") testImplementation("org.jetbrains.kotlin:kotlin-stdlib") testImplementation("org.slf4j:slf4j-api") diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/AbstractJsonMarshalTester.java b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/AbstractJsonMarshalTester.java similarity index 99% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/AbstractJsonMarshalTester.java rename to core/spring-boot-test/src/main/java/org/springframework/boot/test/json/AbstractJsonMarshalTester.java index 57ccf9da519..73055475b9d 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/AbstractJsonMarshalTester.java +++ b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/AbstractJsonMarshalTester.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import java.io.BufferedReader; import java.io.Closeable; diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/BasicJsonTester.java b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/BasicJsonTester.java similarity index 99% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/BasicJsonTester.java rename to core/spring-boot-test/src/main/java/org/springframework/boot/test/json/BasicJsonTester.java index f5e7425eb8a..f23de0f8cfb 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/BasicJsonTester.java +++ b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/BasicJsonTester.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import java.io.File; import java.io.InputStream; diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/DuplicateJsonObjectContextCustomizerFactory.java b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/DuplicateJsonObjectContextCustomizerFactory.java similarity index 98% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/DuplicateJsonObjectContextCustomizerFactory.java rename to core/spring-boot-test/src/main/java/org/springframework/boot/test/json/DuplicateJsonObjectContextCustomizerFactory.java index 30ebaf03a4d..7486b55a769 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/DuplicateJsonObjectContextCustomizerFactory.java +++ b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/DuplicateJsonObjectContextCustomizerFactory.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import java.net.URL; import java.util.Collections; diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/GsonTester.java b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/GsonTester.java similarity index 98% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/GsonTester.java rename to core/spring-boot-test/src/main/java/org/springframework/boot/test/json/GsonTester.java index 1c0572c0f25..ae56423670b 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/GsonTester.java +++ b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/GsonTester.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import java.io.IOException; import java.io.Reader; diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/JacksonTester.java b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JacksonTester.java similarity index 99% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/JacksonTester.java rename to core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JacksonTester.java index a618f923003..b2cfbc0e80e 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/JacksonTester.java +++ b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JacksonTester.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import java.io.IOException; import java.io.InputStream; diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/JsonContent.java b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonContent.java similarity index 98% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/JsonContent.java rename to core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonContent.java index 209042356b6..b963c4c894f 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/JsonContent.java +++ b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonContent.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import com.jayway.jsonpath.Configuration; import org.assertj.core.api.AssertProvider; diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/JsonContentAssert.java b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonContentAssert.java similarity index 99% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/JsonContentAssert.java rename to core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonContentAssert.java index 54d04657ed1..93ce0da1ef1 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/JsonContentAssert.java +++ b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonContentAssert.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import java.io.File; import java.io.InputStream; diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/JsonLoader.java b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonLoader.java similarity index 98% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/JsonLoader.java rename to core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonLoader.java index 47b5d579a15..6d9f9f99896 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/JsonLoader.java +++ b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonLoader.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import java.io.ByteArrayInputStream; import java.io.File; diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/JsonbTester.java b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonbTester.java similarity index 98% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/JsonbTester.java rename to core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonbTester.java index 59448c494a7..b53bac5603f 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/JsonbTester.java +++ b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/JsonbTester.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import java.io.IOException; import java.io.Reader; diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/ObjectContent.java b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/ObjectContent.java similarity index 97% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/ObjectContent.java rename to core/spring-boot-test/src/main/java/org/springframework/boot/test/json/ObjectContent.java index 4b2ce8f7791..61a1f2ab1eb 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/ObjectContent.java +++ b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/ObjectContent.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import org.assertj.core.api.AssertProvider; import org.jspecify.annotations.Nullable; diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/ObjectContentAssert.java b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/ObjectContentAssert.java similarity index 97% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/ObjectContentAssert.java rename to core/spring-boot-test/src/main/java/org/springframework/boot/test/json/ObjectContentAssert.java index 702279e1839..d58612f8595 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/ObjectContentAssert.java +++ b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/ObjectContentAssert.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import org.assertj.core.api.AbstractMapAssert; import org.assertj.core.api.AbstractObjectArrayAssert; diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/package-info.java b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/package-info.java similarity index 94% rename from module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/package-info.java rename to core/spring-boot-test/src/main/java/org/springframework/boot/test/json/package-info.java index f07337965bf..f434c74e693 100644 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/package-info.java +++ b/core/spring-boot-test/src/main/java/org/springframework/boot/test/json/package-info.java @@ -18,6 +18,6 @@ * Support for testing JSON. */ @NullMarked -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import org.jspecify.annotations.NullMarked; diff --git a/core/spring-boot-test/src/main/resources/META-INF/spring.factories b/core/spring-boot-test/src/main/resources/META-INF/spring.factories index acf2470a65d..5be7efde86a 100644 --- a/core/spring-boot-test/src/main/resources/META-INF/spring.factories +++ b/core/spring-boot-test/src/main/resources/META-INF/spring.factories @@ -3,8 +3,8 @@ org.springframework.test.context.ContextCustomizerFactory=\ org.springframework.boot.test.context.ImportsContextCustomizerFactory,\ org.springframework.boot.test.context.PropertyMappingContextCustomizerFactory,\ org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizerFactory,\ -org.springframework.boot.test.context.filter.annotation.TypeExcludeFiltersContextCustomizerFactory - +org.springframework.boot.test.context.filter.annotation.TypeExcludeFiltersContextCustomizerFactory,\ +org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory # Application Context Initializers org.springframework.context.ApplicationContextInitializer=\ diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/AbstractJsonMarshalTesterTests.java b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/AbstractJsonMarshalTesterTests.java similarity index 99% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/AbstractJsonMarshalTesterTests.java rename to core/spring-boot-test/src/test/java/org/springframework/boot/test/json/AbstractJsonMarshalTesterTests.java index 4fceb0393a6..bc1d7b03570 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/AbstractJsonMarshalTesterTests.java +++ b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/AbstractJsonMarshalTesterTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import java.io.ByteArrayInputStream; import java.io.File; diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/BasicJsonTesterTests.java b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/BasicJsonTesterTests.java similarity index 98% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/BasicJsonTesterTests.java rename to core/spring-boot-test/src/test/java/org/springframework/boot/test/json/BasicJsonTesterTests.java index 4ff6c6cf5ea..aa9afc4f4a6 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/BasicJsonTesterTests.java +++ b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/BasicJsonTesterTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import java.io.ByteArrayInputStream; import java.io.File; diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/DuplicateJsonObjectContextCustomizerFactoryTests.java b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/DuplicateJsonObjectContextCustomizerFactoryTests.java similarity index 97% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/DuplicateJsonObjectContextCustomizerFactoryTests.java rename to core/spring-boot-test/src/test/java/org/springframework/boot/test/json/DuplicateJsonObjectContextCustomizerFactoryTests.java index f3e10a50ec3..795f0122e0d 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/DuplicateJsonObjectContextCustomizerFactoryTests.java +++ b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/DuplicateJsonObjectContextCustomizerFactoryTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/ExampleObject.java b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/ExampleObject.java similarity index 96% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/ExampleObject.java rename to core/spring-boot-test/src/test/java/org/springframework/boot/test/json/ExampleObject.java index 3f3fbf81e26..72d09adaec5 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/ExampleObject.java +++ b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/ExampleObject.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import org.springframework.util.ObjectUtils; diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/ExampleObjectWithView.java b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/ExampleObjectWithView.java similarity index 97% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/ExampleObjectWithView.java rename to core/spring-boot-test/src/test/java/org/springframework/boot/test/json/ExampleObjectWithView.java index ce8e7a7f456..9482156faef 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/ExampleObjectWithView.java +++ b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/ExampleObjectWithView.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import com.fasterxml.jackson.annotation.JsonView; diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/GsonTesterIntegrationTests.java b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/GsonTesterIntegrationTests.java similarity index 98% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/GsonTesterIntegrationTests.java rename to core/spring-boot-test/src/test/java/org/springframework/boot/test/json/GsonTesterIntegrationTests.java index b84f77c1616..1bf42e6a3d4 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/GsonTesterIntegrationTests.java +++ b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/GsonTesterIntegrationTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import java.util.LinkedHashMap; import java.util.List; diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/GsonTesterTests.java b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/GsonTesterTests.java similarity index 98% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/GsonTesterTests.java rename to core/spring-boot-test/src/test/java/org/springframework/boot/test/json/GsonTesterTests.java index ceddd3a00c1..b82e837e4e9 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/GsonTesterTests.java +++ b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/GsonTesterTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import java.util.List; diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/JacksonTesterIntegrationTests.java b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/JacksonTesterIntegrationTests.java similarity index 99% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/JacksonTesterIntegrationTests.java rename to core/spring-boot-test/src/test/java/org/springframework/boot/test/json/JacksonTesterIntegrationTests.java index 8a1f7811bb1..13208b3965d 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/JacksonTesterIntegrationTests.java +++ b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/JacksonTesterIntegrationTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import java.io.Reader; import java.io.StringReader; diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/JacksonTesterTests.java b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/JacksonTesterTests.java similarity index 98% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/JacksonTesterTests.java rename to core/spring-boot-test/src/test/java/org/springframework/boot/test/json/JacksonTesterTests.java index 8b50dba46a6..de1d17c7ca1 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/JacksonTesterTests.java +++ b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/JacksonTesterTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import java.util.List; diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/JsonContentAssertTests.java b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/JsonContentAssertTests.java similarity index 99% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/JsonContentAssertTests.java rename to core/spring-boot-test/src/test/java/org/springframework/boot/test/json/JsonContentAssertTests.java index bc65782e82c..9a6a55181fa 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/JsonContentAssertTests.java +++ b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/JsonContentAssertTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import java.io.ByteArrayInputStream; import java.io.File; diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/JsonContentTests.java b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/JsonContentTests.java similarity index 98% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/JsonContentTests.java rename to core/spring-boot-test/src/test/java/org/springframework/boot/test/json/JsonContentTests.java index 250dd2dfa15..4289923778c 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/JsonContentTests.java +++ b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/JsonContentTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import com.jayway.jsonpath.Configuration; import org.junit.jupiter.api.Test; diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/JsonbTesterTests.java b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/JsonbTesterTests.java similarity index 98% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/JsonbTesterTests.java rename to core/spring-boot-test/src/test/java/org/springframework/boot/test/json/JsonbTesterTests.java index 7526d45d9db..eb2a5b4644d 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/JsonbTesterTests.java +++ b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/JsonbTesterTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import java.util.List; diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/ObjectContentAssertTests.java b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/ObjectContentAssertTests.java similarity index 98% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/ObjectContentAssertTests.java rename to core/spring-boot-test/src/test/java/org/springframework/boot/test/json/ObjectContentAssertTests.java index 9775debe7aa..cd4577568e3 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/ObjectContentAssertTests.java +++ b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/ObjectContentAssertTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import java.util.Collections; import java.util.Map; diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/ObjectContentTests.java b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/ObjectContentTests.java similarity index 98% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/ObjectContentTests.java rename to core/spring-boot-test/src/test/java/org/springframework/boot/test/json/ObjectContentTests.java index d2602e3135e..33b25e6e630 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/ObjectContentTests.java +++ b/core/spring-boot-test/src/test/java/org/springframework/boot/test/json/ObjectContentTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test; +package org.springframework.boot.test.json; import org.junit.jupiter.api.Test; diff --git a/module/spring-boot-json-test/src/test/resources/org/springframework/boot/json/test/different.json b/core/spring-boot-test/src/test/resources/org/springframework/boot/test/json/different.json similarity index 100% rename from module/spring-boot-json-test/src/test/resources/org/springframework/boot/json/test/different.json rename to core/spring-boot-test/src/test/resources/org/springframework/boot/test/json/different.json diff --git a/module/spring-boot-json-test/src/test/resources/org/springframework/boot/json/test/example.json b/core/spring-boot-test/src/test/resources/org/springframework/boot/test/json/example.json similarity index 100% rename from module/spring-boot-json-test/src/test/resources/org/springframework/boot/json/test/example.json rename to core/spring-boot-test/src/test/resources/org/springframework/boot/test/json/example.json diff --git a/module/spring-boot-json-test/src/test/resources/org/springframework/boot/json/test/lenient-same.json b/core/spring-boot-test/src/test/resources/org/springframework/boot/test/json/lenient-same.json similarity index 100% rename from module/spring-boot-json-test/src/test/resources/org/springframework/boot/json/test/lenient-same.json rename to core/spring-boot-test/src/test/resources/org/springframework/boot/test/json/lenient-same.json diff --git a/module/spring-boot-json-test/src/test/resources/org/springframework/boot/json/test/nulls.json b/core/spring-boot-test/src/test/resources/org/springframework/boot/test/json/nulls.json similarity index 100% rename from module/spring-boot-json-test/src/test/resources/org/springframework/boot/json/test/nulls.json rename to core/spring-boot-test/src/test/resources/org/springframework/boot/test/json/nulls.json diff --git a/module/spring-boot-json-test/src/test/resources/org/springframework/boot/json/test/simpsons.json b/core/spring-boot-test/src/test/resources/org/springframework/boot/test/json/simpsons.json similarity index 100% rename from module/spring-boot-json-test/src/test/resources/org/springframework/boot/json/test/simpsons.json rename to core/spring-boot-test/src/test/resources/org/springframework/boot/test/json/simpsons.json diff --git a/module/spring-boot-json-test/src/test/resources/org/springframework/boot/json/test/source.json b/core/spring-boot-test/src/test/resources/org/springframework/boot/test/json/source.json similarity index 100% rename from module/spring-boot-json-test/src/test/resources/org/springframework/boot/json/test/source.json rename to core/spring-boot-test/src/test/resources/org/springframework/boot/test/json/source.json diff --git a/module/spring-boot-json-test/src/test/resources/org/springframework/boot/json/test/types.json b/core/spring-boot-test/src/test/resources/org/springframework/boot/test/json/types.json similarity index 100% rename from module/spring-boot-json-test/src/test/resources/org/springframework/boot/json/test/types.json rename to core/spring-boot-test/src/test/resources/org/springframework/boot/test/json/types.json diff --git a/documentation/spring-boot-docs/build.gradle b/documentation/spring-boot-docs/build.gradle index b7ab36cb805..5622fc671e9 100644 --- a/documentation/spring-boot-docs/build.gradle +++ b/documentation/spring-boot-docs/build.gradle @@ -115,7 +115,6 @@ dependencies { implementation(project(path: ":module:spring-boot-jpa")) implementation(project(path: ":module:spring-boot-jms")) implementation(project(path: ":module:spring-boot-jsonb")) - implementation(project(path: ":module:spring-boot-json-test")) implementation(project(path: ":module:spring-boot-ldap")) implementation(project(path: ":module:spring-boot-micrometer-metrics")) implementation(project(path: ":module:spring-boot-persistence")) diff --git a/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/spring-boot-applications.adoc b/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/spring-boot-applications.adoc index 676ae57b7af..5f189951a51 100644 --- a/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/spring-boot-applications.adoc +++ b/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/spring-boot-applications.adoc @@ -292,7 +292,7 @@ You can use this combination if you are not interested in "`slicing`" your appli [[testing.spring-boot-applications.json-tests]] == Auto-configured JSON Tests -To test that object JSON serialization and deserialization is working as expected, you can use the javadoc:org.springframework.boot.json.test.autoconfigure.JsonTest[format=annotation] annotation from the `spring-boot-json-test` module. +To test that object JSON serialization and deserialization is working as expected, you can use the javadoc:org.springframework.boot.json.test.autoconfigure.JsonTest[format=annotation] annotation from the `spring-boot-test-autoconfigure` module. javadoc:org.springframework.boot.json.test.autoconfigure.JsonTest[format=annotation] auto-configures the available supported JSON mapper, which can be one of the following libraries: * Jackson javadoc:tools.jackson.databind.JsonMapper[], any javadoc:org.springframework.boot.jackson.JsonComponent[format=annotation] beans and any Jackson javadoc:tools.jackson.databind.JacksonModule[] diff --git a/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/test-modules.adoc b/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/test-modules.adoc index 53b830f842e..24ea7f0f916 100644 --- a/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/test-modules.adoc +++ b/documentation/spring-boot-docs/src/docs/antora/modules/reference/pages/testing/test-modules.adoc @@ -52,9 +52,6 @@ Spring Boot offers several focused, feature-specific `-test` modules: |`spring-boot-jpa-test` |Testing applications that use JPA. -|`spring-boot-json-test` -|Testing applications that use JSON. Provides the `@JsonTest` test slice. - |`spring-boot-micrometer-metrics-test` |Testing applications that use Micrometer Metrics. diff --git a/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/springbootapplications/jsontests/MyJsonAssertJTests.java b/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/springbootapplications/jsontests/MyJsonAssertJTests.java index 58aa78e1fce..c39f0c2b850 100644 --- a/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/springbootapplications/jsontests/MyJsonAssertJTests.java +++ b/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/springbootapplications/jsontests/MyJsonAssertJTests.java @@ -19,8 +19,8 @@ package org.springframework.boot.docs.testing.springbootapplications.jsontests; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.json.test.JacksonTester; -import org.springframework.boot.json.test.autoconfigure.JsonTest; +import org.springframework.boot.test.autoconfigure.json.JsonTest; +import org.springframework.boot.test.json.JacksonTester; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.within; diff --git a/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/springbootapplications/jsontests/MyJsonTests.java b/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/springbootapplications/jsontests/MyJsonTests.java index 49200f7335d..d15f0cf2087 100644 --- a/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/springbootapplications/jsontests/MyJsonTests.java +++ b/documentation/spring-boot-docs/src/main/java/org/springframework/boot/docs/testing/springbootapplications/jsontests/MyJsonTests.java @@ -19,8 +19,8 @@ package org.springframework.boot.docs.testing.springbootapplications.jsontests; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.json.test.JacksonTester; -import org.springframework.boot.json.test.autoconfigure.JsonTest; +import org.springframework.boot.test.autoconfigure.json.JsonTest; +import org.springframework.boot.test.json.JacksonTester; import static org.assertj.core.api.Assertions.assertThat; diff --git a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/jsontests/MyJsonAssertJTests.kt b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/jsontests/MyJsonAssertJTests.kt index c1a2bcd8f83..71935fbc091 100644 --- a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/jsontests/MyJsonAssertJTests.kt +++ b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/jsontests/MyJsonAssertJTests.kt @@ -21,8 +21,8 @@ import org.assertj.core.api.Assertions.within import org.assertj.core.api.ThrowingConsumer import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.json.test.autoconfigure.JsonTest -import org.springframework.boot.json.test.JacksonTester +import org.springframework.boot.test.autoconfigure.json.JsonTest +import org.springframework.boot.test.json.JacksonTester @JsonTest class MyJsonAssertJTests(@Autowired val json: JacksonTester) { diff --git a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/jsontests/MyJsonTests.kt b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/jsontests/MyJsonTests.kt index cf82fea0884..dd64e262768 100644 --- a/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/jsontests/MyJsonTests.kt +++ b/documentation/spring-boot-docs/src/main/kotlin/org/springframework/boot/docs/testing/springbootapplications/jsontests/MyJsonTests.kt @@ -19,8 +19,8 @@ package org.springframework.boot.docs.testing.springbootapplications.jsontests import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.json.test.autoconfigure.JsonTest -import org.springframework.boot.json.test.JacksonTester +import org.springframework.boot.test.autoconfigure.json.JsonTest +import org.springframework.boot.test.json.JacksonTester @JsonTest class MyJsonTests(@Autowired val json: JacksonTester) { diff --git a/module/spring-boot-actuator/build.gradle b/module/spring-boot-actuator/build.gradle index beae8bcea1e..5078fd94fcb 100644 --- a/module/spring-boot-actuator/build.gradle +++ b/module/spring-boot-actuator/build.gradle @@ -65,7 +65,6 @@ dependencies { testImplementation(project(":core:spring-boot-test")) testImplementation(project(":module:spring-boot-jackson")) testImplementation(project(":module:spring-boot-jsonb")) - testImplementation(project(":module:spring-boot-json-test")) testImplementation(project(":test-support:spring-boot-test-support")) testImplementation("io.micrometer:micrometer-observation-test") testImplementation("io.projectreactor:reactor-test") diff --git a/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/JacksonJmxOperationResponseMapperTests.java b/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/JacksonJmxOperationResponseMapperTests.java index 03509cf53ce..4159aaa31ab 100644 --- a/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/JacksonJmxOperationResponseMapperTests.java +++ b/module/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/jmx/JacksonJmxOperationResponseMapperTests.java @@ -27,7 +27,7 @@ import org.junit.jupiter.api.Test; import tools.jackson.databind.JavaType; import tools.jackson.databind.ObjectMapper; -import org.springframework.boot.json.test.BasicJsonTester; +import org.springframework.boot.test.json.BasicJsonTester; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; diff --git a/module/spring-boot-graphql-test/build.gradle b/module/spring-boot-graphql-test/build.gradle index b2d94a3133b..bdd286d63f9 100644 --- a/module/spring-boot-graphql-test/build.gradle +++ b/module/spring-boot-graphql-test/build.gradle @@ -31,7 +31,6 @@ dependencies { implementation(project(":module:spring-boot-jackson")) optional(project(":core:spring-boot-autoconfigure")) - optional(project(":module:spring-boot-json-test")) optional(project(":module:spring-boot-validation")) optional(project(":module:spring-boot-webclient")) optional(project(":module:spring-boot-webflux-test")) diff --git a/module/spring-boot-graphql-test/src/main/java/org/springframework/boot/graphql/test/autoconfigure/GraphQlTest.java b/module/spring-boot-graphql-test/src/main/java/org/springframework/boot/graphql/test/autoconfigure/GraphQlTest.java index 8e0023192f6..75058bd32bc 100644 --- a/module/spring-boot-graphql-test/src/main/java/org/springframework/boot/graphql/test/autoconfigure/GraphQlTest.java +++ b/module/spring-boot-graphql-test/src/main/java/org/springframework/boot/graphql/test/autoconfigure/GraphQlTest.java @@ -29,8 +29,8 @@ import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.graphql.test.autoconfigure.tester.AutoConfigureGraphQlTester; import org.springframework.boot.graphql.test.autoconfigure.tester.AutoConfigureHttpGraphQlTester; -import org.springframework.boot.json.test.autoconfigure.AutoConfigureJson; import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; +import org.springframework.boot.test.autoconfigure.json.AutoConfigureJson; import org.springframework.boot.test.context.filter.annotation.TypeExcludeFilters; import org.springframework.context.annotation.ComponentScan; import org.springframework.core.annotation.AliasFor; diff --git a/module/spring-boot-gson/build.gradle b/module/spring-boot-gson/build.gradle index 092f295c5ee..6f54395565a 100644 --- a/module/spring-boot-gson/build.gradle +++ b/module/spring-boot-gson/build.gradle @@ -30,8 +30,8 @@ dependencies { api("com.google.code.gson:gson") optional(project(":core:spring-boot-autoconfigure")) + optional(project(":core:spring-boot-test-autoconfigure")) - testImplementation(project(":core:spring-boot-test")) testImplementation(project(":test-support:spring-boot-test-support")) testRuntimeOnly("ch.qos.logback:logback-classic") diff --git a/module/spring-boot-gson/src/main/java/org/springframework/boot/gson/autoconfigure/GsonTesterAutoConfiguration.java b/module/spring-boot-gson/src/main/java/org/springframework/boot/gson/autoconfigure/GsonTesterAutoConfiguration.java new file mode 100644 index 00000000000..b9a3da68a69 --- /dev/null +++ b/module/spring-boot-gson/src/main/java/org/springframework/boot/gson/autoconfigure/GsonTesterAutoConfiguration.java @@ -0,0 +1,59 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.gson.autoconfigure; + +import com.google.gson.Gson; + +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.test.autoconfigure.TestAutoConfiguration; +import org.springframework.boot.test.autoconfigure.json.ConditionalOnJsonTesters; +import org.springframework.boot.test.autoconfigure.json.JsonMarshalTesterRuntimeHints; +import org.springframework.boot.test.autoconfigure.json.JsonTesterFactoryBean; +import org.springframework.boot.test.json.GsonTester; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ImportRuntimeHints; +import org.springframework.context.annotation.Scope; + +/** + * {@link EnableAutoConfiguration Auto-configuration} for {@link GsonTester}. + * + * @author Phjllip Webb + */ +@TestAutoConfiguration(after = GsonAutoConfiguration.class) +@ConditionalOnJsonTesters +final class GsonTesterAutoConfiguration { + + @Bean + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + @ConditionalOnBean(Gson.class) + @ImportRuntimeHints(GsonTesterRuntimeHints.class) + FactoryBean> gsonTesterFactoryBean(Gson gson) { + return new JsonTesterFactoryBean<>(GsonTester.class, gson); + } + + static class GsonTesterRuntimeHints extends JsonMarshalTesterRuntimeHints { + + GsonTesterRuntimeHints() { + super(GsonTester.class); + } + + } + +} diff --git a/module/spring-boot-gson/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters.imports b/module/spring-boot-gson/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters.imports new file mode 100644 index 00000000000..154814b8f3c --- /dev/null +++ b/module/spring-boot-gson/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters.imports @@ -0,0 +1,2 @@ +org.springframework.boot.gson.autoconfigure.GsonAutoConfiguration +org.springframework.boot.gson.autoconfigure.GsonTesterAutoConfiguration \ No newline at end of file diff --git a/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/GsonTesterAutoConfigurationTests.java b/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/GsonTesterAutoConfigurationTests.java new file mode 100644 index 00000000000..7eb0efbccfa --- /dev/null +++ b/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/GsonTesterAutoConfigurationTests.java @@ -0,0 +1,54 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.gson.autoconfigure; + +import org.junit.jupiter.api.Test; + +import org.springframework.aot.hint.predicate.ReflectionHintsPredicates; +import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; +import org.springframework.aot.test.generate.TestGenerationContext; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.autoconfigure.json.JsonTestersAutoConfiguration; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.test.json.GsonTester; +import org.springframework.context.aot.ApplicationContextAotGenerator; +import org.springframework.context.support.GenericApplicationContext; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link GsonTesterAutoConfiguration}. + * + * @author Andy Wilkinson + */ +class GsonTesterAutoConfigurationTests { + + private final ApplicationContextRunner runner = new ApplicationContextRunner().withConfiguration(AutoConfigurations + .of(JsonTestersAutoConfiguration.class, GsonAutoConfiguration.class, GsonTesterAutoConfiguration.class)); + + @Test + void hintsAreContributed() { + this.runner.withPropertyValues("spring.test.jsontesters.enabled=true").prepare((context) -> { + TestGenerationContext generationContext = new TestGenerationContext(); + new ApplicationContextAotGenerator().processAheadOfTime( + (GenericApplicationContext) context.getSourceApplicationContext(), generationContext); + ReflectionHintsPredicates hints = RuntimeHintsPredicates.reflection(); + assertThat(hints.onType(GsonTester.class)).accepts(generationContext.getRuntimeHints()); + }); + } + +} diff --git a/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/JsonTestApplication.java b/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/JsonTestApplication.java new file mode 100644 index 00000000000..d0acfd24e16 --- /dev/null +++ b/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/JsonTestApplication.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.gson.autoconfigure.jsontest; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.autoconfigure.json.JsonTest; + +/** + * Application for testing of {@link JsonTest @JsonTest}. + * + * @author Andy Wilkinson + */ +@SpringBootApplication +class JsonTestApplication { + +} diff --git a/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/JsonTestIntegrationTests.java b/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/JsonTestIntegrationTests.java new file mode 100644 index 00000000000..85fb36b7e8e --- /dev/null +++ b/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/JsonTestIntegrationTests.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.gson.autoconfigure.jsontest; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.gson.autoconfigure.jsontest.app.ExampleBasicObject; +import org.springframework.boot.gson.autoconfigure.jsontest.app.ExampleJsonApplication; +import org.springframework.boot.test.autoconfigure.json.JsonTest; +import org.springframework.boot.test.json.GsonTester; +import org.springframework.test.context.ContextConfiguration; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link JsonTest @JsonTest}. + * + * @author Phillip Webb + * @author Madhura Bhave + * @author Eddú Meléndez + */ +@JsonTest +@ContextConfiguration(classes = ExampleJsonApplication.class) +class JsonTestIntegrationTests { + + @Autowired + private GsonTester gsonJson; + + @Test + void gson() throws Exception { + ExampleBasicObject object = new ExampleBasicObject(); + object.setValue("spring"); + assertThat(this.gsonJson.write(object)).isEqualToJson("example.json"); + } + +} diff --git a/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/JsonTestWithAutoConfigureJsonTestersTests.java b/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/JsonTestWithAutoConfigureJsonTestersTests.java new file mode 100644 index 00000000000..12789e1297d --- /dev/null +++ b/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/JsonTestWithAutoConfigureJsonTestersTests.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.gson.autoconfigure.jsontest; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.gson.autoconfigure.jsontest.app.ExampleBasicObject; +import org.springframework.boot.gson.autoconfigure.jsontest.app.ExampleJsonApplication; +import org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters; +import org.springframework.boot.test.autoconfigure.json.JsonTest; +import org.springframework.boot.test.json.GsonTester; +import org.springframework.test.context.ContextConfiguration; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link JsonTest @JsonTest} with + * {@link AutoConfigureJsonTesters @AutoConfigureJsonTesters}. + * + * @author Phillip Webb + */ +@JsonTest +@AutoConfigureJsonTesters(enabled = false) +@ContextConfiguration(classes = ExampleJsonApplication.class) +class JsonTestWithAutoConfigureJsonTestersTests { + + @Autowired(required = false) + private GsonTester gsonTester; + + @Test + void gson() { + assertThat(this.gsonTester).isNull(); + } + +} diff --git a/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/SpringBootTestWithAutoConfigureJsonTestersTests.java b/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/SpringBootTestWithAutoConfigureJsonTestersTests.java new file mode 100644 index 00000000000..549b4bf7ffc --- /dev/null +++ b/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/SpringBootTestWithAutoConfigureJsonTestersTests.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.gson.autoconfigure.jsontest; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.gson.autoconfigure.jsontest.app.ExampleBasicObject; +import org.springframework.boot.gson.autoconfigure.jsontest.app.ExampleJsonApplication; +import org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.json.GsonTester; +import org.springframework.test.context.ContextConfiguration; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link SpringBootTest @SpringBootTest} with + * {@link AutoConfigureJsonTesters @AutoConfigureJsonTesters}. + * + * @author Andy Wilkinson + */ +@SpringBootTest +@AutoConfigureJsonTesters +@ContextConfiguration(classes = ExampleJsonApplication.class) +class SpringBootTestWithAutoConfigureJsonTestersTests { + + @Autowired + private GsonTester gsonTester; + + @Test + void contextLoads() { + assertThat(this.gsonTester).isNotNull(); + } + +} diff --git a/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/app/ExampleBasicObject.java b/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/app/ExampleBasicObject.java new file mode 100644 index 00000000000..6efe32bee27 --- /dev/null +++ b/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/app/ExampleBasicObject.java @@ -0,0 +1,49 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.gson.autoconfigure.jsontest.app; + +/** + * Example object to read/write as JSON. + * + * @author Phillip Webb + */ +public class ExampleBasicObject { + + private String value; + + public String getValue() { + return this.value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public boolean equals(Object obj) { + if (obj != null && obj.getClass() == getClass()) { + return this.value.equals(((ExampleBasicObject) obj).value); + } + return false; + } + + @Override + public int hashCode() { + return this.value.hashCode(); + } + +} diff --git a/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/app/ExampleJsonApplication.java b/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/app/ExampleJsonApplication.java new file mode 100644 index 00000000000..065b451f4de --- /dev/null +++ b/module/spring-boot-gson/src/test/java/org/springframework/boot/gson/autoconfigure/jsontest/app/ExampleJsonApplication.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.gson.autoconfigure.jsontest.app; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.autoconfigure.json.JsonTest; + +/** + * Example {@link SpringBootApplication @SpringBootApplication} for use with + * {@link JsonTest @JsonTest} tests. + * + * @author Phillip Webb + */ +@SpringBootApplication +public class ExampleJsonApplication { + +} diff --git a/module/spring-boot-json-test/src/test/resources/org/springframework/boot/json/test/autoconfigure/example.json b/module/spring-boot-gson/src/test/resources/org/springframework/boot/gson/autoconfigure/jsontest/example.json similarity index 100% rename from module/spring-boot-json-test/src/test/resources/org/springframework/boot/json/test/autoconfigure/example.json rename to module/spring-boot-gson/src/test/resources/org/springframework/boot/gson/autoconfigure/jsontest/example.json diff --git a/module/spring-boot-jackson/build.gradle b/module/spring-boot-jackson/build.gradle index 3aef287c18d..af34f2bab4c 100644 --- a/module/spring-boot-jackson/build.gradle +++ b/module/spring-boot-jackson/build.gradle @@ -29,6 +29,7 @@ dependencies { api("tools.jackson.core:jackson-databind") optional(project(":core:spring-boot-autoconfigure")) + optional(project(":core:spring-boot-test-autoconfigure")) optional("org.springframework:spring-web") optional("tools.jackson.dataformat:jackson-dataformat-cbor") optional("tools.jackson.dataformat:jackson-dataformat-xml") diff --git a/module/spring-boot-jackson/src/main/java/org/springframework/boot/jackson/autoconfigure/JacksonTesterAutoConfiguration.java b/module/spring-boot-jackson/src/main/java/org/springframework/boot/jackson/autoconfigure/JacksonTesterAutoConfiguration.java new file mode 100644 index 00000000000..a165d50c266 --- /dev/null +++ b/module/spring-boot-jackson/src/main/java/org/springframework/boot/jackson/autoconfigure/JacksonTesterAutoConfiguration.java @@ -0,0 +1,60 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.jackson.autoconfigure; + +import tools.jackson.databind.json.JsonMapper; + +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.test.autoconfigure.TestAutoConfiguration; +import org.springframework.boot.test.autoconfigure.json.ConditionalOnJsonTesters; +import org.springframework.boot.test.autoconfigure.json.JsonMarshalTesterRuntimeHints; +import org.springframework.boot.test.autoconfigure.json.JsonTesterFactoryBean; +import org.springframework.boot.test.json.GsonTester; +import org.springframework.boot.test.json.JacksonTester; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ImportRuntimeHints; +import org.springframework.context.annotation.Scope; + +/** + * {@link EnableAutoConfiguration Auto-configuration} for {@link GsonTester}. + * + * @author Phjllip Webb + */ +@TestAutoConfiguration(after = JacksonAutoConfiguration.class) +@ConditionalOnJsonTesters +final class JacksonTesterAutoConfiguration { + + @Bean + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + @ConditionalOnBean(JsonMapper.class) + @ImportRuntimeHints(JacksonTesterRuntimeHints.class) + FactoryBean> jacksonTesterFactoryBean(JsonMapper mapper) { + return new JsonTesterFactoryBean<>(JacksonTester.class, mapper); + } + + static class JacksonTesterRuntimeHints extends JsonMarshalTesterRuntimeHints { + + JacksonTesterRuntimeHints() { + super(JacksonTester.class); + } + + } + +} diff --git a/module/spring-boot-jackson/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters.imports b/module/spring-boot-jackson/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters.imports new file mode 100644 index 00000000000..ffd53e2f4f6 --- /dev/null +++ b/module/spring-boot-jackson/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters.imports @@ -0,0 +1,2 @@ +org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration +org.springframework.boot.jackson.autoconfigure.JacksonTesterAutoConfiguration diff --git a/module/spring-boot-jackson/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.JsonTest.includes b/module/spring-boot-jackson/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.JsonTest.includes new file mode 100644 index 00000000000..88217c6d606 --- /dev/null +++ b/module/spring-boot-jackson/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.JsonTest.includes @@ -0,0 +1,2 @@ +org.springframework.boot.jackson.JsonComponent +tools.jackson.databind.JacksonModule diff --git a/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/JacksonTesterAutoConfigurationTests.java b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/JacksonTesterAutoConfigurationTests.java new file mode 100644 index 00000000000..2411c7ccef2 --- /dev/null +++ b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/JacksonTesterAutoConfigurationTests.java @@ -0,0 +1,54 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.jackson.autoconfigure; + +import org.junit.jupiter.api.Test; + +import org.springframework.aot.hint.predicate.ReflectionHintsPredicates; +import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; +import org.springframework.aot.test.generate.TestGenerationContext; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.autoconfigure.json.JsonTestersAutoConfiguration; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.test.json.JacksonTester; +import org.springframework.context.aot.ApplicationContextAotGenerator; +import org.springframework.context.support.GenericApplicationContext; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link JsonTestersAutoConfiguration}. + * + * @author Andy Wilkinson + */ +class JacksonTesterAutoConfigurationTests { + + private final ApplicationContextRunner runner = new ApplicationContextRunner().withConfiguration(AutoConfigurations + .of(JsonTestersAutoConfiguration.class, JacksonAutoConfiguration.class, JacksonTesterAutoConfiguration.class)); + + @Test + void hintsAreContributed() { + this.runner.withPropertyValues("spring.test.jsontesters.enabled=true").prepare((context) -> { + TestGenerationContext generationContext = new TestGenerationContext(); + new ApplicationContextAotGenerator().processAheadOfTime( + (GenericApplicationContext) context.getSourceApplicationContext(), generationContext); + ReflectionHintsPredicates hints = RuntimeHintsPredicates.reflection(); + assertThat(hints.onType(JacksonTester.class)).accepts(generationContext.getRuntimeHints()); + }); + } + +} diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/JsonTestIntegrationTests.java b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/JsonTestIntegrationTests.java similarity index 62% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/JsonTestIntegrationTests.java rename to module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/JsonTestIntegrationTests.java index 7c7cbf153ad..0770d7709bb 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/JsonTestIntegrationTests.java +++ b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/JsonTestIntegrationTests.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test.autoconfigure; +package org.springframework.boot.jackson.autoconfigure.jsontest; import java.util.Date; import java.util.UUID; @@ -22,15 +22,13 @@ import java.util.UUID; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.json.test.BasicJsonTester; -import org.springframework.boot.json.test.GsonTester; -import org.springframework.boot.json.test.JacksonTester; -import org.springframework.boot.json.test.JsonContent; -import org.springframework.boot.json.test.JsonbTester; -import org.springframework.boot.json.test.autoconfigure.app.ExampleBasicObject; -import org.springframework.boot.json.test.autoconfigure.app.ExampleCustomObject; -import org.springframework.boot.json.test.autoconfigure.app.ExampleJsonApplication; -import org.springframework.boot.json.test.autoconfigure.app.ExampleJsonObjectWithView; +import org.springframework.boot.jackson.autoconfigure.jsontest.app.ExampleBasicObject; +import org.springframework.boot.jackson.autoconfigure.jsontest.app.ExampleCustomObject; +import org.springframework.boot.jackson.autoconfigure.jsontest.app.ExampleJsonApplication; +import org.springframework.boot.jackson.autoconfigure.jsontest.app.ExampleJsonObjectWithView; +import org.springframework.boot.test.autoconfigure.json.JsonTest; +import org.springframework.boot.test.json.JacksonTester; +import org.springframework.boot.test.json.JsonContent; import org.springframework.test.context.ContextConfiguration; import static org.assertj.core.api.Assertions.assertThat; @@ -46,9 +44,6 @@ import static org.assertj.core.api.Assertions.assertThat; @ContextConfiguration(classes = ExampleJsonApplication.class) class JsonTestIntegrationTests { - @Autowired - private BasicJsonTester basicJson; - @Autowired private JacksonTester jacksonBasicJson; @@ -58,17 +53,6 @@ class JsonTestIntegrationTests { @Autowired private JacksonTester jacksonCustomJson; - @Autowired - private GsonTester gsonJson; - - @Autowired - private JsonbTester jsonbJson; - - @Test - void basicJson() { - assertThat(this.basicJson.from("{\"a\":\"b\"}")).hasJsonPathStringValue("@.a"); - } - @Test void jacksonBasic() throws Exception { ExampleBasicObject object = new ExampleBasicObject(); @@ -82,20 +66,6 @@ class JsonTestIntegrationTests { assertThat(this.jacksonCustomJson.write(object)).isEqualToJson("example.json"); } - @Test - void gson() throws Exception { - ExampleBasicObject object = new ExampleBasicObject(); - object.setValue("spring"); - assertThat(this.gsonJson.write(object)).isEqualToJson("example.json"); - } - - @Test - void jsonb() throws Exception { - ExampleBasicObject object = new ExampleBasicObject(); - object.setValue("spring"); - assertThat(this.jsonbJson.write(object)).isEqualToJson("example.json"); - } - @Test void customView() throws Exception { ExampleJsonObjectWithView object = new ExampleJsonObjectWithView(); diff --git a/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/JsonTestWithAutoConfigureJsonTestersTests.java b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/JsonTestWithAutoConfigureJsonTestersTests.java new file mode 100644 index 00000000000..1612c831b80 --- /dev/null +++ b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/JsonTestWithAutoConfigureJsonTestersTests.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.jackson.autoconfigure.jsontest; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.jackson.autoconfigure.jsontest.app.ExampleBasicObject; +import org.springframework.boot.jackson.autoconfigure.jsontest.app.ExampleJsonApplication; +import org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters; +import org.springframework.boot.test.autoconfigure.json.JsonTest; +import org.springframework.boot.test.json.JacksonTester; +import org.springframework.test.context.ContextConfiguration; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link JsonTest @JsonTest} with + * {@link AutoConfigureJsonTesters @AutoConfigureJsonTesters}. + * + * @author Phillip Webb + */ +@JsonTest +@AutoConfigureJsonTesters(enabled = false) +@ContextConfiguration(classes = ExampleJsonApplication.class) +class JsonTestWithAutoConfigureJsonTestersTests { + + @Autowired(required = false) + private JacksonTester jacksonTester; + + @Test + void jackson() { + assertThat(this.jacksonTester).isNull(); + } + +} diff --git a/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/SpringBootTestWithAutoConfigureJsonTestersTests.java b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/SpringBootTestWithAutoConfigureJsonTestersTests.java new file mode 100644 index 00000000000..0ddf205cb2e --- /dev/null +++ b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/SpringBootTestWithAutoConfigureJsonTestersTests.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.jackson.autoconfigure.jsontest; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.jackson.autoconfigure.jsontest.app.ExampleBasicObject; +import org.springframework.boot.jackson.autoconfigure.jsontest.app.ExampleJsonApplication; +import org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.json.JacksonTester; +import org.springframework.test.context.ContextConfiguration; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link SpringBootTest @SpringBootTest} with + * {@link AutoConfigureJsonTesters @AutoConfigureJsonTesters}. + * + * @author Andy Wilkinson + */ +@SpringBootTest +@AutoConfigureJsonTesters +@ContextConfiguration(classes = ExampleJsonApplication.class) +class SpringBootTestWithAutoConfigureJsonTestersTests { + + @Autowired + private JacksonTester jacksonTester; + + @Test + void contextLoads() { + assertThat(this.jacksonTester).isNotNull(); + } + +} diff --git a/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/app/ExampleBasicObject.java b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/app/ExampleBasicObject.java new file mode 100644 index 00000000000..bacea6cd135 --- /dev/null +++ b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/app/ExampleBasicObject.java @@ -0,0 +1,49 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.jackson.autoconfigure.jsontest.app; + +/** + * Example object to read/write as JSON. + * + * @author Phillip Webb + */ +public class ExampleBasicObject { + + private String value; + + public String getValue() { + return this.value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public boolean equals(Object obj) { + if (obj != null && obj.getClass() == getClass()) { + return this.value.equals(((ExampleBasicObject) obj).value); + } + return false; + } + + @Override + public int hashCode() { + return this.value.hashCode(); + } + +} diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleCustomObject.java b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/app/ExampleCustomObject.java similarity index 93% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleCustomObject.java rename to module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/app/ExampleCustomObject.java index e8ad05b55cc..a3d155f5cc6 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleCustomObject.java +++ b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/app/ExampleCustomObject.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test.autoconfigure.app; +package org.springframework.boot.jackson.autoconfigure.jsontest.app; import java.util.Date; import java.util.UUID; diff --git a/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/app/ExampleJsonApplication.java b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/app/ExampleJsonApplication.java new file mode 100644 index 00000000000..0a0761949cf --- /dev/null +++ b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/app/ExampleJsonApplication.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.jackson.autoconfigure.jsontest.app; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.autoconfigure.json.JsonTest; + +/** + * Example {@link SpringBootApplication @SpringBootApplication} for use with + * {@link JsonTest @JsonTest} tests. + * + * @author Phillip Webb + */ +@SpringBootApplication +public class ExampleJsonApplication { + +} diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleJsonComponent.java b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/app/ExampleJsonComponent.java similarity index 94% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleJsonComponent.java rename to module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/app/ExampleJsonComponent.java index 1f5823abd58..41fd4411652 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleJsonComponent.java +++ b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/app/ExampleJsonComponent.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test.autoconfigure.app; +package org.springframework.boot.jackson.autoconfigure.jsontest.app; import java.util.Date; import java.util.UUID; @@ -28,7 +28,7 @@ import tools.jackson.databind.SerializationContext; import org.springframework.boot.jackson.JsonComponent; import org.springframework.boot.jackson.ObjectValueDeserializer; import org.springframework.boot.jackson.ObjectValueSerializer; -import org.springframework.boot.json.test.autoconfigure.JsonTest; +import org.springframework.boot.test.autoconfigure.json.JsonTest; /** * Example {@link JsonComponent @JsonComponent} for use with {@link JsonTest @JsonTest} diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleJsonObjectWithView.java b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/app/ExampleJsonObjectWithView.java similarity index 95% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleJsonObjectWithView.java rename to module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/app/ExampleJsonObjectWithView.java index bed0357a073..36d2c4f2e1c 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/app/ExampleJsonObjectWithView.java +++ b/module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/jsontest/app/ExampleJsonObjectWithView.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.boot.json.test.autoconfigure.app; +package org.springframework.boot.jackson.autoconfigure.jsontest.app; import com.fasterxml.jackson.annotation.JsonView; diff --git a/module/spring-boot-jackson/src/test/resources/org/springframework/boot/jackson/autoconfigure/jsontest/example.json b/module/spring-boot-jackson/src/test/resources/org/springframework/boot/jackson/autoconfigure/jsontest/example.json new file mode 100644 index 00000000000..40cc01ff6fc --- /dev/null +++ b/module/spring-boot-jackson/src/test/resources/org/springframework/boot/jackson/autoconfigure/jsontest/example.json @@ -0,0 +1,3 @@ +{ + "value" : "spring" +} diff --git a/module/spring-boot-json-test/build.gradle b/module/spring-boot-json-test/build.gradle deleted file mode 100644 index 85364836588..00000000000 --- a/module/spring-boot-json-test/build.gradle +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -plugins { - id "java-library" - id "org.springframework.boot.configuration-properties" - id "org.springframework.boot.deployed" - id "org.springframework.boot.optional-dependencies" - id "org.springframework.boot.test-slice" -} - -description = "Spring Boot JSON Test" - -dependencies { - api(project(":core:spring-boot-test-autoconfigure")) - - optional(project(":core:spring-boot-autoconfigure")) - optional(project(":module:spring-boot-gson")) - optional(project(":module:spring-boot-jackson")) - optional(project(":module:spring-boot-jsonb")) - optional(project(":module:spring-boot-kotlin-serialization")) - optional("com.jayway.jsonpath:json-path") - optional("org.assertj:assertj-core") - optional("org.junit.jupiter:junit-jupiter-api") - optional("org.skyscreamer:jsonassert") - - testImplementation(project(":test-support:spring-boot-test-support")) - - testRuntimeOnly("ch.qos.logback:logback-classic") -} diff --git a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/JsonTestersAutoConfiguration.java b/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/JsonTestersAutoConfiguration.java deleted file mode 100644 index ec93204f9b1..00000000000 --- a/module/spring-boot-json-test/src/main/java/org/springframework/boot/json/test/autoconfigure/JsonTestersAutoConfiguration.java +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Copyright 2012-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.json.test.autoconfigure; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -import com.google.gson.Gson; -import jakarta.json.bind.Jsonb; -import org.jspecify.annotations.Nullable; -import tools.jackson.databind.json.JsonMapper; - -import org.springframework.aot.hint.ExecutableMode; -import org.springframework.aot.hint.MemberCategory; -import org.springframework.aot.hint.ReflectionHints; -import org.springframework.aot.hint.RuntimeHints; -import org.springframework.aot.hint.RuntimeHintsRegistrar; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.FactoryBean; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.json.test.AbstractJsonMarshalTester; -import org.springframework.boot.json.test.BasicJsonTester; -import org.springframework.boot.json.test.GsonTester; -import org.springframework.boot.json.test.JacksonTester; -import org.springframework.boot.json.test.JsonbTester; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportRuntimeHints; -import org.springframework.context.annotation.Scope; -import org.springframework.core.ResolvableType; -import org.springframework.test.util.ReflectionTestUtils; -import org.springframework.util.Assert; -import org.springframework.util.ReflectionUtils; - -/** - * Auto-configuration for Json testers. - * - * @author Phillip Webb - * @author Eddú Meléndez - * @since 4.0.0 - * @see AutoConfigureJsonTesters - */ -@AutoConfiguration(afterName = { "org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration", - "org.springframework.boot.jsonb.autoconfigure.JsonbAutoConfiguration", - "org.springframework.boot.gson.autoconfigure.GsonAutoConfiguration" }) -@ConditionalOnClass(name = "org.assertj.core.api.Assert") -@ConditionalOnBooleanProperty("spring.test.jsontesters.enabled") -public final class JsonTestersAutoConfiguration { - - @Bean - static JsonMarshalTestersBeanPostProcessor jsonMarshalTestersBeanPostProcessor() { - return new JsonMarshalTestersBeanPostProcessor(); - } - - @Bean - @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) - @ImportRuntimeHints(BasicJsonTesterRuntimeHints.class) - FactoryBean basicJsonTesterFactoryBean() { - return new JsonTesterFactoryBean(BasicJsonTester.class, null); - } - - @Configuration(proxyBeanMethods = false) - @ConditionalOnClass(JsonMapper.class) - static class JacksonJsonTestersConfiguration { - - @Bean - @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) - @ConditionalOnBean(JsonMapper.class) - @ImportRuntimeHints(JacksonTesterRuntimeHints.class) - FactoryBean> jacksonTesterFactoryBean(JsonMapper mapper) { - return new JsonTesterFactoryBean<>(JacksonTester.class, mapper); - } - - static class JacksonTesterRuntimeHints extends AbstractJsonMarshalTesterRuntimeHints { - - JacksonTesterRuntimeHints() { - super(JacksonTester.class); - } - - } - - } - - @Configuration(proxyBeanMethods = false) - @ConditionalOnClass(Gson.class) - static class GsonJsonTestersConfiguration { - - @Bean - @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) - @ConditionalOnBean(Gson.class) - @ImportRuntimeHints(GsonTesterRuntimeHints.class) - FactoryBean> gsonTesterFactoryBean(Gson gson) { - return new JsonTesterFactoryBean<>(GsonTester.class, gson); - } - - static class GsonTesterRuntimeHints extends AbstractJsonMarshalTesterRuntimeHints { - - GsonTesterRuntimeHints() { - super(GsonTester.class); - } - - } - - } - - @Configuration(proxyBeanMethods = false) - @ConditionalOnClass(Jsonb.class) - static class JsonbJsonTesterConfiguration { - - @Bean - @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) - @ConditionalOnBean(Jsonb.class) - @ImportRuntimeHints(JsonbJsonTesterRuntimeHints.class) - FactoryBean> jsonbTesterFactoryBean(Jsonb jsonb) { - return new JsonTesterFactoryBean<>(JsonbTester.class, jsonb); - } - - static class JsonbJsonTesterRuntimeHints extends AbstractJsonMarshalTesterRuntimeHints { - - JsonbJsonTesterRuntimeHints() { - super(JsonbTester.class); - } - - } - - } - - /** - * {@link FactoryBean} used to create JSON Tester instances. - * - * @param the object type - * @param the marshaller type - */ - static class JsonTesterFactoryBean implements FactoryBean { - - private final Class objectType; - - private final @Nullable M marshaller; - - JsonTesterFactoryBean(Class objectType, @Nullable M marshaller) { - this.objectType = objectType; - this.marshaller = marshaller; - } - - @Override - public boolean isSingleton() { - return false; - } - - @Override - @SuppressWarnings("unchecked") - public T getObject() throws Exception { - if (this.marshaller == null) { - Constructor constructor = this.objectType.getDeclaredConstructor(); - ReflectionUtils.makeAccessible(constructor); - return (T) BeanUtils.instantiateClass(constructor); - } - Constructor[] constructors = this.objectType.getDeclaredConstructors(); - for (Constructor constructor : constructors) { - if (constructor.getParameterCount() == 1 - && constructor.getParameterTypes()[0].isInstance(this.marshaller)) { - ReflectionUtils.makeAccessible(constructor); - return (T) BeanUtils.instantiateClass(constructor, this.marshaller); - } - } - throw new IllegalStateException(this.objectType + " does not have a usable constructor"); - } - - @Override - public Class getObjectType() { - return this.objectType; - } - - } - - /** - * {@link BeanPostProcessor} used to initialize JSON testers. - */ - static class JsonMarshalTestersBeanPostProcessor implements InstantiationAwareBeanPostProcessor { - - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - ReflectionUtils.doWithFields(bean.getClass(), (field) -> processField(bean, field)); - return bean; - } - - private void processField(Object bean, Field field) { - if (AbstractJsonMarshalTester.class.isAssignableFrom(field.getType())) { - initializeTester(bean, field, bean.getClass(), ResolvableType.forField(field).getGeneric()); - } - else if (BasicJsonTester.class.isAssignableFrom(field.getType())) { - initializeTester(bean, field, bean.getClass()); - } - } - - private void initializeTester(Object bean, Field field, Object... args) { - ReflectionUtils.makeAccessible(field); - Object tester = ReflectionUtils.getField(field, bean); - if (tester != null) { - ReflectionTestUtils.invokeMethod(tester, "initialize", args); - } - } - - } - - @SuppressWarnings("rawtypes") - static class AbstractJsonMarshalTesterRuntimeHints implements RuntimeHintsRegistrar { - - private final Class tester; - - AbstractJsonMarshalTesterRuntimeHints(Class tester) { - this.tester = tester; - } - - @Override - public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { - ReflectionHints reflection = hints.reflection(); - reflection.registerType(this.tester, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); - Method method = ReflectionUtils.findMethod(this.tester, "initialize", Class.class, ResolvableType.class); - Assert.state(method != null, "'method' must not be null"); - reflection.registerMethod(method, ExecutableMode.INVOKE); - } - - } - - static class BasicJsonTesterRuntimeHints implements RuntimeHintsRegistrar { - - @Override - public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { - ReflectionHints reflection = hints.reflection(); - reflection.registerType(BasicJsonTester.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); - Method method = ReflectionUtils.findMethod(BasicJsonTester.class, "initialize", Class.class); - Assert.state(method != null, "'method' must not be null"); - reflection.registerMethod(method, ExecutableMode.INVOKE); - } - - } - -} diff --git a/module/spring-boot-json-test/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/module/spring-boot-json-test/src/main/resources/META-INF/additional-spring-configuration-metadata.json deleted file mode 100644 index 59a95a32f89..00000000000 --- a/module/spring-boot-json-test/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "properties": [ - { - "name": "spring.test.jsontesters.enabled", - "type": "java.lang.Boolean", - "description": "Whether auto-configuration of JSON testers is enabled.", - "defaultValue": "true" - } - ] -} diff --git a/module/spring-boot-json-test/src/main/resources/META-INF/spring.factories b/module/spring-boot-json-test/src/main/resources/META-INF/spring.factories deleted file mode 100644 index f84213ef22a..00000000000 --- a/module/spring-boot-json-test/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,3 +0,0 @@ -# Spring Test Context Customizer Factories -org.springframework.test.context.ContextCustomizerFactory=\ -org.springframework.boot.json.test.DuplicateJsonObjectContextCustomizerFactory diff --git a/module/spring-boot-json-test/src/main/resources/META-INF/spring/org.springframework.boot.json.test.autoconfigure.AutoConfigureJson.imports b/module/spring-boot-json-test/src/main/resources/META-INF/spring/org.springframework.boot.json.test.autoconfigure.AutoConfigureJson.imports deleted file mode 100644 index 1d713034429..00000000000 --- a/module/spring-boot-json-test/src/main/resources/META-INF/spring/org.springframework.boot.json.test.autoconfigure.AutoConfigureJson.imports +++ /dev/null @@ -1,4 +0,0 @@ -optional:org.springframework.boot.gson.autoconfigure.GsonAutoConfiguration -optional:org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration -optional:org.springframework.boot.jsonb.autoconfigure.JsonbAutoConfiguration -optional:org.springframework.boot.kotlin.serialization.autoconfigure.KotlinSerializationAutoConfiguration diff --git a/module/spring-boot-json-test/src/main/resources/META-INF/spring/org.springframework.boot.json.test.autoconfigure.AutoConfigureJsonTesters.imports b/module/spring-boot-json-test/src/main/resources/META-INF/spring/org.springframework.boot.json.test.autoconfigure.AutoConfigureJsonTesters.imports deleted file mode 100644 index 66c3a4a6a9b..00000000000 --- a/module/spring-boot-json-test/src/main/resources/META-INF/spring/org.springframework.boot.json.test.autoconfigure.AutoConfigureJsonTesters.imports +++ /dev/null @@ -1 +0,0 @@ -org.springframework.boot.json.test.autoconfigure.JsonTestersAutoConfiguration diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/JsonTestersAutoConfigurationTests.java b/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/JsonTestersAutoConfigurationTests.java deleted file mode 100644 index 933e0a7574a..00000000000 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/JsonTestersAutoConfigurationTests.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2012-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.json.test.autoconfigure; - -import java.util.function.Consumer; - -import org.junit.jupiter.api.Test; - -import org.springframework.aot.hint.RuntimeHints; -import org.springframework.aot.hint.predicate.ReflectionHintsPredicates; -import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; -import org.springframework.aot.test.generate.TestGenerationContext; -import org.springframework.boot.gson.autoconfigure.GsonAutoConfiguration; -import org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration; -import org.springframework.boot.json.test.BasicJsonTester; -import org.springframework.boot.json.test.GsonTester; -import org.springframework.boot.json.test.JacksonTester; -import org.springframework.boot.json.test.JsonbTester; -import org.springframework.boot.jsonb.autoconfigure.JsonbAutoConfiguration; -import org.springframework.boot.test.util.TestPropertyValues; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.aot.ApplicationContextAotGenerator; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link JsonTestersAutoConfiguration}. - * - * @author Andy Wilkinson - */ -class JsonTestersAutoConfigurationTests { - - @Test - void withNoMarshallersOnlyBasicJsonTesterHintsAreContributed() { - jsonTesters((runtimeHints) -> { - ReflectionHintsPredicates reflection = RuntimeHintsPredicates.reflection(); - assertThat(reflection.onType(BasicJsonTester.class)).accepts(runtimeHints); - assertThat(reflection.onType(JacksonTester.class).negate()).accepts(runtimeHints); - assertThat(reflection.onType(JsonbTester.class).negate()).accepts(runtimeHints); - assertThat(reflection.onType(GsonTester.class).negate()).accepts(runtimeHints); - }); - } - - @Test - void withObjectMapperBeanJacksonTesterHintsAreContributed() { - jsonTestersWith(JacksonAutoConfiguration.class, (runtimeHints) -> { - ReflectionHintsPredicates reflection = RuntimeHintsPredicates.reflection(); - assertThat(reflection.onType(BasicJsonTester.class)).accepts(runtimeHints); - assertThat(reflection.onType(JacksonTester.class)).accepts(runtimeHints); - assertThat(reflection.onType(JsonbTester.class).negate()).accepts(runtimeHints); - assertThat(reflection.onType(GsonTester.class).negate()).accepts(runtimeHints); - }); - } - - @Test - void withGsonBeanGsonTesterHintsAreContributed() { - jsonTestersWith(GsonAutoConfiguration.class, (runtimeHints) -> { - ReflectionHintsPredicates reflection = RuntimeHintsPredicates.reflection(); - assertThat(reflection.onType(BasicJsonTester.class)).accepts(runtimeHints); - assertThat(reflection.onType(JacksonTester.class).negate()).accepts(runtimeHints); - assertThat(reflection.onType(JsonbTester.class).negate()).accepts(runtimeHints); - assertThat(reflection.onType(GsonTester.class)).accepts(runtimeHints); - }); - } - - @Test - void withJsonbBeanJsonbTesterHintsAreContributed() { - jsonTestersWith(JsonbAutoConfiguration.class, (runtimeHints) -> { - ReflectionHintsPredicates reflection = RuntimeHintsPredicates.reflection(); - assertThat(reflection.onType(BasicJsonTester.class)).accepts(runtimeHints); - assertThat(reflection.onType(JacksonTester.class).negate()).accepts(runtimeHints); - assertThat(reflection.onType(JsonbTester.class)).accepts(runtimeHints); - assertThat(reflection.onType(GsonTester.class).negate()).accepts(runtimeHints); - }); - } - - private void jsonTesters(Consumer hintsConsumer) { - jsonTestersWith(null, hintsConsumer); - } - - private void jsonTestersWith(Class configuration, Consumer hintsConsumer) { - try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) { - TestPropertyValues.of("spring.test.jsontesters.enabled=true").applyTo(context); - if (configuration != null) { - context.register(configuration); - } - context.register(JsonTestersAutoConfiguration.class); - TestGenerationContext generationContext = new TestGenerationContext(); - new ApplicationContextAotGenerator().processAheadOfTime(context, generationContext); - hintsConsumer.accept(generationContext.getRuntimeHints()); - } - } - -} diff --git a/module/spring-boot-jsonb/build.gradle b/module/spring-boot-jsonb/build.gradle index 84d67def94d..aab70223095 100644 --- a/module/spring-boot-jsonb/build.gradle +++ b/module/spring-boot-jsonb/build.gradle @@ -29,7 +29,7 @@ dependencies { api("org.eclipse:yasson") optional(project(":core:spring-boot-autoconfigure")) - optional(project(":core:spring-boot-autoconfigure")) + optional(project(":core:spring-boot-test-autoconfigure")) testImplementation(project(":core:spring-boot-test")) testImplementation(project(":test-support:spring-boot-test-support")) diff --git a/module/spring-boot-jsonb/src/main/java/org/springframework/boot/jsonb/autoconfigure/JsonbTesterAutoConfiguration.java b/module/spring-boot-jsonb/src/main/java/org/springframework/boot/jsonb/autoconfigure/JsonbTesterAutoConfiguration.java new file mode 100644 index 00000000000..849da29e240 --- /dev/null +++ b/module/spring-boot-jsonb/src/main/java/org/springframework/boot/jsonb/autoconfigure/JsonbTesterAutoConfiguration.java @@ -0,0 +1,59 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.jsonb.autoconfigure; + +import jakarta.json.bind.Jsonb; + +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.test.autoconfigure.TestAutoConfiguration; +import org.springframework.boot.test.autoconfigure.json.ConditionalOnJsonTesters; +import org.springframework.boot.test.autoconfigure.json.JsonMarshalTesterRuntimeHints; +import org.springframework.boot.test.autoconfigure.json.JsonTesterFactoryBean; +import org.springframework.boot.test.json.JsonbTester; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ImportRuntimeHints; +import org.springframework.context.annotation.Scope; + +/** + * {@link EnableAutoConfiguration Auto-configuration} for {@link JsonbTester}. + * + * @author Phjllip Webb + */ +@TestAutoConfiguration(after = JsonbAutoConfiguration.class) +@ConditionalOnJsonTesters +final class JsonbTesterAutoConfiguration { + + @Bean + @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) + @ConditionalOnBean(Jsonb.class) + @ImportRuntimeHints(JsonbJsonTesterRuntimeHints.class) + FactoryBean> jsonbTesterFactoryBean(Jsonb jsonb) { + return new JsonTesterFactoryBean<>(JsonbTester.class, jsonb); + } + + static class JsonbJsonTesterRuntimeHints extends JsonMarshalTesterRuntimeHints { + + JsonbJsonTesterRuntimeHints() { + super(JsonbTester.class); + } + + } + +} diff --git a/module/spring-boot-jsonb/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters.imports b/module/spring-boot-jsonb/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters.imports new file mode 100644 index 00000000000..32a6c51941e --- /dev/null +++ b/module/spring-boot-jsonb/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters.imports @@ -0,0 +1,2 @@ +org.springframework.boot.jsonb.autoconfigure.JsonbAutoConfiguration +org.springframework.boot.jsonb.autoconfigure.JsonbTesterAutoConfiguration \ No newline at end of file diff --git a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/JsonTestApplication.java b/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/JsonTestApplication.java similarity index 87% rename from module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/JsonTestApplication.java rename to module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/JsonTestApplication.java index 0d004f435e8..ab30917b7b6 100644 --- a/module/spring-boot-json-test/src/test/java/org/springframework/boot/json/test/autoconfigure/JsonTestApplication.java +++ b/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/JsonTestApplication.java @@ -14,9 +14,10 @@ * limitations under the License. */ -package org.springframework.boot.json.test.autoconfigure; +package org.springframework.boot.jsonb.autoconfigure; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.autoconfigure.json.JsonTest; /** * Application for testing of {@link JsonTest @JsonTest}. diff --git a/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/JsonbTesterAutoConfigurationTests.java b/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/JsonbTesterAutoConfigurationTests.java new file mode 100644 index 00000000000..e30646d2c87 --- /dev/null +++ b/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/JsonbTesterAutoConfigurationTests.java @@ -0,0 +1,54 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.jsonb.autoconfigure; + +import org.junit.jupiter.api.Test; + +import org.springframework.aot.hint.predicate.ReflectionHintsPredicates; +import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; +import org.springframework.aot.test.generate.TestGenerationContext; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.autoconfigure.json.JsonTestersAutoConfiguration; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.boot.test.json.JsonbTester; +import org.springframework.context.aot.ApplicationContextAotGenerator; +import org.springframework.context.support.GenericApplicationContext; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link JsonbTesterAutoConfiguration}. + * + * @author Andy Wilkinson + */ +class JsonbTesterAutoConfigurationTests { + + private final ApplicationContextRunner runner = new ApplicationContextRunner().withConfiguration(AutoConfigurations + .of(JsonTestersAutoConfiguration.class, JsonbAutoConfiguration.class, JsonbTesterAutoConfiguration.class)); + + @Test + void hintsAreContributed() { + this.runner.withPropertyValues("spring.test.jsontesters.enabled=true").prepare((context) -> { + TestGenerationContext generationContext = new TestGenerationContext(); + new ApplicationContextAotGenerator().processAheadOfTime( + (GenericApplicationContext) context.getSourceApplicationContext(), generationContext); + ReflectionHintsPredicates hints = RuntimeHintsPredicates.reflection(); + assertThat(hints.onType(JsonbTester.class)).accepts(generationContext.getRuntimeHints()); + }); + } + +} diff --git a/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/JsonTestApplication.java b/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/JsonTestApplication.java new file mode 100644 index 00000000000..e7dd07eb45c --- /dev/null +++ b/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/JsonTestApplication.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.jsonb.autoconfigure.jsontest; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.autoconfigure.json.JsonTest; + +/** + * Application for testing of {@link JsonTest @JsonTest}. + * + * @author Andy Wilkinson + */ +@SpringBootApplication +class JsonTestApplication { + +} diff --git a/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/JsonTestIntegrationTests.java b/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/JsonTestIntegrationTests.java new file mode 100644 index 00000000000..a437c31f7f7 --- /dev/null +++ b/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/JsonTestIntegrationTests.java @@ -0,0 +1,51 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.jsonb.autoconfigure.jsontest; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.jsonb.autoconfigure.jsontest.app.ExampleBasicObject; +import org.springframework.boot.jsonb.autoconfigure.jsontest.app.ExampleJsonApplication; +import org.springframework.boot.test.autoconfigure.json.JsonTest; +import org.springframework.boot.test.json.JsonbTester; +import org.springframework.test.context.ContextConfiguration; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link JsonTest @JsonTest}. + * + * @author Phillip Webb + * @author Madhura Bhave + * @author Eddú Meléndez + */ +@JsonTest +@ContextConfiguration(classes = ExampleJsonApplication.class) +class JsonTestIntegrationTests { + + @Autowired + private JsonbTester jsonbJson; + + @Test + void jsonb() throws Exception { + ExampleBasicObject object = new ExampleBasicObject(); + object.setValue("spring"); + assertThat(this.jsonbJson.write(object)).isEqualToJson("example.json"); + } + +} diff --git a/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/JsonTestWithAutoConfigureJsonTestersTests.java b/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/JsonTestWithAutoConfigureJsonTestersTests.java new file mode 100644 index 00000000000..847e22be43f --- /dev/null +++ b/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/JsonTestWithAutoConfigureJsonTestersTests.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.jsonb.autoconfigure.jsontest; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.jsonb.autoconfigure.jsontest.app.ExampleBasicObject; +import org.springframework.boot.jsonb.autoconfigure.jsontest.app.ExampleJsonApplication; +import org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters; +import org.springframework.boot.test.autoconfigure.json.JsonTest; +import org.springframework.boot.test.json.JsonbTester; +import org.springframework.test.context.ContextConfiguration; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link JsonTest @JsonTest} with + * {@link AutoConfigureJsonTesters @AutoConfigureJsonTesters}. + * + * @author Phillip Webb + */ +@JsonTest +@AutoConfigureJsonTesters(enabled = false) +@ContextConfiguration(classes = ExampleJsonApplication.class) +class JsonTestWithAutoConfigureJsonTestersTests { + + @Autowired(required = false) + private JsonbTester jsonbTester; + + @Test + void jsonb() { + assertThat(this.jsonbTester).isNull(); + } + +} diff --git a/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/SpringBootTestWithAutoConfigureJsonTestersTests.java b/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/SpringBootTestWithAutoConfigureJsonTestersTests.java new file mode 100644 index 00000000000..b989deab2d9 --- /dev/null +++ b/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/SpringBootTestWithAutoConfigureJsonTestersTests.java @@ -0,0 +1,50 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.jsonb.autoconfigure.jsontest; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.jsonb.autoconfigure.jsontest.app.ExampleBasicObject; +import org.springframework.boot.jsonb.autoconfigure.jsontest.app.ExampleJsonApplication; +import org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.json.JsonbTester; +import org.springframework.test.context.ContextConfiguration; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Integration tests for {@link SpringBootTest @SpringBootTest} with + * {@link AutoConfigureJsonTesters @AutoConfigureJsonTesters}. + * + * @author Andy Wilkinson + */ +@SpringBootTest +@AutoConfigureJsonTesters +@ContextConfiguration(classes = ExampleJsonApplication.class) +class SpringBootTestWithAutoConfigureJsonTestersTests { + + @Autowired + private JsonbTester jsonbTester; + + @Test + void contextLoads() { + assertThat(this.jsonbTester).isNotNull(); + } + +} diff --git a/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/app/ExampleBasicObject.java b/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/app/ExampleBasicObject.java new file mode 100644 index 00000000000..38c7c7469e7 --- /dev/null +++ b/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/app/ExampleBasicObject.java @@ -0,0 +1,49 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.jsonb.autoconfigure.jsontest.app; + +/** + * Example object to read/write as JSON. + * + * @author Phillip Webb + */ +public class ExampleBasicObject { + + private String value; + + public String getValue() { + return this.value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public boolean equals(Object obj) { + if (obj != null && obj.getClass() == getClass()) { + return this.value.equals(((ExampleBasicObject) obj).value); + } + return false; + } + + @Override + public int hashCode() { + return this.value.hashCode(); + } + +} diff --git a/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/app/ExampleJsonApplication.java b/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/app/ExampleJsonApplication.java new file mode 100644 index 00000000000..483761026ff --- /dev/null +++ b/module/spring-boot-jsonb/src/test/java/org/springframework/boot/jsonb/autoconfigure/jsontest/app/ExampleJsonApplication.java @@ -0,0 +1,31 @@ +/* + * Copyright 2012-present the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.jsonb.autoconfigure.jsontest.app; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.autoconfigure.json.JsonTest; + +/** + * Example {@link SpringBootApplication @SpringBootApplication} for use with + * {@link JsonTest @JsonTest} tests. + * + * @author Phillip Webb + */ +@SpringBootApplication +public class ExampleJsonApplication { + +} diff --git a/module/spring-boot-jsonb/src/test/resources/org/springframework/boot/jsonb/autoconfigure/jsontest/example.json b/module/spring-boot-jsonb/src/test/resources/org/springframework/boot/jsonb/autoconfigure/jsontest/example.json new file mode 100644 index 00000000000..40cc01ff6fc --- /dev/null +++ b/module/spring-boot-jsonb/src/test/resources/org/springframework/boot/jsonb/autoconfigure/jsontest/example.json @@ -0,0 +1,3 @@ +{ + "value" : "spring" +} diff --git a/module/spring-boot-kotlin-serialization/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.AutoConfigureJson.imports b/module/spring-boot-kotlin-serialization/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.AutoConfigureJson.imports new file mode 100644 index 00000000000..0b21f6c60a4 --- /dev/null +++ b/module/spring-boot-kotlin-serialization/src/main/resources/META-INF/spring/org.springframework.boot.test.autoconfigure.json.AutoConfigureJson.imports @@ -0,0 +1 @@ +optional:org.springframework.boot.kotlin.serialization.autoconfigure.KotlinSerializationAutoConfiguration diff --git a/module/spring-boot-restclient-test/build.gradle b/module/spring-boot-restclient-test/build.gradle index edda6ceba10..b3786fe0f59 100644 --- a/module/spring-boot-restclient-test/build.gradle +++ b/module/spring-boot-restclient-test/build.gradle @@ -29,7 +29,6 @@ dependencies { optional(project(":core:spring-boot-autoconfigure")) optional(project(":module:spring-boot-jackson")) - optional(project(":module:spring-boot-json-test")) optional(project(":module:spring-boot-restclient")) optional("org.junit.jupiter:junit-jupiter-api") optional("org.springframework:spring-test") diff --git a/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/autoconfigure/AutoConfigureWebClient.java b/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/autoconfigure/AutoConfigureWebClient.java index 269a34db3bb..5377cd319df 100644 --- a/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/autoconfigure/AutoConfigureWebClient.java +++ b/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/autoconfigure/AutoConfigureWebClient.java @@ -24,8 +24,8 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.json.test.autoconfigure.AutoConfigureJson; import org.springframework.boot.restclient.RestTemplateBuilder; +import org.springframework.boot.test.autoconfigure.json.AutoConfigureJson; import org.springframework.boot.test.context.PropertyMapping; import org.springframework.web.client.RestTemplate; diff --git a/module/spring-boot-webflux-test/build.gradle b/module/spring-boot-webflux-test/build.gradle index 54c2bd59fef..f01ac7b3d40 100644 --- a/module/spring-boot-webflux-test/build.gradle +++ b/module/spring-boot-webflux-test/build.gradle @@ -30,7 +30,6 @@ dependencies { optional(project(":core:spring-boot-autoconfigure")) optional(project(":module:spring-boot-http-codec")) optional(project(":module:spring-boot-jackson")) - optional(project(":module:spring-boot-json-test")) optional(project(":module:spring-boot-validation")) optional(project(":module:spring-boot-web-server-test")) optional("org.junit.jupiter:junit-jupiter-api") diff --git a/module/spring-boot-webflux-test/src/main/java/org/springframework/boot/webflux/test/autoconfigure/WebFluxTest.java b/module/spring-boot-webflux-test/src/main/java/org/springframework/boot/webflux/test/autoconfigure/WebFluxTest.java index fb520b0f690..1720ee42285 100644 --- a/module/spring-boot-webflux-test/src/main/java/org/springframework/boot/webflux/test/autoconfigure/WebFluxTest.java +++ b/module/spring-boot-webflux-test/src/main/java/org/springframework/boot/webflux/test/autoconfigure/WebFluxTest.java @@ -27,8 +27,8 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.json.test.autoconfigure.AutoConfigureJson; import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; +import org.springframework.boot.test.autoconfigure.json.AutoConfigureJson; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.filter.annotation.TypeExcludeFilters; import org.springframework.context.annotation.ComponentScan; diff --git a/module/spring-boot-webmvc-test/build.gradle b/module/spring-boot-webmvc-test/build.gradle index 469c2aefbcd..50454445034 100644 --- a/module/spring-boot-webmvc-test/build.gradle +++ b/module/spring-boot-webmvc-test/build.gradle @@ -37,7 +37,6 @@ dependencies { optional(project(":core:spring-boot-autoconfigure")) optional(project(":core:spring-boot-test-autoconfigure")) optional(project(":module:spring-boot-jackson")) - optional(project(":module:spring-boot-json-test")) optional(project(":module:spring-boot-validation")) optional(project(":module:spring-boot-webflux")) optional("org.junit.jupiter:junit-jupiter-api") diff --git a/module/spring-boot-webmvc-test/src/main/java/org/springframework/boot/webmvc/test/autoconfigure/AutoConfigureWebMvc.java b/module/spring-boot-webmvc-test/src/main/java/org/springframework/boot/webmvc/test/autoconfigure/AutoConfigureWebMvc.java index dccb816ef36..f12614a6509 100644 --- a/module/spring-boot-webmvc-test/src/main/java/org/springframework/boot/webmvc/test/autoconfigure/AutoConfigureWebMvc.java +++ b/module/spring-boot-webmvc-test/src/main/java/org/springframework/boot/webmvc/test/autoconfigure/AutoConfigureWebMvc.java @@ -24,7 +24,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.json.test.autoconfigure.AutoConfigureJson; +import org.springframework.boot.test.autoconfigure.json.AutoConfigureJson; /** * {@link ImportAutoConfiguration Auto-configuration imports} for typical Spring MVC diff --git a/platform/spring-boot-dependencies/build.gradle b/platform/spring-boot-dependencies/build.gradle index cb41a7d58e3..5723210cecf 100644 --- a/platform/spring-boot-dependencies/build.gradle +++ b/platform/spring-boot-dependencies/build.gradle @@ -2040,7 +2040,6 @@ bom { "spring-boot-jooq-test", "spring-boot-jpa", "spring-boot-jpa-test", - "spring-boot-json-test", "spring-boot-jsonb", "spring-boot-kafka", "spring-boot-kotlin-serialization", diff --git a/settings.gradle b/settings.gradle index 0fad3157a07..97f524b86fb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -140,7 +140,6 @@ include "module:spring-boot-jooq" include "module:spring-boot-jooq-test" include "module:spring-boot-jpa" include "module:spring-boot-jpa-test" -include "module:spring-boot-json-test" include "module:spring-boot-jsonb" include "module:spring-boot-kafka" include "module:spring-boot-kotlin-serialization" diff --git a/smoke-test/spring-boot-smoke-test-test/build.gradle b/smoke-test/spring-boot-smoke-test-test/build.gradle index eb7f6a7c757..42d6ed4e220 100644 --- a/smoke-test/spring-boot-smoke-test-test/build.gradle +++ b/smoke-test/spring-boot-smoke-test-test/build.gradle @@ -30,7 +30,6 @@ dependencies { testImplementation(project(":starter:spring-boot-starter-test")) testImplementation(project(":module:spring-boot-data-jpa-test")) testImplementation(project(":module:spring-boot-jdbc-test")) - testImplementation(project(":module:spring-boot-json-test")) testImplementation(project(":module:spring-boot-restclient-test")) testImplementation(project(":module:spring-boot-webmvc-test")) testImplementation("org.htmlunit:htmlunit") diff --git a/smoke-test/spring-boot-smoke-test-test/src/test/java/smoketest/test/service/VehicleDetailsJsonTests.java b/smoke-test/spring-boot-smoke-test-test/src/test/java/smoketest/test/service/VehicleDetailsJsonTests.java index 90d613c18e8..b9439620b51 100644 --- a/smoke-test/spring-boot-smoke-test-test/src/test/java/smoketest/test/service/VehicleDetailsJsonTests.java +++ b/smoke-test/spring-boot-smoke-test-test/src/test/java/smoketest/test/service/VehicleDetailsJsonTests.java @@ -19,8 +19,8 @@ package smoketest.test.service; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.json.test.JacksonTester; -import org.springframework.boot.json.test.autoconfigure.JsonTest; +import org.springframework.boot.test.autoconfigure.json.JsonTest; +import org.springframework.boot.test.json.JacksonTester; import static org.assertj.core.api.Assertions.assertThat; diff --git a/system-test/spring-boot-image-system-tests/build.gradle b/system-test/spring-boot-image-system-tests/build.gradle index 1a20b8a9fd4..a422136f527 100644 --- a/system-test/spring-boot-image-system-tests/build.gradle +++ b/system-test/spring-boot-image-system-tests/build.gradle @@ -51,7 +51,6 @@ dependencies { } systemTestImplementation(project(":buildpack:spring-boot-buildpack-platform")) - systemTestImplementation(project(":module:spring-boot-json-test")) systemTestImplementation(project(":starter:spring-boot-starter-test")) systemTestImplementation(project(":test-support:spring-boot-gradle-test-support")) systemTestImplementation(gradleTestKit()) diff --git a/system-test/spring-boot-image-system-tests/src/systemTest/java/org/springframework/boot/image/assertions/ContainerConfigAssert.java b/system-test/spring-boot-image-system-tests/src/systemTest/java/org/springframework/boot/image/assertions/ContainerConfigAssert.java index cf529c1e311..dbf5dcea437 100644 --- a/system-test/spring-boot-image-system-tests/src/systemTest/java/org/springframework/boot/image/assertions/ContainerConfigAssert.java +++ b/system-test/spring-boot-image-system-tests/src/systemTest/java/org/springframework/boot/image/assertions/ContainerConfigAssert.java @@ -31,7 +31,7 @@ import org.assertj.core.api.AbstractObjectAssert; import org.assertj.core.api.ListAssert; import org.assertj.core.api.ObjectAssert; -import org.springframework.boot.json.test.JsonContentAssert; +import org.springframework.boot.test.json.JsonContentAssert; /** * AssertJ {@link org.assertj.core.api.Assert} for Docker image container configuration. diff --git a/system-test/spring-boot-image-system-tests/src/systemTest/java/org/springframework/boot/image/assertions/ImageAssert.java b/system-test/spring-boot-image-system-tests/src/systemTest/java/org/springframework/boot/image/assertions/ImageAssert.java index d185a76e6f8..fbc242a647d 100644 --- a/system-test/spring-boot-image-system-tests/src/systemTest/java/org/springframework/boot/image/assertions/ImageAssert.java +++ b/system-test/spring-boot-image-system-tests/src/systemTest/java/org/springframework/boot/image/assertions/ImageAssert.java @@ -33,7 +33,7 @@ import org.assertj.core.api.ListAssert; import org.springframework.boot.buildpack.platform.docker.DockerApi; import org.springframework.boot.buildpack.platform.docker.type.ImageReference; import org.springframework.boot.buildpack.platform.docker.type.Layer; -import org.springframework.boot.json.test.JsonContentAssert; +import org.springframework.boot.test.json.JsonContentAssert; import org.springframework.util.StreamUtils; /**