Skip to content

Commit

Permalink
ServletContextInitializer IT test
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Oct 14, 2024
1 parent 8d1764e commit 49f7647
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import jakarta.servlet.ServletContainerInitializer;

import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

Expand All @@ -16,6 +17,7 @@ public class ServletContainerInitializerTestCase {
static QuarkusUnitTest runner = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addAsServiceProvider(ServletContainerInitializer.class, TestSCI.class)
.addAsResource(new StringAsset("index.html"), "META-INF/resources/index.html")
.addClasses(SCIInterface.class, SCIImplementation.class, TestSCI.class, SCIAnnotation.class,
AnnotatedSCIClass.class));

Expand All @@ -27,4 +29,4 @@ public void testSci() {
containsString("io.quarkus.undertow.test.AnnotatedSCIClass"));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import org.jboss.logging.Logger;

@HandlesTypes({ SCIInterface.class, SCIAnnotation.class })
public class TestSCI implements ServletContainerInitializer {

private static final Logger log = Logger.getLogger(TestSCI.class);

@Override
public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
ServletRegistration.Dynamic info = ctx.addServlet("test", new HttpServlet() {
Expand All @@ -25,5 +30,16 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
}
});
info.addMapping("/sci");

log.info("Checking servlet resource paths...");

Set<String> resourcePaths = ctx.getResourcePaths("/");
for (String resourcePath : resourcePaths) {
log.info("Resource: " + resourcePath);
}

if (resourcePaths.isEmpty()) {
throw new RuntimeException("NO servlet resource paths found!");
}
}
}
}

0 comments on commit 49f7647

Please sign in to comment.