Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServletContextInitializer IT test #33018

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!");
}
}
}
}