Search in sources :

Example 11 with Application

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

the class SeBootstrapTest method shouldDelegateClassApplicationStartupToRuntimeDelegate.

/**
 * Assert that {@link SeBootstrap#start(Class, Configuration)} will delegate to
 * {@link RuntimeDelegate#bootstrap(Class, Configuration)}.
 *
 * @since 3.1
 */
@Test
public void shouldDelegateClassApplicationStartupToRuntimeDelegate() {
    // given
    final Application application = mock(Application.class);
    final Class<? extends Application> clazz = application.getClass();
    final Configuration configuration = mock(Configuration.class);
    @SuppressWarnings("unchecked") final CompletionStage<SeBootstrap.Instance> nativeCompletionStage = mock(CompletionStage.class);
    given(RuntimeDelegate.getInstance().bootstrap(clazz, configuration)).willReturn(nativeCompletionStage);
    // when
    final CompletionStage<SeBootstrap.Instance> actualCompletionStage = SeBootstrap.start(clazz, configuration);
    // then
    assertThat(actualCompletionStage, is(sameInstance(nativeCompletionStage)));
}
Also used : Configuration(jakarta.ws.rs.SeBootstrap.Configuration) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) Application(jakarta.ws.rs.core.Application) Test(org.junit.jupiter.api.Test)

Example 12 with Application

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

the class SeBootstrapTest method shouldDelegateApplicationStartupToRuntimeDelegate.

/**
 * Assert that {@link SeBootstrap#start(Application, Configuration)} will delegate to
 * {@link RuntimeDelegate#bootstrap(Application, Configuration)}.
 *
 * @since 3.1
 */
@Test
public void shouldDelegateApplicationStartupToRuntimeDelegate() {
    // given
    final Application application = mock(Application.class);
    final Configuration configuration = mock(Configuration.class);
    @SuppressWarnings("unchecked") final CompletionStage<SeBootstrap.Instance> nativeCompletionStage = mock(CompletionStage.class);
    given(RuntimeDelegate.getInstance().bootstrap(application, configuration)).willReturn(nativeCompletionStage);
    // when
    final CompletionStage<SeBootstrap.Instance> actualCompletionStage = SeBootstrap.start(application, configuration);
    // then
    assertThat(actualCompletionStage, is(sameInstance(nativeCompletionStage)));
}
Also used : Configuration(jakarta.ws.rs.SeBootstrap.Configuration) CoreMatchers.sameInstance(org.hamcrest.CoreMatchers.sameInstance) Application(jakarta.ws.rs.core.Application) Test(org.junit.jupiter.api.Test)

Example 13 with Application

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

the class ExternalConfigJavaSeBootstrapExample method main.

/**
 * Runs this example.
 *
 * @param args unused command line arguments
 * @throws InterruptedException when process is killed
 */
public static void main(final String[] args) throws InterruptedException {
    final Application application = new HelloWorld();
    final Config config = ConfigProvider.getConfig();
    final SeBootstrap.Configuration requestedConfiguration = SeBootstrap.Configuration.builder().from(config).protocol("HTTPS").build();
    SeBootstrap.start(application, requestedConfiguration).thenAccept(instance -> {
        instance.stopOnShutdown(stopResult -> System.out.printf("Stop result: %s [Native stop result: %s].%n", stopResult, stopResult.unwrap(Object.class)));
        final URI uri = instance.configuration().baseUri();
        System.out.printf("Instance %s running at %s [Native handle: %s].%n", instance, uri, instance.unwrap(Object.class));
        System.out.println("Send SIGKILL to shutdown.");
    });
    Thread.currentThread().join();
}
Also used : Config(org.eclipse.microprofile.config.Config) SeBootstrap(jakarta.ws.rs.SeBootstrap) Application(jakarta.ws.rs.core.Application) URI(java.net.URI)

Example 14 with Application

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

the class PropertyProviderJavaSeBootstrapExample method main.

/**
 * Runs this example.
 *
 * @param args unused command line arguments
 * @throws InterruptedException when process is killed
 */
public static void main(final String[] args) throws InterruptedException {
    final Application application = new HelloWorld();
    final Config config = ConfigProvider.getConfig();
    final SeBootstrap.Configuration requestedConfiguration = SeBootstrap.Configuration.builder().from(config::getOptionalValue).protocol("HTTPS").build();
    SeBootstrap.start(application, requestedConfiguration).thenAccept(instance -> {
        instance.stopOnShutdown(stopResult -> System.out.printf("Stop result: %s [Native stop result: %s].%n", stopResult, stopResult.unwrap(Object.class)));
        final URI uri = instance.configuration().baseUri();
        System.out.printf("Instance %s running at %s [Native handle: %s].%n", instance, uri, instance.unwrap(Object.class));
        System.out.println("Send SIGKILL to shutdown.");
    });
    Thread.currentThread().join();
}
Also used : Config(org.eclipse.microprofile.config.Config) SeBootstrap(jakarta.ws.rs.SeBootstrap) Application(jakarta.ws.rs.core.Application) URI(java.net.URI)

Example 15 with Application

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

the class SeBootstrapIT method shouldBootInstanceUsingSelfDetectedFreeIpPort.

/**
 * Verifies that an instance will boot using a self-detected free IP port.
 *
 * @throws ExecutionException   if the instance didn't boot correctly
 * @throws InterruptedException if the test took much longer than usually
 *                              expected
 */
@Test
public final void shouldBootInstanceUsingSelfDetectedFreeIpPort() throws InterruptedException, ExecutionException {
    // 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(SeBootstrap.Configuration.FREE_PORT).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(greaterThan(0)));
    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)

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