private static HashLoginService loginService;
private final static int port = 8089;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
server = new Server(port);
ClassList classList = ClassList.setServerDefault(server);
// uncommenting this line will avoid the error but require us to specify all the configuration from jetty-web.xml by hand.
// boolean removed = classList.remove("org.eclipse.jetty.webapp.JettyWebXmlConfiguration");
classList.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration", "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");
WebAppContext context = new WebAppContext("eyerep-data", "/eyerep-data");
context.setDescriptor("src/main/webapp/WEB-INF/web.xml");
context.setResourceBase("src/main/webapp");
//we want a custom configuration for the tests so we need to supply an override descriptor
context.setOverrideDescriptors(Arrays.asList("src/test/resources/override-web.xml"));
// Creating the LoginService for the realm
loginService = new HashLoginService("EyeRep");
// Setting the realm configuration there the users, passwords and roles reside
loginService.setConfig("src/test/resources/realm.properties");
context.getSecurityHandler().setLoginService(loginService);
context.getSecurityHandler().setAuthenticator(new BasicAuthenticator());
BasicDataSource ds = null;
ds = new BasicDataSource();
ds.setUrl("jdbc:h2:mem:myDB;create=true;MODE=MSSQLServer;DATABASE_TO_UPPER=FALSE;");
org.eclipse.jetty.plus.jndi.Resource mydatasource = new org.eclipse.jetty.plus.jndi.Resource(null, "jdbc/NavDS",ds);
server.setHandler(context);
server.start();
}
If I run the test with that code, it will end up overriding my custom security handler with the values from jetty-web.xml when server.start() is called. I can work around it by removing org.eclipse.jetty.webapp.JettyWebXmlConfiguration from the class list, but then I have to specify everything that would normally be handled by jetty-web.xml by hand. I'm trying to keep my test configuration as close to the production config as possible and only override the things that need to be different for the test environment.