diff --git a/ci/smoke-tests.yml b/ci/smoke-tests.yml index 0194859a..6f7cedb9 100644 --- a/ci/smoke-tests.yml +++ b/ci/smoke-tests.yml @@ -46,6 +46,7 @@ smoke_tests: - security-thymeleaf - security-webflux - security-webmvc + - servlet-tomcat - session-jdbc - session-redis-webflux - spring-amqp-rabbit diff --git a/servlet-tomcat/README.adoc b/servlet-tomcat/README.adoc new file mode 100644 index 00000000..dd109b18 --- /dev/null +++ b/servlet-tomcat/README.adoc @@ -0,0 +1 @@ +Tests if Servlets with Tomcat works diff --git a/servlet-tomcat/build.gradle b/servlet-tomcat/build.gradle new file mode 100644 index 00000000..6a814643 --- /dev/null +++ b/servlet-tomcat/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(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)) + implementation("org.springframework.boot:spring-boot-starter-web") + + testImplementation("org.springframework.boot:spring-boot-starter-test") + + aotTestImplementation(project(":aot-smoke-test-support")) + aotTestImplementation("org.awaitility:awaitility:4.2.0") +} + +aotSmokeTest { + webApplication = true +} diff --git a/servlet-tomcat/src/aotTest/java/com/example/servlet/tomcat/ServletTomcatApplicationAotTests.java b/servlet-tomcat/src/aotTest/java/com/example/servlet/tomcat/ServletTomcatApplicationAotTests.java new file mode 100644 index 00000000..5879bb5e --- /dev/null +++ b/servlet-tomcat/src/aotTest/java/com/example/servlet/tomcat/ServletTomcatApplicationAotTests.java @@ -0,0 +1,19 @@ +package com.example.servlet.tomcat; + +import org.junit.jupiter.api.Test; + +import org.springframework.aot.smoketest.support.junit.AotSmokeTest; +import org.springframework.test.web.reactive.server.WebTestClient; + +import static org.assertj.core.api.Assertions.assertThat; + +@AotSmokeTest +class ServletTomcatApplicationAotTests { + + @Test + void servletIsInvokable(WebTestClient client) { + client.get().uri("/?name=Servlet").exchange().expectStatus().isOk().expectBody().consumeWith( + (result) -> assertThat(new String(result.getResponseBodyContent())).isEqualTo("Hello Servlet")); + } + +} diff --git a/servlet-tomcat/src/main/java/com/example/servlet/tomcat/ServletConfiguration.java b/servlet-tomcat/src/main/java/com/example/servlet/tomcat/ServletConfiguration.java new file mode 100644 index 00000000..47851dcc --- /dev/null +++ b/servlet-tomcat/src/main/java/com/example/servlet/tomcat/ServletConfiguration.java @@ -0,0 +1,15 @@ +package com.example.servlet.tomcat; + +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration(proxyBeanMethods = false) +class ServletConfiguration { + + @Bean + ServletRegistrationBean testServletServletRegistrationBean() { + return new ServletRegistrationBean<>(new TestServlet(), "/*"); + } + +} diff --git a/servlet-tomcat/src/main/java/com/example/servlet/tomcat/ServletTomcatApplication.java b/servlet-tomcat/src/main/java/com/example/servlet/tomcat/ServletTomcatApplication.java new file mode 100644 index 00000000..2f9961b7 --- /dev/null +++ b/servlet-tomcat/src/main/java/com/example/servlet/tomcat/ServletTomcatApplication.java @@ -0,0 +1,14 @@ +package com.example.servlet.tomcat; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ServletTomcatApplication { + + public static void main(String[] args) throws InterruptedException { + SpringApplication.run(ServletTomcatApplication.class, args); + Thread.currentThread().join(); // To be able to measure memory consumption + } + +} diff --git a/servlet-tomcat/src/main/java/com/example/servlet/tomcat/TestServlet.java b/servlet-tomcat/src/main/java/com/example/servlet/tomcat/TestServlet.java new file mode 100644 index 00000000..936f5dd1 --- /dev/null +++ b/servlet-tomcat/src/main/java/com/example/servlet/tomcat/TestServlet.java @@ -0,0 +1,24 @@ +package com.example.servlet.tomcat; + +import java.io.IOException; + +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +class TestServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + String[] names = req.getParameterValues("name"); + String name; + if (names == null || names.length == 0) { + name = "world"; + } + else { + name = names[0]; + } + resp.getWriter().printf("Hello %s", name); + } + +} diff --git a/servlet-tomcat/src/test/java/com/example/servlet/tomcat/ServletTomcatApplicationTests.java b/servlet-tomcat/src/test/java/com/example/servlet/tomcat/ServletTomcatApplicationTests.java new file mode 100644 index 00000000..d9d7ea86 --- /dev/null +++ b/servlet-tomcat/src/test/java/com/example/servlet/tomcat/ServletTomcatApplicationTests.java @@ -0,0 +1,14 @@ +package com.example.servlet.tomcat; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class ServletTomcatApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/settings.gradle b/settings.gradle index 4b1d0cfd..f96f59d2 100644 --- a/settings.gradle +++ b/settings.gradle @@ -74,6 +74,7 @@ include "security-method" include "security-thymeleaf" include "security-webflux" include "security-webmvc" +include "servlet-tomcat" include "session-jdbc" include "session-redis-webflux" include "spring-amqp-rabbit"