org.glassfish.jersey.test.spi.TestContainerFactory Java Examples

The following examples show how to use org.glassfish.jersey.test.spi.TestContainerFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 6 votes vote down vote up
/**
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest() throws TestContainerException {
    ResourceConfig config = getResourceConfig(configure());
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));

    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #2
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 6 votes vote down vote up
/**
 * Construct a new instance with a test container factory.
 * <p/>
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @param testContainerFactory the test container factory to use for testing.
 * @throws TestContainerException if the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(TestContainerFactory testContainerFactory) {
    setTestContainerFactory(testContainerFactory);

    ResourceConfig config = getResourceConfig(configure());
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, testContainerFactory);
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #3
Source File: SecurityModuleIntTest.java    From crnk-framework with Apache License 2.0 6 votes vote down vote up
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;
        }
    };
}
 
Example #4
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 6 votes vote down vote up
/**
 * Construct a new instance with a test container factory.
 * <p/>
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @param testContainerFactory the test container factory to use for testing.
 * @throws TestContainerException if the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(TestContainerFactory testContainerFactory) {
    setTestContainerFactory(testContainerFactory);

    ResourceConfig config = getResourceConfig(configure());
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, testContainerFactory);
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #5
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 6 votes vote down vote up
/**
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest() throws TestContainerException {
    ResourceConfig config = getResourceConfig(configure());
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));

    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #6
Source File: AbstractRestIT.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@Override
protected TestContainerFactory getTestContainerFactory() {
    final URI baseURI = getBaseURI();
    return (uri, deploymentContext) -> new TestContainer() {
        @Override
        public ClientConfig getClientConfig() {
            return clientConfig;
        }

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

        @Override
        public void start() {
            // noop
        }

        @Override
        public void stop() {
            // noop
        }
    };
}
 
Example #7
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 6 votes vote down vote up
/**
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest() throws TestContainerException {
    ResourceConfig config = getResourceConfig(configure());
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));

    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #8
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 6 votes vote down vote up
/**
 * Construct a new instance with a test container factory.
 * <p/>
 * An extending class must implement the {@link #configure()} method to
 * provide an application descriptor.
 *
 * @param testContainerFactory the test container factory to use for testing.
 * @throws TestContainerException if the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(TestContainerFactory testContainerFactory) {
    setTestContainerFactory(testContainerFactory);

    ResourceConfig config = getResourceConfig(configure());
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, testContainerFactory);
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #9
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 5 votes vote down vote up
private TestContainer getContainer(ApplicationHandler application, TestContainerFactory tcf) {
    if (application == null) {
        throw new IllegalArgumentException("The application cannot be null");
    }

    return tcf.create(getBaseUri(), application);
}
 
Example #10
Source File: AbstractTestClass.java    From helix with Apache License 2.0 5 votes vote down vote up
@Override
protected TestContainerFactory getTestContainerFactory()
    throws TestContainerException {
  return new TestContainerFactory() {
    @Override
    public TestContainer create(final URI baseUri, DeploymentContext deploymentContext) {
      return new TestContainer() {

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

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

        @Override
        public void start() {
          if (_helixRestServer == null) {
            _helixRestServer = startRestServer();
          }
        }

        @Override
        public void stop() {
        }
      };
    }
  };
}
 
Example #11
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 5 votes vote down vote up
/**
 * Construct a new instance with an application descriptor that defines
 * how the test container is configured.
 *
 * @param jaxrsApplication an application describing how to configure the
 *                         test container.
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(Application jaxrsApplication) throws TestContainerException {
    ResourceConfig config = getResourceConfig(jaxrsApplication);
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #12
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 5 votes vote down vote up
/**
 * Construct a new instance with an {@link Application} class.
 *
 * @param jaxrsApplicationClass an application describing how to configure the
 *                              test container.
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(Class<? extends Application> jaxrsApplicationClass) throws TestContainerException {
    ResourceConfig config = ResourceConfig.forApplicationClass(jaxrsApplicationClass);
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #13
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-jpa2-hibernate with MIT License 5 votes vote down vote up
private TestContainer getContainer(ApplicationHandler application, TestContainerFactory tcf) {
    if (application == null) {
        throw new IllegalArgumentException("The application cannot be null");
    }

    return tcf.create(getBaseUri(), application);
}
 
Example #14
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 5 votes vote down vote up
/**
 * Construct a new instance with an application descriptor that defines
 * how the test container is configured.
 *
 * @param jaxrsApplication an application describing how to configure the
 *                         test container.
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(Application jaxrsApplication) throws TestContainerException {
    ResourceConfig config = getResourceConfig(jaxrsApplication);
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #15
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 5 votes vote down vote up
/**
 * Construct a new instance with an {@link Application} class.
 *
 * @param jaxrsApplicationClass an application describing how to configure the
 *                              test container.
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(Class<? extends Application> jaxrsApplicationClass) throws TestContainerException {
    ResourceConfig config = ResourceConfig.forApplicationClass(jaxrsApplicationClass);
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #16
Source File: OrganizationTest.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
protected TestContainerFactory getTestContainerFactory() {
    final URI baseURI = getBaseUri();
    
    return new TestContainerFactory() {
        @Override
        public TestContainer create(URI uri, DeploymentContext deploymentContext) {
            return new TestContainer() {

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

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

                @Override
                public void start() {
                    // noop
                }

                @Override
                public void stop() {
                    // noop
                }
            };
        }
    };

}
 
Example #17
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 5 votes vote down vote up
/**
 * Construct a new instance with an application descriptor that defines
 * how the test container is configured.
 *
 * @param jaxrsApplication an application describing how to configure the
 *                         test container.
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(Application jaxrsApplication) throws TestContainerException {
    ResourceConfig config = getResourceConfig(jaxrsApplication);
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #18
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 5 votes vote down vote up
/**
 * Construct a new instance with an {@link Application} class.
 *
 * @param jaxrsApplicationClass an application describing how to configure the
 *                              test container.
 * @throws TestContainerException if the default test container factory
 *                                cannot be obtained, or the application descriptor is not
 *                                supported by the test container factory.
 */
public SpringContextJerseyTest(Class<? extends Application> jaxrsApplicationClass) throws TestContainerException {
    ResourceConfig config = ResourceConfig.forApplicationClass(jaxrsApplicationClass);
    config.register(new ServiceFinderBinder<TestContainerFactory>(TestContainerFactory.class, null, RuntimeType.SERVER));
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    this.application = new ApplicationHandler(config);
    this.tc = getContainer(application, getTestContainerFactory());
    if (isLogRecordingEnabled()) {
        loggedStartupRecords.addAll(loggedRuntimeRecords);
        loggedRuntimeRecords.clear();
        unregisterLogHandler();
    }
}
 
Example #19
Source File: SpringContextJerseyTest.java    From demo-restWS-spring-jersey-tomcat-mybatis with MIT License 5 votes vote down vote up
private TestContainer getContainer(ApplicationHandler application, TestContainerFactory tcf) {
    if (application == null) {
        throw new IllegalArgumentException("The application cannot be null");
    }

    return tcf.create(getBaseUri(), application);
}
 
Example #20
Source File: AbstractServingTest.java    From oryx with Apache License 2.0 4 votes vote down vote up
@Override
public final TestContainerFactory getTestContainerFactory() {
  return new GrizzlyWebTestContainerFactory();
}
 
Example #21
Source File: TestTransformJSONResource.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public TestContainerFactory getTestContainerFactory() {
    return new InMemoryTestContainerFactory();
}
 
Example #22
Source File: TestProcessorResource.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public TestContainerFactory getTestContainerFactory() {
    return new InMemoryTestContainerFactory();
}
 
Example #23
Source File: ServerTest.java    From divide with Apache License 2.0 4 votes vote down vote up
@Override
protected TestContainerFactory getTestContainerFactory() {
    return new WebContainerFactory();
}
 
Example #24
Source File: ResourceTest.java    From dependency-track with Apache License 2.0 4 votes vote down vote up
@Override
protected TestContainerFactory getTestContainerFactory() {
    return new GrizzlyWebTestContainerFactory();
}
 
Example #25
Source File: AuthBaseTest.java    From dropwizard-java8 with Apache License 2.0 4 votes vote down vote up
@Override
protected TestContainerFactory getTestContainerFactory()
    throws TestContainerException {
    return new GrizzlyWebTestContainerFactory();
}
 
Example #26
Source File: UriInfoServiceUrlProviderTest.java    From crnk-framework with Apache License 2.0 4 votes vote down vote up
@Override
protected TestContainerFactory getTestContainerFactory() {
    return new JettyTestContainerFactory();
}
 
Example #27
Source File: ModelResourceTest.java    From openscoring with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected TestContainerFactory getTestContainerFactory(){
	return new JdkHttpServerTestContainerFactory();
}
 
Example #28
Source File: HttpClientSourceIT.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@Override
protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
  return new GrizzlyWebTestContainerFactory();
}
 
Example #29
Source File: InteroperabilityTest.java    From crnk-framework with Apache License 2.0 4 votes vote down vote up
@Override
protected TestContainerFactory getTestContainerFactory() {
    return new JettyTestContainerFactory();
}
 
Example #30
Source File: ControllerWithoutPrefixTest.java    From crnk-framework with Apache License 2.0 4 votes vote down vote up
@Override
protected TestContainerFactory getTestContainerFactory() {
	return new JettyTestContainerFactory();
}