I have my servlets configuration in class I
that extends ServletContainerInitializer
. I register servlets and define mappings there. I don't want to do same work in my integration tests. Is there are common way to reuse I
config in my jetty tests?
So I have I
public class I implements ServletContainerInitializer {
public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
Servlet servlet = new MyServlet();
ctx.addServlet("foo", servlet).addMapping("/*");
}
}
And tests like
Server server = new Server(0);
Context servletContext = new Context(server, "/", Context.SESSIONS);
Servlet servlet = new MyServlet(); //Duplicated
servletContext.addServlet(new ServletHolder(servlet), "/*"); //Duplicated
server.start();
How I can do it without duplication?