aboutsummaryrefslogtreecommitdiffstats
path: root/rest-services/aai-client/src/test
diff options
context:
space:
mode:
authorpwielebs <piotr.wielebski@nokia.com>2019-02-26 16:00:40 +0100
committerpwielebs <piotr.wielebski@nokia.com>2019-02-26 16:00:40 +0100
commitddfb652b619c7e42d84b11930d0453663df63d0b (patch)
treeee34b2e79245d7b6892b1e52e27282538c828095 /rest-services/aai-client/src/test
parent95f179eb1e2144a47f5cf436d70a786c6dc6cb6c (diff)
Remove usage of Spring in SDK II
- AAI Http Clients Change-Id: Id83a72699e860d1d71f0bdcd2e977c6c0cfc113e Issue-ID: DCAEGEN2-1277 Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
Diffstat (limited to 'rest-services/aai-client/src/test')
-rw-r--r--rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiReactiveWebClientFactoryTest.java77
-rw-r--r--rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java83
-rw-r--r--rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClientTest.java140
-rw-r--r--rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiReactiveHttpPutClientTest.java140
4 files changed, 0 insertions, 440 deletions
diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiReactiveWebClientFactoryTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiReactiveWebClientFactoryTest.java
deleted file mode 100644
index 46a57b69..00000000
--- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiReactiveWebClientFactoryTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * DCAEGEN2-SERVICES-SDK
- * ================================================================================
- * Copyright (C) 2018 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.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import io.netty.handler.ssl.SslContext;
-import org.junit.jupiter.api.Assertions;
-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.ssl.SslFactory;
-
-import javax.net.ssl.SSLException;
-
-
-class AaiReactiveWebClientFactoryTest {
-
- private static final String TRUST_STORE_PATH = "trust_store_path";
- private static final String TRUST_STORE_PASS_PATH = "trust_store_pass_path";
- private static final String KEY_STORE_PATH = "key_store_path";
- private static final String KEY_STORE_PASS_PATH = "key_store_pass_path";
- private SslFactory sslFactory = mock(SslFactory.class);
- private AaiClientConfiguration aaiClientConfiguration = mock(AaiClientConfiguration.class);
- private AaiReactiveWebClientFactory aaiReactiveWebClientFactory;
- private SslContext dummySslContext = mock(SslContext.class);
-
- @Test
- void shouldCreateWebClientWithSecureSslContext() throws SSLException {
- givenEnabledAaiCertAuthConfiguration();
- aaiReactiveWebClientFactory = new AaiReactiveWebClientFactory(sslFactory, aaiClientConfiguration);
-
- Assertions.assertNotNull(aaiReactiveWebClientFactory.build());
- verify(sslFactory).createSecureContext(KEY_STORE_PATH, KEY_STORE_PASS_PATH,
- TRUST_STORE_PATH, TRUST_STORE_PASS_PATH);
- }
-
- @Test
- void shouldCreateWebClientWithInsecureSslContext() throws SSLException {
- when(aaiClientConfiguration.enableAaiCertAuth()).thenReturn(false);
- when(sslFactory.createInsecureContext()).thenReturn(dummySslContext);
- aaiReactiveWebClientFactory = new AaiReactiveWebClientFactory(sslFactory, aaiClientConfiguration);
-
- Assertions.assertNotNull(aaiReactiveWebClientFactory.build());
- verify(sslFactory).createInsecureContext();
- }
-
- private void givenEnabledAaiCertAuthConfiguration() throws SSLException {
- when(aaiClientConfiguration.enableAaiCertAuth()).thenReturn(true);
- when(aaiClientConfiguration.trustStorePath()).thenReturn(TRUST_STORE_PATH);
- when(aaiClientConfiguration.trustStorePasswordPath()).thenReturn(TRUST_STORE_PASS_PATH);
- when(aaiClientConfiguration.keyStorePath()).thenReturn(KEY_STORE_PATH);
- when(aaiClientConfiguration.keyStorePasswordPath()).thenReturn(KEY_STORE_PASS_PATH);
- when(sslFactory.createSecureContext(KEY_STORE_PATH, KEY_STORE_PASS_PATH, TRUST_STORE_PATH, TRUST_STORE_PASS_PATH))
- .thenReturn(dummySslContext);
- }
-}
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
deleted file mode 100644
index 41a532d9..00000000
--- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/get/AaiHttpGetClientTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * ============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.get;
-
-
-import org.junit.jupiter.api.BeforeEach;
-import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
-import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel;
-import reactor.netty.http.client.HttpClient;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class AaiHttpGetClientTest {
-
- private static final String SUCCESS_RESPONSE = "{\"correlationId\":\"NOKnhfsadhff\"," +
- "\"ipaddress-v4\":\"256.22.33.155\", " +
- "\"ipaddress-v6\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"}";
-
- private AaiHttpGetClient aaiReactiveHttpGetClient;
- private HttpClient httpClient;
-
- private AaiClientConfiguration aaiConfigurationMock;
- private AaiModel aaiModel;
- private Map<String,String> aaiHeaders;
-
-
- @BeforeEach
- void setUp() {
- setupHeaders();
- aaiModel = mock(AaiModel.class);
- aaiConfigurationMock = mock(AaiClientConfiguration.class);
-
- when(aaiConfigurationMock.aaiHost()).thenReturn("54.45.33.2");
- when(aaiConfigurationMock.aaiProtocol()).thenReturn("https");
- when(aaiConfigurationMock.aaiPort()).thenReturn(1234);
- when(aaiConfigurationMock.aaiUserName()).thenReturn("PRH");
- when(aaiConfigurationMock.aaiUserPassword()).thenReturn("PRH");
- when(aaiConfigurationMock.aaiBasePath()).thenReturn("/aai/v11");
- when(aaiConfigurationMock.aaiPnfPath()).thenReturn("/network/pnfs/pnf");
- when(aaiConfigurationMock.aaiHeaders()).thenReturn(aaiHeaders);
-
- when(aaiModel.getCorrelationId()).thenReturn("NOKnhfsadhff");
-
-
- }
-
-
- private void setupHeaders() {
- aaiHeaders = new HashMap<>();
- aaiHeaders.put("X-FromAppId", "PRH");
- aaiHeaders.put("X-TransactionId", "vv-temp");
- aaiHeaders.put("Accept", "application/json");
- aaiHeaders.put("Real-Time", "true");
- aaiHeaders.put("Content-Type", "application/json");
- }
-
- private void mockHttpClientObject() {
- //when(HttpClient.create().)
- }
-
-} \ No newline at end of file
diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClientTest.java
deleted file mode 100644
index 7e34256f..00000000
--- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClientTest.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * DCAEGEN2-SERVICES-SDK
- * ================================================================================
- * Copyright (C) 2018 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.patch;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-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.model.AaiModel;
-import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
-import org.springframework.web.reactive.function.client.ClientResponse;
-import org.springframework.web.reactive.function.client.WebClient;
-import reactor.core.publisher.Mono;
-import reactor.test.StepVerifier;
-
-import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication;
-
-
-class AaiReactiveHttpPatchClientTest {
- private static final Integer SUCCESS_RESPONSE = 200;
- private static AaiClientConfiguration aaiConfigurationMock = mock(AaiClientConfiguration.class);
-
-
- private AaiReactiveHttpPatchClient httpClient;
- private WebClient webClient;
- private WebClient.RequestBodyUriSpec requestBodyUriSpec;
- private WebClient.ResponseSpec responseSpec;
-
- private Map<String, String> aaiHeaders;
- private ClientResponse clientResponse;
- private Mono<ClientResponse> clientResponseMono;
-
- private AaiModel aaiModel = mock(AaiModel.class);
- private JsonBodyBuilder<AaiModel> jsonBodyBuilder = mock(JsonBodyBuilder.class);
-
- @BeforeEach
- void setUp() {
- setupHeaders();
- clientResponse = mock(ClientResponse.class);
- clientResponseMono = Mono.just(clientResponse);
-
- when(aaiConfigurationMock.aaiHost()).thenReturn("54.45.33.2");
- when(aaiConfigurationMock.aaiProtocol()).thenReturn("https");
- when(aaiConfigurationMock.aaiPort()).thenReturn(1234);
- when(aaiConfigurationMock.aaiUserName()).thenReturn("PRH");
- when(aaiConfigurationMock.aaiUserPassword()).thenReturn("PRH");
- when(aaiConfigurationMock.aaiBasePath()).thenReturn("/aai/v11");
- when(aaiConfigurationMock.aaiPnfPath()).thenReturn("/network/pnfs/pnf");
- when(aaiConfigurationMock.aaiHeaders()).thenReturn(aaiHeaders);
-
- when(aaiModel.getCorrelationId()).thenReturn("NOKnhfsadhff");
-
- when(jsonBodyBuilder.createJsonBody(aaiModel)).thenReturn(
- "{\"correlationId\":\"NOKnhfsadhff\"," +
- "\"ipaddress-v4\":\"256.22.33.155\", " +
- "\"ipaddress-v6\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"}");
-
- httpClient = new AaiReactiveHttpPatchClient(aaiConfigurationMock, jsonBodyBuilder);
-
- webClient = spy(WebClient.builder()
- .defaultHeaders(httpHeaders -> httpHeaders.setAll(aaiHeaders))
- .filter(basicAuthentication(aaiConfigurationMock.aaiUserName(), aaiConfigurationMock.aaiUserPassword()))
- .build());
-
- requestBodyUriSpec = mock(WebClient.RequestBodyUriSpec.class);
- responseSpec = mock(WebClient.ResponseSpec.class);
- }
-
- @Test
- void getAaiProducerResponse_shouldReturn200() {
- //given
- Mono<Integer> expectedResult = Mono.just(SUCCESS_RESPONSE);
-
- //when
- mockWebClientDependantObject();
- doReturn(expectedResult).when(responseSpec).bodyToMono(Integer.class);
- httpClient.createAaiWebClient(webClient);
-
- //then
- StepVerifier.create(httpClient.getAaiProducerResponse(aaiModel)).expectSubscription()
- .expectNextMatches(results -> {
- Assertions.assertEquals(results, clientResponse);
- return true;
- }).verifyComplete();
- }
-
-
- @Test
- void getAppropriateUri_whenPassingCorrectedPathForPnf() {
- Assertions.assertEquals(httpClient.getUri("NOKnhfsadhff"),
- URI.create("https://54.45.33.2:1234/aai/v11/network/pnfs/pnf/NOKnhfsadhff"));
- }
-
-
- private void setupHeaders() {
- aaiHeaders = new HashMap<>();
- aaiHeaders.put("X-FromAppId", "PRH");
- aaiHeaders.put("X-TransactionId", "vv-temp");
- aaiHeaders.put("Accept", "application/json");
- aaiHeaders.put("Real-Time", "true");
- aaiHeaders.put("Content-Type", "application/merge-patch+json");
- }
-
- private void mockWebClientDependantObject() {
- WebClient.RequestHeadersSpec requestHeadersSpec = mock(WebClient.RequestHeadersSpec.class);
- when(webClient.patch()).thenReturn(requestBodyUriSpec);
- when(requestBodyUriSpec.uri((URI) any())).thenReturn(requestBodyUriSpec);
- when(requestBodyUriSpec.header(any(), any())).thenReturn(requestBodyUriSpec);
- when(requestBodyUriSpec.body(any(), (Class<Object>) any())).thenReturn(requestHeadersSpec);
- when(requestHeadersSpec.exchange()).thenReturn(clientResponseMono);
- }
-} \ No newline at end of file
diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiReactiveHttpPutClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiReactiveHttpPutClientTest.java
deleted file mode 100644
index 3b694496..00000000
--- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/put/AaiReactiveHttpPutClientTest.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * DCAEGEN2-SERVICES-SDK
- * ================================================================================
- * Copyright (C) 2018 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 org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeEach;
-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.model.AaiModel;
-import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
-import org.springframework.web.reactive.function.client.ClientResponse;
-import org.springframework.web.reactive.function.client.WebClient;
-import reactor.core.publisher.Mono;
-import reactor.test.StepVerifier;
-
-import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication;
-
-
-class AaiReactiveHttpPutClientTest {
- private static final Integer SUCCESS_RESPONSE = 200;
- private static AaiClientConfiguration aaiConfigurationMock = mock(AaiClientConfiguration.class);
-
-
- private AaiReactiveHttpPutClient httpClient;
- private WebClient webClient;
- private WebClient.RequestBodyUriSpec requestBodyUriSpec;
- private WebClient.ResponseSpec responseSpec;
-
- private Map<String, String> aaiHeaders;
- private ClientResponse clientResponse;
- private Mono<ClientResponse> clientResponseMono;
-
- private AaiModel aaiModel = mock(AaiModel.class);
- private JsonBodyBuilder<AaiModel> jsonBodyBuilder = mock(JsonBodyBuilder.class);
-
- @BeforeEach
- void setUp() {
- setupHeaders();
- clientResponse = mock(ClientResponse.class);
- clientResponseMono = Mono.just(clientResponse);
-
- when(aaiConfigurationMock.aaiHost()).thenReturn("54.45.33.2");
- when(aaiConfigurationMock.aaiProtocol()).thenReturn("https");
- when(aaiConfigurationMock.aaiPort()).thenReturn(1234);
- when(aaiConfigurationMock.aaiUserName()).thenReturn("PRH");
- when(aaiConfigurationMock.aaiUserPassword()).thenReturn("PRH");
- when(aaiConfigurationMock.aaiBasePath()).thenReturn("/aai/v11");
- when(aaiConfigurationMock.aaiPnfPath()).thenReturn("/network/pnfs/pnf");
- when(aaiConfigurationMock.aaiHeaders()).thenReturn(aaiHeaders);
-
- when(aaiModel.getCorrelationId()).thenReturn("NOKnhfsadhff");
-
- when(jsonBodyBuilder.createJsonBody(aaiModel)).thenReturn(
- "{\"correlationId\":\"NOKnhfsadhff\"," +
- "\"ipaddress-v4\":\"256.22.33.155\", " +
- "\"ipaddress-v6\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"}");
-
- httpClient = new AaiReactiveHttpPutClient(aaiConfigurationMock, jsonBodyBuilder);
-
- webClient = spy(WebClient.builder()
- .defaultHeaders(httpHeaders -> httpHeaders.setAll(aaiHeaders))
- .filter(basicAuthentication(aaiConfigurationMock.aaiUserName(), aaiConfigurationMock.aaiUserPassword()))
- .build());
-
- requestBodyUriSpec = mock(WebClient.RequestBodyUriSpec.class);
- responseSpec = mock(WebClient.ResponseSpec.class);
- }
-
- @Test
- void getAaiProducerResponse_shouldReturn200() {
- //given
- Mono<Integer> expectedResult = Mono.just(SUCCESS_RESPONSE);
-
- //when
- mockWebClientDependantObject();
- doReturn(expectedResult).when(responseSpec).bodyToMono(Integer.class);
- httpClient.createAaiWebClient(webClient);
-
- //then
- StepVerifier.create(httpClient.getAaiProducerResponse(aaiModel)).expectSubscription()
- .expectNextMatches(results -> {
- Assertions.assertEquals(results, clientResponse);
- return true;
- }).verifyComplete();
- }
-
-
- @Test
- void getAppropriateUri_whenPassingCorrectedPathForPnf() {
- Assertions.assertEquals(httpClient.getUri("NOKnhfsadhff"),
- URI.create("https://54.45.33.2:1234/aai/v11/network/pnfs/pnf/NOKnhfsadhff"));
- }
-
-
- private void setupHeaders() {
- aaiHeaders = new HashMap<>();
- aaiHeaders.put("X-FromAppId", "PRH");
- aaiHeaders.put("X-TransactionId", "vv-temp");
- aaiHeaders.put("Accept", "application/json");
- aaiHeaders.put("Real-Time", "true");
- aaiHeaders.put("Content-Type", "application/json");
- }
-
- private void mockWebClientDependantObject() {
- WebClient.RequestHeadersSpec requestHeadersSpec = mock(WebClient.RequestHeadersSpec.class);
- when(webClient.put()).thenReturn(requestBodyUriSpec);
- when(requestBodyUriSpec.uri((URI) any())).thenReturn(requestBodyUriSpec);
- when(requestBodyUriSpec.header(any(), any())).thenReturn(requestBodyUriSpec);
- when(requestBodyUriSpec.body(any(), (Class<Object>) any())).thenReturn(requestHeadersSpec);
- when(requestHeadersSpec.exchange()).thenReturn(clientResponseMono);
- }
-} \ No newline at end of file