Search in sources :

Example 1 with DeploymentContext

use of org.glassfish.jersey.test.DeploymentContext 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 DeploymentContext

use of org.glassfish.jersey.test.DeploymentContext in project helix by apache.

the class AbstractTestClass method getTestContainerFactory.

@Override
protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
    return new TestContainerFactory() {

        @Override
        public TestContainer create(final URI baseUri, DeploymentContext deploymentContext) {
            return new TestContainer() {

                private HelixRestServer _helixRestServer;

                @Override
                public ClientConfig getClientConfig() {
                    return null;
                }

                @Override
                public URI getBaseUri() {
                    return baseUri;
                }

                @Override
                public void start() {
                    // Create namespace manifest map
                    List<HelixRestNamespace> namespaces = new ArrayList<>();
                    // Add test namespace
                    namespaces.add(new HelixRestNamespace(TEST_NAMESPACE, HelixRestNamespace.HelixMetadataStoreType.ZOOKEEPER, _zkAddrTestNS, false));
                    // Add default namesapce
                    namespaces.add(new HelixRestNamespace(ZK_ADDR));
                    try {
                        _helixRestServer = new HelixRestServer(namespaces, baseUri.getPort(), baseUri.getPath(), Arrays.<AuditLogger>asList(_auditLogger));
                        _helixRestServer.start();
                    } catch (Exception ex) {
                        throw new TestContainerException(ex);
                    }
                }

                @Override
                public void stop() {
                    _helixRestServer.shutdown();
                }
            };
        }
    };
}
Also used : DeploymentContext(org.glassfish.jersey.test.DeploymentContext) AuditLogger(org.apache.helix.rest.server.auditlog.AuditLogger) TestContainer(org.glassfish.jersey.test.spi.TestContainer) ArrayList(java.util.ArrayList) HelixRestNamespace(org.apache.helix.rest.common.HelixRestNamespace) URI(java.net.URI) TestContainerException(org.glassfish.jersey.test.spi.TestContainerException) TestContainerException(org.glassfish.jersey.test.spi.TestContainerException) IOException(java.io.IOException) TestContainerFactory(org.glassfish.jersey.test.spi.TestContainerFactory)

Example 3 with DeploymentContext

use of org.glassfish.jersey.test.DeploymentContext 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)

Example 4 with DeploymentContext

use of org.glassfish.jersey.test.DeploymentContext in project crnk-framework by crnk-project.

the class SecurityModuleIntTest method getTestContainerFactory.

protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
    final TestContainerFactory testContainerFactory = super.getTestContainerFactory();
    return new TestContainerFactory() {

        @Override
        public TestContainer create(URI baseUri, DeploymentContext deploymentContext) {
            TestContainer container = testContainerFactory.create(baseUri, deploymentContext);
            try {
                Field field = container.getClass().getDeclaredField("server");
                field.setAccessible(true);
                Server server = (Server) field.get(container);
                Handler handler = server.getHandler();
                SecurityHandler securityHandler = identityManager.getSecurityHandler();
                if (securityHandler.getHandler() == null) {
                    securityHandler.setHandler(handler);
                }
                server.setHandler(securityHandler);
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
            return container;
        }
    };
}
Also used : DeploymentContext(org.glassfish.jersey.test.DeploymentContext) Field(java.lang.reflect.Field) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) TestContainer(org.glassfish.jersey.test.spi.TestContainer) Server(org.eclipse.jetty.server.Server) Handler(org.eclipse.jetty.server.Handler) SecurityHandler(org.eclipse.jetty.security.SecurityHandler) URI(java.net.URI) UnauthorizedException(io.crnk.core.exception.UnauthorizedException) IOException(java.io.IOException) TestContainerException(org.glassfish.jersey.test.spi.TestContainerException) ForbiddenException(io.crnk.core.exception.ForbiddenException) TestContainerFactory(org.glassfish.jersey.test.spi.TestContainerFactory)

Aggregations

DeploymentContext (org.glassfish.jersey.test.DeploymentContext)4 URI (java.net.URI)3 TestContainerFactory (org.glassfish.jersey.test.spi.TestContainerFactory)3 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)2 IOException (java.io.IOException)2 ClientConfig (org.glassfish.jersey.client.ClientConfig)2 JerseyTest (org.glassfish.jersey.test.JerseyTest)2 ServletDeploymentContext (org.glassfish.jersey.test.ServletDeploymentContext)2 TestContainer (org.glassfish.jersey.test.spi.TestContainer)2 TestContainerException (org.glassfish.jersey.test.spi.TestContainerException)2 ForbiddenException (io.crnk.core.exception.ForbiddenException)1 UnauthorizedException (io.crnk.core.exception.UnauthorizedException)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 HelixRestNamespace (org.apache.helix.rest.common.HelixRestNamespace)1 AuditLogger (org.apache.helix.rest.server.auditlog.AuditLogger)1 SecurityHandler (org.eclipse.jetty.security.SecurityHandler)1 Handler (org.eclipse.jetty.server.Handler)1 Server (org.eclipse.jetty.server.Server)1 InMemoryTestContainerFactory (org.glassfish.jersey.test.inmemory.InMemoryTestContainerFactory)1