Search in sources :

Example 16 with Application

use of jakarta.ws.rs.core.Application in project jaxrs-api by eclipse-ee4j.

the class SeBootstrapIT method shouldBootInstanceUsingProperties.

/**
 * Verifies that an instance will boot using explicit configuration given by
 * properties.
 *
 * @throws ExecutionException   if the instance didn't boot correctly
 * @throws InterruptedException if the test took much longer than usually
 *                              expected
 * @throws IOException          if no IP port was free
 */
@Test
public final void shouldBootInstanceUsingProperties() throws InterruptedException, ExecutionException, IOException {
    // given
    final int expectedResponse = mockInt();
    final Application application = new StaticApplication(expectedResponse);
    final SeBootstrap.Configuration.Builder bootstrapConfigurationBuilder = SeBootstrap.Configuration.builder();
    final SeBootstrap.Configuration requestedConfiguration = bootstrapConfigurationBuilder.property(SeBootstrap.Configuration.PROTOCOL, "HTTP").property(SeBootstrap.Configuration.HOST, "localhost").property(SeBootstrap.Configuration.PORT, someFreeIpPort()).property(SeBootstrap.Configuration.ROOT_PATH, "/root/path").build();
    // when
    final CompletionStage<SeBootstrap.Instance> completionStage = SeBootstrap.start(application, requestedConfiguration);
    final SeBootstrap.Instance instance = completionStage.toCompletableFuture().get();
    final SeBootstrap.Configuration actualConfiguration = instance.configuration();
    final int actualResponse = client.target(UriBuilder.newInstance().scheme(actualConfiguration.protocol()).host(actualConfiguration.host()).port(actualConfiguration.port()).path(actualConfiguration.rootPath()).path("application/resource")).request().get(int.class);
    // then
    assertThat(actualResponse, is(expectedResponse));
    assertThat(actualConfiguration.protocol(), is(requestedConfiguration.protocol()));
    assertThat(actualConfiguration.host(), is(requestedConfiguration.host()));
    assertThat(actualConfiguration.port(), is(requestedConfiguration.port()));
    assertThat(actualConfiguration.rootPath(), is(requestedConfiguration.rootPath()));
    instance.stop().toCompletableFuture().get();
}
Also used : SeBootstrap(jakarta.ws.rs.SeBootstrap) Application(jakarta.ws.rs.core.Application) Test(org.junit.jupiter.api.Test)

Example 17 with Application

use of jakarta.ws.rs.core.Application in project jaxrs-api by eclipse-ee4j.

the class SeBootstrapIT method shouldBootInstanceUsingConvenienceMethods.

/**
 * Verifies that an instance will boot using explicit configuration given by
 * convenience methods.
 *
 * @throws ExecutionException   if the instance didn't boot correctly
 * @throws InterruptedException if the test took much longer than usually
 *                              expected
 * @throws IOException          if no IP port was free
 */
@Test
public final void shouldBootInstanceUsingConvenienceMethods() throws InterruptedException, ExecutionException, IOException {
    // given
    final int expectedResponse = mockInt();
    final Application application = new StaticApplication(expectedResponse);
    final SeBootstrap.Configuration.Builder bootstrapConfigurationBuilder = SeBootstrap.Configuration.builder();
    final SeBootstrap.Configuration requestedConfiguration = bootstrapConfigurationBuilder.protocol("HTTP").host("localhost").port(someFreeIpPort()).rootPath("/root/path").build();
    // when
    final CompletionStage<SeBootstrap.Instance> completionStage = SeBootstrap.start(application, requestedConfiguration);
    final SeBootstrap.Instance instance = completionStage.toCompletableFuture().get();
    final SeBootstrap.Configuration actualConfiguration = instance.configuration();
    final int actualResponse = client.target(UriBuilder.newInstance().scheme(actualConfiguration.protocol()).host(actualConfiguration.host()).port(actualConfiguration.port()).path(actualConfiguration.rootPath()).path("application/resource")).request().get(int.class);
    // then
    assertThat(actualResponse, is(expectedResponse));
    assertThat(actualConfiguration.protocol(), is(requestedConfiguration.protocol()));
    assertThat(actualConfiguration.host(), is(requestedConfiguration.host()));
    assertThat(actualConfiguration.port(), is(requestedConfiguration.port()));
    assertThat(actualConfiguration.rootPath(), is(requestedConfiguration.rootPath()));
    instance.stop().toCompletableFuture().get();
}
Also used : SeBootstrap(jakarta.ws.rs.SeBootstrap) Application(jakarta.ws.rs.core.Application) Test(org.junit.jupiter.api.Test)

Example 18 with Application

use of jakarta.ws.rs.core.Application in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method defaultGetPropertiesIsEmptyTest.

/*
   * @testName: defaultGetPropertiesIsEmptyTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:1035;
   * 
   * @test_Strategy: The default implementation returns an empty set.
   */
@Test
public void defaultGetPropertiesIsEmptyTest() throws Fault {
    Application application = new Application();
    Map<String, Object> properties = application.getProperties();
    assertNotNull(properties, "Default implementation is not empty map, but null");
    assertTrue(properties.isEmpty(), "Default implementation is not empty, but" + JaxrsUtil.mapToString(properties));
    logMsg("Default implementation gets empty map as expected");
}
Also used : Application(jakarta.ws.rs.core.Application) Test(org.junit.jupiter.api.Test)

Aggregations

Application (jakarta.ws.rs.core.Application)18 SeBootstrap (jakarta.ws.rs.SeBootstrap)13 Test (org.junit.jupiter.api.Test)12 URI (java.net.URI)6 Configuration (jakarta.ws.rs.SeBootstrap.Configuration)3 JaxrsUtil.unprivilegedPort (ee.jakarta.tck.ws.rs.common.util.JaxrsUtil.unprivilegedPort)2 ApplicationPath (jakarta.ws.rs.ApplicationPath)2 GET (jakarta.ws.rs.GET)2 Path (jakarta.ws.rs.Path)2 Client (jakarta.ws.rs.client.Client)2 ClientBuilder (jakarta.ws.rs.client.ClientBuilder)2 UriBuilder (jakarta.ws.rs.core.UriBuilder)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 Optional (java.util.Optional)2 Set (java.util.Set)2 CompletionStage (java.util.concurrent.CompletionStage)2 ExecutionException (java.util.concurrent.ExecutionException)2 HOURS (java.util.concurrent.TimeUnit.HOURS)2 Config (org.eclipse.microprofile.config.Config)2