Search in sources :

Example 1 with TestContainer

use of org.glassfish.jersey.test.spi.TestContainer in project jersey by jersey.

the class ContainerPerClassTestNgStrategy method testContainer.

@Override
public TestContainer testContainer(final TestContainer testContainer) {
    final TestContainer old = this.testContainer;
    this.testContainer = testContainer;
    return old;
}
Also used : TestContainer(org.glassfish.jersey.test.spi.TestContainer)

Example 2 with TestContainer

use of org.glassfish.jersey.test.spi.TestContainer in project jersey by jersey.

the class JerseyTest method setTestContainer.

/**
     * Returns old test container used to run the tests in and set a new one. This method can be overridden.
     *
     * @param testContainer a test container instance or {@code null} it the current test container should be released.
     * @return old test container instance.
     */
/* package */
TestContainer setTestContainer(final TestContainer testContainer) {
    final TestContainer old = this.testContainer;
    this.testContainer = testContainer;
    return old;
}
Also used : TestContainer(org.glassfish.jersey.test.spi.TestContainer)

Example 3 with TestContainer

use of org.glassfish.jersey.test.spi.TestContainer in project jersey by jersey.

the class JerseyTest method setUp.

/**
     * Set up the test by creating a test container instance, {@link TestContainer#start() starting} it and by creating a new
     * {@link #configureClient(org.glassfish.jersey.client.ClientConfig) pre-configured} test client.
     * The test container is obtained from the {@link #getTestContainerFactory() test container factory}.
     *
     * @throws TestContainerException if the default test container factory cannot be obtained,
     *                                or the test application deployment context is not supported
     *                                by the test container factory.
     * @throws Exception              if an exception is thrown during setting up the test environment.
     */
@Before
public void setUp() throws Exception {
    if (isLogRecordingEnabled()) {
        registerLogHandler();
    }
    final TestContainer testContainer = createTestContainer(context);
    // Set current instance of test container and start it.
    setTestContainer(testContainer);
    testContainer.start();
    // Create an set new client.
    setClient(getClient(testContainer.getClientConfig()));
}
Also used : TestContainer(org.glassfish.jersey.test.spi.TestContainer) Before(org.junit.Before)

Example 4 with TestContainer

use of org.glassfish.jersey.test.spi.TestContainer 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 5 with TestContainer

use of org.glassfish.jersey.test.spi.TestContainer in project jersey by jersey.

the class JerseyTest method getPort.

/**
     * Get the port to be used for test application deployments.
     *
     * @return The HTTP port of the URI
     */
protected final int getPort() {
    final TestContainer container = getTestContainer();
    if (container != null) {
        // called from outside of JerseyTest constructor
        return container.getBaseUri().getPort();
    }
    // called from within JerseyTest constructor
    final String value = getProperty(TestProperties.CONTAINER_PORT);
    if (value != null) {
        try {
            final int i = Integer.parseInt(value);
            if (i < 0) {
                throw new NumberFormatException("Value not positive.");
            }
            return i;
        } catch (final NumberFormatException e) {
            LOGGER.log(Level.CONFIG, "Value of " + TestProperties.CONTAINER_PORT + " property is not a valid positive integer [" + value + "]." + " Reverting to default [" + TestProperties.DEFAULT_CONTAINER_PORT + "].", e);
        }
    }
    return TestProperties.DEFAULT_CONTAINER_PORT;
}
Also used : TestContainer(org.glassfish.jersey.test.spi.TestContainer)

Aggregations

TestContainer (org.glassfish.jersey.test.spi.TestContainer)6 IOException (java.io.IOException)2 URI (java.net.URI)2 DeploymentContext (org.glassfish.jersey.test.DeploymentContext)2 TestContainerException (org.glassfish.jersey.test.spi.TestContainerException)2 TestContainerFactory (org.glassfish.jersey.test.spi.TestContainerFactory)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 Before (org.junit.Before)1