Merge branch '3.1.x' into 3.2.x

This commit is contained in:
Stéphane Nicoll
2024-04-24 16:50:53 +02:00
7 changed files with 159 additions and 0 deletions

View File

@@ -0,0 +1 @@
Tests if WebMVC with a complex scoped controller is working

View File

@@ -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
}

View File

@@ -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");
}
}

View File

@@ -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";
}
}

View File

@@ -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();
}
}

View File

@@ -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);
}
}