public void before() throws Throwable { DropwizardTestResourceConfig.CONFIGURATION_REGISTRY.put(configuration.getId(), configuration); 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(); }
public void after() throws Throwable { DropwizardTestResourceConfig.CONFIGURATION_REGISTRY.remove(configuration.getId()); requireNonNull(test).tearDown(); } }
/** * Create a JAX-RS web target whose URI refers to the {@link #getBaseUri() base URI} the tested * JAX-RS / Jersey application is deployed at, plus the path specified in the {@code path} argument. * <p> * This method is an equivalent of calling {@code target().path(path)}. * </p> * * @param path relative path (from tested application base URI) this web target should point to. * @return the created JAX-RS web target. */ public final WebTarget target(final String path) { return target().path(path); }
/** * Create a JAX-RS web target whose URI refers to the {@link #getBaseUri() base URI} the tested * JAX-RS / Jersey application is deployed at, plus the path specified in the {@code path} argument. * <p> * This method is an equivalent of calling <tt>client().target(getBaseUri())</tt>. * </p> * * @return the created JAX-RS web target. */ public final WebTarget target() { return client().target(getTestContainer().getBaseUri()); }
/** * Create an instance of test {@link Client} using the client configuration provided by the configured * {@link org.glassfish.jersey.test.spi.TestContainer}. * <p> * If the {@code TestContainer} does not provide any client configuration (passed {@code clientConfig} is {@code null}), * the default implementation of this method first creates an empty new {@link org.glassfish.jersey.client.ClientConfig} * instance. The client configuration (provided by test container or created) is then passed to * {@link #configureClient(org.glassfish.jersey.client.ClientConfig)} which can be overridden in the {@code JerseyTest} * subclass to provide custom client configuration. At last, new JAX-RS {@link Client} instance is created based on the * resulting client configuration. * </p> * * @param clientConfig test client default configuration. May be {@code null}. * @return A Client instance. */ private Client getClient(ClientConfig clientConfig) { if (clientConfig == null) { clientConfig = new ClientConfig(); } //check if logging is required if (isEnabled(TestProperties.LOG_TRAFFIC)) { clientConfig.register(new LoggingFeature(LOGGER, isEnabled(TestProperties.DUMP_ENTITY) ? LoggingFeature.Verbosity.PAYLOAD_ANY : LoggingFeature.Verbosity.HEADERS_ONLY)); } configureClient(clientConfig); return ClientBuilder.newClient(clientConfig); }
return _jerseyTest.target(path); public void setup() throws Exception _jerseyTest.setUp(); public void tearDown() throws Exception _jerseyTest.tearDown(); public void setApplicationContext(final ApplicationContext context) _jerseyTest = new JerseyTest()
/** * <ol> * <li>calls {@link JerseyTest#setUp()} * <li>passes the initialized JerseyTest to the consumer. * <li>calls {@link JerseyTest#tearDown()} * </ol> * * @param jerseyTest * @param test * @throws Exception */ public void runJerseyTest(JerseyTest jerseyTest, ThrowingConsumer<JerseyTest> test) throws Exception { try { jerseyTest.setUp(); test.accept(jerseyTest); } finally { jerseyTest.tearDown(); } }
public void setUp() throws Exception { initJerseyTest() jerseyTest.setUp(); jerseyTest.tearDown(); jerseyTest = new JerseyTest() { @Override protected Application configure() {
/** * Returns the pre-configured {@link Client} for this test. For sending * requests prefer {@link #target(String)} * * @return the {@link JerseyTest} configured {@link Client} */ public Client client() { return getJerseyTest().client(); }
@Override protected void configureClient(ClientConfig config) { super.configureClient(config); config.register(MultiPartFeature.class); }
jerseyTest.setUp(); jerseyTest.tearDown(); return jerseyTest.target(); return jerseyTest.target().path(path); jerseyTest = new JerseyTest(configure(applicationContext)) { };
@Test public void testTearsDownTestOnSetupFailure() throws Exception { doThrow(new RuntimeException()).when(jerseyTest).setUp(); try { runner.runJerseyTest(jerseyTest, consumer); fail("expected exception to be thrown"); } catch (RuntimeException re) { } verify(jerseyTest).setUp(); verify(jerseyTest).tearDown(); }
/** * Create a JAX-RS web target whose URI refers to the {@link #getBaseUri() base URI} the tested * JAX-RS / Jersey application is deployed at, plus the path specified in the {@code path} argument. * <p> * This method is an equivalent of calling <tt>client().target(getBaseUri())</tt>. * </p> * * @return the created JAX-RS web target. */ public final WebTarget target() { return client().target(getTestContainer().getBaseUri()); }
/** * Create an instance of test {@link Client} using the client configuration provided by the configured * {@link org.glassfish.jersey.test.spi.TestContainer}. * <p> * If the {@code TestContainer} does not provide any client configuration (passed {@code clientConfig} is {@code null}), * the default implementation of this method first creates an empty new {@link org.glassfish.jersey.client.ClientConfig} * instance. The client configuration (provided by test container or created) is then passed to * {@link #configureClient(org.glassfish.jersey.client.ClientConfig)} which can be overridden in the {@code JerseyTest} * subclass to provide custom client configuration. At last, new JAX-RS {@link Client} instance is created based on the * resulting client configuration. * </p> * * @param clientConfig test client default configuration. May be {@code null}. * @return A Client instance. */ private Client getClient(ClientConfig clientConfig) { if (clientConfig == null) { clientConfig = new ClientConfig(); } //check if logging is required if (isEnabled(TestProperties.LOG_TRAFFIC)) { clientConfig.register(new LoggingFeature(LOGGER, isEnabled(TestProperties.DUMP_ENTITY) ? LoggingFeature.Verbosity.PAYLOAD_ANY : LoggingFeature.Verbosity.HEADERS_ONLY)); } configureClient(clientConfig); return ClientBuilder.newClient(clientConfig); }
/** * Returns the pre-configured {@link Client} for this test. For sending * requests prefer {@link #target(String)} * * @return the {@link JerseyTest} configured {@link Client} */ public Client client() { return getJerseyTest().client(); }
public void after() throws Throwable { DropwizardTestResourceConfig.CONFIGURATION_REGISTRY.remove(configuration.getId()); requireNonNull(test).tearDown(); } }
public void before() throws Throwable { DropwizardTestResourceConfig.CONFIGURATION_REGISTRY.put(configuration.getId(), configuration); 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(); }
@Test public void testCallSetupConsumerAndTearDownInOrder() throws Exception { runner.runJerseyTest(jerseyTest, consumer); InOrder inOrder = Mockito.inOrder(jerseyTest, consumer); inOrder.verify(jerseyTest).setUp(); inOrder.verify(consumer).accept(jerseyTest); inOrder.verify(jerseyTest).tearDown(); }
/** * Creates a web target to be sent to the resource under testing. * * @param path relative path (from tested application base URI) this web target should point to. * @return the created JAX-RS web target. */ public WebTarget target(String path) { return getJerseyTest().target(path); }
public void tearDown() throws Exception { log.info("tearDown in class: {}", this.getClass().getCanonicalName()); super.tearDown(); } protected int getTestPort() {