forked from quarkus-qe/quarkus-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test coverage for the issue quarkusio/quarkus#43825
Ensure the missing servlet class in web.xml is ignored Test coverage for quarkusio/quarkus#44063 scenario (cherry picked from commit 49f299a)
- Loading branch information
1 parent
c01e5f7
commit 5c24349
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...let-undertow/src/test/java/io/quarkus/ts/http/undertow/UndertowMissingServletClassIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.quarkus.ts.http.undertow; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardCopyOption; | ||
|
||
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.services.QuarkusApplication; | ||
|
||
@QuarkusScenario | ||
public class UndertowMissingServletClassIT { | ||
@QuarkusApplication(builder = WithMissingServlet.class) | ||
static RestService app = new RestService() | ||
.setAutoStart(false); | ||
|
||
@Tag("https://github.com/quarkusio/quarkus/issues/44063") | ||
@Test | ||
void verifyUndertowIgnoreServletClassMissing() { | ||
assertDoesNotThrow(() -> app.start(), | ||
"The app should start without any issue"); | ||
app.logs().assertDoesNotContain("Local name must not be null"); | ||
} | ||
|
||
public static void replaceForInvalidXML(Service service) { | ||
if (service instanceof RestService) { | ||
RestService restService = (RestService) service; | ||
Path invalidWebXml = Path.of("src/test/resources/META-INF/invalid-web.xml"); | ||
|
||
Path targetWebXml = restService.getServiceFolder().resolve("META-INF/web.xml"); | ||
try { | ||
Files.createDirectories(targetWebXml.getParent()); | ||
Files.copy(invalidWebXml, targetWebXml, StandardCopyOption.REPLACE_EXISTING); | ||
} 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"); | ||
} | ||
|
||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
http/servlet-undertow/src/test/java/io/quarkus/ts/http/undertow/WithMissingServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.quarkus.ts.http.undertow; | ||
|
||
import static io.quarkus.ts.http.undertow.UndertowMissingServletClassIT.replaceForInvalidXML; | ||
|
||
import java.lang.annotation.Annotation; | ||
|
||
import io.quarkus.test.services.quarkus.ProdQuarkusApplicationManagedResourceBuilder; | ||
import io.quarkus.test.utils.ClassPathUtils; | ||
|
||
public class WithMissingServlet extends ProdQuarkusApplicationManagedResourceBuilder { | ||
|
||
@Override | ||
protected void copyResourcesToAppFolder() { | ||
super.copyResourcesToAppFolder(); | ||
replaceForInvalidXML(getContext().getOwner()); | ||
} | ||
|
||
/** | ||
* It was suggested here: https://github.com/quarkus-qe/quarkus-test-suite/pull/2218#issuecomment-2504972950, | ||
* and slightly different from main because there it's used TF version 1.6.z and for 3.15 we use 1.5.z | ||
*/ | ||
@Override | ||
public void init(Annotation annotation) { | ||
super.init(annotation); | ||
initAppClasses(ClassPathUtils.findAllClassesFromSource()); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
http/servlet-undertow/src/test/resources/META-INF/invalid-web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<web-app> | ||
<servlet> | ||
<servlet-name>InvalidServlet</servlet-name> | ||
</servlet> | ||
<servlet-mapping> | ||
<servlet-name>InvalidServlet</servlet-name> | ||
<url-pattern>/invalid</url-pattern> | ||
</servlet-mapping> | ||
</web-app> |