aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid/aai
diff options
context:
space:
mode:
authorWojciech Sliwka <wojciech.sliwka@nokia.com>2019-02-01 07:23:42 +0100
committerWojciech Sliwka <wojciech.sliwka@nokia.com>2019-02-28 09:52:01 +0100
commit1196463dbf4c6ef051dd7f68580fc7d77c5d054c (patch)
treecc7886d3f7a07cb499955bf9fb803d2eccac3dc6 /vid-app-common/src/test/java/org/onap/vid/aai
parent58cbfa63f239b22e8feb1440919b5fc2cf0118ce (diff)
First part of Tests
Issue-ID: VID-385 add first part of new tests for AAI, move some files to proper directory Change-Id: I6600c48d26387faf9e6cd6dbe7107e10428f4b52 Signed-off-by: Wojciech Sliwka <wojciech.sliwka@nokia.com>
Diffstat (limited to 'vid-app-common/src/test/java/org/onap/vid/aai')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AAITreeConverterTest.java251
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java17
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java12
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/AaiResponseTranslatorTest.java151
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/PombaClientImplTest.java4
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/PombaRestInterfaceTest.java127
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/util/HttpsAuthClientTest.java15
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java16
8 files changed, 565 insertions, 28 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/AAITreeConverterTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AAITreeConverterTest.java
new file mode 100644
index 000000000..8bcadd139
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/AAITreeConverterTest.java
@@ -0,0 +1,251 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nokia. 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.vid.aai;
+
+import com.google.common.collect.ImmutableList;
+import org.mockito.InjectMocks;
+import org.mockito.MockitoAnnotations;
+import org.onap.vid.aai.util.AAITreeConverter;
+import org.onap.vid.model.Action;
+import org.onap.vid.model.aaiTree.AAITreeNode;
+import org.onap.vid.model.aaiTree.Network;
+import org.onap.vid.model.aaiTree.ServiceInstance;
+import org.onap.vid.model.aaiTree.VfModule;
+import org.onap.vid.model.aaiTree.Vnf;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.DataProvider;
+import org.testng.annotations.Test;
+
+import java.util.List;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.emptyOrNullString;
+import static org.hamcrest.Matchers.hasKey;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.onap.vid.asdc.parser.ToscaParserImpl2.Constants.A_LA_CARTE;
+
+public class AAITreeConverterTest {
+
+ @InjectMocks
+ private AAITreeConverter aaiTreeConverter;
+
+ @BeforeTest
+ public void initMocks() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testConvertTreeToUIModel_NoChildren() throws Exception {
+
+ AAITreeNode aaiTree = generateAaiTreeToConvert(0, 0);
+
+ ServiceInstance result = aaiTreeConverter.convertTreeToUIModel(aaiTree, "global-customer-id", "service-type", A_LA_CARTE);
+
+ assertService(result, 0, 0, true);
+ }
+
+ @Test
+ public void testConvertTreeToUIModel_MultipleChildren() throws Exception {
+
+ AAITreeNode aaiTree = generateAaiTreeToConvert(2, 2);
+
+ ServiceInstance serviceInstance = aaiTreeConverter.convertTreeToUIModel(aaiTree, "global-customer-id", "service-type", null);
+
+ assertService(serviceInstance, 2, 2, false);
+
+ int nodesCounter = 0;
+ assertThat(serviceInstance.getVnfs().entrySet(), hasSize(2));
+ assertVnf(serviceInstance.getVnfs().get("vnf-model-version-id:00"+(nodesCounter++)), 0, 0, false);
+ assertVnf(serviceInstance.getVnfs().get("vnf-model-version-id:00"+(nodesCounter++)), 0, 0, false);
+
+ assertThat(serviceInstance.getNetworks().entrySet(), hasSize(2));
+ assertNetwork(serviceInstance.getNetworks().get("network-model-version-id:00"+(nodesCounter++)), false);
+ assertNetwork(serviceInstance.getNetworks().get("network-model-version-id:00"+(nodesCounter)), false);
+ }
+
+ @DataProvider
+ public static Object[][] vnfWithChildren() {
+ return new Object[][]{
+ {ImmutableList.of(), ImmutableList.of()},
+ {ImmutableList.of(true, false), ImmutableList.of()},
+ {ImmutableList.of(), ImmutableList.of(false)}
+ };
+ }
+
+ @Test(dataProvider = "vnfWithChildren")
+ public void testComplexVnfConversion(List<Boolean> vfModules, List<Boolean> networks) {
+
+ AAITreeNode vnfTreeNode = createVnf(1, false);
+ int nodesCounter = 0;
+
+ for (Boolean customizationName: vfModules) {
+ vnfTreeNode.getChildren().add(createVfModule(nodesCounter++, customizationName));
+ }
+
+ for (Boolean customizationName: networks) {
+ vnfTreeNode.getChildren().add(createNetwork(nodesCounter++, customizationName));
+ }
+
+ Vnf actualVnf = Vnf.from(vnfTreeNode);
+
+ assertVnf(actualVnf, vfModules.size(), networks.size(), false);
+
+ nodesCounter = 0;
+ for (Boolean customizationName: vfModules) {
+ String key = customizationName ? "vfModule key in model" : "vfModule-model-version-id";
+
+ assertThat(actualVnf.getVfModules(), hasKey(key));
+ assertThat(actualVnf.getVfModules().get(key), hasKey(key + ":00" + nodesCounter));
+ VfModule actualVfModule = actualVnf.getVfModules().get(key).get(key + ":00" + nodesCounter);
+ assertVfModule(actualVfModule, customizationName);
+ nodesCounter++;
+ }
+
+ for (Boolean customizationName: networks) {
+ String key = customizationName ? "network key in model" : "network-model-version-id";
+
+ assertThat(actualVnf.getNetworks(), hasKey(key + ":00" + nodesCounter));
+ Network actualNetwork = actualVnf.getNetworks().get(key + ":00" + nodesCounter);
+ assertNetwork(actualNetwork, customizationName);
+ nodesCounter++;
+ }
+ }
+
+ @Test
+ public void testNetworkConversion() {
+ AAITreeNode networkTreeNode = createNetwork(1, true);
+
+ Network actualNetwork = Network.from(networkTreeNode);
+
+ assertNetwork(actualNetwork, true);
+ }
+
+ private AAITreeNode createVnf(int uniqueNumber, boolean hasCustomizationName) {
+ AAITreeNode vnfTreeNode = new AAITreeNode();
+ vnfTreeNode.setId("vnf-instance-id");
+ vnfTreeNode.setName("vnf-instance-name");
+ vnfTreeNode.setType("generic-vnf");
+ vnfTreeNode.setModelVersionId("vnf-model-version-id");
+ if (hasCustomizationName) {
+ vnfTreeNode.setModelCustomizationName("vnf model customization name");
+ vnfTreeNode.setKeyInModel("vnf key in model");
+ }
+ vnfTreeNode.setUniqueNumber(uniqueNumber);
+ return vnfTreeNode;
+ }
+
+ private AAITreeNode createVfModule(int uniqueNumber, boolean hasCustomizationName) {
+ AAITreeNode vfModuleTreeNode = new AAITreeNode();
+ vfModuleTreeNode.setId("vfModule-instance-id");
+ vfModuleTreeNode.setName("vfModule-instance-name");
+ vfModuleTreeNode.setType("vf-module");
+ vfModuleTreeNode.setModelVersionId("vfModule-model-version-id");
+ if (hasCustomizationName) {
+ vfModuleTreeNode.setModelCustomizationName("vfModule model customization name");
+ vfModuleTreeNode.setKeyInModel("vfModule key in model");
+ }
+ vfModuleTreeNode.setUniqueNumber(uniqueNumber);
+
+ return vfModuleTreeNode;
+ }
+
+ private AAITreeNode createNetwork(int uniqueNumber, boolean hasCustomizationName) {
+ AAITreeNode networkTreeNode = new AAITreeNode();
+ networkTreeNode.setId("network-instance-id");
+ networkTreeNode.setName("network-instance-name");
+ networkTreeNode.setType("l3-network");
+ networkTreeNode.setModelVersionId("network-model-version-id");
+ if (hasCustomizationName) {
+ networkTreeNode.setModelCustomizationName("network model customization name");
+ networkTreeNode.setKeyInModel("network key in model");
+ }
+ networkTreeNode.setUniqueNumber(uniqueNumber);
+
+ return networkTreeNode;
+ }
+
+ private void assertService(ServiceInstance serviceInstance, int expectedVnfs, int expectedNetworks, boolean isALaCarte) {
+ assertThat(serviceInstance.getInstanceId(), is("service-instance-id"));
+ assertThat(serviceInstance.getInstanceName(), is("service-instance-name"));
+ assertThat(serviceInstance.getAction(), is(Action.None));
+ assertThat(serviceInstance.getGlobalSubscriberId(), is("global-customer-id"));
+ assertThat(serviceInstance.getSubscriptionServiceType(), is("service-type"));
+ assertThat(serviceInstance.getModelInfo().getModelType(), is("service"));
+ assertThat(serviceInstance.getVnfs().entrySet(), hasSize(expectedVnfs));
+ assertThat(serviceInstance.getNetworks().entrySet(), hasSize(expectedNetworks));
+ assertThat(serviceInstance.getIsALaCarte(), is(isALaCarte));
+ }
+
+ private void assertVnf(Vnf actualVnf, int expectedVfModules, int expectedNetworks, boolean hasCustomizationName) {
+ assertThat(actualVnf.getInstanceId(), is("vnf-instance-id"));
+ assertThat(actualVnf.getInstanceName(), is("vnf-instance-name"));
+ assertThat(actualVnf.getAction(), is(Action.None));
+ assertThat(actualVnf.getModelInfo().getModelType(), is("vnf"));
+ assertThat(actualVnf.getModelInfo().getModelVersionId(), is("vnf-model-version-id"));
+ assertThat(actualVnf.getVfModules().entrySet(), hasSize(expectedVfModules));
+ assertThat(actualVnf.getNetworks().entrySet(), hasSize(expectedNetworks));
+ assertThat(actualVnf.getTrackById(), is(not(emptyOrNullString())));
+ String expectedCustomizationName = hasCustomizationName ? "vnf model customization name" : null;
+ assertThat(actualVnf.getModelInfo().getModelCustomizationName(), is(expectedCustomizationName));
+ }
+
+ private void assertVfModule(VfModule actualVfModule, boolean hasCustomizationName) {
+ assertThat(actualVfModule.getInstanceId(), is("vfModule-instance-id"));
+ assertThat(actualVfModule.getInstanceName(), is("vfModule-instance-name"));
+ assertThat(actualVfModule.getAction(), is(Action.None));
+ assertThat(actualVfModule.getModelInfo().getModelType(), is("vfModule"));
+ assertThat(actualVfModule.getModelInfo().getModelVersionId(), is("vfModule-model-version-id"));
+ assertThat(actualVfModule.getTrackById(), is(not(emptyOrNullString())));
+ String expectedCustomizationName = hasCustomizationName ? "vfModule model customization name" : null;
+ assertThat(actualVfModule.getModelInfo().getModelCustomizationName(), is(expectedCustomizationName));
+ }
+
+ private void assertNetwork(Network actualNetwork, boolean hasCustomizationName) {
+ assertThat(actualNetwork.getInstanceId(), is("network-instance-id"));
+ assertThat(actualNetwork.getInstanceName(), is("network-instance-name"));
+ assertThat(actualNetwork.getAction(), is(Action.None));
+ assertThat(actualNetwork.getModelInfo().getModelType(), is("network"));
+ assertThat(actualNetwork.getModelInfo().getModelVersionId(), is("network-model-version-id"));
+ assertThat(actualNetwork.getTrackById(), is(not(emptyOrNullString())));
+ String expectedCustomizationName = hasCustomizationName ? "network model customization name" : null;
+ assertThat(actualNetwork.getModelInfo().getModelCustomizationName(), is(expectedCustomizationName));
+ }
+
+ private AAITreeNode generateAaiTreeToConvert(int numberOfVnfs, int numberOfNetworks) {
+ int counter = 0;
+ AAITreeNode aaiTree = new AAITreeNode();
+ aaiTree.setId("service-instance-id");
+ aaiTree.setName("service-instance-name");
+
+ for (int i = 0; i < numberOfVnfs; i++) {
+ aaiTree.getChildren().add(createVnf(counter++, false));
+ }
+
+ for (int i = 0; i < numberOfNetworks; i++) {
+ aaiTree.getChildren().add(createNetwork(counter++, false));
+ }
+
+ return aaiTree;
+ }
+}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java
index fce9fa211..dd7b26c12 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientServerTest.java
@@ -28,20 +28,20 @@ import org.assertj.core.api.Assertions;
import org.glassfish.grizzly.http.util.HttpStatus;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
import org.onap.vid.aai.model.ResourceType;
import org.onap.vid.client.SyncRestClient;
import org.onap.vid.model.SubscriberList;
import org.onap.vid.testUtils.StubServerUtil;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import java.io.IOException;
-@RunWith(MockitoJUnitRunner.class)
+import static org.mockito.MockitoAnnotations.initMocks;
+
public class AaiOverTLSClientServerTest {
@Mock
@@ -100,6 +100,11 @@ public class AaiOverTLSClientServerTest {
serverUtil.stopServer();
}
+ @BeforeMethod
+ public void setUp(){
+ initMocks(this);
+ }
+
@Test
public void shouldSearchNodeTypeByName() throws IOException, ParseException {
ObjectMapper objectMapper = getFasterXmlObjectMapper();
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java
index 702a9e0a8..43fb5a3bb 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/AaiOverTLSClientTest.java
@@ -21,24 +21,23 @@
package org.onap.vid.aai;
import com.google.common.collect.ImmutableMap;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+
import org.onap.vid.aai.model.ResourceType;
import org.onap.vid.client.SyncRestClient;
import org.onap.vid.model.SubscriberList;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import java.util.Collections;
import java.util.Map;
import static org.mockito.ArgumentMatchers.contains;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.MockitoAnnotations.initMocks;
-@RunWith(MockitoJUnitRunner.class)
public class AaiOverTLSClientTest {
private static final String SEARCH_NODES_QUERY_SEARCH_NODE_TYPE = "nodes/generic-vnfs?vnf-name=name";
@@ -50,8 +49,9 @@ public class AaiOverTLSClientTest {
@Mock
private AaiOverTLSPropertySupplier propertySupplier;
- @Before
+ @BeforeMethod
public void setUp() {
+ initMocks(this);
aaiRestClient = new AaiOverTLSClient(syncRestClient, propertySupplier);
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/AaiResponseTranslatorTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AaiResponseTranslatorTest.java
new file mode 100644
index 000000000..12f7429eb
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/AaiResponseTranslatorTest.java
@@ -0,0 +1,151 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 Nokia. 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.vid.aai;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigData;
+import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigDataError;
+import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigDataOk;
+import org.testng.annotations.Test;
+
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class AaiResponseTranslatorTest {
+
+ private static final ObjectMapper objectMapper = new ObjectMapper();
+
+ @Test
+ public void extractPortMirroringConfigData_givenValidAaiResponse_yieldCloudRegionId() throws IOException {
+
+ final JsonNode aaiPayload = objectMapper.readTree("" +
+ "{" +
+ " \"results\": [{" +
+ " \"id\": \"2979590232\"," +
+ " \"node-type\": \"cloud-region\"," +
+ " \"url\": \"/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/att-aic/SDNO-S-BcloudReg-E1802\"," +
+ " \"properties\": {" +
+ " \"cloud-owner\": \"att-aic\"," +
+ " \"cloud-region-id\": \"THE-EXPECTED-REGION-ID\"," +
+ " \"sriov-automation\": false," +
+ " \"resource-version\": \"1513631040564\"" +
+ " }" +
+ " }," +
+ " {" +
+ " \"id\": \"2979598424\"," +
+ " \"node-type\": \"generic-vnf\"," +
+ " \"url\": \"/aai/v12/network/generic-vnfs/generic-vnf/SOURCE-gVnf-E1802\"," +
+ " \"properties\": {" +
+ " \"vnf-id\": \"SOURCE-gVnf-E1802\"," +
+ " \"vnf-name\": \"SOURCE-vnf-SDNO\"," +
+ " \"vnf-type\": \"S-1-SDNO\"," +
+ " \"service-id\": \"a9a77d5a-123e-4-SDNO\"," +
+ " \"orchestration-status\": \"active\"," +
+ " \"in-maint\": true," +
+ " \"is-closed-loop-disabled\": false," +
+ " \"resource-version\": \"1513631043149\"" +
+ " }" +
+ " }" +
+ " ]" +
+ "}");
+
+ PortMirroringConfigData portMirroringConfigData =
+ new AaiResponseTranslator().extractPortMirroringConfigData(aaiPayload);
+
+ assertThat(portMirroringConfigData, is(instanceOf(PortMirroringConfigDataOk.class)));
+ assertThat(((PortMirroringConfigDataOk) portMirroringConfigData).getCloudRegionId(), is("THE-EXPECTED-REGION-ID"));
+
+ }
+
+ @Test
+ public void extractPortMirroringConfigData_givenKindOfValidAaiResponse_yieldCloudRegionId() throws IOException {
+ // some completley different response, but with
+ // the results[cloud-region]->properties->cloud-region-id
+
+ final JsonNode aaiPayload = objectMapper.readTree("" +
+ "{ " +
+ " \"results\": [{ " +
+ " \"node-type\": \"generic-vnf\", " +
+ " \"url\": \"configuration entries) so that git\" " +
+ " }, " +
+ " {}, " +
+ " { " +
+ " \"node-type\": \"cloud-region\", " +
+ " \"but it will not switch\": \"tip commits are reachable\", " +
+ " \"named\": [{ " +
+ " \"resource-version\": \"1513631040564\" " +
+ " }], " +
+ " \"properties\": { " +
+ " \"cloud-region-id\": \"THE-EXPECTED-REGION-ID\", " +
+ " \"oldbranch> will be renamed\": false " +
+ " } " +
+ " }, " +
+ " { " +
+ " \"node-type\": [\"generic-vnf\", \"can be overridden by using\"] " +
+ " } " +
+ " ] " +
+ "}");
+
+ PortMirroringConfigData portMirroringConfigData =
+ new AaiResponseTranslator().extractPortMirroringConfigData(aaiPayload);
+
+ assertThat(portMirroringConfigData, is(instanceOf(PortMirroringConfigDataOk.class)));
+ assertThat(((PortMirroringConfigDataOk) portMirroringConfigData).getCloudRegionId(), is("THE-EXPECTED-REGION-ID"));
+
+ }
+
+ public void extractPortMirroringConfigData_givenAaiResponseWithoutRegionIdName_yieldException() throws IOException {
+
+ final JsonNode aaiPayload = objectMapper.readTree("" +
+ "{" +
+ " \"results\": [{" +
+ " \"node-type\": \"cloud-region\"," +
+ " \"url\": \"/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/att-aic/SDNO-S-BcloudReg-E1802\"," +
+ " \"properties\": {" +
+ " \"resource-version\": \"1513631040564\"" +
+ " }" +
+ " }" +
+ " ]" +
+ "}");
+
+ PortMirroringConfigData portMirroringConfigData =
+ new AaiResponseTranslator().extractPortMirroringConfigData(aaiPayload);
+
+ assertThat(portMirroringConfigData, is(instanceOf(PortMirroringConfigDataError.class)));
+ assertThat(((PortMirroringConfigDataError) portMirroringConfigData).getErrorDescription(),
+ containsString("The node-type 'cloud-region' does not contain the property 'cloud-region-id'"));
+ assertThat(((PortMirroringConfigDataError) portMirroringConfigData).getRawAaiResponse(),
+ containsString(aaiPayload.toString())
+ );
+
+ }
+
+ /*
+ More tests:
+ [x] cloud-region-id field is missing -- descriptive exception is thrown, including the problematic payload itself
+ [ ] cloud-region-id field is empty -- descriptive exception etc.
+ [ ] node-type=="cloud-region" entry is empty -- descriptive exception etc.
+ */
+}
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/PombaClientImplTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/PombaClientImplTest.java
index 483feec91..222bf1e5b 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/PombaClientImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/PombaClientImplTest.java
@@ -7,9 +7,9 @@
* 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.
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/PombaRestInterfaceTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/PombaRestInterfaceTest.java
new file mode 100644
index 000000000..b409c1f46
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/PombaRestInterfaceTest.java
@@ -0,0 +1,127 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2019 Nokia
+ * ================================================================================
+ * 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.vid.aai;
+
+
+import org.mockito.Mock;
+import org.onap.vid.aai.util.HttpClientMode;
+import org.onap.vid.aai.util.HttpsAuthClient;
+import org.onap.vid.aai.util.ServletRequestHelper;
+import org.onap.vid.aai.util.SystemPropertyHelper;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import java.io.IOException;
+import java.security.GeneralSecurityException;
+import java.util.UUID;
+import java.util.regex.Pattern;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.matches;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.FROM_APP_ID_HEADER;
+import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.TRANSACTION_ID_HEADER;
+import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY;
+
+public class PombaRestInterfaceTest {
+ private static final String UUID_REGEX = "[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}";
+ private static final String SAMPLE_APP_ID = "vid";
+ private static final String SAMPLE_URL = "sampleUrl";
+ private static final String SAMPLE_PAYLOAD = "samplePayload";
+ private static final Pattern UUID_PATTERN = Pattern.compile(UUID_REGEX);
+
+ @Mock
+ private HttpsAuthClient authClient;
+
+ @Mock
+ private ServletRequestHelper requestHelper;
+
+ @Mock
+ private SystemPropertyHelper systemPropertyHelper;
+
+ @Mock
+ private Client client;
+
+ @Mock
+ private WebTarget webTarget;
+
+ @Mock
+ private Invocation.Builder builder;
+
+ @Mock
+ private Response response;
+
+ private PombaRestInterface pombaRestInterface;
+
+ @BeforeMethod
+ public void setUp() throws GeneralSecurityException, IOException {
+ initMocks(this);
+
+ when(requestHelper.extractOrGenerateRequestId()).thenReturn(UUID.randomUUID().toString());
+ when(authClient.getClient(HttpClientMode.WITH_KEYSTORE)).thenReturn(client);
+ setUpBuilder();
+ pombaRestInterface = new PombaRestInterface(authClient, requestHelper, systemPropertyHelper);
+ }
+
+
+ @Test
+ public void shouldProperlySendRequestWithAllRequiredHeaders() {
+ Response actualResponse = pombaRestInterface.RestPost(SAMPLE_APP_ID, SAMPLE_URL, SAMPLE_PAYLOAD);
+
+ assertThat(actualResponse).isEqualTo(response);
+
+ verify(builder).accept(MediaType.APPLICATION_JSON);
+ verify(builder).header(FROM_APP_ID_HEADER, SAMPLE_APP_ID);
+ verify(builder).header(matches(TRANSACTION_ID_HEADER), matches(UUID_PATTERN));
+ verify(builder).header(matches(REQUEST_ID_HEADER_KEY), matches(UUID_PATTERN));
+ verify(builder).post(any(Entity.class));
+ }
+
+ @Test
+ public void shouldReturnNullWhenExceptionWasRaised() {
+ doThrow(new RuntimeException()).when(client).target(anyString());
+
+ Response actualResponse = pombaRestInterface.RestPost(SAMPLE_APP_ID, SAMPLE_URL, SAMPLE_PAYLOAD);
+
+ assertThat(actualResponse).isNull();
+ }
+
+ private void setUpBuilder() {
+ when(client.target(anyString())).thenReturn(webTarget);
+ when(webTarget.request()).thenReturn(builder);
+ when(builder.accept(MediaType.APPLICATION_JSON)).thenReturn(builder);
+ when(builder.header(anyString(), any())).thenReturn(builder);
+ when(builder.post(any(Entity.class))).thenReturn(response);
+ when(response.getStatusInfo()).thenReturn(Response.Status.OK);
+ }
+} \ No newline at end of file
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/util/HttpsAuthClientTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/util/HttpsAuthClientTest.java
index aff6c7f76..3336a8af9 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/util/HttpsAuthClientTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/util/HttpsAuthClientTest.java
@@ -21,13 +21,13 @@
package org.onap.vid.aai.util;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+
import org.onap.vid.aai.exceptions.HttpClientBuilderException;
import org.onap.vid.exceptions.GenericUncheckedException;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import org.togglz.core.manager.FeatureManager;
import javax.net.ssl.SSLContext;
@@ -35,8 +35,8 @@ import java.util.Optional;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;
+import static org.mockito.MockitoAnnotations.initMocks;
-@RunWith(MockitoJUnitRunner.class)
public class HttpsAuthClientTest {
@Mock
private SystemPropertyHelper systemPropertyHelper;
@@ -51,14 +51,15 @@ public class HttpsAuthClientTest {
return new HttpsAuthClient(CERT_FILE_PATH, systemPropertyHelper, sslContextProvider, mock(FeatureManager.class));
}
- @Before
+ @BeforeMethod
public void setUp() throws Exception {
+ initMocks(this);
when(systemPropertyHelper.getAAITruststoreFilename()).thenReturn(Optional.of("filename"));
when(systemPropertyHelper.getDecryptedKeystorePassword()).thenReturn("password");
when(systemPropertyHelper.getDecryptedTruststorePassword()).thenReturn("password");
}
- @Test(expected = HttpClientBuilderException.class)
+ @Test(expectedExceptions = {HttpClientBuilderException.class})
public void testHttpClientBuilderExceptionOnGetClient() throws Exception {
//when
when(systemPropertyHelper.isClientCertEnabled()).thenReturn(true);
diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java
index 69e8ddcec..3393aa7c1 100644
--- a/vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/aai/util/SingleAAIRestInterfaceTest.java
@@ -20,18 +20,18 @@
package org.onap.vid.aai.util;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+
import org.onap.vid.aai.ExceptionWithRequestInfo;
import org.onap.vid.aai.exceptions.InvalidPropertyException;
import org.onap.vid.exceptions.GenericUncheckedException;
import org.onap.vid.utils.Unchecked;
import org.springframework.http.HttpMethod;
import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.client.Client;
@@ -51,8 +51,9 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+
-@RunWith(MockitoJUnitRunner.class)
public class SingleAAIRestInterfaceTest {
private static final String PATH = "path";
@@ -78,8 +79,9 @@ public class SingleAAIRestInterfaceTest {
private AAIRestInterface testSubject;
- @Before
+ @BeforeMethod
public void setUp() throws Exception {
+ initMocks(this);
mockSystemProperties();
testSubject = createTestSubject();
when(client.target(HTTP_LOCALHOST+PATH)).thenReturn(webTarget);
@@ -130,7 +132,7 @@ public class SingleAAIRestInterfaceTest {
Assert.assertEquals(response, finalResponse);
}
- @Test(expected = ExceptionWithRequestInfo.class)
+ @Test(expectedExceptions = {ExceptionWithRequestInfo.class})
public void testFailedRestJsonPut() {
// given
String methodName = "RestPut";