Ejemplo n.º 1
0
  /**
   * Set up the test by invoking {@link TestContainer#start() } on the test container obtained from
   * 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()) {
      loggedRuntimeRecords.clear();
      registerLogHandler();
    }

    tc.start();
    Client old = client.getAndSet(getClient(tc, application));
    close(old);
  }
Ejemplo n.º 2
0
  /**
   * 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()));
  }
Ejemplo n.º 3
0
 /**
  * Construct a new instance with an application descriptor that defines how the test container is
  * configured.
  *
  * @param jaxrsApplication an application describing how to configure the test container.
  * @throws TestContainerException if the default test container factory cannot be obtained, or the
  *     application descriptor is not supported by the test container factory.
  */
 public JerseyTest(Application jaxrsApplication) throws TestContainerException {
   ResourceConfig config = getResourceConfig(jaxrsApplication);
   config.register(
       new ServiceFinderBinder<TestContainerFactory>(
           TestContainerFactory.class, null, RuntimeType.SERVER));
   if (isLogRecordingEnabled()) {
     registerLogHandler();
   }
   this.application = new ApplicationHandler(config);
   this.tc = getContainer(application, getTestContainerFactory());
   if (isLogRecordingEnabled()) {
     loggedStartupRecords.addAll(loggedRuntimeRecords);
     loggedRuntimeRecords.clear();
     unregisterLogHandler();
   }
 }