users@jersey.java.net

[Jersey] Servlet context in Jersey test

From: ax487 <ax487_at_gmx.de>
Date: Tue, 21 Apr 2015 16:57:53 +0200

Hello again,

I am almost done with writing my unit tests, there is just one thing
that still bothers me: My applications has a back end which has to be
initialized at the start of the server. I used a class "Creator" which
implements the "ServletContextListener" interface. This works with
normal deployment, however the "contextInitialized" method is never
called in the test. I used the following snippet in a class extending
JerseyTest to configure:

    protected Application createConfig() {
        enable(TestProperties.LOG_TRAFFIC);
        return new ResourceConfig(
                Resource1.class,
                Resource2.class);
    }

    @Override
    protected DeploymentContext configureDeployment() {
        return
ServletDeploymentContext.builder(createConfig()).addListener(Creator.class).build();
    }

So I add the listener to the the "DeploymentContext". The method
"configureDeployment" is called during the test, but still nothing (I am
using Grizzly 2 as a container btw).


ax487