Search in sources :

Example 1 with JerseyTest

use of org.glassfish.jersey.test.JerseyTest in project dropwizard by dropwizard.

the class ResourceTestRule method apply.

@Override
public Statement apply(Statement base, Description description) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            DropwizardTestResourceConfig.CONFIGURATION_REGISTRY.put(configuration.getId(), configuration);
            try {
                test = new JerseyTest() {

                    @Override
                    protected TestContainerFactory getTestContainerFactory() {
                        return configuration.testContainerFactory;
                    }

                    @Override
                    protected DeploymentContext configureDeployment() {
                        return ServletDeploymentContext.builder(new DropwizardTestResourceConfig(configuration)).initParam(ServletProperties.JAXRS_APPLICATION_CLASS, DropwizardTestResourceConfig.class.getName()).initParam(DropwizardTestResourceConfig.CONFIGURATION_ID, configuration.getId()).build();
                    }

                    @Override
                    protected void configureClient(ClientConfig clientConfig) {
                        final JacksonJsonProvider jsonProvider = new JacksonJsonProvider();
                        jsonProvider.setMapper(configuration.mapper);
                        configuration.clientConfigurator.accept(clientConfig);
                        clientConfig.register(jsonProvider);
                    }
                };
                test.setUp();
                base.evaluate();
            } finally {
                DropwizardTestResourceConfig.CONFIGURATION_REGISTRY.remove(configuration.getId());
                test.tearDown();
            }
        }
    };
}
Also used : DeploymentContext(org.glassfish.jersey.test.DeploymentContext) ServletDeploymentContext(org.glassfish.jersey.test.ServletDeploymentContext) JerseyTest(org.glassfish.jersey.test.JerseyTest) Statement(org.junit.runners.model.Statement) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ClientConfig(org.glassfish.jersey.client.ClientConfig) TestContainerFactory(org.glassfish.jersey.test.spi.TestContainerFactory) InMemoryTestContainerFactory(org.glassfish.jersey.test.inmemory.InMemoryTestContainerFactory)

Example 2 with JerseyTest

use of org.glassfish.jersey.test.JerseyTest in project dropwizard by dropwizard.

the class DropwizardResourceConfigBenchmark method setUp.

@Setup
public void setUp() throws Exception {
    dropwizardResourceConfig.register(DistributionResource.class);
    dropwizardResourceConfig.register(AssetResource.class);
    dropwizardResourceConfig.register(ClustersResource.class);
    final JerseyTest jerseyTest = new JerseyTest() {

        @Override
        protected Application configure() {
            return dropwizardResourceConfig;
        }
    };
    jerseyTest.setUp();
    jerseyTest.tearDown();
}
Also used : JerseyTest(org.glassfish.jersey.test.JerseyTest) Setup(org.openjdk.jmh.annotations.Setup)

Example 3 with JerseyTest

use of org.glassfish.jersey.test.JerseyTest in project dropwizard by dropwizard.

the class Resource method before.

public void before() throws Throwable {
    DropwizardTestResourceConfig.CONFIGURATION_REGISTRY.put(configuration.getId(), configuration);
    test = new JerseyTest(configuration.testContainerFactory) {

        @Override
        protected URI getBaseUri() {
            forceSet(TestProperties.CONTAINER_PORT, "0");
            return super.getBaseUri();
        }

        @Override
        protected DeploymentContext configureDeployment() {
            return ServletDeploymentContext.builder(new DropwizardTestResourceConfig(configuration)).initParam(ServletProperties.JAXRS_APPLICATION_CLASS, DropwizardTestResourceConfig.class.getName()).initParam(DropwizardTestResourceConfig.CONFIGURATION_ID, configuration.getId()).build();
        }

        @Override
        protected void configureClient(ClientConfig clientConfig) {
            final JacksonJsonProvider jsonProvider = new JacksonJsonProvider();
            jsonProvider.setMapper(configuration.mapper);
            configuration.clientConfigurator.accept(clientConfig);
            clientConfig.register(jsonProvider);
        }
    };
    test.setUp();
}
Also used : DeploymentContext(org.glassfish.jersey.test.DeploymentContext) ServletDeploymentContext(org.glassfish.jersey.test.ServletDeploymentContext) JerseyTest(org.glassfish.jersey.test.JerseyTest) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ClientConfig(org.glassfish.jersey.client.ClientConfig) URI(java.net.URI)

Aggregations

JerseyTest (org.glassfish.jersey.test.JerseyTest)3 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)2 ClientConfig (org.glassfish.jersey.client.ClientConfig)2 DeploymentContext (org.glassfish.jersey.test.DeploymentContext)2 ServletDeploymentContext (org.glassfish.jersey.test.ServletDeploymentContext)2 URI (java.net.URI)1 InMemoryTestContainerFactory (org.glassfish.jersey.test.inmemory.InMemoryTestContainerFactory)1 TestContainerFactory (org.glassfish.jersey.test.spi.TestContainerFactory)1 Statement (org.junit.runners.model.Statement)1 Setup (org.openjdk.jmh.annotations.Setup)1