summaryrefslogtreecommitdiffstats
path: root/rest-services/common-dependency
diff options
context:
space:
mode:
authormicdzied <michal.1.dziedzic@nokia.com>2019-03-08 13:12:31 +0100
committermicdzied <michal.1.dziedzic@nokia.com>2019-03-11 10:48:19 +0100
commitbfb97f75cf421315ec0f52af5a6de80083455151 (patch)
tree6aeff235b6332d18e067404c8a5b081a5c3685d8 /rest-services/common-dependency
parenta557b012ab5c51f9a5fb88328eb678eb78091118 (diff)
add post request test
Change-Id: I8d488a48b68d99d72439901616a5e3053aa836fd Issue-ID: DCAEGEN2-1315 Signed-off-by: micdzied <michal.1.dziedzic@nokia.com>
Diffstat (limited to 'rest-services/common-dependency')
-rw-r--r--rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClientIT.java55
1 files changed, 43 insertions, 12 deletions
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;
}