aboutsummaryrefslogtreecommitdiffstats
path: root/prh-aai-client/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'prh-aai-client/src/test/java/org')
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIConsumerClientTest.java17
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java29
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/config/AAIHttpClientConfigurationTest.java4
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/utils/HttpRequestDetailsTest.java61
4 files changed, 28 insertions, 83 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
index b95cc8d6..5e45d844 100644
--- 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
@@ -27,7 +27,7 @@ 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 org.onap.dcaegen2.services.model.ConsumerDmaapModel;
import java.io.IOException;
import java.lang.reflect.Field;
@@ -44,8 +44,9 @@ 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\" }";
+ private static ConsumerDmaapModel consumerDmaapModelMock = mock(ConsumerDmaapModel.class);
+ private static final String PNF_NAME = "nokia-pnf-nhfsadhff";
@BeforeAll
public static void setup() throws NoSuchFieldException, IllegalAccessException {
@@ -54,7 +55,7 @@ public class AAIConsumerClientTest {
aaiHeaders.put("X-FromAppId", "prh");
aaiHeaders.put("X-TransactionId", "9999");
aaiHeaders.put("Accept", "application/json");
- aaiHeaders.put("authentication", "Basic QUFJOkFBSQ==");
+ aaiHeaders.put("Authorization", "Basic QUFJOkFBSQ==");
aaiHeaders.put("Real-Time", "true");
aaiHeaders.put("Content-Type", "application/json");
@@ -63,11 +64,11 @@ public class AAIConsumerClientTest {
when(aaiHttpClientConfigurationMock.aaiHostPortNumber()).thenReturn(1234);
when(aaiHttpClientConfigurationMock.aaiUserName()).thenReturn("PRH");
when(aaiHttpClientConfigurationMock.aaiUserPassword()).thenReturn("PRH");
+ when(aaiHttpClientConfigurationMock.aaiBasePath()).thenReturn("/aai/v11");
+ when(aaiHttpClientConfigurationMock.aaiPnfPath()).thenReturn("/network/pnfs/pnf");
+ when(aaiHttpClientConfigurationMock.aaiHeaders()).thenReturn(aaiHeaders);
- 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));
+ when(consumerDmaapModelMock.getPnfName()).thenReturn(PNF_NAME);
testedObject = new AAIConsumerClient(aaiHttpClientConfigurationMock);
setField();
@@ -79,7 +80,7 @@ public class AAIConsumerClientTest {
when(closeableHttpClientMock.execute(any(HttpGet.class), any(ResponseHandler.class))).
thenReturn(Optional.of(JSON_MESSAGE));
- Optional<String> actualResult = testedObject.getHttpResponse(httpRequestDetailsMock);
+ Optional<String> actualResult = testedObject.getHttpResponse(consumerDmaapModelMock);
Assertions.assertEquals(Optional.of(JSON_MESSAGE),actualResult);
}
diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java
index 7f3978bd..59c90dc8 100644
--- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java
+++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/AAIProducerClientTest.java
@@ -27,7 +27,9 @@ 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 org.onap.dcaegen2.services.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModelForUnitTest;
+
import java.io.IOException;
import java.lang.reflect.Field;
@@ -41,17 +43,17 @@ import static org.mockito.Mockito.when;
public class AAIProducerClientTest {
+ private static final Integer SUCCESS = 200;
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 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";
+ private static ConsumerDmaapModel consumerDmaapModel = new ConsumerDmaapModelForUnitTest();
+
@BeforeAll
public static void init() throws NoSuchFieldException, IllegalAccessException {
+ //given
Map<String, String> aaiHeaders = new HashMap<>();
aaiHeaders.put("X-FromAppId", "prh");
aaiHeaders.put("X-TransactionId", "vv-temp");
@@ -59,29 +61,28 @@ public class AAIProducerClientTest {
aaiHeaders.put("Real-Time", "true");
aaiHeaders.put("Content-Type", "application/merge-patch+json");
+ //when
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.pnfName()).thenReturn(PNF_NAME);
- when(httpRequestDetailsMock.jsonBody()).thenReturn(Optional.of(JsonBody));
+ when(aaiHttpClientConfigurationMock.aaiBasePath()).thenReturn("/aai/v11");
+ when(aaiHttpClientConfigurationMock.aaiPnfPath()).thenReturn("/network/pnfs/pnf");
+ when(aaiHttpClientConfigurationMock.aaiHeaders()).thenReturn(aaiHeaders);
testedObject = new AAIProducerClient(aaiHttpClientConfigurationMock);
setField();
}
@Test
- public void getHttpResponsePatch_success() throws IOException {
-
+ public void getHttpResponsePatch_shouldReturnSuccessStatusCode() throws IOException {
+ //when
when(closeableHttpClientMock.execute(any(HttpPatch.class), any(ResponseHandler.class)))
.thenReturn(Optional.of(SUCCESS));
- Optional<String> actualResult = testedObject.getHttpResponse(httpRequestDetailsMock);
+ Optional<Integer> actualResult = testedObject.getHttpResponse(consumerDmaapModel);
+ //then
Assertions.assertEquals(SUCCESS, actualResult.get());
}
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 29a00927..447e0ecc 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
@@ -33,6 +33,8 @@ public class AAIHttpClientConfigurationTest {
private static final Integer PORT = 1234;
private static final String PROTOCOL = "https";
private static final String USER_NAME_PASSWORD = "PRH";
+ private static final String BASE_PATH = "/aai/v11";
+ private static final String PNF_PATH = "/network/pnfs/pnf";
@BeforeAll
public static void init() {
@@ -43,6 +45,8 @@ public class AAIHttpClientConfigurationTest {
.aaiUserName(USER_NAME_PASSWORD)
.aaiUserPassword(USER_NAME_PASSWORD)
.aaiIgnoreSSLCertificateErrors(true)
+ .aaiBasePath(BASE_PATH)
+ .aaiPnfPath(PNF_PATH)
.build();
}
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
deleted file mode 100644
index 0deb8adb..00000000
--- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/service/utils/HttpRequestDetailsTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*-
- * ============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.utils;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-
-import org.onap.dcaegen2.services.utils.HttpRequestDetails;
-import org.onap.dcaegen2.services.utils.ImmutableHttpRequestDetails;
-import org.onap.dcaegen2.services.utils.RequestVerbs;
-
-import java.util.Optional;
-
-
-public class HttpRequestDetailsTest {
-
- private static HttpRequestDetails testObject;
-
- private static final String AAI_PATH = "aaiPathTest";
- 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)
- .pnfName(PNF_NAME)
- .putHeaders(HEADERS_KEY1,HEADERS_VALUE1)
- .jsonBody(JSON_MESSAGE)
- .build();
- }
-
- @Test
- public void testGetters_success() {
- Assertions.assertEquals(AAI_PATH, testObject.aaiAPIPath());
- Assertions.assertEquals(HEADERS_VALUE1, testObject.headers().get(HEADERS_KEY1));
- Assertions.assertEquals(PNF_NAME, testObject.pnfName());
- Assertions.assertEquals(Optional.of(JSON_MESSAGE), testObject.jsonBody());
- }
-}