private final AaiClientConfiguration configuration;
- public AaiHttpGetClient(AaiClientConfiguration configuration) {
+ public AaiHttpGetClient(AaiClientConfiguration configuration, CloudHttpClient httpGetClient) {
this.configuration = configuration;
+ this.httpGetClient = httpGetClient;
}
@Override
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())
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) {
.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())
--- /dev/null
+/*-
+ * ============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);
+ }
+}
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,
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());