private InMemoryTestContainer(final URI baseUri, final DeploymentContext context) { this.baseUri = UriBuilder.fromUri(baseUri).path(context.getContextPath()).build(); if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("Creating InMemoryTestContainer configured at the base URI " + this.baseUri); } this.appHandler = new ApplicationHandler(context.getResourceConfig()); }
/** * Initialize JerseyTest instance. * <p> * This constructor can be used from an extending subclass. * <p> * When this constructor is used, the extending concrete subclass must implement one of the * {@link #configure()} or {@link #configureDeployment()} methods are ignored. * </p> * <p> * Please note that when this constructor is used, recording of startup logs as well as configuring * other {@code JerseyTest} properties and features may not work properly. While using this constructor * should generally be avoided, in certain scenarios it may be necessary to use this constructor. * (E.g. when running parameterized tests in which application is created based on test parameters * passed in by JUnit framework via test constructor - in such case it is not possible to propagate * the necessary information to one of the overridden {@code JerseyTest.configure...} methods). * </p> * * @param jaxrsApplication tested application. */ public JerseyTest(final Application jaxrsApplication) { this.context = DeploymentContext.newInstance(jaxrsApplication); this.testContainerFactory = getTestContainerFactory(); }
/** * Build a new application deployment context configured by the current state of this * application deployment context builder. * * @return this application deployment context builder. */ public DeploymentContext build() { final DeploymentContext lld = new DeploymentContext(this); reset(); return lld; }
NettyTestContainer(URI baseUri, DeploymentContext deploymentContext) { this.baseUri = UriBuilder.fromUri(baseUri).path(deploymentContext.getContextPath()).build(); this.deploymentContext = deploymentContext; }
@Override public void start() { server = NettyHttpContainerProvider.createServer(getBaseUri(), deploymentContext.getResourceConfig(), false); }
/** * Create and configure deployment context for the tested application. * <p> * This method may be overridden by subclasses to provide custom test container deployment context for the tested * application. The method may be also used to configure {@code JerseyTest} instance properties. * <p> * The method is invoked from {@code JerseyTest} constructors to provide deployment context for the tested application. * Default implementation of this method creates * {@link DeploymentContext#newInstance(javax.ws.rs.core.Application) new deployment context} * using JAX-RS application instance obtained by calling the {@link #configure()} method. * </p> * <p> * Note that since the method is invoked from {@code JerseyTest} constructor, the overriding implementation of the method * must not depend on any subclass fields as those will not be initialized yet when the method is invoked. * </p> * <p> * Also note that in case the {@link #JerseyTest(javax.ws.rs.core.Application)} constructor is used, the method is never * invoked. * </p> * * @return configured deployment context for the tested application. * @since 2.8 */ protected DeploymentContext configureDeployment() { return DeploymentContext.builder(configure()).build(); }
private ExternalTestContainer(final URI baseUri, final DeploymentContext context) { final UriBuilder uriBuilder = UriBuilder.fromUri(baseUri).path(context.getContextPath()); if (context instanceof ServletDeploymentContext) { uriBuilder.path(((ServletDeploymentContext) context).getServletPath()); } this.baseUri = uriBuilder.build(); if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("Creating ExternalTestContainer configured at the base URI " + this.baseUri); } }
@Override public void start() { LOGGER.log(Level.FINE, "Starting SimpleTestContainer..."); try { server = SimpleContainerFactory.create(baseUri, deploymentContext.getResourceConfig()); if (baseUri.getPort() == 0) { baseUri = UriBuilder.fromUri(baseUri) .port(server.getPort()) .build(); LOGGER.log(Level.INFO, "Started SimpleTestContainer at the base URI " + baseUri); } } catch (ProcessingException e) { throw new TestContainerException(e); } }
@Override protected DeploymentContext configureDeployment() { return DeploymentContext.builder(configure()).contextPath(CONTEXT_ROOT).build(); }
private JdkHttpServerTestContainer(final URI baseUri, final DeploymentContext context) { this.baseUri = UriBuilder.fromUri(baseUri).path(context.getContextPath()).build(); if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("Creating JdkHttpServerTestContainer configured at the base URI " + TestHelper.zeroPortToAvailablePort(baseUri)); } this.server = JdkHttpServerFactory.createHttpServer(this.baseUri, context.getResourceConfig(), false); }
private SimpleTestContainer(final URI baseUri, final DeploymentContext context) { final URI base = UriBuilder.fromUri(baseUri).path(context.getContextPath()).build(); if (!"/".equals(base.getRawPath())) { throw new TestContainerException(String.format( "Cannot deploy on %s. Simple framework container only supports deployment on root path.", base.getRawPath())); } this.baseUri = base; if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("Creating SimpleTestContainer configured at the base URI " + this.baseUri); } this.deploymentContext = context; }
/** * Initialize JerseyTest instance. * <p> * This constructor can be used from an extending subclass. * <p> * When this constructor is used, the extending concrete subclass must implement one of the * {@link #configure()} or {@link #configureDeployment()} methods are ignored. * </p> * <p> * Please note that when this constructor is used, recording of startup logs as well as configuring * other {@code JerseyTest} properties and features may not work properly. While using this constructor * should generally be avoided, in certain scenarios it may be necessary to use this constructor. * (E.g. when running parameterized tests in which application is created based on test parameters * passed in by JUnit framework via test constructor - in such case it is not possible to propagate * the necessary information to one of the overridden {@code JerseyTest.configure...} methods). * </p> * * @param jaxrsApplication tested application. */ public JerseyTest(final Application jaxrsApplication) { this.context = DeploymentContext.newInstance(jaxrsApplication); this.testContainerFactory = getTestContainerFactory(); }
/** * Create and configure deployment context for the tested application. * <p> * This method may be overridden by subclasses to provide custom test container deployment context for the tested * application. The method may be also used to configure {@code JerseyTest} instance properties. * <p> * The method is invoked from {@code JerseyTest} constructors to provide deployment context for the tested application. * Default implementation of this method creates * {@link DeploymentContext#newInstance(javax.ws.rs.core.Application) new deployment context} * using JAX-RS application instance obtained by calling the {@link #configure()} method. * </p> * <p> * Note that since the method is invoked from {@code JerseyTest} constructor, the overriding implementation of the method * must not depend on any subclass fields as those will not be initialized yet when the method is invoked. * </p> * <p> * Also note that in case the {@link #JerseyTest(javax.ws.rs.core.Application)} constructor is used, the method is never * invoked. * </p> * * @return configured deployment context for the tested application. * @since 2.8 */ protected DeploymentContext configureDeployment() { return DeploymentContext.builder(configure()).build(); }
/** * Build a new application deployment context configured by the current state of this * application deployment context builder. * * @return this application deployment context builder. */ public DeploymentContext build() { final DeploymentContext lld = new DeploymentContext(this); reset(); return lld; }
private GrizzlyTestContainer(final URI baseUri, final DeploymentContext context) { this.baseUri = UriBuilder.fromUri(baseUri).path(context.getContextPath()).build(); if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("Creating GrizzlyTestContainer configured at the base URI " + TestHelper.zeroPortToAvailablePort(baseUri)); } this.server = GrizzlyHttpServerFactory.createHttpServer(this.baseUri, context.getResourceConfig(), false); }
private ExternalTestContainer(final URI baseUri, final DeploymentContext context) { final UriBuilder uriBuilder = UriBuilder.fromUri(baseUri).path(context.getContextPath()); if (context instanceof ServletDeploymentContext) { uriBuilder.path(((ServletDeploymentContext) context).getServletPath()); } this.baseUri = uriBuilder.build(); if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("Creating ExternalTestContainer configured at the base URI " + this.baseUri); } }
public JaxrsTestingHttpProcessor(URI baseUri, Object... jaxRsSingletons) { Set<Object> jaxRsSingletonsSet = ImmutableSet.copyOf(jaxRsSingletons); Application application = new Application() { @Override public Set<Object> getSingletons() { return jaxRsSingletonsSet; } }; TestContainer testContainer = new InMemoryTestContainerFactory() .create(baseUri, DeploymentContext.newInstance(application)); ClientConfig clientConfig = testContainer.getClientConfig(); this.client = JerseyClientBuilder.createClient(clientConfig); }
private JettyTestContainer(final URI baseUri, final DeploymentContext context) { final URI base = UriBuilder.fromUri(baseUri).path(context.getContextPath()).build(); if (!"/".equals(base.getRawPath())) { throw new TestContainerException(String.format( "Cannot deploy on %s. Jetty HTTP container only supports deployment on root path.", base.getRawPath())); } this.baseUri = base; if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("Creating JettyTestContainer configured at the base URI " + TestHelper.zeroPortToAvailablePort(baseUri)); } this.server = JettyHttpContainerFactory.createServer(this.baseUri, context.getResourceConfig(), false); }
public JaxrsTestingHttpProcessor(URI baseUri, Object... jaxRsSingletons) { Set<Object> jaxRsSingletonsSet = ImmutableSet.copyOf(jaxRsSingletons); Application application = new Application() { @Override public Set<Object> getSingletons() { return jaxRsSingletonsSet; } }; TestContainer testContainer = new InMemoryTestContainerFactory() .create(baseUri, DeploymentContext.newInstance(application)); ClientConfig clientConfig = testContainer.getClientConfig(); this.client = JerseyClientBuilder.createClient(clientConfig); }
private GrizzlyTestContainer(final URI baseUri, final DeploymentContext context) { this.baseUri = UriBuilder.fromUri(baseUri).path(context.getContextPath()).build(); if (LOGGER.isLoggable(Level.INFO)) { LOGGER.info("Creating GrizzlyTestContainer configured at the base URI " + TestHelper.zeroPortToAvailablePort(baseUri)); } this.server = GrizzlyHttpServerFactory.createHttpServer(this.baseUri, context.getResourceConfig(), false); }