From b27147ef392140e51c6ef6b8ca6356c8e418c4b9 Mon Sep 17 00:00:00 2001 From: jcarranzan Date: Tue, 26 Nov 2024 07:35:17 +0100 Subject: [PATCH] Add test coverage for the issue https://github.com/quarkusio/quarkus/issues/43825 Ensure the missing servlet class in web.xml is ignored Test coverage for https://github.com/quarkusio/quarkus/pull/44063 scenario --- .../undertow/UndertowMissServletClassIT.java | 54 +++++++++++++++++++ .../test/resources/META-INF/invalid-web.xml | 10 ++++ 2 files changed, 64 insertions(+) create mode 100644 http/servlet-undertow/src/test/java/io/quarkus/ts/http/undertow/UndertowMissServletClassIT.java create mode 100644 http/servlet-undertow/src/test/resources/META-INF/invalid-web.xml diff --git a/http/servlet-undertow/src/test/java/io/quarkus/ts/http/undertow/UndertowMissServletClassIT.java b/http/servlet-undertow/src/test/java/io/quarkus/ts/http/undertow/UndertowMissServletClassIT.java new file mode 100644 index 000000000..7642396ff --- /dev/null +++ b/http/servlet-undertow/src/test/java/io/quarkus/ts/http/undertow/UndertowMissServletClassIT.java @@ -0,0 +1,54 @@ +package io.quarkus.ts.http.undertow; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertFalse; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.bootstrap.RestService; +import io.quarkus.test.bootstrap.Service; +import io.quarkus.test.scenarios.QuarkusScenario; +import io.quarkus.test.scenarios.annotations.DisabledOnQuarkusVersion; +import io.quarkus.test.services.QuarkusApplication; + +@QuarkusScenario +@DisabledOnQuarkusVersion(version = "3\\.(8|9|10|11|12|13|14)\\..*|3\\.15\\.(0|1)(\\..*)?", reason = "Disabled on Quarkus versions before 3.15.2 due to build fail because missing servlet class configuration undertow issue https://github.com/quarkusio/quarkus/issues/43825") +public class UndertowMissServletClassIT { + @QuarkusApplication + static RestService app = new RestService() + .setAutoStart(false) + .onPreStart(UndertowMissServletClassIT::replaceForInvalidXML); + + @Tag("https://github.com/quarkusio/quarkus/issues/44063") + @Test + void verifyUndertowIgnoreServletClassMissing() { + assertDoesNotThrow(() -> app.start(), + "The app should start without any issue"); + String logs = app.getLogs().toString(); + assertFalse(logs.contains("Local name must not be null")); + + } + + private static void replaceForInvalidXML(Service service) { + if (service instanceof RestService) { + RestService restService = (RestService) service; + Path invalidWebXml = Path.of("src/test/resources/invalid-web.xml"); + + Path targetWebXml = restService.getServiceFolder().resolve("src/main/resources/META-INF/web.xml"); + try { + Files.createDirectories(targetWebXml.getParent()); + Files.copy(invalidWebXml, targetWebXml); + } catch (IOException e) { + throw new RuntimeException("Failed to replace web.xml with invalid version", e); + } + } else { + throw new IllegalArgumentException("Service is not an instance of RestService"); + } + + } +} diff --git a/http/servlet-undertow/src/test/resources/META-INF/invalid-web.xml b/http/servlet-undertow/src/test/resources/META-INF/invalid-web.xml new file mode 100644 index 000000000..098b807c8 --- /dev/null +++ b/http/servlet-undertow/src/test/resources/META-INF/invalid-web.xml @@ -0,0 +1,10 @@ + + + + InvalidServlet + + + InvalidServlet + /invalid + +