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;
}
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;
}
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()));
}
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();
}
};
}
};
}
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;
}
Aggregations