diff options
Diffstat (limited to 'prh-aai-client/src/test/java')
-rw-r--r-- | prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java | 92 | ||||
-rw-r--r-- | prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIHttpClientImplTest.java | 10 | ||||
-rw-r--r-- | prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java (renamed from prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClientImplTest.java) | 98 | ||||
-rw-r--r-- | prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/config/AAIHttpClientConfigurationTest.java | 8 | ||||
-rw-r--r-- | prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/utils/HttpRequestDetailsTest.java | 10 |
5 files changed, 131 insertions, 87 deletions
diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java new file mode 100644 index 00000000..b95cc8d6 --- /dev/null +++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * PNF-REGISTRATION-HANDLER + * ================================================================================ + * 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.service; + +import org.apache.http.client.ResponseHandler; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.config.AAIClientConfiguration; +import org.onap.dcaegen2.services.utils.HttpRequestDetails; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class AAIConsumerClientTest { + + private static AAIConsumerClient testedObject; + private static AAIClientConfiguration aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class); + private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class); + private static HttpRequestDetails httpRequestDetailsMock = mock(HttpRequestDetails.class); + private static final String JSON_MESSAGE = "{ \"pnf-id\": \"example-pnf-id-val-22343\", \"regional-resource-zone\":null, \"ipaddress-v4-oam\": \"11.22.33.44\" }"; + + @BeforeAll + public static void setup() throws NoSuchFieldException, IllegalAccessException { + + Map<String, String> aaiHeaders = new HashMap<>(); + aaiHeaders.put("X-FromAppId", "prh"); + aaiHeaders.put("X-TransactionId", "9999"); + aaiHeaders.put("Accept", "application/json"); + aaiHeaders.put("authentication", "Basic QUFJOkFBSQ=="); + aaiHeaders.put("Real-Time", "true"); + aaiHeaders.put("Content-Type", "application/json"); + + when(aaiHttpClientConfigurationMock.aaiHost()).thenReturn("54.45.33.2"); + when(aaiHttpClientConfigurationMock.aaiProtocol()).thenReturn("https"); + when(aaiHttpClientConfigurationMock.aaiHostPortNumber()).thenReturn(1234); + when(aaiHttpClientConfigurationMock.aaiUserName()).thenReturn("PRH"); + when(aaiHttpClientConfigurationMock.aaiUserPassword()).thenReturn("PRH"); + + when(httpRequestDetailsMock.aaiAPIPath()).thenReturn("/aai/v11/network/pnfs/pnf"); + when(httpRequestDetailsMock.headers()).thenReturn(aaiHeaders); + when(httpRequestDetailsMock.pnfName()).thenReturn("pnf-nokia-45fsfcx"); + when(httpRequestDetailsMock.jsonBody()).thenReturn(Optional.of(JSON_MESSAGE)); + + testedObject = new AAIConsumerClient(aaiHttpClientConfigurationMock); + setField(); + } + + + @Test + public void getExtendedDetails_returnsSuccess() throws IOException { + + when(closeableHttpClientMock.execute(any(HttpGet.class), any(ResponseHandler.class))). + thenReturn(Optional.of(JSON_MESSAGE)); + Optional<String> actualResult = testedObject.getHttpResponse(httpRequestDetailsMock); + Assertions.assertEquals(Optional.of(JSON_MESSAGE),actualResult); + } + + + private static void setField() throws NoSuchFieldException, IllegalAccessException { + Field field = testedObject.getClass().getDeclaredField("closeableHttpClient"); + field.setAccessible(true); + field.set(testedObject, closeableHttpClientMock); + } +} diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIHttpClientImplTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIHttpClientImplTest.java index fd13f1e7..cfe1a7f6 100644 --- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIHttpClientImplTest.java +++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIHttpClientImplTest.java @@ -21,7 +21,7 @@ package org.onap.dcaegen2.services.service; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration; +import org.onap.dcaegen2.services.config.AAIClientConfiguration; import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.mock; @@ -30,13 +30,13 @@ import static org.mockito.Mockito.when; public class AAIHttpClientImplTest { - private static AAIHttpClientImpl testedObject; - private static AAIHttpClientConfiguration aaiHttpClientConfigurationMock; + private static AAIClientImpl testedObject; + private static AAIClientConfiguration aaiHttpClientConfigurationMock; @BeforeAll public static void setup() { - aaiHttpClientConfigurationMock = mock(AAIHttpClientConfiguration.class); + aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class); when(aaiHttpClientConfigurationMock.aaiHost()).thenReturn("54.45.33.2"); when(aaiHttpClientConfigurationMock.aaiProtocol()).thenReturn("https"); when(aaiHttpClientConfigurationMock.aaiHostPortNumber()).thenReturn(1234); @@ -44,7 +44,7 @@ public class AAIHttpClientImplTest { when(aaiHttpClientConfigurationMock.aaiUserPassword()).thenReturn("PNF"); when(aaiHttpClientConfigurationMock.aaiIgnoreSSLCertificateErrors()).thenReturn(true); - testedObject = new AAIHttpClientImpl(aaiHttpClientConfigurationMock); + testedObject = new AAIClientImpl(aaiHttpClientConfigurationMock); } @Test diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClientImplTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java index 9ff34b8e..7f3978bd 100644 --- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIExtendedHttpClientImplTest.java +++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java @@ -1,4 +1,4 @@ -/*- +/* * ============LICENSE_START======================================================= * PNF-REGISTRATION-HANDLER * ================================================================================ @@ -20,113 +20,69 @@ package org.onap.dcaegen2.services.service; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import org.apache.http.client.ResponseHandler; +import org.apache.http.client.methods.HttpPatch; +import org.apache.http.impl.client.CloseableHttpClient; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.onap.dcaegen2.services.config.AAIClientConfiguration; +import org.onap.dcaegen2.services.utils.HttpRequestDetails; import java.io.IOException; import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; import java.util.Optional; -import org.apache.http.client.ResponseHandler; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPatch; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.impl.client.CloseableHttpClient; -import org.immutables.value.internal.$processor$.meta.$GsonMirrors; -import org.junit.Ignore; -import org.junit.jupiter.api.*; -import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration; -import org.onap.dcaegen2.services.utils.HttpRequestDetails; -import org.onap.dcaegen2.services.utils.RequestVerbs; -public class AAIExtendedHttpClientImplTest { +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class AAIProducerClientTest { - private static AAIExtendedHttpClientImpl testedObject; - private static AAIHttpClientConfiguration aaiHttpClientConfigurationMock = mock(AAIHttpClientConfiguration.class); + private static AAIProducerClient testedObject; + private static AAIClientConfiguration aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class); private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class); private static HttpRequestDetails httpRequestDetailsMock = mock(HttpRequestDetails.class); - private static Optional<String> expectedResult = Optional.empty(); - private static final String JSON_MESSAGE = "{ \"ipaddress-v4-oam\": \"11.22.33.44\" }"; - private static final String PNF_ID = "NOKQTFCOC540002E"; + private static final String JsonBody = "{\"ipaddress-v4-oam\":\"11.22.33.155\"}"; + private static final String SUCCESS = "200"; + private static final String PNF_NAME = "nokia-pnf-nhfsadhff"; @BeforeAll public static void init() throws NoSuchFieldException, IllegalAccessException { - Map<String, String> queryParams = new HashMap<>(); - queryParams.put("pnf-id", PNF_ID); - Map<String, String> 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"); + aaiHeaders.put("Content-Type", "application/merge-patch+json"); - when(aaiHttpClientConfigurationMock.aaiHost()).thenReturn("54.45.33.2"); + when(aaiHttpClientConfigurationMock.aaiHost()).thenReturn("eucalyptus.es-si-eu-dhn-20.eecloud.nsn-net.net"); when(aaiHttpClientConfigurationMock.aaiProtocol()).thenReturn("https"); when(aaiHttpClientConfigurationMock.aaiHostPortNumber()).thenReturn(1234); when(aaiHttpClientConfigurationMock.aaiUserName()).thenReturn("PRH"); when(aaiHttpClientConfigurationMock.aaiUserPassword()).thenReturn("PRH"); when(httpRequestDetailsMock.aaiAPIPath()).thenReturn("/aai/v11/network/pnfs/pnf"); + when(httpRequestDetailsMock.headers()).thenReturn(aaiHeaders); - when(httpRequestDetailsMock.queryParameters()).thenReturn(queryParams); - when(httpRequestDetailsMock.jsonBody()).thenReturn(Optional.of(JSON_MESSAGE)); + when(httpRequestDetailsMock.pnfName()).thenReturn(PNF_NAME); + when(httpRequestDetailsMock.jsonBody()).thenReturn(Optional.of(JsonBody)); - testedObject = new AAIExtendedHttpClientImpl(aaiHttpClientConfigurationMock); + testedObject = new AAIProducerClient(aaiHttpClientConfigurationMock); setField(); } - @AfterAll - public static void teardown() { - testedObject = null; - aaiHttpClientConfigurationMock = null; - closeableHttpClientMock = null; - httpRequestDetailsMock = null; - expectedResult = null; - } - @Test public void getHttpResponsePatch_success() throws IOException { - when(httpRequestDetailsMock.requestVerb()).thenReturn(RequestVerbs.PATCH); - - expectedResult = Optional.of(JSON_MESSAGE); when(closeableHttpClientMock.execute(any(HttpPatch.class), any(ResponseHandler.class))) - .thenReturn(expectedResult); + .thenReturn(Optional.of(SUCCESS)); Optional<String> actualResult = testedObject.getHttpResponse(httpRequestDetailsMock); - Assertions.assertEquals(expectedResult.get(), actualResult.get()); - } - - @Test - public void getHttpResponsePut_success() throws IOException { - when(httpRequestDetailsMock.requestVerb()).thenReturn(RequestVerbs.PUT); - - expectedResult = Optional.of("getExtendedDetailsOK"); - - when(closeableHttpClientMock.execute(any(HttpPut.class), any(ResponseHandler.class))). - thenReturn(expectedResult); - Optional<String> actualResult = testedObject.getHttpResponse(httpRequestDetailsMock); - - Assertions.assertEquals(expectedResult.get(), actualResult.get()); - } - - @Test - public void getExtendedDetails_returnsNull() throws IOException { - when(httpRequestDetailsMock.requestVerb()).thenReturn(RequestVerbs.GET); - when(closeableHttpClientMock.execute(any(HttpGet.class), any(ResponseHandler.class))). - thenReturn(Optional.empty()); - Optional<String> actualResult = testedObject.getHttpResponse(httpRequestDetailsMock); - Assertions.assertEquals(Optional.empty(),actualResult); - } - - @Test - public void getHttpResponsePut_failure() { - when(httpRequestDetailsMock.requestVerb()).thenReturn(RequestVerbs.PUT); - + Assertions.assertEquals(SUCCESS, actualResult.get()); } private static void setField() throws NoSuchFieldException, IllegalAccessException { diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/config/AAIHttpClientConfigurationTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/config/AAIHttpClientConfigurationTest.java index 76c2969a..29a00927 100644 --- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/config/AAIHttpClientConfigurationTest.java +++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/config/AAIHttpClientConfigurationTest.java @@ -23,12 +23,12 @@ package org.onap.dcaegen2.services.service.config; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.onap.dcaegen2.services.config.AAIHttpClientConfiguration; -import org.onap.dcaegen2.services.config.ImmutableAAIHttpClientConfiguration; +import org.onap.dcaegen2.services.config.AAIClientConfiguration; +import org.onap.dcaegen2.services.config.ImmutableAAIClientConfiguration; public class AAIHttpClientConfigurationTest { - private static AAIHttpClientConfiguration client; + private static AAIClientConfiguration client; private static final String AAI_HOST = "/aai/v11/network/pnfs/pnf/NOKQTFCOC540002E"; private static final Integer PORT = 1234; private static final String PROTOCOL = "https"; @@ -36,7 +36,7 @@ public class AAIHttpClientConfigurationTest { @BeforeAll public static void init() { - client = new ImmutableAAIHttpClientConfiguration.Builder() + client = new ImmutableAAIClientConfiguration.Builder() .aaiHost(AAI_HOST) .aaiHostPortNumber(PORT) .aaiProtocol(PROTOCOL) diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/utils/HttpRequestDetailsTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/utils/HttpRequestDetailsTest.java index 563e6921..0deb8adb 100644 --- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/utils/HttpRequestDetailsTest.java +++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/utils/HttpRequestDetailsTest.java @@ -36,19 +36,16 @@ public class HttpRequestDetailsTest { private static HttpRequestDetails testObject; private static final String AAI_PATH = "aaiPathTest"; - private static final RequestVerbs HTTP_VERB = RequestVerbs.PATCH; - private static final String QUERY_KEY1 = "queryKey1"; - private static final String QUERY_VALUE1 = "queryValue1"; private static final String HEADERS_KEY1 = "headersKey1"; private static final String HEADERS_VALUE1 = "headersValue1"; private static final String JSON_MESSAGE = "{\"dare_to\": \"dream_big\"}"; + private static final String PNF_NAME = "pnf-nokia-5454885485"; @BeforeAll public static void init() { testObject = ImmutableHttpRequestDetails.builder() .aaiAPIPath(AAI_PATH) - .requestVerb(HTTP_VERB) - .putQueryParameters(QUERY_KEY1,QUERY_VALUE1) + .pnfName(PNF_NAME) .putHeaders(HEADERS_KEY1,HEADERS_VALUE1) .jsonBody(JSON_MESSAGE) .build(); @@ -58,8 +55,7 @@ public class HttpRequestDetailsTest { public void testGetters_success() { Assertions.assertEquals(AAI_PATH, testObject.aaiAPIPath()); Assertions.assertEquals(HEADERS_VALUE1, testObject.headers().get(HEADERS_KEY1)); - Assertions.assertEquals(QUERY_VALUE1, testObject.queryParameters().get(QUERY_KEY1)); - Assertions.assertEquals(RequestVerbs.PATCH, testObject.requestVerb()); + Assertions.assertEquals(PNF_NAME, testObject.pnfName()); Assertions.assertEquals(Optional.of(JSON_MESSAGE), testObject.jsonBody()); } } |