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