diff options
Diffstat (limited to 'rest-services/common-dependency')
2 files changed, 40 insertions, 0 deletions
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 e83a069e..8e317f8b 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 @@ -99,6 +99,14 @@ public class CloudHttpClient { return callForRawResponse(url, context, customHeaders, jsonBodyBuilder, clientModel, HttpMethod.PATCH); } + public Mono<HttpClientResponse> put( + String url, + RequestDiagnosticContext context, + Map<String, String> customHeaders, + JsonBodyBuilder jsonBodyBuilder, + ClientModel clientModel) { + return callForRawResponse(url, context, customHeaders, jsonBodyBuilder, clientModel, HttpMethod.PUT); + } private Mono<HttpClientResponse> callForRawResponse( String url, 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 a913a93f..9844ef1d 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 @@ -154,6 +154,38 @@ class CloudHttpClientIT { server.disposeNow(); } + @Test + void successfulPutResponse() { + DisposableServer server = createValidServer(); + RxHttpClient httpClient = createHttpClientForContextWithAddress(server); + CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient); + + when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn(JSON_BODY); + Mono<HttpClientResponse> content = cloudHttpClient + .put(SAMPLE_URL, createRequestDiagnosticContext(), createCustomHeaders(), + jsonBodyBuilder, dmaapModel); + HttpClientResponse httpClientResponse = content.block(); + + assertEquals(HttpResponseStatus.OK, httpClientResponse.status()); + server.disposeNow(); + } + + @Test + void errorPutRequest() { + DisposableServer server = createInvalidServer(); + RxHttpClient httpClient = createHttpClientForContextWithAddress(server); + CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient); + + when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn(JSON_BODY); + Mono<HttpClientResponse> content = cloudHttpClient + .put(SAMPLE_URL, createRequestDiagnosticContext(), createCustomHeaders(), + jsonBodyBuilder, dmaapModel); + HttpClientResponse httpClientResponse = content.block(); + + assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR, httpClientResponse.status()); + server.disposeNow(); + } + private Map<String, String> createCustomHeaders() { Map<String, String> customHeaders = new HashMap<>(); customHeaders.put("X_INVOCATION_ID", UUID.randomUUID().toString()); |