use of jakarta.ws.rs.core.Application in project jaxrs-api by eclipse-ee4j.
the class SeBootstrapIT method shouldBootInstanceUsingExternalConfiguration.
/**
* Verifies that an instance will boot using external configuration.
*
* @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 shouldBootInstanceUsingExternalConfiguration() throws InterruptedException, ExecutionException, IOException {
// given
final int someFreeIpPort = someFreeIpPort();
final int expectedResponse = mockInt();
final Application application = new StaticApplication(expectedResponse);
final SeBootstrap.Configuration.Builder bootstrapConfigurationBuilder = SeBootstrap.Configuration.builder();
final SeBootstrap.Configuration requestedConfiguration = bootstrapConfigurationBuilder.from((property, type) -> {
switch(property) {
case SeBootstrap.Configuration.PROTOCOL:
return Optional.of("HTTP");
case SeBootstrap.Configuration.HOST:
return Optional.of("localhost");
case SeBootstrap.Configuration.PORT:
return Optional.of(someFreeIpPort);
case SeBootstrap.Configuration.ROOT_PATH:
return Optional.of("/root/path");
default:
return Optional.empty();
}
}).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();
}
use of jakarta.ws.rs.core.Application in project jaxrs-api by eclipse-ee4j.
the class SeBootstrapIT method shouldBootInstanceUsingImplementationsDefaultIpPort.
/**
* Verifies that an instance will boot using the implementation's default 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 shouldBootInstanceUsingImplementationsDefaultIpPort() 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.DEFAULT_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();
}
use of jakarta.ws.rs.core.Application in project jaxrs-api by eclipse-ee4j.
the class SeBootstrapIT method shouldBootInstanceUsingDefaults.
/**
* Verifies that an instance will boot using default configuration.
*
* @throws ExecutionException if the instance didn't boot correctly
* @throws InterruptedException if the test took much longer than usually
* expected
*/
@Test
public final void shouldBootInstanceUsingDefaults() 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.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("HTTP"));
assertThat(actualConfiguration.host(), is("localhost"));
assertThat(actualConfiguration.port(), is(greaterThan(0)));
assertThat(actualConfiguration.rootPath(), is("/"));
instance.stop().toCompletableFuture().get();
}
use of jakarta.ws.rs.core.Application in project jaxrs-api by eclipse-ee4j.
the class SeBootstrapIT method shouldBootInstanceDespiteUnknownConfigurationParameters.
/**
* Verifies that an instance will ignore unknown configuration parameters.
*
* @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 shouldBootInstanceDespiteUnknownConfigurationParameters() 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").from((property, type) -> {
switch(property) {
case "ee.jakarta.tck.ws.rs.sebootstrap.SeBootstrapIT$Unknown_1":
return Optional.of("Silently ignored value A");
default:
return Optional.empty();
}
}).property("ee.jakarta.tck.ws.rs.sebootstrap.SeBootstrapIT$Unknown_2", "Silently ignored value B").from(new Object()).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();
}
use of jakarta.ws.rs.core.Application in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method createEndpointTest.
/*
* @testName: createEndpointTest
*
* @assertion_ids: JAXRS:JAVADOC:284; JAXRS:JAVADOC:285; JAXRS:JAVADOC:286;
*
* @test_Strategy: Create a configured instance of the supplied endpoint type.
* How the returned endpoint instance is published is dependent on the type of
* endpoint.
*
* IllegalArgumentException - if application is null or the requested endpoint
* type is not supported. UnsupportedOperationException - if the
* implementation supports no endpoint types.
*
* Note that these assertions are almost untestable, as it can either create
* an instance or throw one exception or the other.
*/
@Test
public void createEndpointTest() throws Fault {
Application application = new Application() {
public java.util.Set<java.lang.Class<?>> getClasses() {
java.util.Set<java.lang.Class<?>> set = new HashSet<Class<?>>();
set.add(Resource.class);
return set;
}
};
RuntimeDelegate delegate = RuntimeDelegate.getInstance();
HttpHandler handler = null;
try {
handler = delegate.createEndpoint(application, com.sun.net.httpserver.HttpHandler.class);
} catch (IllegalArgumentException e) {
logMsg("IllegalArgumentException has been thrown as expected", e);
return;
} catch (UnsupportedOperationException e) {
logMsg("UnsupportedOperationException has been thrown as expected", e);
return;
}
assertNotNull(handler, "HttpHandler end point should be created, or an exception thrown otherwise");
logMsg("HttpHandler endpoint has been sucessfully created");
}
Aggregations