Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Inject test variables under unittest

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:
    public static void setUpClass() throws Exception {
        server = new Server(8082);
        ServletHolder servletHolder = new ServletHolder(org.glassfish.jersey.servlet.ServletContainer.class);
        servletHolder.setInitParameter("", ApplicationConfig.class.getName());
        ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
        contextHandler.addServlet(servletHolder, "/api/*");
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.

Sofus Albertsen

Back to the top