diff options
author | micdzied <michal.1.dziedzic@nokia.com> | 2019-03-08 13:12:31 +0100 |
---|---|---|
committer | micdzied <michal.1.dziedzic@nokia.com> | 2019-03-11 10:48:19 +0100 |
commit | bfb97f75cf421315ec0f52af5a6de80083455151 (patch) | |
tree | 6aeff235b6332d18e067404c8a5b081a5c3685d8 | |
parent | a557b012ab5c51f9a5fb88328eb678eb78091118 (diff) |
add post request test
Change-Id: I8d488a48b68d99d72439901616a5e3053aa836fd
Issue-ID: DCAEGEN2-1315
Signed-off-by: micdzied <michal.1.dziedzic@nokia.com>
-rw-r--r-- | pom.xml | 2 | ||||
-rw-r--r-- | rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClientIT.java | 55 |
2 files changed, 44 insertions, 13 deletions
@@ -39,7 +39,7 @@ <vavr.version>0.10.0</vavr.version> <jetbrains-annotations.version>16.0.3</jetbrains-annotations.version> <protoc-jar-maven-plugin.version>3.6.0.2</protoc-jar-maven-plugin.version> - <maven-failsafe-plugin.version>2.22.1</maven-failsafe-plugin.version> + <maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version> </properties> <modules> 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 37c189ee..936ef0c5 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,6 +20,7 @@ package org.onap.dcaegen2.services.sdk.rest.services.adapters.http; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -27,7 +28,6 @@ import io.netty.handler.codec.http.HttpResponseStatus; import java.util.HashMap; import java.util.Map; import java.util.UUID; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.onap.dcaegen2.services.sdk.rest.services.model.DmaapModel; import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; @@ -53,7 +53,6 @@ class CloudHttpClientIT { private DmaapModel dmaapModel = mock(DmaapModel.class); private JsonBodyBuilder<DmaapModel> jsonBodyBuilder = mock(JsonBodyBuilder.class); - @Disabled @Test void successfulPatchResponse() { DisposableServer server = createValidServer(); @@ -63,15 +62,12 @@ class CloudHttpClientIT { when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn(JSON_BODY); Mono<HttpClientResponse> content = cloudHttpClient.patch(SAMPLE_URL, createRequestDiagnosticContext(), createCustomHeaders(), jsonBodyBuilder, dmaapModel); + HttpClientResponse httpClientResponse = content.block(); - StepVerifier.create(content) - .expectNext(content.block()) - .expectComplete() - .verify(); + assertEquals(HttpResponseStatus.OK, httpClientResponse.status()); server.disposeNow(); } - @Disabled @Test void errorPatchRequest() { DisposableServer server = createInvalidServer(); @@ -81,11 +77,39 @@ class CloudHttpClientIT { when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn(JSON_BODY); Mono<HttpClientResponse> content = cloudHttpClient.patch(SAMPLE_URL, createRequestDiagnosticContext(), createCustomHeaders(), jsonBodyBuilder, dmaapModel); + HttpClientResponse httpClientResponse = content.block(); - StepVerifier.create(content) - .expectNext(content.block()) - .expectComplete() - .verify(); + assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR, httpClientResponse.status()); + server.disposeNow(); + } + + @Test + void successfulPostResponse() { + DisposableServer server = createValidServer(); + HttpClient httpClient = createHttpClientForContextWithAddress(server, connectionProvider); + CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient); + + when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn(JSON_BODY); + Mono<HttpClientResponse> content = cloudHttpClient.post(SAMPLE_URL, createRequestDiagnosticContext(), createCustomHeaders(), + jsonBodyBuilder, dmaapModel); + HttpClientResponse httpClientResponse = content.block(); + + assertEquals(HttpResponseStatus.OK, httpClientResponse.status()); + server.disposeNow(); + } + + @Test + void errorPostRequest() { + DisposableServer server = createInvalidServer(); + HttpClient httpClient = createHttpClientForContextWithAddress(server, connectionProvider); + CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient); + + when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn(JSON_BODY); + Mono<HttpClientResponse> content = cloudHttpClient.post(SAMPLE_URL, createRequestDiagnosticContext(), createCustomHeaders(), + jsonBodyBuilder, dmaapModel); + HttpClientResponse httpClientResponse = content.block(); + + assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR, httpClientResponse.status()); server.disposeNow(); } @@ -95,14 +119,22 @@ class CloudHttpClientIT { HttpClient httpClient = createHttpClientForContextWithAddress(server, connectionProvider); CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient); + when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn(JSON_BODY); Mono<String> content = cloudHttpClient.get(SAMPLE_URL, String.class); + Mono<String> contentWithHeaders = cloudHttpClient.get(SAMPLE_URL, createRequestDiagnosticContext(), + createCustomHeaders(), String.class); StepVerifier.create(content) .expectNext(SAMPLE_STRING) .expectComplete() .verify(); + StepVerifier.create(contentWithHeaders) + .expectNext(SAMPLE_STRING) + .expectComplete() + .verify(); server.disposeNow(); } + @Test void errorGetRequest() { DisposableServer server = createInvalidServer(); @@ -120,7 +152,6 @@ class CloudHttpClientIT { private Map<String, String> createCustomHeaders() { Map<String, String> customHeaders = new HashMap<>(); customHeaders.put("X_INVOCATION_ID", UUID.randomUUID().toString()); - return customHeaders; } |