summaryrefslogtreecommitdiffstats
path: root/adapters/mso-openstack-adapters/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-openstack-adapters/src/test/java')
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java150
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java332
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java241
3 files changed, 723 insertions, 0 deletions
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java
new file mode 100644
index 0000000000..52b67b8eb9
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java
@@ -0,0 +1,150 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017-2019 AT&T 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.so.adapters.audit;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doReturn;
+
+import java.io.IOException;
+import java.util.Optional;
+
+import org.camunda.bpm.client.task.ExternalTask;
+import org.camunda.bpm.client.task.ExternalTaskService;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.aai.domain.yang.LInterface;
+import org.onap.so.audit.beans.AuditInventory;
+import org.springframework.core.env.Environment;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+
+public class AuditStackServiceDataTest extends AuditStackServiceData {
+
+ @InjectMocks
+ AuditStackServiceData auditStackService = new AuditStackServiceData();
+
+ @Mock
+ HeatStackAudit heatStackAuditMock;
+
+ @Mock
+ Environment mockEnv;
+
+ @Mock
+ ExternalTask mockExternalTask;
+
+ @Mock
+ ExternalTaskService mockExternalTaskService;
+
+ AuditInventory auditInventory = new AuditInventory();
+
+ @Before
+ public void setup() {
+ auditInventory.setCloudOwner("cloudOwner");
+ auditInventory.setCloudRegion("cloudRegion");
+ auditInventory.setTenantId("tenantId");
+ auditInventory.setHeatStackName("stackName");
+ MockitoAnnotations.initMocks(this);
+ doReturn(auditInventory).when(mockExternalTask).getVariable("auditInventory");
+ doReturn("6000").when(mockEnv).getProperty("mso.workflow.topics.retryMultiplier","6000");
+ doReturn("aasdfasdf").when(mockExternalTask).getId();
+ }
+
+ @Test
+ public void execute_external_task_audit_success_Test() {
+ doReturn(true).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", "stackName");
+ auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService);
+ Mockito.verify(mockExternalTaskService).complete(mockExternalTask);
+ }
+
+ @Test
+ public void execute_external_task_audit_first_failure_Test() {
+ doReturn(false).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", "stackName");
+ doReturn(null).when(mockExternalTask).getRetries();
+ auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService);
+ Mockito.verify(mockExternalTaskService).handleFailure(mockExternalTask,
+ "Unable to find all VServers and L-Interaces in A&AI",
+ "Unable to find all VServers and L-Interaces in A&AI", 8, 10000L);
+ }
+
+ @Test
+ public void execute_external_task_audit_intermediate_failure_Test() {
+ doReturn(false).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", "stackName");
+ doReturn(6).when(mockExternalTask).getRetries();
+ auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService);
+ Mockito.verify(mockExternalTaskService).handleFailure(mockExternalTask,
+ "Unable to find all VServers and L-Interaces in A&AI",
+ "Unable to find all VServers and L-Interaces in A&AI", 5, 12000L);
+
+ }
+
+ @Test
+ public void execute_external_task_audit_final_failure_Test() {
+ doReturn(false).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", "stackName");
+ doReturn(1).when(mockExternalTask).getRetries();
+ auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService);
+ Mockito.verify(mockExternalTaskService).handleBpmnError(mockExternalTask,
+ "AuditAAIInventoryFailure", "Number of Retries Exceeded auditing inventory");
+ }
+
+ @Test
+ public void retry_sequence_calculation_Test() {
+ long firstRetry = auditStackService.calculateRetryDelay(8);
+ assertEquals(6000L, firstRetry);
+ long secondRetry = auditStackService.calculateRetryDelay(7);
+ assertEquals(6000L, secondRetry);
+ long thirdRetry = auditStackService.calculateRetryDelay(6);
+ assertEquals(12000L, thirdRetry);
+ long fourthRetry = auditStackService.calculateRetryDelay(5);
+ assertEquals(18000L, fourthRetry);
+ long fifthRetry = auditStackService.calculateRetryDelay(4);
+ assertEquals(30000L, fifthRetry);
+ long sixRetry = auditStackService.calculateRetryDelay(3);
+ assertEquals(48000L, sixRetry);
+ long seventhRetry = auditStackService.calculateRetryDelay(2);
+ assertEquals(78000L, seventhRetry);
+ long eigthRetry = auditStackService.calculateRetryDelay(1);
+ assertEquals(120000L, eigthRetry);
+ }
+
+ @Test
+ public void retry_sequence_Test() {
+ long firstRetry = auditStackService.calculateRetryDelay(8);
+ assertEquals(6000L, firstRetry);
+ long secondRetry = auditStackService.calculateRetryDelay(7);
+ assertEquals(6000L, secondRetry);
+ long thirdRetry = auditStackService.calculateRetryDelay(6);
+ assertEquals(12000L, thirdRetry);
+ long fourthRetry = auditStackService.calculateRetryDelay(5);
+ assertEquals(18000L, fourthRetry);
+ long fifthRetry = auditStackService.calculateRetryDelay(4);
+ assertEquals(30000L, fifthRetry);
+ long sixRetry = auditStackService.calculateRetryDelay(3);
+ assertEquals(48000L, sixRetry);
+ long seventhRetry = auditStackService.calculateRetryDelay(2);
+ assertEquals(78000L, seventhRetry);
+ long eigthRetry = auditStackService.calculateRetryDelay(1);
+ assertEquals(120000L, eigthRetry);
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java
new file mode 100644
index 0000000000..11e54404f4
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java
@@ -0,0 +1,332 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017-2019 AT&T 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.so.adapters.audit;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Stream;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.aai.domain.yang.LInterface;
+import org.onap.aai.domain.yang.LInterfaces;
+import org.onap.aai.domain.yang.Vserver;
+import org.onap.so.client.aai.AAIObjectPlurals;
+import org.onap.so.client.aai.AAIObjectType;
+import org.onap.so.client.aai.AAIResourcesClient;
+import org.onap.so.client.aai.entities.AAIResultWrapper;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.woorea.openstack.heat.model.Resource;
+import com.woorea.openstack.heat.model.Resources;
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class AuditVServerTest extends AuditVServer {
+
+ private ObjectMapper objectMapper = new ObjectMapper();
+
+ @InjectMocks
+ private AuditVServer auditNova = new AuditVServer();
+
+ @Mock
+ private AAIResourcesClient aaiResourcesMock;
+
+ private String cloudOwner = "cloudOwner";
+ private String cloudRegion = "cloudRegion";
+ private String tenantId = "tenantId";
+
+ private AAIResourceUri vserverURI = AAIUriFactory.createResourceUri(AAIObjectType.VSERVER,cloudOwner, cloudRegion,
+ tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db");
+
+ private AAIResourceUri vserverURI2 = AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner, cloudRegion,
+ tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4dz");
+
+ private AAIResourceUri ssc_1_trusted_port_0_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.L_INTERFACE,
+ cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db").queryParam("interface-id", "dec8bdc7-5718-41dc-bfbb-561ff6eeb81c");
+
+ private AAIResourceUri ssc_1_avpn_port_0_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.L_INTERFACE,
+ cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db").queryParam("interface-id", "1c56a24b-5f03-435a-850d-31cd4252de56");
+
+ private AAIResourceUri ssc_1_mgmt_port_1_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.L_INTERFACE,
+ cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db").queryParam("interface-id", "12afcd28-929f-4d80-8a5a-0833bfd5e20b");
+
+ private AAIResourceUri ssc_1_mgmt_port_0_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.L_INTERFACE,
+ cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db").queryParam("interface-id", "80baec42-ffae-425f-ad8c-3f7b2c24bfff");
+
+ private AAIResourceUri ssc_1_mis_port_0_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.L_INTERFACE,
+ cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db").queryParam("interface-id", "13eddf95-4cf3-45f2-823a-2d890a6549b4");
+
+ private AAIResourceUri ssc_1_int_ha_port_0_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.L_INTERFACE,
+ cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db").queryParam("interface-id", "9cab2903-70f7-44fd-b681-491d6ae2adb8");
+
+ private AAIResourceUri test_port_1_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.L_INTERFACE,
+ cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4dz").queryParam("interface-id", "9cab2903-70f7-44fd-b681-491d6ae2adz1");
+
+
+ private AAIResourceUri test_port_2_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.L_INTERFACE,
+ cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4dz").queryParam("interface-id", "9cab2903-70f7-44fd-b681-491d6ae2adz2");
+
+
+
+ private AAIResourceUri mis_sub_1_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.SUB_L_INTERFACE,
+ cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db","interface-name").queryParam("interface-id", "f711be16-2654-4a09-b89d-0511fda20e81");
+
+ private AAIResourceUri avpn_sub_0_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.SUB_L_INTERFACE,
+ cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db","interface-name").queryParam("interface-id", "0d9cd813-2ae1-46c0-9ebb-48081f6cffbb");
+
+ private AAIResourceUri avpn_sub_1_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.SUB_L_INTERFACE,
+ cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db","interface-name").queryParam("interface-id", "b7019dd0-2ee9-4447-bdef-ac25676b205a");
+
+
+
+ private Set<Vserver> vserversToAudit = new HashSet<>();
+
+
+ LInterface test_port_1 = new LInterface();
+ LInterface test_port_2 = new LInterface();
+ LInterface ssc_1_int_ha_port_0 = new LInterface();
+ LInterface mis_sub_interface_1 = new LInterface();
+ LInterface ssc_1_mis_port_0 = new LInterface();
+ LInterface ssc_1_mgmt_port_0 = new LInterface();
+ LInterface ssc_1_mgmt_port_1 = new LInterface();
+ LInterface avpn_sub_interface_2 = new LInterface();
+ LInterface avpn_sub_interface_1 = new LInterface();
+ LInterface ssc_1_avpn_port_0 = new LInterface();
+ LInterface ssc_1_trusted_port_0 = new LInterface();
+
+ LInterfaces test_port_1_plural = new LInterfaces();
+ LInterfaces test_port_2_plural = new LInterfaces();
+ LInterfaces ssc_1_int_ha_port_0_plural = new LInterfaces();
+ LInterfaces mis_sub_interface_1_plural = new LInterfaces();
+ LInterfaces ssc_1_mis_port_0_plural = new LInterfaces();
+ LInterfaces ssc_1_mgmt_port_0_plural = new LInterfaces();
+ LInterfaces ssc_1_mgmt_port_1_plural = new LInterfaces();
+ LInterfaces avpn_sub_interface_2_plural = new LInterfaces();
+ LInterfaces avpn_sub_interface_1_plural = new LInterfaces();
+ LInterfaces ssc_1_avpn_port_0_plural = new LInterfaces();
+ LInterfaces ssc_1_trusted_port_0_plural = new LInterfaces();
+
+
+ @Before
+ public void setup() {
+ auditNova.setAaiClient(aaiResourcesMock);
+
+ Vserver vServer1= new Vserver();
+ vServer1.setVserverId("3a4c2ca5-27b3-4ecc-98c5-06804867c4db");
+ LInterfaces vServer1Linterfaces = new LInterfaces();
+ vServer1.setLInterfaces(vServer1Linterfaces);
+
+ ssc_1_trusted_port_0.setInterfaceId("dec8bdc7-5718-41dc-bfbb-561ff6eeb81c");
+ ssc_1_trusted_port_0.setInterfaceName("interface-name");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_trusted_port_0);
+
+
+ ssc_1_avpn_port_0.setInterfaceId("1c56a24b-5f03-435a-850d-31cd4252de56");
+ ssc_1_avpn_port_0.setInterfaceName("interface-name");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_avpn_port_0);
+ ssc_1_avpn_port_0.setLInterfaces(new LInterfaces());
+
+
+ avpn_sub_interface_1.setInterfaceId("0d9cd813-2ae1-46c0-9ebb-48081f6cffbb");
+ ssc_1_avpn_port_0.getLInterfaces().getLInterface().add(avpn_sub_interface_1);
+
+
+ avpn_sub_interface_2.setInterfaceId("b7019dd0-2ee9-4447-bdef-ac25676b205a");
+ ssc_1_avpn_port_0.getLInterfaces().getLInterface().add(avpn_sub_interface_2);
+
+
+ ssc_1_mgmt_port_1.setInterfaceId("12afcd28-929f-4d80-8a5a-0833bfd5e20b");
+ ssc_1_mgmt_port_1.setInterfaceName("interface-name");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_mgmt_port_1);
+
+ ssc_1_mgmt_port_0.setInterfaceId("80baec42-ffae-425f-ad8c-3f7b2c24bfff");
+ ssc_1_mgmt_port_0.setInterfaceName("interface-name");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_mgmt_port_0);
+
+
+ ssc_1_mis_port_0.setLInterfaces(new LInterfaces());
+ ssc_1_mis_port_0.setInterfaceId("13eddf95-4cf3-45f2-823a-2d890a6549b4");
+ ssc_1_mis_port_0.setInterfaceName("interface-name");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_mis_port_0);
+
+
+ mis_sub_interface_1.setInterfaceId("f711be16-2654-4a09-b89d-0511fda20e81");
+ ssc_1_mis_port_0.getLInterfaces().getLInterface().add(mis_sub_interface_1);
+
+
+ ssc_1_int_ha_port_0.setInterfaceId("9cab2903-70f7-44fd-b681-491d6ae2adb8");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_int_ha_port_0);
+
+
+ Vserver vServer2= new Vserver();
+ vServer2.setVserverId("3a4c2ca5-27b3-4ecc-98c5-06804867c4dz");
+ LInterfaces vServer2Linterfaces = new LInterfaces();
+ vServer2.setLInterfaces(vServer2Linterfaces);
+
+ test_port_1.setInterfaceId("9cab2903-70f7-44fd-b681-491d6ae2adz1");
+ test_port_1.setInterfaceName("interface-name");
+
+
+ test_port_2.setInterfaceId("9cab2903-70f7-44fd-b681-491d6ae2adz2");
+ test_port_2.setInterfaceName("interface-name");
+
+ vServer2.getLInterfaces().getLInterface().add(test_port_1);
+ vServer2.getLInterfaces().getLInterface().add(test_port_2);
+
+ vserversToAudit.add(vServer1);
+ vserversToAudit.add(vServer2);
+
+
+ test_port_1_plural.getLInterface().add(test_port_1);
+ test_port_2_plural.getLInterface().add(test_port_2);
+ ssc_1_int_ha_port_0_plural.getLInterface().add(ssc_1_int_ha_port_0);
+ ssc_1_mis_port_0_plural.getLInterface().add(ssc_1_mis_port_0);
+ ssc_1_mgmt_port_0_plural.getLInterface().add(ssc_1_mgmt_port_0);
+ ssc_1_mgmt_port_1_plural.getLInterface().add(ssc_1_mgmt_port_1);
+ ssc_1_avpn_port_0_plural.getLInterface().add(ssc_1_avpn_port_0);
+ ssc_1_trusted_port_0_plural.getLInterface().add(ssc_1_trusted_port_0);
+
+ }
+
+ @Test
+ public void audit_Vserver_Empty_HashSet() throws JsonParseException, JsonMappingException, IOException {
+ boolean exists = auditNova.auditVservers(new HashSet<Vserver>(), tenantId, cloudOwner, cloudRegion);
+ assertEquals(false, exists);
+ }
+
+ @Test
+ public void audit_Vserver_Found_Test() throws JsonParseException, JsonMappingException, IOException {
+ doReturn(true).when(aaiResourcesMock).exists(vserverURI);
+ doReturn(true).when(aaiResourcesMock).exists(vserverURI2);
+ doReturn(Optional.of(ssc_1_trusted_port_0_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_trusted_port_0_uri);
+ doReturn(Optional.of(ssc_1_avpn_port_0_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_avpn_port_0_uri);
+ doReturn(Optional.of(ssc_1_mgmt_port_1_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_mgmt_port_1_uri);
+ doReturn(Optional.of(ssc_1_mgmt_port_0_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_mgmt_port_0_uri);
+ doReturn(Optional.of(ssc_1_mis_port_0_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_mis_port_0_uri);
+ doReturn(Optional.of(ssc_1_int_ha_port_0_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_int_ha_port_0_uri);
+ doReturn(Optional.of(test_port_1_plural)).when(aaiResourcesMock).get(LInterfaces.class,test_port_1_uri);
+ doReturn(Optional.of(test_port_2_plural)).when(aaiResourcesMock).get(LInterfaces.class,test_port_2_uri);
+
+ doReturn(true).when(aaiResourcesMock).exists(mis_sub_1_uri);
+ doReturn(true).when(aaiResourcesMock).exists(avpn_sub_0_uri);
+ doReturn(true).when(aaiResourcesMock).exists(avpn_sub_1_uri);
+
+ boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion);
+ assertEquals(true, exists);
+ }
+
+ @Test
+ public void audit_Vserver_Found_Test_Network_Not_Found()
+ throws JsonParseException, JsonMappingException, IOException {
+ doReturn(true).when(aaiResourcesMock).exists(vserverURI);
+ doReturn(true).when(aaiResourcesMock).exists(vserverURI2);
+ doReturn(Optional.of(ssc_1_trusted_port_0_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_trusted_port_0_uri);
+ doReturn(Optional.of(ssc_1_avpn_port_0_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_avpn_port_0_uri);
+ doReturn(Optional.of(ssc_1_mgmt_port_1_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_mgmt_port_1_uri);
+ doReturn(Optional.empty()).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_mgmt_port_0_uri);
+ doReturn(Optional.of(ssc_1_mis_port_0_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_mis_port_0_uri);
+ doReturn(Optional.of(ssc_1_int_ha_port_0_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_int_ha_port_0_uri);
+ doReturn(Optional.of(test_port_1_plural)).when(aaiResourcesMock).get(LInterfaces.class,test_port_1_uri);
+ doReturn(Optional.of(test_port_2_plural)).when(aaiResourcesMock).get(LInterfaces.class,test_port_2_uri);
+
+ doReturn(true).when(aaiResourcesMock).exists(mis_sub_1_uri);
+ doReturn(true).when(aaiResourcesMock).exists(avpn_sub_0_uri);
+ doReturn(true).when(aaiResourcesMock).exists(avpn_sub_1_uri);
+
+ boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion);
+ assertEquals(false, exists);
+ }
+
+ @Test
+ public void audit_Vserver_Found_Test_Network_Not_Found_Second_Server()
+ throws JsonParseException, JsonMappingException, IOException {
+ doReturn(true).when(aaiResourcesMock).exists(vserverURI);
+ doReturn(true).when(aaiResourcesMock).exists(vserverURI2);
+ doReturn(Optional.of(ssc_1_trusted_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_trusted_port_0_uri);
+ doReturn(Optional.of(ssc_1_avpn_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_avpn_port_0_uri);
+ doReturn(Optional.of(ssc_1_mgmt_port_1_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_mgmt_port_1_uri);
+ doReturn(Optional.of(ssc_1_mgmt_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_mgmt_port_0_uri);
+ doReturn(Optional.of(ssc_1_mis_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_mis_port_0_uri);
+ doReturn(Optional.of(ssc_1_int_ha_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_int_ha_port_0_uri);
+ doReturn(Optional.of(test_port_1_plural)).when(aaiResourcesMock).get(LInterface.class,test_port_1_uri);
+ doReturn(Optional.empty()).when(aaiResourcesMock).get(LInterface.class,test_port_2_uri);
+ doReturn(true).when(aaiResourcesMock).exists(mis_sub_1_uri);
+ doReturn(true).when(aaiResourcesMock).exists(avpn_sub_0_uri);
+ doReturn(true).when(aaiResourcesMock).exists(avpn_sub_1_uri);
+ boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion);
+ assertEquals(false, exists);
+ }
+
+ @Test
+ public void audit_Vserver_Not_Found_Test() throws JsonParseException, JsonMappingException, IOException {
+ doReturn(false).when(aaiResourcesMock).exists(vserverURI);
+ doReturn(false).when(aaiResourcesMock).exists(vserverURI2);
+ boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion);
+ assertEquals(false, exists);
+ }
+
+ @Test
+ public void audit_Vserver_first_Not_Found_Test() throws JsonParseException, JsonMappingException, IOException {
+ doReturn(false).when(aaiResourcesMock).exists(vserverURI);
+ doReturn(true).when(aaiResourcesMock).exists(vserverURI2);
+ doReturn(Optional.of(test_port_1_plural)).when(aaiResourcesMock).get(LInterface.class,test_port_1_uri);
+ doReturn(Optional.of(test_port_2_plural)).when(aaiResourcesMock).get(LInterface.class,test_port_2_uri);
+ boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion);
+ assertEquals(false, exists);
+ }
+
+ @Test
+ public void audit_Vserver_Second_Not_Found_Test() throws JsonParseException, JsonMappingException, IOException {
+ doReturn(true).when(aaiResourcesMock).exists(vserverURI);
+ doReturn(Optional.of(ssc_1_trusted_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_trusted_port_0_uri);
+ doReturn(Optional.of(ssc_1_avpn_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_avpn_port_0_uri);
+ doReturn(Optional.of(ssc_1_mgmt_port_1_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_mgmt_port_1_uri);
+ doReturn(Optional.of(ssc_1_mgmt_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_mgmt_port_0_uri);
+ doReturn(Optional.of(ssc_1_mis_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_mis_port_0_uri);
+ doReturn(Optional.of(ssc_1_int_ha_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_int_ha_port_0_uri);
+ doReturn(Optional.of(test_port_1_plural)).when(aaiResourcesMock).get(LInterface.class,test_port_1_uri);
+ doReturn(Optional.of(test_port_2_plural)).when(aaiResourcesMock).get(LInterface.class,test_port_2_uri);
+ doReturn(true).when(aaiResourcesMock).exists(mis_sub_1_uri);
+ doReturn(true).when(aaiResourcesMock).exists(avpn_sub_0_uri);
+ doReturn(true).when(aaiResourcesMock).exists(avpn_sub_1_uri);
+ doReturn(false).when(aaiResourcesMock).exists(vserverURI2);
+ boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion);
+ assertEquals(false, exists);
+ }
+
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java
new file mode 100644
index 0000000000..5df5d8200f
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java
@@ -0,0 +1,241 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017-2019 AT&T 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.so.adapters.audit;
+
+import static com.shazam.shazamcrest.MatcherAssert.assertThat;
+import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.doReturn;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.aai.domain.yang.LInterface;
+import org.onap.aai.domain.yang.LInterfaces;
+import org.onap.aai.domain.yang.Vserver;
+import org.onap.so.openstack.utils.MsoHeatUtils;
+import org.skyscreamer.jsonassert.JSONAssert;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.woorea.openstack.heat.model.Resource;
+import com.woorea.openstack.heat.model.Resources;
+import com.woorea.openstack.heat.model.Stack;
+
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class HeatStackAuditTest extends HeatStackAudit {
+
+ @InjectMocks
+ private HeatStackAudit heatStackAudit = new HeatStackAudit();
+
+ @Mock
+ private MsoHeatUtils msoHeatUtilsMock;
+
+ @Mock
+ private AuditVServer auditVserver;
+
+ private static final String cloudRegion = "cloudRegion";
+ private static final String tenantId = "tenantId";
+
+ private Resources resources = new Resources();
+
+ private ObjectMapper objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+
+ private ObjectMapper stackObjectMapper = new ObjectMapper().configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
+
+ @Before
+ public void setup() throws Exception{
+ resources= objectMapper.readValue(new File("src/test/resources/GetResources.json"), Resources.class);
+
+ }
+
+ @Test
+ public void extract_proper_path_Test(){
+ Optional<String> actualResult = extractStackPathFromHref("https://orchestration.com:8004/v1/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81");
+ assertEquals("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81", actualResult.get());
+ }
+
+ @Test
+ public void extract_proper_resources_path_Test(){
+ Optional<String> actualResult = extractResourcePathFromHref("https://orchestration.com:8004/v1/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81");
+ assertEquals("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81/resources", actualResult.get());
+ }
+
+ @Test
+ public void extract_invalid_uri_Test(){
+ Optional<String> actualResult = extractStackPathFromHref("orchestrn.com:8004/v18b44d60a6f94bdcb2738f9e/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81");
+ assertEquals(false, actualResult.isPresent());
+ }
+
+ @Test
+ public void createVserverSet_Test() throws Exception{
+ List<Resource> novaResources = resources.getList().stream()
+ .filter(p -> "OS::Nova::Server".equals(p.getType())).collect(Collectors.toList());
+
+ List<Resource> resourceGroups = resources.getList().stream()
+ .filter(p -> "OS::Heat::ResourceGroup".equals(p.getType())).collect(Collectors.toList());
+
+ Set<Vserver> expectedVservers = new HashSet<>();
+ Vserver vServer1= new Vserver();
+ vServer1.setVserverId("92272b67-d23f-42ca-87fa-7b06a9ec81f3");
+ LInterfaces vServer1Linterfaces = new LInterfaces();
+ vServer1.setLInterfaces(vServer1Linterfaces);
+
+ LInterface ssc_1_trusted_port_0 = new LInterface();
+ ssc_1_trusted_port_0.setInterfaceId("d2f51f82-0ec2-4581-bd1a-d2a82073e52b");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_trusted_port_0);
+
+
+
+ LInterface ssc_1_mgmt_port_1 = new LInterface();
+ ssc_1_mgmt_port_1.setInterfaceId("07f5b14c-147a-4d14-8c94-a9e94dbc097b");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_mgmt_port_1);
+
+ LInterface ssc_1_mgmt_port_0 = new LInterface();
+ ssc_1_mgmt_port_0.setInterfaceId("8d93f63e-e972-48c7-ad98-b2122da47315");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_mgmt_port_0);
+
+ LInterface ssc_1_mis_port_0 = new LInterface();
+ ssc_1_mis_port_0.setLInterfaces(new LInterfaces());
+ ssc_1_mis_port_0.setInterfaceId("0594a2f2-7ea4-42eb-abc2-48ea49677fca");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_mis_port_0);
+
+ LInterface mis_sub_interface_1 = new LInterface();
+ mis_sub_interface_1.setInterfaceId("2bbfa345-33bb-495a-94b2-fb514ee1cffc");
+ ssc_1_mis_port_0.getLInterfaces().getLInterface().add(mis_sub_interface_1);
+
+ LInterface ssc_1_int_ha_port_0 = new LInterface();
+ ssc_1_int_ha_port_0.setInterfaceId("00bb8407-650e-48b5-b919-33b88d6f8fe3");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_int_ha_port_0);
+
+
+ LInterface ssc_1_avpn_port_0 = new LInterface();
+ ssc_1_avpn_port_0.setInterfaceId("27391d94-33af-474a-927d-d409249e8fd3");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_avpn_port_0);
+ ssc_1_avpn_port_0.setLInterfaces(new LInterfaces());
+
+ LInterface avpn_sub_interface_0 = new LInterface();
+ avpn_sub_interface_0.setInterfaceId("d54dfd09-75c6-4e04-b204-909455b8f933");
+ ssc_1_avpn_port_0.getLInterfaces().getLInterface().add(avpn_sub_interface_0);
+
+ LInterface avpn_sub_interface_1 = new LInterface();
+ avpn_sub_interface_1.setInterfaceId("f7a998c0-8939-4b07-bf4a-0862e9c325e1");
+ ssc_1_avpn_port_0.getLInterfaces().getLInterface().add(avpn_sub_interface_1);
+
+ LInterface avpn_sub_interface_2 = new LInterface();
+ avpn_sub_interface_2.setInterfaceId("621c1fea-60b8-44ee-aede-c01b8b1aaa70");
+ ssc_1_avpn_port_0.getLInterfaces().getLInterface().add(avpn_sub_interface_2);
+
+
+ expectedVservers.add(vServer1);
+
+ Resources avpnQueryResponse = objectMapper.readValue(new File("src/test/resources/AVPNResourceGroupResponse.json"), Resources.class);
+ doReturn(avpnQueryResponse).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_avpn_port_0_subinterfaces-dtmxjmny7yjz/31d0647a-6043-49a4-81b6-ccab29380672/resources", cloudRegion, tenantId, Resources.class);
+
+ Resources misQueryResponse =objectMapper.readValue(new File("src/test/resources/MISResourceGroupResponse.json"), Resources.class);
+ doReturn(misQueryResponse).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_mis_port_0_subinterfaces-hlzdigtimzst/447a9b41-714e-434b-b1d0-6cce8d9f0f0c/resources", cloudRegion, tenantId, Resources.class);
+
+
+ Stack misStackQuerySubInt = stackObjectMapper.readValue(new File("src/test/resources/MISSubInterface0.json"), Stack.class);
+ doReturn(misStackQuerySubInt).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_mis_port_0_subinterfaces-hlzdigtimzst-0-upfi5nhurk7y/f711be16-2654-4a09-b89d-0511fda20e81", cloudRegion,tenantId, Stack.class);
+ Resources misResourceQuerySubInt = objectMapper.readValue(new File("src/test/resources/MISSubInterface1Resources.json"), Resources.class);
+ doReturn(misResourceQuerySubInt).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_mis_port_0_subinterfaces-hlzdigtimzst-0-upfi5nhurk7y/f711be16-2654-4a09-b89d-0511fda20e81/resources", cloudRegion,tenantId, Resources.class);
+
+ Stack avpnStackQuerySubInt1 =stackObjectMapper.readValue(new File("src/test/resources/AVPNSubInterface0.json"), Stack.class);
+ doReturn(avpnStackQuerySubInt1).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_avpn_port_0_subinterfaces-dtmxjmny7yjz-1-fmn5laetg5cs/0d9cd813-2ae1-46c0-9ebb-48081f6cffbb", cloudRegion,tenantId, Stack.class);
+ Resources avpnResourceQuerySubInt1 = objectMapper.readValue(new File("src/test/resources/AVPNSubInterface0Resources.json"), Resources.class);
+ doReturn(avpnResourceQuerySubInt1).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_avpn_port_0_subinterfaces-dtmxjmny7yjz-1-fmn5laetg5cs/0d9cd813-2ae1-46c0-9ebb-48081f6cffbb/resources", cloudRegion,tenantId, Resources.class);
+
+
+ Stack avpnStackQuerySubInt2 =stackObjectMapper.readValue(new File("src/test/resources/AVPNSubInterface1.json"), Stack.class);
+ doReturn(avpnStackQuerySubInt2).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_avpn_port_0_subinterfaces-dtmxjmny7yjz-0-yghihziaf36m/b7019dd0-2ee9-4447-bdef-ac25676b205a", cloudRegion,tenantId, Stack.class);
+ Resources avpnResourceQuerySubInt2 = objectMapper.readValue(new File("src/test/resources/AVPNSubInterface1Resources.json"), Resources.class);
+ doReturn(avpnResourceQuerySubInt2).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_avpn_port_0_subinterfaces-dtmxjmny7yjz-0-yghihziaf36m/b7019dd0-2ee9-4447-bdef-ac25676b205a/resources", cloudRegion,tenantId, Resources.class);
+
+ Stack avpnStackQuerySubInt3 =stackObjectMapper.readValue(new File("src/test/resources/AVPNSubInterface2.json"), Stack.class);
+ doReturn(avpnStackQuerySubInt3).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_avpn_port_0_subinterfaces-dtmxjmny7yjz-2-y3ndsavmsymv/bd0fc728-cbde-4301-a581-db56f494675c", cloudRegion,tenantId, Stack.class);
+ Resources avpnResourceQuerySubInt3 = objectMapper.readValue(new File("src/test/resources/AVPNSubInterface2Resources.json"), Resources.class);
+ doReturn(avpnResourceQuerySubInt3).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_avpn_port_0_subinterfaces-dtmxjmny7yjz-2-y3ndsavmsymv/bd0fc728-cbde-4301-a581-db56f494675c/resources", cloudRegion,tenantId, Resources.class);
+
+ Set<Vserver> vServersToAudit = heatStackAudit.createVserverSet(resources, novaResources);
+ Set<Vserver> vserversWithSubInterfaces = heatStackAudit.processSubInterfaces(cloudRegion,tenantId,resourceGroups, vServersToAudit);
+
+ String actualValue = objectMapper.writeValueAsString(vserversWithSubInterfaces);
+ String expectedValue = objectMapper.writeValueAsString(expectedVservers);
+
+ JSONAssert.assertEquals(expectedValue, actualValue, false);
+ }
+
+
+ @Test
+ public void findInterfaceInformation_Test(){
+ List<Resource> novaResources = resources.getList().stream()
+ .filter(p -> "OS::Nova::Server".equals(p.getType())).collect(Collectors.toList());
+ Set<Vserver> expectedVservers = new HashSet<>();
+ Vserver vServer1= new Vserver();
+ vServer1.setVserverId("92272b67-d23f-42ca-87fa-7b06a9ec81f3");
+ LInterfaces vServer1Linterfaces = new LInterfaces();
+ vServer1.setLInterfaces(vServer1Linterfaces);
+
+ LInterface ssc_1_trusted_port_0 = new LInterface();
+ ssc_1_trusted_port_0.setInterfaceId("d2f51f82-0ec2-4581-bd1a-d2a82073e52b");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_trusted_port_0);
+
+ LInterface ssc_1_avpn_port_0 = new LInterface();
+ ssc_1_avpn_port_0.setInterfaceId("27391d94-33af-474a-927d-d409249e8fd3");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_avpn_port_0);
+
+ LInterface ssc_1_mgmt_port_1 = new LInterface();
+ ssc_1_mgmt_port_1.setInterfaceId("07f5b14c-147a-4d14-8c94-a9e94dbc097b");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_mgmt_port_1);
+
+ LInterface ssc_1_mgmt_port_0 = new LInterface();
+ ssc_1_mgmt_port_0.setInterfaceId("8d93f63e-e972-48c7-ad98-b2122da47315");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_mgmt_port_0);
+
+ LInterface ssc_1_mis_port_0 = new LInterface();
+ ssc_1_mis_port_0.setInterfaceId("0594a2f2-7ea4-42eb-abc2-48ea49677fca");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_mis_port_0);
+
+ LInterface ssc_1_int_ha_port_0 = new LInterface();
+ ssc_1_int_ha_port_0.setInterfaceId("00bb8407-650e-48b5-b919-33b88d6f8fe3");
+ vServer1.getLInterfaces().getLInterface().add(ssc_1_int_ha_port_0);
+
+ expectedVservers.add(vServer1);
+
+ Set<Vserver> actualVservers = heatStackAudit.createVserverSet(resources, novaResources);
+
+ assertThat(actualVservers, sameBeanAs(expectedVservers));
+ }
+
+
+}