Add servlet-tomcat smoke test

See gh-70
This commit is contained in:
Moritz Halbritter
2022-08-10 10:27:13 +02:00
parent dfda0a30be
commit 08dd532532
9 changed files with 109 additions and 0 deletions

View File

@@ -46,6 +46,7 @@ smoke_tests:
- security-thymeleaf
- security-webflux
- security-webmvc
- servlet-tomcat
- session-jdbc
- session-redis-webflux
- spring-amqp-rabbit

View File

@@ -0,0 +1 @@
Tests if Servlets with Tomcat works

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

View File

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

View File

@@ -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<TestServlet> testServletServletRegistrationBean() {
return new ServletRegistrationBean<>(new TestServlet(), "/*");
}
}

View File

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

View File

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

View File

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

View File

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