diff options
author | micdzied <michal.1.dziedzic@nokia.com> | 2019-03-07 10:03:43 +0100 |
---|---|---|
committer | micdzied <michal.1.dziedzic@nokia.com> | 2019-03-07 10:07:00 +0100 |
commit | 3b60664a85d84233d3f2005d1758f256c8cbd547 (patch) | |
tree | a7204ab4652300bb5e230cc7af255d9b2e19d980 /rest-services | |
parent | 3666e89b3411e84b138279cccc8130df60c81f4c (diff) |
add get request test
Change-Id: I94a4337ca2a335587382c9965f6543af619e16ea
Issue-ID: DCAEGEN2-1315
Signed-off-by: micdzied <michal.1.dziedzic@nokia.com>
Diffstat (limited to 'rest-services')
3 files changed, 64 insertions, 5 deletions
diff --git a/rest-services/common-dependency/pom.xml b/rest-services/common-dependency/pom.xml index 1b34fb67..4bda1750 100644 --- a/rest-services/common-dependency/pom.xml +++ b/rest-services/common-dependency/pom.xml @@ -56,5 +56,10 @@ <artifactId>junit-jupiter-engine</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>io.projectreactor</groupId> + <artifactId>reactor-test</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project>
\ No newline at end of file diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java index 33c39fa6..f645bc91 100644 --- a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java +++ b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java @@ -58,7 +58,7 @@ public class CloudHttpClient { this(HttpClient.create().secure(sslContextSpec -> sslContextSpec.sslContext(sslContext))); } - private CloudHttpClient(HttpClient httpClient) { + CloudHttpClient(HttpClient httpClient) { this.httpClient = httpClient; } diff --git a/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClientIT.java b/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClientIT.java index 2553b9be..328df2dc 100644 --- a/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClientIT.java +++ b/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClientIT.java @@ -20,24 +20,78 @@ package org.onap.dcaegen2.services.sdk.rest.services.adapters.http; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; +import reactor.core.publisher.Mono; +import reactor.netty.DisposableServer; +import reactor.netty.http.client.HttpClient; +import reactor.netty.http.server.HttpServer; +import reactor.netty.resources.ConnectionProvider; +import reactor.test.StepVerifier; class CloudHttpClientIT { + private static final String SAMPLE_URL = "/sampleURL"; + private static final int MAX_CONNECTIONS = 1; + private static final ConnectionProvider connectionProvider = ConnectionProvider.fixed("test", MAX_CONNECTIONS); + @Test public void post() { assertTrue(true); } @Test - public void get() { + public void patch() { assertTrue(true); } @Test - public void patch() { - assertTrue(true); + void successfulGetResponse() { + String sampleString = "sampleString"; + Mono<String> response = Mono.just(sampleString); + DisposableServer server = + HttpServer.create() + .handle((req, resp) -> resp.sendString(response)) + .wiretap(true) + .bindNow(); + HttpClient httpClient = createHttpClientForContextWithAddress(server, connectionProvider); + CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient); + + Mono<String> content = cloudHttpClient.get(SAMPLE_URL, String.class); + + StepVerifier.create(content) + .expectNext(sampleString) + .expectComplete() + .verify(); + server.disposeNow(); + } + + @Test + void errorGetRequest() { + DisposableServer server = + HttpServer.create() + .handle((req, resp) -> Mono.error(new Exception("returnError"))) + .wiretap(true) + .bindNow(); + HttpClient httpClient = createHttpClientForContextWithAddress(server, connectionProvider); + CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient); + + Mono<String> content = cloudHttpClient.get(SAMPLE_URL, String.class); + + StepVerifier.create(content) + .expectError() + .verify(); + server.disposeNow(); + } + + private HttpClient createHttpClientForContextWithAddress(DisposableServer context) { + return createHttpClientForContextWithAddress(context, null); + } + + private HttpClient createHttpClientForContextWithAddress(DisposableServer disposableServer, + ConnectionProvider connectionProvider) { + HttpClient client = connectionProvider == null? HttpClient.create() : HttpClient.create(connectionProvider); + return client.addressSupplier(disposableServer::address).wiretap(true); } }
\ No newline at end of file |