Add servlet-undertow smoke test

See gh-70
This commit is contained in:
Andy Wilkinson
2022-09-13 12:20:19 +01:00
parent 5590e64578
commit 87d06e583f
11 changed files with 181 additions and 1 deletions

View File

@@ -48,7 +48,8 @@ final class ApplicationUnderTest {
}
List<Pattern> portPatterns = List.of(Pattern.compile("Tomcat started on port\\(s\\): ([0-9]+)"),
Pattern.compile("Netty started on port ([0-9]+)"),
Pattern.compile("Jetty started on port\\(s\\) ([0-9]+)"));
Pattern.compile("Jetty started on port\\(s\\) ([0-9]+)"),
Pattern.compile("Undertow started on port\\(s\\) ([0-9]+)"));
List<String> lines = Output.current().lines();
for (String line : lines) {
for (Pattern portPattern : portPatterns) {

View File

@@ -0,0 +1,61 @@
/*
* 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 org.springframework.aot.smoketest.thirdpartyhints;
import org.springframework.aot.hint.MemberCategory;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeReference;
/**
* A {@link RuntimeHintsRegistrar} for Undertow.
*
* @author Andy Wilkinson
*/
public class UndertowRuntimeHints implements RuntimeHintsRegistrar {
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
invokePublicConstructorsOf(hints, "io.undertow.UndertowLogger_$logger",
"io.undertow.server.protocol.http.HttpRequestParser$$generated",
"io.undertow.servlet.UndertowServletLogger_$logger", "io.undertow.servlet.handlers.DefaultServlet",
"io.undertow.util.FastConcurrentDirectDeque", "io.undertow.util.PortableConcurrentDirectDeque",
"io.undertow.websockets.core.WebSocketLogger_$logger", "io.undertow.websockets.jsr.JsrWebSocketFilter",
"io.undertow.websockets.jsr.JsrWebSocketFilter$LogoutListener",
"io.undertow.websockets.jsr.JsrWebSocketLogger_$logger", "org.xnio._private.Messages_$logger",
"org.xnio.nio.Log_$logger");
registerMessages(hints, "io.undertow.UndertowMessages_$bundle",
"io.undertow.servlet.UndertowServletMessages_$bundle",
"io.undertow.websockets.core.WebSocketMessages_$bundle",
"io.undertow.websockets.jsr.JsrWebSocketMessages_$bundle");
hints.reflection().registerType(TypeReference.of("io.undertow.websockets.jsr.Bootstrap$WebSocketListener"),
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
}
private void invokePublicConstructorsOf(RuntimeHints hints, String... typeNames) {
for (String typeName : typeNames) {
hints.reflection().registerType(TypeReference.of(typeName), MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
}
}
private void registerMessages(RuntimeHints hints, String... names) {
for (String name : names) {
hints.reflection().registerType(TypeReference.of(name), (hint) -> hint.withField("INSTANCE"));
}
}
}

View File

@@ -21,6 +21,7 @@ groups:
- mustache-webmvc
- servlet-jetty
- servlet-tomcat
- servlet-undertow
- thymeleaf-webmvc
- thymeleaf-webflux
- tracing-brave-zipkin

View File

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

View File

@@ -0,0 +1,27 @@
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(project(":aot-smoke-test-third-party-hints"))
implementation("org.springframework.boot:spring-boot-starter-undertow")
implementation("org.springframework.boot:spring-boot-starter-web")
modules {
module("org.springframework.boot:spring-boot-starter-tomcat") {
replacedBy("org.springframework.boot:spring-boot-starter-undertow", "Use Undertow instead of Tomcat")
}
}
testImplementation("org.springframework.boot:spring-boot-starter-test")
aotSmokeTestImplementation(project(":aot-smoke-test-support"))
aotSmokeTestImplementation("org.awaitility:awaitility:4.2.0")
}
aotSmokeTest {
webApplication = true
}

View File

@@ -0,0 +1,19 @@
package com.example.servlet.undertow;
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 ServletUndertowApplicationAotTests {
@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.undertow;
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,16 @@
package com.example.servlet.undertow;
import org.springframework.aot.smoketest.thirdpartyhints.UndertowRuntimeHints;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ImportRuntimeHints;
@SpringBootApplication
@ImportRuntimeHints(UndertowRuntimeHints.class)
public class ServletUndertowApplication {
public static void main(String[] args) throws InterruptedException {
SpringApplication.run(ServletUndertowApplication.class, args);
}
}

View File

@@ -0,0 +1,24 @@
package com.example.servlet.undertow;
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.undertow;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ServletUndertowApplicationTests {
@Test
void contextLoads() {
}
}

View File

@@ -94,6 +94,7 @@ include "security-oauth2-authorization-server"
include "security-oauth2-resource-server"
include "servlet-jetty"
include "servlet-tomcat"
include "servlet-undertow"
include "session-jdbc"
include "session-redis-webflux"
include "spring-amqp-rabbit"