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)));
}
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)));
}
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();
}
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();
}
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();
}
Aggregations