Hello
I'm setting up a REST API testing scenario with Jetty, and would like to switch persistence unit to a test unit when running my Unit-tests.
I start the server with the following code:
@BeforeClass
public static void setUpClass() throws Exception {
server = new Server(8082);
ServletHolder servletHolder = new ServletHolder(org.glassfish.jersey.servlet.ServletContainer.class);
servletHolder.setInitParameter("javax.ws.rs.Application", ApplicationConfig.class.getName());
ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
contextHandler.setContextPath("/");
contextHandler.addServlet(servletHolder, "/api/*");
server.setHandler(contextHandler);
server.start();
}
I would like to check a boolean (eg. isTesting) whether or not to use the production persistance unit.
I would love to avoid making an XML file and parse that in production. Much rather call a method directly.
Does anyone have an example on how to achive that?
I'm using JPA/Eclipselink, but that should not be of any concern.
Regards
Sofus Albertsen
|