From 49cc1be535bc7cda28a605dea03c794013b1b469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Wed, 24 Apr 2024 10:51:38 +0200 Subject: [PATCH] Add smoke test to exercise scoped proxy scenario This commit adds a smoke test that is a companion of https://github.com/spring-projects/spring-framework/issues/32669 Closes gh-215 --- framework/webmvc-scoped-proxy/README.adoc | 1 + framework/webmvc-scoped-proxy/build.gradle | 20 +++++++++ .../WebMvcScopedProxyApplicationAotTests.java | 41 +++++++++++++++++++ .../webmvc/scopedproxy/TestController.java | 33 +++++++++++++++ .../scopedproxy/TestControllerAspect.java | 35 ++++++++++++++++ .../WebMvcScopedProxyApplication.java | 29 +++++++++++++ .../src/main/resources/application.properties | 0 7 files changed, 159 insertions(+) create mode 100644 framework/webmvc-scoped-proxy/README.adoc create mode 100644 framework/webmvc-scoped-proxy/build.gradle create mode 100644 framework/webmvc-scoped-proxy/src/appTest/java/com/example/webmvc/scopedproxy/WebMvcScopedProxyApplicationAotTests.java create mode 100644 framework/webmvc-scoped-proxy/src/main/java/com/example/webmvc/scopedproxy/TestController.java create mode 100644 framework/webmvc-scoped-proxy/src/main/java/com/example/webmvc/scopedproxy/TestControllerAspect.java create mode 100644 framework/webmvc-scoped-proxy/src/main/java/com/example/webmvc/scopedproxy/WebMvcScopedProxyApplication.java create mode 100644 framework/webmvc-scoped-proxy/src/main/resources/application.properties diff --git a/framework/webmvc-scoped-proxy/README.adoc b/framework/webmvc-scoped-proxy/README.adoc new file mode 100644 index 00000000..bc4030d7 --- /dev/null +++ b/framework/webmvc-scoped-proxy/README.adoc @@ -0,0 +1 @@ +Tests if WebMVC with a complex scoped controller is working diff --git a/framework/webmvc-scoped-proxy/build.gradle b/framework/webmvc-scoped-proxy/build.gradle new file mode 100644 index 00000000..0da128b7 --- /dev/null +++ b/framework/webmvc-scoped-proxy/build.gradle @@ -0,0 +1,20 @@ +plugins { + id "java" + id "org.springframework.boot" + id "org.springframework.aot.smoke-test" + id "org.graalvm.buildtools.native" +} + +dependencies { + implementation(enforcedPlatform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)) + implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.springframework.boot:spring-boot-starter-aop") + + testImplementation("org.springframework.boot:spring-boot-starter-test") + + appTestImplementation(project(":aot-smoke-test-support")) +} + +aotSmokeTest { + webApplication = true +} diff --git a/framework/webmvc-scoped-proxy/src/appTest/java/com/example/webmvc/scopedproxy/WebMvcScopedProxyApplicationAotTests.java b/framework/webmvc-scoped-proxy/src/appTest/java/com/example/webmvc/scopedproxy/WebMvcScopedProxyApplicationAotTests.java new file mode 100644 index 00000000..c895fdc3 --- /dev/null +++ b/framework/webmvc-scoped-proxy/src/appTest/java/com/example/webmvc/scopedproxy/WebMvcScopedProxyApplicationAotTests.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 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 com.example.webmvc.scopedproxy; + +import org.junit.jupiter.api.Test; + +import org.springframework.aot.smoketest.support.assertj.AssertableOutput; +import org.springframework.aot.smoketest.support.junit.ApplicationTest; +import org.springframework.test.web.reactive.server.WebTestClient; + +import static org.assertj.core.api.Assertions.assertThat; + +@ApplicationTest +class WebMvcScopedProxyApplicationAotTests { + + @Test + void scopedControllerIsInvoked(WebTestClient client, AssertableOutput output) { + client.get() + .exchange() + .expectStatus() + .isOk() + .expectBody() + .consumeWith((result) -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("Hello World")); + assertThat(output).hasSingleLineContaining("Invoking controller"); + } + +} diff --git a/framework/webmvc-scoped-proxy/src/main/java/com/example/webmvc/scopedproxy/TestController.java b/framework/webmvc-scoped-proxy/src/main/java/com/example/webmvc/scopedproxy/TestController.java new file mode 100644 index 00000000..0b0c246c --- /dev/null +++ b/framework/webmvc-scoped-proxy/src/main/java/com/example/webmvc/scopedproxy/TestController.java @@ -0,0 +1,33 @@ +/* + * Copyright 2022 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 com.example.webmvc.scopedproxy; + +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.context.annotation.ApplicationScope; + +@RestController +@ApplicationScope +public class TestController { + + @GetMapping(value = "/", produces = MediaType.TEXT_PLAIN_VALUE) + public String index() { + return "Hello World"; + } + +} diff --git a/framework/webmvc-scoped-proxy/src/main/java/com/example/webmvc/scopedproxy/TestControllerAspect.java b/framework/webmvc-scoped-proxy/src/main/java/com/example/webmvc/scopedproxy/TestControllerAspect.java new file mode 100644 index 00000000..2f21a59b --- /dev/null +++ b/framework/webmvc-scoped-proxy/src/main/java/com/example/webmvc/scopedproxy/TestControllerAspect.java @@ -0,0 +1,35 @@ +/* + * Copyright 2022 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 com.example.webmvc.scopedproxy; + +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; + +import org.springframework.stereotype.Component; + +@Component +@Aspect +public class TestControllerAspect { + + @Around("within(@org.springframework.web.bind.annotation.RestController *)") + public Object invokeAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { + System.out.println("Invoking controller"); + return proceedingJoinPoint.proceed(); + } + +} diff --git a/framework/webmvc-scoped-proxy/src/main/java/com/example/webmvc/scopedproxy/WebMvcScopedProxyApplication.java b/framework/webmvc-scoped-proxy/src/main/java/com/example/webmvc/scopedproxy/WebMvcScopedProxyApplication.java new file mode 100644 index 00000000..7db26980 --- /dev/null +++ b/framework/webmvc-scoped-proxy/src/main/java/com/example/webmvc/scopedproxy/WebMvcScopedProxyApplication.java @@ -0,0 +1,29 @@ +/* + * Copyright 2022 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 com.example.webmvc.scopedproxy; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class WebMvcScopedProxyApplication { + + public static void main(String[] args) { + SpringApplication.run(WebMvcScopedProxyApplication.class, args); + } + +} diff --git a/framework/webmvc-scoped-proxy/src/main/resources/application.properties b/framework/webmvc-scoped-proxy/src/main/resources/application.properties new file mode 100644 index 00000000..e69de29b