package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service;
-import io.netty.handler.ssl.SslContext;
import io.vavr.control.Try;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.UUID;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
-import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClientFactory;
import org.onap.dcaegen2.services.sdk.rest.services.model.logging.ImmutableRequestDiagnosticContext;
import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeys;
import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeysStore;
import org.onap.dcaegen2.services.sdk.security.ssl.Passwords;
import org.onap.dcaegen2.services.sdk.security.ssl.SecurityKeys;
-import org.onap.dcaegen2.services.sdk.security.ssl.SslFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOGGER = LoggerFactory.getLogger(AaiHttpClientFactory.class);
private final AaiClientConfiguration configuration;
- private final SslFactory sslFactory;
public AaiHttpClientFactory(AaiClientConfiguration configuration) {
- this(configuration, new SslFactory());
- }
-
- public AaiHttpClientFactory(AaiClientConfiguration configuration, SslFactory sslFactory) {
this.configuration = configuration;
- this.sslFactory = sslFactory;
}
- public CloudHttpClient build() {
+ public RxHttpClient build() {
LOGGER.debug("Setting ssl context");
- return new CloudHttpClient(createSslContext());
- }
- private SslContext createSslContext() {
if (configuration.enableAaiCertAuth()) {
- final SecurityKeys collectorSecurityKeys = ImmutableSecurityKeys.builder()
- .keyStore(ImmutableSecurityKeysStore.of(resource(configuration.keyStorePath()).get()))
- .keyStorePassword(Passwords.fromResource(configuration.keyStorePasswordPath()))
- .trustStore(ImmutableSecurityKeysStore.of(resource(configuration.trustStorePath()).get()))
- .trustStorePassword(Passwords.fromResource(configuration.trustStorePasswordPath()))
- .build();
- return sslFactory.createSecureClientContext(collectorSecurityKeys);
+ return RxHttpClientFactory.create(createSslKeys());
+ } else {
+ return RxHttpClientFactory.createInsecure();
}
- return sslFactory.createInsecureClientContext();
}
- private Try<Path> resource(String resource) {
- return Try.of(() -> Paths.get(Passwords.class.getResource(resource).toURI()));
+ private SecurityKeys createSslKeys() {
+ return ImmutableSecurityKeys.builder()
+ .keyStore(ImmutableSecurityKeysStore.of(Paths.get(configuration.keyStorePath())))
+ .keyStorePassword(Passwords.fromPath(Paths.get(configuration.keyStorePasswordPath())))
+ .trustStore(ImmutableSecurityKeysStore.of(Paths.get(configuration.trustStorePath())))
+ .trustStorePassword(Passwords.fromPath(Paths.get(configuration.trustStorePasswordPath())))
+ .build();
}
public static RequestDiagnosticContext createRequestDiagnosticContext() {
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * DCAEGEN2-SERVICES-SDK
+ * ================================================================================
+ * Copyright (C) 2018-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;
+
+import io.vavr.collection.HashMap;
+import java.util.Map;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpMethod;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.ImmutableHttpRequest;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RequestBody;
+import org.onap.dcaegen2.services.sdk.rest.services.model.ClientModel;
+import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
+import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
+
+public final class AaiRequests {
+
+ private AaiRequests(){}
+
+ public static HttpRequest createAaiPatchRequest(String url,
+ RequestDiagnosticContext context,
+ Map<String, String> customHeaders,
+ JsonBodyBuilder jsonBodyBuilder,
+ ClientModel clientModel) {
+
+ return buildAaiRequestWithBody(url, context, customHeaders,
+ jsonBodyBuilder, clientModel, HttpMethod.PATCH);
+ }
+
+ public static HttpRequest createAaiPutRequest(String url,
+ RequestDiagnosticContext context,
+ Map<String, String> customHeaders,
+ JsonBodyBuilder jsonBodyBuilder,
+ ClientModel clientModel) {
+
+ return buildAaiRequestWithBody(url, context, customHeaders,
+ jsonBodyBuilder, clientModel, HttpMethod.PUT);
+ }
+
+ private static HttpRequest buildAaiRequestWithBody(String url,
+ RequestDiagnosticContext context,
+ Map<String, String> customHeaders,
+ JsonBodyBuilder jsonBodyBuilder,
+ ClientModel clientModel,
+ HttpMethod method) {
+
+ String jsonBody = jsonBodyBuilder.createJsonBody(clientModel);
+
+ return ImmutableHttpRequest.builder()
+ .url(url)
+ .customHeaders(HashMap.ofAll(customHeaders))
+ .diagnosticContext(context)
+ .body(RequestBody.fromString(jsonBody))
+ .method(method)
+ .build();
+ }
+
+ public static HttpRequest createAaiGetRequest(String url,
+ RequestDiagnosticContext context,
+ Map<String, String> customHeaders) {
+ return ImmutableHttpRequest.builder()
+ .method(HttpMethod.GET)
+ .url(url)
+ .customHeaders(HashMap.ofAll(customHeaders))
+ .diagnosticContext(context)
+ .build();
+ }
+}
package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.get;
+import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiRequests.createAaiGetRequest;
import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.createRequestDiagnosticContext;
import io.vavr.collection.HashMap;
import org.apache.commons.text.StringSubstitutor;
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.adapters.http.HttpRequest;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient;
import org.onap.dcaegen2.services.sdk.rest.services.model.AaiServiceInstanceQueryModel;
import org.onap.dcaegen2.services.sdk.rest.services.uri.URI;
import reactor.core.publisher.Mono;
private static final String SERVICE_TYPE = "serviceType";
private static final String SERVICE_INSTANCE_ID = "serviceInstanceId";
- private final CloudHttpClient httpGetClient;
+ private final RxHttpClient httpClient;
private final AaiClientConfiguration configuration;
public AaiGetServiceInstanceClient(final AaiClientConfiguration configuration,
- final CloudHttpClient httpGetClient) {
+ final RxHttpClient httpClient) {
this.configuration = configuration;
- this.httpGetClient = httpGetClient;
+ this.httpClient = httpClient;
}
@Override
final StringSubstitutor substitutor = new StringSubstitutor(mapping.toJavaMap());
final String replaced = substitutor.replace(configuration.aaiServiceInstancePath());
- return httpGetClient.get(
- getUri(replaced),
- createRequestDiagnosticContext(),
- configuration.aaiHeaders());
+ final HttpRequest getRequest = createAaiGetRequest(getUri(replaced),
+ createRequestDiagnosticContext(), configuration.aaiHeaders());
+
+ return httpClient.call(getRequest);
}
private String getUri(final String endpoint) {
package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.get;
+import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiRequests.createAaiGetRequest;
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.adapters.http.HttpRequest;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient;
import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
import org.onap.dcaegen2.services.sdk.rest.services.uri.URI;
import reactor.core.publisher.Mono;
public final class AaiHttpGetClient implements AaiHttpClient<AaiModel, HttpResponse> {
- private final CloudHttpClient httpGetClient;
+ private final RxHttpClient httpClient;
private final AaiClientConfiguration configuration;
- public AaiHttpGetClient(AaiClientConfiguration configuration, CloudHttpClient httpGetClient) {
+ public AaiHttpGetClient(AaiClientConfiguration configuration, RxHttpClient httpClient) {
this.configuration = configuration;
- this.httpGetClient = httpGetClient;
+ this.httpClient = httpClient;
}
@Override
public Mono<HttpResponse> getAaiResponse(AaiModel aaiModel) {
- return httpGetClient
- .get(getUri(aaiModel.getCorrelationId()), createRequestDiagnosticContext(), configuration.aaiHeaders());
+ final HttpRequest getRequest = createAaiGetRequest(getUri(aaiModel.getCorrelationId()),
+ createRequestDiagnosticContext(), configuration.aaiHeaders());
+
+ return httpClient.call(getRequest);
}
+
private String getUri(String pnfName) {
return new URI.URIBuilder()
.scheme(configuration.aaiProtocol())
package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.patch;
+import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AaiRequests.createAaiPatchRequest;
import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.AaiHttpClientFactory.createRequestDiagnosticContext;
import io.vavr.collection.HashMap;
import io.vavr.collection.Map;
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.adapters.http.HttpRequest;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient;
import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
import org.onap.dcaegen2.services.sdk.rest.services.uri.URI;
private final static Map<String, String> CONTENT_TYPE = HashMap.of("Content-Type", "application/merge-patch+json");
- private CloudHttpClient httpPatchClient;
+ private RxHttpClient httpClient;
private final AaiClientConfiguration configuration;
private final JsonBodyBuilder jsonBodyBuilder;
public AaiHttpPatchClient(final AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder,
- CloudHttpClient httpPatchClient) {
+ RxHttpClient httpClient) {
this.configuration = configuration;
this.jsonBodyBuilder = jsonBodyBuilder;
- this.httpPatchClient = httpPatchClient;
+ this.httpClient = httpClient;
}
public Mono<HttpResponse> getAaiResponse(AaiModel aaiModel) {
final Map<String, String> headers = CONTENT_TYPE.merge(HashMap.ofAll(configuration.aaiHeaders()));
- return httpPatchClient.patch(
+ final HttpRequest aaiPatchRequest = createAaiPatchRequest(
getUri(aaiModel.getCorrelationId()),
createRequestDiagnosticContext(),
headers.toJavaMap(),
jsonBodyBuilder,
aaiModel);
+
+ return httpClient.call(aaiPatchRequest);
}
private String getUri(String pnfName) {
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.http.AaiRequests.createAaiPutRequest;
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.adapters.http.HttpRequest;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient;
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;
public class AaiHttpPutClient implements AaiHttpClient<AaiModel, HttpResponse> {
- private CloudHttpClient httpPutClient;
+ private RxHttpClient httpClient;
private final AaiClientConfiguration configuration;
private final JsonBodyBuilder jsonBodyBuilder;
private final String uri;
public AaiHttpPutClient(final AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder, String uri,
- CloudHttpClient httpPutClient) {
+ RxHttpClient httpClient) {
this.configuration = configuration;
this.jsonBodyBuilder = jsonBodyBuilder;
this.uri = uri;
- this.httpPutClient = httpPutClient;
+ this.httpClient = httpClient;
}
@Override
public Mono<HttpResponse> getAaiResponse(AaiModel aaiModel) {
- return httpPutClient
- .put(uri, createRequestDiagnosticContext(), configuration.aaiHeaders(), jsonBodyBuilder, aaiModel);
+ final HttpRequest aaiPutRequest = createAaiPutRequest(uri, createRequestDiagnosticContext(),
+ configuration.aaiHeaders(), jsonBodyBuilder, aaiModel);
+ return httpClient.call(aaiPutRequest);
}
}
+++ /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;
-
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.AaiClientConfigurations.insecureConfiguration;
-import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.AaiClientConfigurations.secureConfiguration;
-
-import io.netty.handler.ssl.SslContext;
-import javax.net.ssl.SSLException;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-import org.onap.dcaegen2.services.sdk.security.ssl.SecurityKeys;
-import org.onap.dcaegen2.services.sdk.security.ssl.SslFactory;
-
-class AaiHttpClientFactoryTest {
-
- private SslFactory sslFactory;
-
- @BeforeEach
- void setup() {
- this.sslFactory = Mockito.mock(SslFactory.class);
- }
-
- @Test
- void createRequestDiagnosticContext_shouldReturnNonNullContext() {
- assertNotNull(AaiHttpClientFactory.createRequestDiagnosticContext());
- }
-
- @Test
- void build_onSecureConfigurationProvided_shouldReturnSecureClient() throws SSLException {
- when(sslFactory.createSecureClientContext(any())).thenReturn(SslContext.newClientContext());
- AaiHttpClientFactory cut = new AaiHttpClientFactory(secureConfiguration(), sslFactory);
-
- cut.build();
-
- verify(sslFactory).createSecureClientContext(any(SecurityKeys.class));
- verify(sslFactory, never()).createInsecureClientContext();
- }
-
- @Test
- void build_onInsecureConfigurationProvided_shouldReturnInsecureClient() throws SSLException {
- when(sslFactory.createInsecureClientContext()).thenReturn(SslContext.newClientContext());
- AaiHttpClientFactory cut = new AaiHttpClientFactory(insecureConfiguration(), sslFactory);
-
- cut.build();
-
- verify(sslFactory).createInsecureClientContext();
- verify(sslFactory, never()).createSecureClientContext(any(SecurityKeys.class));
- }
-}
import static org.mockito.Mockito.mock;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
-import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpResponse;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.RxHttpClient;
import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
import org.onap.dcaegen2.services.sdk.rest.services.uri.URI;
public class AbstractHttpClientTest {
protected final AaiModel aaiModel = () -> "test-id";
- protected final CloudHttpClient httpClient = mock(CloudHttpClient.class);
+ protected final RxHttpClient httpClient = mock(RxHttpClient.class);
protected final JsonBodyBuilder bodyBuilder = mock(JsonBodyBuilder.class);
protected final HttpResponse response = mock(HttpResponse.class);
package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.get;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyMap;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.AaiClientConfigurations.secureConfiguration;
-import java.util.HashMap;
-import java.util.Map;
+import io.vavr.collection.HashMap;
+import io.vavr.collection.Map;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AbstractHttpClientTest;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest;
import org.onap.dcaegen2.services.sdk.rest.services.model.AaiServiceInstanceQueryModel;
-import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@Test
void getAaiResponse_shouldCallGetMethod_withGivenAaiHeaders() {
+
+ // given
AaiServiceInstanceQueryModel model = mock(AaiServiceInstanceQueryModel.class);
- Map<String, String> headers = new HashMap<>();
- AaiGetServiceInstanceClient cut = new AaiGetServiceInstanceClient(secureConfiguration(headers), httpClient);
+ Map<String, String> headers = HashMap.of("sample-key", "sample-value");
+ AaiGetServiceInstanceClient cut = new AaiGetServiceInstanceClient(secureConfiguration(headers.toJavaMap()),
+ httpClient);
- given(httpClient.get(anyString(), any(RequestDiagnosticContext.class), anyMap()))
+ given(httpClient.call(any(HttpRequest.class)))
.willReturn(Mono.just(response));
+ // when
StepVerifier
.create(cut.getAaiResponse(model))
.expectNext(response)
.verifyComplete();
+ //then
verify(httpClient)
- .get(anyString(), any(RequestDiagnosticContext.class), eq(headers));
+ .call(argThat(httpRequest -> httpRequest.customHeaders().equals(headers)));
}
}
package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.get;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyMap;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.AaiClientConfigurations.secureConfiguration;
-import java.util.HashMap;
-import java.util.Map;
+import io.vavr.collection.HashMap;
+import io.vavr.collection.Map;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AbstractHttpClientTest;
-import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@Test
void getAaiResponse_shouldCallGetMethod_withGivenAaiHeaders() {
- Map<String, String> headers = new HashMap<>();
- AaiHttpGetClient cut = new AaiHttpGetClient(secureConfiguration(headers), httpClient);
- given(httpClient.get(
- anyString(),
- any(RequestDiagnosticContext.class),
- anyMap()
- )).willReturn(Mono.just(response));
+ // given
+ Map<String, String> headers = HashMap.of("sample-key", "sample-value");
+ AaiHttpGetClient cut = new AaiHttpGetClient(secureConfiguration(headers.toJavaMap()), httpClient);
+ given(httpClient.call(any(HttpRequest.class)))
+ .willReturn(Mono.just(response));
+
+ // when
StepVerifier
.create(cut.getAaiResponse(aaiModel))
.expectNext(response)
.verifyComplete();
- verify(httpClient).get(
- anyString(),
- any(RequestDiagnosticContext.class),
- eq(headers)
- );
+ //then
+ verify(httpClient)
+ .call(argThat(httpRequest -> httpRequest.customHeaders().equals(headers)));
}
@Test
void getAaiResponse_shouldCallGetMethod_withProperUri() {
+
+ // given
AaiClientConfiguration configuration = secureConfiguration();
- String expectedUri = constructAaiUri(configuration, aaiModel.getCorrelationId());
+ String uri = constructAaiUri(configuration, aaiModel.getCorrelationId());
AaiHttpGetClient cut = new AaiHttpGetClient(configuration, httpClient);
- given(httpClient.get(
- anyString(),
- any(RequestDiagnosticContext.class),
- anyMap()
- )).willReturn(Mono.just(response));
+ given(httpClient.call(any(HttpRequest.class)))
+ .willReturn(Mono.just(response));
+ // when
StepVerifier
.create(cut.getAaiResponse(aaiModel))
.expectNext(response)
.verifyComplete();
- verify(httpClient).get(
- eq(expectedUri),
- any(RequestDiagnosticContext.class),
- anyMap()
- );
+ // then
+ verify(httpClient)
+ .call(argThat(httpRequest -> httpRequest.url().equals(uri)));
}
}
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AbstractHttpClientTest;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest;
import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
@Test
void getAaiResponse_shouldCallPatchMethod_withGivenHeaders_combinedWithContentType() {
+ // given
Map<String, String> headers = HashMap.of("sample-key", "sample-value");
Map<String, String> expectedHeaders = DEFAULT_PATCH_HEADERS.merge(headers);
+
AaiHttpPatchClient cut =
new AaiHttpPatchClient(secureConfiguration(headers.toJavaMap()), bodyBuilder, httpClient);
- given(httpClient.patch(
- anyString(),
- any(RequestDiagnosticContext.class),
- anyMap(),
- any(JsonBodyBuilder.class),
- any(AaiModel.class)
- )).willReturn(Mono.just(response));
+ given(bodyBuilder.createJsonBody(eq(aaiModel)))
+ .willReturn("test-body");
+
+ given(httpClient.call(any(HttpRequest.class)))
+ .willReturn(Mono.just(response));
+ // when
StepVerifier
.create(cut.getAaiResponse(aaiModel))
.expectNext(response)
.verifyComplete();
- verify(httpClient).patch(
- anyString(),
- any(RequestDiagnosticContext.class),
- eq(expectedHeaders.toJavaMap()),
- eq(bodyBuilder),
- eq(aaiModel)
- );
+ // then
+ verify(httpClient)
+ .call(argThat(httpRequest -> httpRequest.customHeaders().equals(expectedHeaders)));
}
@Test
void getAaiResponse_shouldCallPatchMethod_withProperUri() {
+
+ // given
AaiClientConfiguration configuration = secureConfiguration();
- String expectedUri = constructAaiUri(configuration, aaiModel.getCorrelationId());
+ String uri = constructAaiUri(configuration, aaiModel.getCorrelationId());
AaiHttpPatchClient cut = new AaiHttpPatchClient(configuration, bodyBuilder, httpClient);
- given(httpClient.patch(
- anyString(),
- any(RequestDiagnosticContext.class),
- anyMap(),
- any(JsonBodyBuilder.class),
- any(AaiModel.class)
- )).willReturn(Mono.just(response));
+ given(bodyBuilder.createJsonBody(eq(aaiModel)))
+ .willReturn("test-body");
+
+ given(httpClient.call(any(HttpRequest.class)))
+ .willReturn(Mono.just(response));
+ // when
StepVerifier
.create(cut.getAaiResponse(aaiModel))
.expectNext(response)
.verifyComplete();
- verify(httpClient).patch(
- eq(expectedUri),
- any(RequestDiagnosticContext.class),
- anyMap(),
- eq(bodyBuilder),
- eq(aaiModel)
- );
+ // then
+ verify(httpClient)
+ .call(argThat(httpRequest -> httpRequest.url().equals(uri)));
}
}
package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.put;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyMap;
-import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.onap.dcaegen2.services.sdk.rest.services.aai.client.AaiClientConfigurations.secureConfiguration;
-import java.util.HashMap;
-import java.util.Map;
+import io.vavr.collection.HashMap;
+import io.vavr.collection.Map;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.AbstractHttpClientTest;
-import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
-import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
-import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.HttpRequest;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@Test
void getAaiResponse_shouldCallPutMethod_withGivenAaiHeaders() {
- Map<String, String> headers = new HashMap<>();
- AaiHttpPutClient cut = new AaiHttpPutClient(secureConfiguration(headers), bodyBuilder, "", httpClient);
+ Map<String, String> headers = HashMap.of("sample-key", "sample-value");
+ AaiHttpPutClient cut = new AaiHttpPutClient(secureConfiguration(headers.toJavaMap()), bodyBuilder, "",
+ httpClient);
- given(httpClient.put(
- anyString(),
- any(RequestDiagnosticContext.class),
- anyMap(),
- any(JsonBodyBuilder.class),
- any(AaiModel.class)
- )).willReturn(Mono.just(response));
+ given(bodyBuilder.createJsonBody(eq(aaiModel)))
+ .willReturn("test-body");
+
+ given(httpClient.call(any(HttpRequest.class)))
+ .willReturn(Mono.just(response));
StepVerifier
.create(cut.getAaiResponse(aaiModel))
.expectNext(response)
.verifyComplete();
- verify(httpClient).put(
- anyString(),
- any(RequestDiagnosticContext.class),
- eq(headers),
- eq(bodyBuilder),
- eq(aaiModel)
- );
+ verify(httpClient)
+ .call(argThat(httpRequest -> httpRequest.customHeaders().equals(headers)));
}
@Test
String uri = "test-uri";
AaiHttpPutClient cut = new AaiHttpPutClient(secureConfiguration(), bodyBuilder, uri, httpClient);
- given(httpClient.put(
- anyString(),
- any(RequestDiagnosticContext.class),
- anyMap(),
- any(JsonBodyBuilder.class),
- any(AaiModel.class)
- )).willReturn(Mono.just(response));
+ given(bodyBuilder.createJsonBody(eq(aaiModel)))
+ .willReturn("test-body");
+
+ given(httpClient.call(any(HttpRequest.class)))
+ .willReturn(Mono.just(response));
StepVerifier
.create(cut.getAaiResponse(aaiModel))
.expectNext(response)
.verifyComplete();
- verify(httpClient).put(
- eq(uri),
- any(RequestDiagnosticContext.class),
- anyMap(),
- eq(bodyBuilder),
- eq(aaiModel)
- );
+ verify(httpClient)
+ .call(argThat(httpRequest -> httpRequest.url().equals(uri)));
+
}
}