use of org.glassfish.jersey.test.spi.TestContainerFactory 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.spi.TestContainerFactory 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.TestContainerFactory in project jersey by jersey.
the class JerseyTest method getDefaultTestContainerFactory.
private static synchronized TestContainerFactory getDefaultTestContainerFactory() {
if (defaultTestContainerFactoryClass == null) {
final String factoryClassName = getSystemProperty(TestProperties.CONTAINER_FACTORY);
if (factoryClassName != null) {
LOGGER.log(Level.CONFIG, "Loading test container factory '{0}' specified in the '{1}' system property.", new Object[] { factoryClassName, TestProperties.CONTAINER_FACTORY });
defaultTestContainerFactoryClass = loadFactoryClass(factoryClassName);
} else {
final TestContainerFactory[] factories = ServiceFinder.find(TestContainerFactory.class).toArray();
if (factories.length > 0) {
// if there is only one factory instance, just return it
if (factories.length == 1) {
// cache the class for future reuse
defaultTestContainerFactoryClass = factories[0].getClass();
LOGGER.log(Level.CONFIG, "Using the single found TestContainerFactory service provider '{0}'", defaultTestContainerFactoryClass.getName());
return factories[0];
}
// if default factory is present, use it.
for (final TestContainerFactory tcf : factories) {
if (TestProperties.DEFAULT_CONTAINER_FACTORY.equals(tcf.getClass().getName())) {
// cache the class for future reuse
defaultTestContainerFactoryClass = tcf.getClass();
LOGGER.log(Level.CONFIG, "Found multiple TestContainerFactory service providers, using the default found '{0}'", TestProperties.DEFAULT_CONTAINER_FACTORY);
return tcf;
}
}
// default factory is not in the list - log warning and return the first found factory instance
// cache the class for future reuse
defaultTestContainerFactoryClass = factories[0].getClass();
LOGGER.log(Level.WARNING, "Found multiple TestContainerFactory service providers, using the first found '{0}'", defaultTestContainerFactoryClass.getName());
return factories[0];
}
LOGGER.log(Level.CONFIG, "No TestContainerFactory configured, trying to load and instantiate the default implementation '{0}'", TestProperties.DEFAULT_CONTAINER_FACTORY);
defaultTestContainerFactoryClass = loadFactoryClass(TestProperties.DEFAULT_CONTAINER_FACTORY);
}
}
try {
return defaultTestContainerFactoryClass.newInstance();
} catch (final Exception ex) {
throw new TestContainerException(String.format("Could not instantiate test container factory '%s'", defaultTestContainerFactoryClass.getName()), ex);
}
}
use of org.glassfish.jersey.test.spi.TestContainerFactory 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