diff options
Diffstat (limited to 'rest-services/aai-client/src/test')
6 files changed, 85 insertions, 180 deletions
diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactoryTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactoryTest.java deleted file mode 100644 index 7f5096e5..00000000 --- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiHttpClientFactoryTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * ============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)); - } -} diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AbstractHttpClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AbstractHttpClientTest.java index ee428713..7a8d39d1 100644 --- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AbstractHttpClientTest.java +++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/AbstractHttpClientTest.java @@ -22,8 +22,8 @@ package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http; 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; @@ -31,7 +31,7 @@ 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); diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClientTest.java index d6199acd..ce5d2c95 100644 --- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClientTest.java +++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiGetServiceInstanceClientTest.java @@ -20,20 +20,18 @@ 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; @@ -41,19 +39,24 @@ class AaiGetServiceInstanceClientTest extends AbstractHttpClientTest { @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))); } } diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java index 1dddc27e..758ef601 100644 --- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java +++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java @@ -20,19 +20,17 @@ 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; @@ -40,48 +38,44 @@ class AaiHttpGetClientTest extends AbstractHttpClientTest { @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))); } } diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClientTest.java index 302395ac..2def498c 100644 --- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClientTest.java +++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiHttpPatchClientTest.java @@ -22,6 +22,7 @@ package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.pat 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; @@ -32,6 +33,7 @@ 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.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; @@ -46,58 +48,52 @@ class AaiHttpPatchClientTest extends AbstractHttpClientTest { @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))); } } diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClientTest.java index 7ce47a00..d14eca18 100644 --- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClientTest.java +++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiHttpPutClientTest.java @@ -20,20 +20,17 @@ 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; @@ -41,29 +38,23 @@ class AaiHttpPutClientTest extends AbstractHttpClientTest { @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 @@ -71,25 +62,19 @@ class AaiHttpPutClientTest extends AbstractHttpClientTest { 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))); + } } |