diff options
author | Joanna Jeremicz <joanna.jeremicz@nokia.com> | 2019-03-20 08:01:32 +0100 |
---|---|---|
committer | Joanna Jeremicz <joanna.jeremicz@nokia.com> | 2019-03-22 10:15:15 +0100 |
commit | b80f611db0e70964edd72947ccf14240b55b397b (patch) | |
tree | e1cff36d6fee71f96b454401f52097f5c2cd5327 | |
parent | 5d90e4cc1354199d4a816e14f5fc431e7ff3ad65 (diff) |
Add PUT method
Change-Id: I1ae710a005f245f0a83af1e0e430b95a93516aa0
Issue-ID: DCAEGEN2-1353
Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com>
5 files changed, 97 insertions, 12 deletions
diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java index 4ff500a3..dad1c1f1 100644 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java @@ -35,8 +35,9 @@ public final class AaiHttpGetClient implements AaiHttpClient<String> { private final AaiClientConfiguration configuration; - public AaiHttpGetClient(AaiClientConfiguration configuration) { + public AaiHttpGetClient(AaiClientConfiguration configuration, CloudHttpClient httpGetClient) { this.configuration = configuration; + this.httpGetClient = httpGetClient; } @Override @@ -44,11 +45,6 @@ public final class AaiHttpGetClient implements AaiHttpClient<String> { return httpGetClient.get(getUri(aaiModel.getCorrelationId()), createRequestDiagnosticContext(), configuration.aaiHeaders(), String.class); } - public AaiHttpGetClient createAaiHttpClient(CloudHttpClient httpGetClient) { - this.httpGetClient = httpGetClient; - return this; - } - private String getUri(String pnfName) { return new URI.URIBuilder() .scheme(configuration.aaiProtocol()) diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java index 20592194..18511008 100644 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java @@ -38,9 +38,10 @@ public final class AaiHttpPatchClient implements AaiHttpClient<HttpClientRespons private final JsonBodyBuilder jsonBodyBuilder; - public AaiHttpPatchClient(final AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder) { + public AaiHttpPatchClient(final AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder, CloudHttpClient httpPatchClient) { this.configuration = configuration; this.jsonBodyBuilder = jsonBodyBuilder; + this.httpPatchClient = httpPatchClient; } public Mono<HttpClientResponse> getAaiResponse(AaiModel aaiModel) { @@ -48,11 +49,6 @@ public final class AaiHttpPatchClient implements AaiHttpClient<HttpClientRespons .patch(getUri(aaiModel.getCorrelationId()), createRequestDiagnosticContext(), configuration.aaiHeaders(), jsonBodyBuilder, aaiModel); } - public AaiHttpPatchClient createAaiHttpClient(CloudHttpClient httpPatchClient) { - this.httpPatchClient = httpPatchClient; - return this; - } - private String getUri(String pnfName) { return new URI.URIBuilder() .scheme(configuration.aaiProtocol()) diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClient.java new file mode 100644 index 00000000..33fcfcce --- /dev/null +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClient.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 2019 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.put; + +import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.createRequestDiagnosticContext; + +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient; +import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel; +import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; +import reactor.core.publisher.Mono; +import reactor.netty.http.client.HttpClientResponse; + +public class AaiHttpPutClient implements AaiHttpClient<HttpClientResponse> { + + private CloudHttpClient httpPutClient; + private final AaiClientConfiguration configuration; + private final JsonBodyBuilder jsonBodyBuilder; + private final String uri; + + public AaiHttpPutClient(final AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder, String uri, CloudHttpClient httpPutClient) { + this.configuration = configuration; + this.jsonBodyBuilder = jsonBodyBuilder; + this.uri = uri; + this.httpPutClient = httpPutClient; + } + + @Override + public Mono<HttpClientResponse> getAaiResponse(AaiModel aaiModel) { + return httpPutClient + .put(uri, createRequestDiagnosticContext(), configuration.aaiHeaders(), jsonBodyBuilder, aaiModel); + } +} 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()); |