From e7f3ae19f8bb86ad4be3dc0c5f732b0bf62713f6 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 10 Oct 2025 14:08:16 -0700 Subject: [PATCH] Add Jackson 2 smoke tests See gh-47688 Co-authored-by: Andy Wilkinson --- settings.gradle | 2 + .../build.gradle | 30 +++++++ .../java/smoketest/jackson2/mixed/Name.java | 21 +++++ .../jackson2/mixed/NamesEndpoint.java | 39 ++++++++++ .../jackson2/mixed/SampleController.java | 32 ++++++++ .../mixed/SampleJackson2MixedApplication.java | 29 +++++++ .../mixed/SampleJacksonComponent.java | 38 +++++++++ .../jackson2/mixed/SampleJsonComponent.java | 40 ++++++++++ .../jackson2/mixed/package-info.java | 20 +++++ .../src/main/resources/application.properties | 2 + .../mixed/MixedJacksonPresenceTests.java | 42 ++++++++++ .../SampleJackson2MixedApplicationTests.java | 77 ++++++++++++++++++ ...ApplicationWithJackson3PreferredTests.java | 78 +++++++++++++++++++ .../build.gradle | 34 ++++++++ .../only/SampleJackson2OnlyApplication.java | 29 +++++++ .../smoketest/jackson2/only/package-info.java | 20 +++++ .../src/main/resources/application.properties | 1 + .../only/OnlyJackson2PresenceTests.java | 42 ++++++++++ .../SampleJackson2OnlyApplicationTests.java | 67 ++++++++++++++++ 19 files changed, 643 insertions(+) create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-mixed/build.gradle create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/Name.java create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/NamesEndpoint.java create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/SampleController.java create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/SampleJackson2MixedApplication.java create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/SampleJacksonComponent.java create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/SampleJsonComponent.java create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/package-info.java create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/resources/application.properties create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-mixed/src/test/java/smoketest/jackson2/mixed/MixedJacksonPresenceTests.java create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-mixed/src/test/java/smoketest/jackson2/mixed/SampleJackson2MixedApplicationTests.java create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-mixed/src/test/java/smoketest/jackson2/mixed/SampleJackson2MixedApplicationWithJackson3PreferredTests.java create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-only/build.gradle create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-only/src/main/java/smoketest/jackson2/only/SampleJackson2OnlyApplication.java create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-only/src/main/java/smoketest/jackson2/only/package-info.java create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-only/src/main/resources/application.properties create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-only/src/test/java/smoketest/jackson2/only/OnlyJackson2PresenceTests.java create mode 100644 smoke-test/spring-boot-smoke-test-jackson2-only/src/test/java/smoketest/jackson2/only/SampleJackson2OnlyApplicationTests.java diff --git a/settings.gradle b/settings.gradle index 2fca806bdd4..bbcd67e46da 100644 --- a/settings.gradle +++ b/settings.gradle @@ -414,6 +414,8 @@ include ":smoke-test:spring-boot-smoke-test-graphql" include ":smoke-test:spring-boot-smoke-test-hateoas" include ":smoke-test:spring-boot-smoke-test-hibernate" include ":smoke-test:spring-boot-smoke-test-integration" +include ":smoke-test:spring-boot-smoke-test-jackson2-mixed" +include ":smoke-test:spring-boot-smoke-test-jackson2-only" include ":smoke-test:spring-boot-smoke-test-jetty" include ":smoke-test:spring-boot-smoke-test-jetty-jsp" include ":smoke-test:spring-boot-smoke-test-jetty-ssl" diff --git a/smoke-test/spring-boot-smoke-test-jackson2-mixed/build.gradle b/smoke-test/spring-boot-smoke-test-jackson2-mixed/build.gradle new file mode 100644 index 00000000000..c9fcf508ae3 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-mixed/build.gradle @@ -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. + */ + +plugins { + id "java" +} + +description = "Spring Boot Jackson 2 mixed with Jackson 3 smoke test" + +dependencies { + implementation(project(":module:spring-boot-jackson2")) + implementation(project(":starter:spring-boot-starter-actuator")) + implementation(project(":starter:spring-boot-starter-webmvc")) + + testImplementation(project(":starter:spring-boot-starter-test")) + testImplementation(project(":starter:spring-boot-starter-webmvc-test")) +} diff --git a/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/Name.java b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/Name.java new file mode 100644 index 00000000000..b39cd2940da --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/Name.java @@ -0,0 +1,21 @@ +/* + * 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 smoketest.jackson2.mixed; + +public record Name(String first, String last) { + +} diff --git a/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/NamesEndpoint.java b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/NamesEndpoint.java new file mode 100644 index 00000000000..74f83c4654c --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/NamesEndpoint.java @@ -0,0 +1,39 @@ +/* + * 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 smoketest.jackson2.mixed; + +import java.util.List; + +import org.springframework.boot.actuate.endpoint.annotation.Endpoint; +import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; +import org.springframework.stereotype.Component; + +/** + * Names endpoint. + * + * @author Andy Wilkinson + */ +@Component +@Endpoint(id = "names") +public class NamesEndpoint { + + @ReadOperation + List names() { + return List.of(new Name("Spring", "Boot")); + } + +} diff --git a/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/SampleController.java b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/SampleController.java new file mode 100644 index 00000000000..45d449de5cc --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/SampleController.java @@ -0,0 +1,32 @@ +/* + * 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 smoketest.jackson2.mixed; + +import java.util.List; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class SampleController { + + @GetMapping("/names") + List names() { + return List.of(new Name("Spring", "Boot")); + } + +} diff --git a/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/SampleJackson2MixedApplication.java b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/SampleJackson2MixedApplication.java new file mode 100644 index 00000000000..f2a83c9b7ae --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/SampleJackson2MixedApplication.java @@ -0,0 +1,29 @@ +/* + * 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 smoketest.jackson2.mixed; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleJackson2MixedApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleJackson2MixedApplication.class, args); + } + +} diff --git a/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/SampleJacksonComponent.java b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/SampleJacksonComponent.java new file mode 100644 index 00000000000..e74fc0d6925 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/SampleJacksonComponent.java @@ -0,0 +1,38 @@ +/* + * 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 smoketest.jackson2.mixed; + +import tools.jackson.core.JacksonException; +import tools.jackson.core.JsonGenerator; +import tools.jackson.databind.SerializationContext; +import tools.jackson.databind.ValueSerializer; + +import org.springframework.boot.jackson.JacksonComponent; + +@JacksonComponent +public class SampleJacksonComponent { + + public static class Serializer extends ValueSerializer { + + @Override + public void serialize(Name value, JsonGenerator gen, SerializationContext ctxt) throws JacksonException { + gen.writeString("JACKSON:%s:%s".formatted(value.first(), value.last())); + } + + } + +} diff --git a/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/SampleJsonComponent.java b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/SampleJsonComponent.java new file mode 100644 index 00000000000..f6a13a5fef5 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/SampleJsonComponent.java @@ -0,0 +1,40 @@ +/* + * 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 smoketest.jackson2.mixed; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; + +import org.springframework.boot.jackson2.JsonComponent; + +@JsonComponent +@SuppressWarnings("removal") +public class SampleJsonComponent { + + public static class Serializer extends JsonSerializer { + + @Override + public void serialize(Name value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeString("JACKSON2:%s:%s".formatted(value.first(), value.last())); + } + + } + +} diff --git a/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/package-info.java b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/package-info.java new file mode 100644 index 00000000000..5f429cddee0 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/java/smoketest/jackson2/mixed/package-info.java @@ -0,0 +1,20 @@ +/* + * 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. + */ + +@NullMarked +package smoketest.jackson2.mixed; + +import org.jspecify.annotations.NullMarked; diff --git a/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/resources/application.properties b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/resources/application.properties new file mode 100644 index 00000000000..1288f44c6f3 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/main/resources/application.properties @@ -0,0 +1,2 @@ +management.endpoints.web.exposure.include=* +spring.http.converters.preferred-json-mapper=jackson2 diff --git a/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/test/java/smoketest/jackson2/mixed/MixedJacksonPresenceTests.java b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/test/java/smoketest/jackson2/mixed/MixedJacksonPresenceTests.java new file mode 100644 index 00000000000..8c797c56e5c --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/test/java/smoketest/jackson2/mixed/MixedJacksonPresenceTests.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 smoketest.jackson2.mixed; + +import org.junit.jupiter.api.Test; + +import org.springframework.util.ClassUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for the presence of mixed versions of Jackson. + * + * @author Andy Wilkinson + */ +class MixedJacksonPresenceTests { + + @Test + void jackson2IsPresent() { + assertThat(ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", null)).isTrue(); + } + + @Test + void jackson3IsPresent() { + assertThat(ClassUtils.isPresent("tools.jackson.databind.ObjectMapper", null)).isTrue(); + } + +} diff --git a/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/test/java/smoketest/jackson2/mixed/SampleJackson2MixedApplicationTests.java b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/test/java/smoketest/jackson2/mixed/SampleJackson2MixedApplicationTests.java new file mode 100644 index 00000000000..da4d76a8a5c --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/test/java/smoketest/jackson2/mixed/SampleJackson2MixedApplicationTests.java @@ -0,0 +1,77 @@ +/* + * 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 smoketest.jackson2.mixed; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureRestTestClient; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.web.servlet.client.RestTestClient; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SampleJackson2MixedApplication}. + * + * @author Andy Wilkinson + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@AutoConfigureRestTestClient +class SampleJackson2MixedApplicationTests { + + @Autowired + RestTestClient rest; + + @Test + void jackson2IsUsedForHttpMessageConversion() { + this.rest.get().uri("/names").exchange().expectBody().json("[\"JACKSON2:Spring:Boot\"]"); + } + + @Test + void jackson2IsUsedForActuatorEndpoints() { + this.rest.get().uri("/actuator/names").exchange().expectBody().json("[\"JACKSON2:Spring:Boot\"]"); + } + + @Test + @SuppressWarnings("unchecked") + void configPropsShouldReturnOk() { + this.rest.get() + .uri("/actuator/configprops") + .exchange() + .expectStatus() + .isOk() + .expectBody(Map.class) + .value((body) -> assertThat(body).containsOnlyKeys("contexts")); + } + + @Test + @SuppressWarnings("unchecked") + void actuatorLinksShouldReturnOk() { + this.rest.get() + .uri("/actuator") + .exchange() + .expectStatus() + .isOk() + .expectBody(Map.class) + .value((body) -> assertThat(body).containsOnlyKeys("_links")); + } + +} diff --git a/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/test/java/smoketest/jackson2/mixed/SampleJackson2MixedApplicationWithJackson3PreferredTests.java b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/test/java/smoketest/jackson2/mixed/SampleJackson2MixedApplicationWithJackson3PreferredTests.java new file mode 100644 index 00000000000..f17e1e918d5 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-mixed/src/test/java/smoketest/jackson2/mixed/SampleJackson2MixedApplicationWithJackson3PreferredTests.java @@ -0,0 +1,78 @@ +/* + * 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 smoketest.jackson2.mixed; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureRestTestClient; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.web.servlet.client.RestTestClient; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for {@link SampleJackson2MixedApplication} when Jackson 3 is preferred. + * + * @author Andy Wilkinson + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, + properties = "spring.http.converters.preferred-json-mapper=jackson") +@AutoConfigureRestTestClient +class SampleJackson2MixedApplicationWithJackson3PreferredTests { + + @Autowired + RestTestClient rest; + + @Test + void jacksonIsUsedForHttpMessageConversion() { + this.rest.get().uri("/names").exchange().expectBody().json("[\"JACKSON:Spring:Boot\"]"); + } + + @Test + void jacksonIsUsedForActuatorEndpoints() { + this.rest.get().uri("/actuator/names").exchange().expectBody().json("[\"JACKSON:Spring:Boot\"]"); + } + + @Test + @SuppressWarnings("unchecked") + void configPropsShouldReturnOk() { + this.rest.get() + .uri("/actuator/configprops") + .exchange() + .expectStatus() + .isOk() + .expectBody(Map.class) + .value((body) -> assertThat(body).containsOnlyKeys("contexts")); + } + + @Test + @SuppressWarnings("unchecked") + void actuatorLinksShouldReturnOk() { + this.rest.get() + .uri("/actuator") + .exchange() + .expectStatus() + .isOk() + .expectBody(Map.class) + .value((body) -> assertThat(body).containsOnlyKeys("_links")); + } + +} diff --git a/smoke-test/spring-boot-smoke-test-jackson2-only/build.gradle b/smoke-test/spring-boot-smoke-test-jackson2-only/build.gradle new file mode 100644 index 00000000000..136d32d6701 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-only/build.gradle @@ -0,0 +1,34 @@ +/* + * 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" +} + +description = "Spring Boot Jackson 2 without Jackson 3 smoke test" + +dependencies { + implementation(project(":module:spring-boot-jackson2")) + implementation(project(":starter:spring-boot-starter-actuator")) + implementation(project(":starter:spring-boot-starter-webmvc")) { + exclude module: 'spring-boot-starter-jackson' + } + + testImplementation(project(":starter:spring-boot-starter-test")) + testImplementation(project(":starter:spring-boot-starter-webmvc-test")) { + exclude module: 'spring-boot-starter-jackson' + } +} diff --git a/smoke-test/spring-boot-smoke-test-jackson2-only/src/main/java/smoketest/jackson2/only/SampleJackson2OnlyApplication.java b/smoke-test/spring-boot-smoke-test-jackson2-only/src/main/java/smoketest/jackson2/only/SampleJackson2OnlyApplication.java new file mode 100644 index 00000000000..4ed4b1faf53 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-only/src/main/java/smoketest/jackson2/only/SampleJackson2OnlyApplication.java @@ -0,0 +1,29 @@ +/* + * 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 smoketest.jackson2.only; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SampleJackson2OnlyApplication { + + public static void main(String[] args) { + SpringApplication.run(SampleJackson2OnlyApplication.class, args); + } + +} diff --git a/smoke-test/spring-boot-smoke-test-jackson2-only/src/main/java/smoketest/jackson2/only/package-info.java b/smoke-test/spring-boot-smoke-test-jackson2-only/src/main/java/smoketest/jackson2/only/package-info.java new file mode 100644 index 00000000000..ecf34f0a59e --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-only/src/main/java/smoketest/jackson2/only/package-info.java @@ -0,0 +1,20 @@ +/* + * 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. + */ + +@NullMarked +package smoketest.jackson2.only; + +import org.jspecify.annotations.NullMarked; diff --git a/smoke-test/spring-boot-smoke-test-jackson2-only/src/main/resources/application.properties b/smoke-test/spring-boot-smoke-test-jackson2-only/src/main/resources/application.properties new file mode 100644 index 00000000000..821da092741 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-only/src/main/resources/application.properties @@ -0,0 +1 @@ +management.endpoints.web.exposure.include=* diff --git a/smoke-test/spring-boot-smoke-test-jackson2-only/src/test/java/smoketest/jackson2/only/OnlyJackson2PresenceTests.java b/smoke-test/spring-boot-smoke-test-jackson2-only/src/test/java/smoketest/jackson2/only/OnlyJackson2PresenceTests.java new file mode 100644 index 00000000000..00ada803a7d --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-only/src/test/java/smoketest/jackson2/only/OnlyJackson2PresenceTests.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 smoketest.jackson2.only; + +import org.junit.jupiter.api.Test; + +import org.springframework.util.ClassUtils; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for the presence of mixed versions of Jackson. + * + * @author Andy Wilkinson + */ +class OnlyJackson2PresenceTests { + + @Test + void jackson2IsPresent() { + assertThat(ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", null)).isTrue(); + } + + @Test + void jackson3IsNotPresent() { + assertThat(ClassUtils.isPresent("tools.jackson.databind.ObjectMapper", null)).isFalse(); + } + +} diff --git a/smoke-test/spring-boot-smoke-test-jackson2-only/src/test/java/smoketest/jackson2/only/SampleJackson2OnlyApplicationTests.java b/smoke-test/spring-boot-smoke-test-jackson2-only/src/test/java/smoketest/jackson2/only/SampleJackson2OnlyApplicationTests.java new file mode 100644 index 00000000000..fce0b81cb12 --- /dev/null +++ b/smoke-test/spring-boot-smoke-test-jackson2-only/src/test/java/smoketest/jackson2/only/SampleJackson2OnlyApplicationTests.java @@ -0,0 +1,67 @@ +/* + * 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 smoketest.jackson2.only; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.resttestclient.autoconfigure.AutoConfigureRestTestClient; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.web.servlet.client.RestTestClient; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Tests for Actuator running in {@link SampleJackson2OnlyApplication}. + * + * @author Andy Wilkinson + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@AutoConfigureRestTestClient +class SampleJackson2OnlyApplicationTests { + + @Autowired + RestTestClient rest; + + @Test + @SuppressWarnings("unchecked") + void configPropsShouldReturnOk() { + this.rest.get() + .uri("/actuator/configprops") + .exchange() + .expectStatus() + .isOk() + .expectBody(Map.class) + .value((body) -> assertThat(body).containsOnlyKeys("contexts")); + } + + @Test + @SuppressWarnings("unchecked") + void actuatorLinksShouldReturnOk() { + this.rest.get() + .uri("/actuator") + .exchange() + .expectStatus() + .isOk() + .expectBody(Map.class) + .value((body) -> assertThat(body).containsOnlyKeys("_links")); + } + +}