Add PUT method 80/82780/3
authorJoanna Jeremicz <joanna.jeremicz@nokia.com>
Wed, 20 Mar 2019 07:01:32 +0000 (08:01 +0100)
committerJoanna Jeremicz <joanna.jeremicz@nokia.com>
Fri, 22 Mar 2019 09:15:15 +0000 (10:15 +0100)
Change-Id: I1ae710a005f245f0a83af1e0e430b95a93516aa0
Issue-ID: DCAEGEN2-1353
Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com>
rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClient.java
rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClient.java
rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClient.java [new file with mode: 0644]
rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java
rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClientIT.java

index 4ff500a..dad1c1f 100644 (file)
@@ -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())
index 2059219..1851100 100644 (file)
@@ -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 (file)
index 0000000..33fcfcc
--- /dev/null
@@ -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);
+    }
+}
index e83a069..8e317f8 100644 (file)
@@ -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,
index a913a93..9844ef1 100644 (file)
@@ -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());