From cd4e5b408603a13dabc58f832e4aae4194e81995 Mon Sep 17 00:00:00 2001 From: "Boslet, Cory" Date: Wed, 25 Mar 2020 16:04:41 -0400 Subject: convert openstack to external tasks Use external tasks to communicate with openstack adapter Will be more resilient to failures Refactored all flows to use external tasks not REST calls Rollback is now an external task Ensured backwards compatibility Issue-ID: SO-2767 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I8afdb89c688d756aed0f25f7d9a7fb898142554d --- .../so/adapters/audit/AuditDataServiceTest.java | 101 ----- .../adapters/audit/AuditStackServiceDataTest.java | 187 --------- .../onap/so/adapters/audit/AuditVServerTest.java | 432 -------------------- .../onap/so/adapters/audit/HeatStackAuditTest.java | 296 -------------- .../inventory/create/CreateAAIInventoryTest.java | 122 ------ .../inventory/create/CreateInventoryTaskTest.java | 80 ---- .../adapters/tasks/audit/AuditDataServiceTest.java | 102 +++++ .../tasks/audit/AuditStackServiceDataTest.java | 191 +++++++++ .../so/adapters/tasks/audit/AuditVServerTest.java | 433 +++++++++++++++++++++ .../adapters/tasks/audit/HeatStackAuditTest.java | 298 ++++++++++++++ .../tasks/inventory/CreateAAIInventoryTest.java | 123 ++++++ .../tasks/inventory/CreateInventoryTaskTest.java | 83 ++++ .../tasks/orchestration/PollServiceTest.java | 82 ++++ .../tasks/orchestration/RollbackServiceTest.java | 82 ++++ .../tasks/orchestration/StackServiceTest.java | 113 ++++++ 15 files changed, 1507 insertions(+), 1218 deletions(-) delete mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditDataServiceTest.java delete mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java delete mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java delete mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java delete mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateAAIInventoryTest.java delete mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java create mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditDataServiceTest.java create mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditStackServiceDataTest.java create mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditVServerTest.java create mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/HeatStackAuditTest.java create mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventoryTest.java create mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTaskTest.java create mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/PollServiceTest.java create mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/RollbackServiceTest.java create mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/StackServiceTest.java (limited to 'adapters/mso-openstack-adapters/src/test/java') diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditDataServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditDataServiceTest.java deleted file mode 100644 index d3380a6a33..0000000000 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditDataServiceTest.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.onap.so.adapters.audit; - -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; -import java.util.ArrayList; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.aai.domain.yang.Vserver; -import org.onap.so.audit.beans.AuditInventory; -import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider; -import org.onap.so.db.request.beans.RequestProcessingData; -import org.onap.so.db.request.client.RequestsDbClient; -import org.onap.so.objects.audit.AAIObjectAudit; -import org.onap.so.objects.audit.AAIObjectAuditList; -import com.fasterxml.jackson.core.JsonProcessingException; - -@RunWith(MockitoJUnitRunner.Silent.class) -public class AuditDataServiceTest { - - @InjectMocks - AuditDataService auditDataService = new AuditDataService(); - - @Mock - protected RequestsDbClient requestsDbClient; - - AuditInventory auditInventory = new AuditInventory(); - - @Before - public void before() throws JsonProcessingException { - auditInventory.setCloudOwner("testCloudOwner"); - auditInventory.setCloudRegion("testLcpCloudRegionId"); - auditInventory.setHeatStackName("testVfModuleName1"); - auditInventory.setVfModuleId("testVnfModuleId"); - auditInventory.setTenantId("testTenantId"); - auditInventory.setGenericVnfId("testVnfId1"); - } - - @Test - public void testWriteStackDataToRequestDb() throws Exception { - Mockito.doReturn(new ArrayList()).when(requestsDbClient) - .getRequestProcessingDataByGroupingIdAndNameAndTag(Mockito.any(), Mockito.any(), Mockito.any()); - Mockito.doNothing().when(requestsDbClient).saveRequestProcessingData(Mockito.any()); - - AAIObjectAuditList auditList = new AAIObjectAuditList(); - auditList.setHeatStackName("testHeatStackName"); - AAIObjectAudit audit = new AAIObjectAudit(); - Vserver vserver = new Vserver(); - vserver.setVserverId("testVserverId"); - audit.setAaiObject(vserver); - auditList.getAuditList().add(audit); - - GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider(); - String auditListString = objectMapper.getMapper().writeValueAsString(auditList);; - - RequestProcessingData requestProcessingData = new RequestProcessingData(); - requestProcessingData.setSoRequestId(auditInventory.getMsoRequestId()); - requestProcessingData.setGroupingId(auditInventory.getVfModuleId()); - requestProcessingData.setName(auditInventory.getHeatStackName()); - requestProcessingData.setTag("AuditStackData"); - requestProcessingData.setValue(auditListString); - - auditDataService.writeStackDataToRequestDb(auditInventory, auditList); - Mockito.verify(requestsDbClient, Mockito.times(1)).saveRequestProcessingData(requestProcessingData); - } - - @Test - public void testGetStackDataToRequestDb() throws Exception { - AAIObjectAuditList auditList = new AAIObjectAuditList(); - auditList.setHeatStackName("testHeatStackName"); - AAIObjectAudit audit = new AAIObjectAudit(); - Vserver vserver = new Vserver(); - vserver.setVserverId("testVserverId"); - audit.setAaiObject(vserver); - auditList.getAuditList().add(audit); - GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider(); - String auditListString = objectMapper.getMapper().writeValueAsString(audit); - - List list = new ArrayList(); - RequestProcessingData requestProcessingData = new RequestProcessingData(); - requestProcessingData.setId(234321432); - requestProcessingData.setGroupingId("testVfModuleId"); - requestProcessingData.setName("heatStackName"); - requestProcessingData.setTag("AuditStackData"); - requestProcessingData.setValue(auditListString); - list.add(requestProcessingData); - - Mockito.doReturn(list).when(requestsDbClient).getRequestProcessingDataByGroupingIdAndNameAndTag(Mockito.any(), - Mockito.any(), Mockito.any()); - auditDataService.getStackDataFromRequestDb(auditInventory); - Mockito.verify(requestsDbClient, Mockito.times(1)).getRequestProcessingDataByGroupingIdAndNameAndTag( - "testVnfModuleId", "testVfModuleName1", "AuditStackData"); - } - -} 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 deleted file mode 100644 index cff4d5f994..0000000000 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java +++ /dev/null @@ -1,187 +0,0 @@ -/*- - * ============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.junit.Assert.assertNotNull; -import static org.mockito.Mockito.doReturn; -import java.io.File; -import java.io.IOException; -import java.util.Map; -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.ArgumentCaptor; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.onap.so.audit.beans.AuditInventory; -import org.onap.so.externaltasks.logging.AuditMDCSetup; -import org.onap.so.objects.audit.AAIObjectAuditList; -import org.springframework.core.env.Environment; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class AuditStackServiceDataTest extends AuditCreateStackService { - - @InjectMocks - private AuditCreateStackService auditStackService = new AuditCreateStackService(); - - @InjectMocks - private AuditQueryStackService auditQueryStackService = new AuditQueryStackService(); - - @Mock - private HeatStackAudit heatStackAuditMock; - - @Mock - private Environment mockEnv; - - @Mock - private ExternalTask mockExternalTask; - - @Mock - private ExternalTaskService mockExternalTaskService; - - @Mock - private AuditDataService auditDataService; - - @Mock - private AuditMDCSetup mdcSetup; - - private ObjectMapper objectMapper = new ObjectMapper(); - - private AuditInventory auditInventory = new AuditInventory(); - - Optional auditListOptSuccess; - - Optional auditListOptFailure; - - @Before - public void setup() throws JsonParseException, JsonMappingException, IOException { - auditInventory.setCloudOwner("cloudOwner"); - auditInventory.setCloudRegion("cloudRegion"); - auditInventory.setTenantId("tenantId"); - auditInventory.setHeatStackName("stackName"); - MockitoAnnotations.initMocks(this); - - AAIObjectAuditList auditListSuccess = objectMapper - .readValue(new File("src/test/resources/ExpectedVServerFound.json"), AAIObjectAuditList.class); - auditListOptSuccess = Optional.of(auditListSuccess); - - AAIObjectAuditList auditListFailure = objectMapper.readValue( - new File("src/test/resources/Vserver2_Found_VServer1_Not_Found.json"), AAIObjectAuditList.class); - auditListOptFailure = Optional.of(auditListFailure); - String[] retrySequence = new String[8]; - retrySequence[0] = "1"; - retrySequence[1] = "1"; - retrySequence[2] = "2"; - retrySequence[3] = "3"; - retrySequence[4] = "5"; - retrySequence[5] = "8"; - retrySequence[6] = "13"; - retrySequence[7] = "20"; - doReturn(auditInventory).when(mockExternalTask).getVariable("auditInventory"); - doReturn("6000").when(mockEnv).getProperty("mso.workflow.topics.retryMultiplier", "6000"); - doReturn(retrySequence).when(mockEnv).getProperty("mso.workflow.topics.retrySequence", String[].class); - doReturn("aasdfasdf").when(mockExternalTask).getId(); - } - - @Test - public void execute_external_task_audit_success_Test() { - doReturn(auditListOptSuccess).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", - "stackName"); - auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); - ArgumentCaptor captor = ArgumentCaptor.forClass(Map.class); - ArgumentCaptor taskCaptor = ArgumentCaptor.forClass(ExternalTask.class); - Mockito.verify(mockExternalTaskService).complete(taskCaptor.capture(), captor.capture()); - Map actualMap = captor.getValue(); - assertEquals(true, actualMap.get("auditIsSuccessful")); - assertNotNull(actualMap.get("auditInventoryResult")); - } - - @Test - public void executeExternalTaskQueryAuditTest() throws JsonProcessingException { - doReturn(auditListOptSuccess).when(heatStackAuditMock).queryHeatStack("cloudOwner", "cloudRegion", "tenantId", - "stackName"); - Mockito.doNothing().when(auditDataService).writeStackDataToRequestDb(Mockito.any(AuditInventory.class), - Mockito.any(AAIObjectAuditList.class)); - auditQueryStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); - ArgumentCaptor captor = ArgumentCaptor.forClass(Map.class); - ArgumentCaptor taskCaptor = ArgumentCaptor.forClass(ExternalTask.class); - Mockito.verify(mockExternalTaskService).complete(taskCaptor.capture(), captor.capture()); - Mockito.verify(auditDataService).writeStackDataToRequestDb(Mockito.any(AuditInventory.class), - Mockito.any(AAIObjectAuditList.class)); - } - - @Test - public void execute_external_task_audit_first_failure_Test() { - doReturn(auditListOptFailure).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(auditListOptFailure).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(auditListOptFailure).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", - "stackName"); - doReturn(1).when(mockExternalTask).getRetries(); - auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); - ArgumentCaptor captor = ArgumentCaptor.forClass(Map.class); - ArgumentCaptor taskCaptor = ArgumentCaptor.forClass(ExternalTask.class); - Mockito.verify(mockExternalTaskService).complete(taskCaptor.capture(), captor.capture()); - Map actualMap = captor.getValue(); - assertEquals(false, actualMap.get("auditIsSuccessful")); - assertNotNull(actualMap.get("auditInventoryResult")); - } - - @Test - public void determineAuditResult_Test() throws Exception { - boolean actual = auditStackService.didCreateAuditFail(auditListOptSuccess); - assertEquals(false, actual); - } - - @Test - public void determineAuditResult_Failure_Test() throws Exception { - boolean actual = auditStackService.didCreateAuditFail(auditListOptFailure); - assertEquals(true, actual); - } -} 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 deleted file mode 100644 index 8e71ec46b0..0000000000 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java +++ /dev/null @@ -1,432 +0,0 @@ -/*- - * ============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 perservice2sions 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.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashSet; -import java.util.Optional; -import java.util.Set; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -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.VfModule; -import org.onap.aai.domain.yang.VfModules; -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 org.onap.so.objects.audit.AAIObjectAudit; -import org.onap.so.objects.audit.AAIObjectAuditList; -import org.skyscreamer.jsonassert.JSONAssert; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -@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(AAIObjectType.L_INTERFACE, - cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_trusted_port_0"); - - private AAIResourceUri ssc_1_service1_port_0_uri = AAIUriFactory.createResourceUri(AAIObjectType.L_INTERFACE, - cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_service1_port_0"); - - private AAIResourceUri ssc_1_mgmt_port_1_uri = AAIUriFactory.createResourceUri(AAIObjectType.L_INTERFACE, - cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_mgmt_port_1"); - - private AAIResourceUri ssc_1_mgmt_port_0_uri = AAIUriFactory.createResourceUri(AAIObjectType.L_INTERFACE, - cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_mgmt_port_0"); - - private AAIResourceUri ssc_1_service2_port_0_uri = AAIUriFactory.createResourceUri(AAIObjectType.L_INTERFACE, - cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_service2_port_0"); - - private AAIResourceUri ssc_1_int_ha_port_0_uri = AAIUriFactory.createResourceUri(AAIObjectType.L_INTERFACE, - cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_int_ha_port_0"); - - private AAIResourceUri test_port_1_uri = AAIUriFactory.createResourceUri(AAIObjectType.L_INTERFACE, cloudOwner, - cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4dz", "test_port_1"); - - private AAIResourceUri test_port_2_uri = AAIUriFactory.createResourceUri(AAIObjectType.L_INTERFACE, cloudOwner, - cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4dz", "test_port_2"); - - private AAIResourceUri service2_sub_1_uri = - AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, cloudOwner, cloudRegion, tenantId, - "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_service2_port_0", "service2_sub_interface_1"); - - private AAIResourceUri service1_sub_0_uri = - AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, cloudOwner, cloudRegion, tenantId, - "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_service1_port_0", "service1_sub_interface_1"); - - private AAIResourceUri service1_sub_1_uri = - AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, cloudOwner, cloudRegion, tenantId, - "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_service1_port_0", "service1_sub_interface_2"); - - - - private Set 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 service2_sub_interface_1 = new LInterface(); - LInterface ssc_1_service2_port_0 = new LInterface(); - LInterface ssc_1_mgmt_port_0 = new LInterface(); - LInterface ssc_1_mgmt_port_1 = new LInterface(); - LInterface service1_sub_interface_2 = new LInterface(); - LInterface service1_sub_interface_1 = new LInterface(); - LInterface ssc_1_service1_port_0 = new LInterface(); - LInterface ssc_1_trusted_port_0 = new LInterface(); - - - - @Before - public void setup() { - objectMapper.setSerializationInclusion(Include.NON_NULL); - 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("ssc_1_trusted_port_0"); - vServer1.getLInterfaces().getLInterface().add(ssc_1_trusted_port_0); - - - ssc_1_service1_port_0.setInterfaceId("1c56a24b-5f03-435a-850d-31cd4252de56"); - ssc_1_service1_port_0.setInterfaceName("ssc_1_service1_port_0"); - vServer1.getLInterfaces().getLInterface().add(ssc_1_service1_port_0); - ssc_1_service1_port_0.setLInterfaces(new LInterfaces()); - - - service1_sub_interface_1.setInterfaceId("0d9cd813-2ae1-46c0-9ebb-48081f6cffbb"); - service1_sub_interface_1.setInterfaceName("service1_sub_interface_1"); - ssc_1_service1_port_0.getLInterfaces().getLInterface().add(service1_sub_interface_1); - - - service1_sub_interface_2.setInterfaceId("b7019dd0-2ee9-4447-bdef-ac25676b205a"); - service1_sub_interface_2.setInterfaceName("service1_sub_interface_2"); - ssc_1_service1_port_0.getLInterfaces().getLInterface().add(service1_sub_interface_2); - - - ssc_1_mgmt_port_1.setInterfaceId("12afcd28-929f-4d80-8a5a-0833bfd5e20b"); - ssc_1_mgmt_port_1.setInterfaceName("ssc_1_mgmt_port_1"); - 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("ssc_1_mgmt_port_0"); - vServer1.getLInterfaces().getLInterface().add(ssc_1_mgmt_port_0); - - - ssc_1_service2_port_0.setLInterfaces(new LInterfaces()); - ssc_1_service2_port_0.setInterfaceId("13eddf95-4cf3-45f2-823a-2d890a6549b4"); - ssc_1_service2_port_0.setInterfaceName("ssc_1_service2_port_0"); - vServer1.getLInterfaces().getLInterface().add(ssc_1_service2_port_0); - - - service2_sub_interface_1.setInterfaceId("f711be16-2654-4a09-b89d-0511fda20e81"); - service2_sub_interface_1.setInterfaceName("service2_sub_interface_1"); - ssc_1_service2_port_0.getLInterfaces().getLInterface().add(service2_sub_interface_1); - - - ssc_1_int_ha_port_0.setInterfaceId("9cab2903-70f7-44fd-b681-491d6ae2adb8"); - ssc_1_int_ha_port_0.setInterfaceName("ssc_1_int_ha_port_0"); - 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("test_port_1"); - - - test_port_2.setInterfaceId("9cab2903-70f7-44fd-b681-491d6ae2adz2"); - test_port_2.setInterfaceName("test_port_2"); - - vServer2.getLInterfaces().getLInterface().add(test_port_1); - vServer2.getLInterfaces().getLInterface().add(test_port_2); - - vserversToAudit.add(vServer1); - vserversToAudit.add(vServer2); - } - - @Test - public void audit_Vserver_Empty_HashSet() throws JsonParseException, JsonMappingException, IOException { - Optional actual = - auditNova.auditVservers(new HashSet(), tenantId, cloudOwner, cloudRegion); - assertEquals(Optional.empty(), actual); - } - - @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)).when(aaiResourcesMock).get(LInterface.class, - ssc_1_trusted_port_0_uri); - doReturn(Optional.of(ssc_1_service1_port_0)).when(aaiResourcesMock).get(LInterface.class, - ssc_1_service1_port_0_uri); - doReturn(Optional.of(ssc_1_mgmt_port_1)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_1_uri); - doReturn(Optional.of(ssc_1_mgmt_port_0)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_0_uri); - doReturn(Optional.of(ssc_1_service2_port_0)).when(aaiResourcesMock).get(LInterface.class, - ssc_1_service2_port_0_uri); - doReturn(Optional.of(service2_sub_interface_1)).when(aaiResourcesMock).get(LInterface.class, - service1_sub_1_uri); - doReturn(Optional.of(ssc_1_int_ha_port_0)).when(aaiResourcesMock).get(LInterface.class, - ssc_1_int_ha_port_0_uri); - doReturn(Optional.of(test_port_1)).when(aaiResourcesMock).get(LInterface.class, test_port_1_uri); - doReturn(Optional.of(test_port_2)).when(aaiResourcesMock).get(LInterface.class, test_port_2_uri); - - doReturn(true).when(aaiResourcesMock).exists(service2_sub_1_uri); - doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri); - doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri); - - Optional actual = - auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); - String actualString = objectMapper.writeValueAsString(actual.get()); - String expected = getJson("ExpectedVServerFound.json"); - JSONAssert.assertEquals(expected, actualString, false); - } - - @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)).when(aaiResourcesMock).get(LInterface.class, - ssc_1_trusted_port_0_uri); - doReturn(Optional.of(ssc_1_service1_port_0)).when(aaiResourcesMock).get(LInterface.class, - ssc_1_service1_port_0_uri); - doReturn(Optional.of(ssc_1_mgmt_port_1)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_1_uri); - doReturn(Optional.empty()).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_0_uri); - doReturn(Optional.of(ssc_1_service2_port_0)).when(aaiResourcesMock).get(LInterface.class, - ssc_1_service2_port_0_uri); - doReturn(Optional.of(ssc_1_int_ha_port_0)).when(aaiResourcesMock).get(LInterface.class, - ssc_1_int_ha_port_0_uri); - doReturn(Optional.of(test_port_1)).when(aaiResourcesMock).get(LInterface.class, test_port_1_uri); - doReturn(Optional.of(test_port_2)).when(aaiResourcesMock).get(LInterface.class, test_port_2_uri); - - doReturn(true).when(aaiResourcesMock).exists(service2_sub_1_uri); - doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri); - doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri); - - Optional actual = - auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); - String actualString = objectMapper.writeValueAsString(actual.get()); - String expected = getJson("VServer_Found_network_Not_Found.json"); - JSONAssert.assertEquals(expected, actualString, false); - } - - @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)).when(aaiResourcesMock).get(LInterface.class, - ssc_1_trusted_port_0_uri); - doReturn(Optional.of(ssc_1_service1_port_0)).when(aaiResourcesMock).get(LInterface.class, - ssc_1_service1_port_0_uri); - doReturn(Optional.of(ssc_1_mgmt_port_1)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_1_uri); - doReturn(Optional.of(ssc_1_mgmt_port_0)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_0_uri); - doReturn(Optional.of(ssc_1_service2_port_0)).when(aaiResourcesMock).get(LInterface.class, - ssc_1_service2_port_0_uri); - doReturn(Optional.of(ssc_1_int_ha_port_0)).when(aaiResourcesMock).get(LInterface.class, - ssc_1_int_ha_port_0_uri); - doReturn(Optional.of(test_port_1)).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(service2_sub_1_uri); - doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri); - doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri); - Optional actual = - auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); - String actualString = objectMapper.writeValueAsString(actual.get()); - String expected = getJson("VServer_Found_Network_Sec_Server_Not_Found.json"); - JSONAssert.assertEquals(expected, actualString, false); - } - - @Test - public void audit_Vserver_Not_Found_Test() throws JsonParseException, JsonMappingException, IOException { - doReturn(false).when(aaiResourcesMock).exists(vserverURI); - doReturn(false).when(aaiResourcesMock).exists(vserverURI2); - Optional actual = - auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); - String actualString = objectMapper.writeValueAsString(actual.get()); - String expected = getJson("Vservers_Not_Found.json"); - JSONAssert.assertEquals(expected, actualString, false); - } - - @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)).when(aaiResourcesMock).get(LInterface.class, test_port_1_uri); - doReturn(Optional.of(test_port_2)).when(aaiResourcesMock).get(LInterface.class, test_port_2_uri); - Optional actual = - auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); - String actualString = objectMapper.writeValueAsString(actual.get()); - String expected = getJson("Vserver2_Found_VServer1_Not_Found.json"); - JSONAssert.assertEquals(expected, actualString, false); - } - - - @Test - public void doesSubInterfaceExistinAAI_Test() { - AAIResourceUri subInterfaceURI = AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, cloudOwner, - cloudRegion, tenantId, "vserverId", "l-interface", "sub-interface"); - - assertEquals( - "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner/cloudRegion/tenants/tenant/tenantId/vservers/vserver/vserverId/l-interfaces/l-interface/l-interface/l-interfaces/l-interface/sub-interface", - subInterfaceURI.build().toString()); - } - - @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)).when(aaiResourcesMock).get(LInterface.class, - ssc_1_trusted_port_0_uri); - doReturn(Optional.of(ssc_1_service1_port_0)).when(aaiResourcesMock).get(LInterface.class, - ssc_1_service1_port_0_uri); - doReturn(Optional.of(ssc_1_mgmt_port_1)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_1_uri); - doReturn(Optional.of(ssc_1_mgmt_port_0)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_0_uri); - doReturn(Optional.of(ssc_1_service2_port_0)).when(aaiResourcesMock).get(LInterface.class, - ssc_1_service2_port_0_uri); - doReturn(Optional.of(ssc_1_int_ha_port_0)).when(aaiResourcesMock).get(LInterface.class, - ssc_1_int_ha_port_0_uri); - doReturn(Optional.empty()).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(service2_sub_1_uri); - doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri); - doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri); - - doReturn(false).when(aaiResourcesMock).exists(vserverURI2); - Optional actual = - auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); - String actualString = objectMapper.writeValueAsString(actual.get()); - String expected = getJson("VServer_Found_Sec_Server_Not_Found2.json"); - - JSONAssert.assertEquals(expected, actualString, false); - } - - @Test - public void testAuditVserversWithList() { - - AAIObjectAuditList auditList = new AAIObjectAuditList(); - AAIObjectAudit obj1 = new AAIObjectAudit(); - Vserver vserver = new Vserver(); - vserver.setVserverId("testVserverId"); - obj1.setAaiObject(vserver); - obj1.setResourceURI(AAIUriFactory - .createResourceUri(AAIObjectType.VSERVER, cloudOwner, cloudRegion, tenantId, "testVserverId").build()); - auditList.getAuditList().add(obj1); - - doReturn(false).when(aaiResourcesMock).exists(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner, - cloudRegion, tenantId, "testVserverId")); - - auditNova.auditVservers(auditList); - - Mockito.verify(aaiResourcesMock).exists(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner, - cloudRegion, tenantId, "testVserverId")); - - Assert.assertEquals(false, auditList.getAuditList().get(0).isDoesObjectExist()); - } - - @Test - public void testAuditVserversThroughRelationships() { - - VfModule vfModule = new VfModule(); - vfModule.setVfModuleId("id"); - - AAIResultWrapper wrapper = new AAIResultWrapper(vfModule); - - doReturn(Optional.of(wrapper)).when(aaiResourcesMock).getFirstWrapper(VfModules.class, VfModule.class, - AAIUriFactory.createResourceUri(AAIObjectPlurals.VF_MODULE, "genericVnfId").queryParam("vf-module-name", - "vfModuleName")); - - Optional auditList = - auditNova.auditVserversThroughRelationships("genericVnfId", "vfModuleName"); - - Assert.assertTrue(auditList.get().getAuditList().isEmpty()); - } - - @Test - public void testAuditVserversThroughRelationships_exists() throws IOException { - - String vfModule = getJson("vfModule.json"); - - AAIResultWrapper wrapper = new AAIResultWrapper(vfModule); - AAIResultWrapper vserverWrapper = new AAIResultWrapper(new Vserver()); - - doReturn(Optional.of(wrapper)).when(aaiResourcesMock).getFirstWrapper(VfModules.class, VfModule.class, - AAIUriFactory.createResourceUri(AAIObjectPlurals.VF_MODULE, "genericVnfId").queryParam("vf-module-name", - "vfModuleName")); - - doReturn(vserverWrapper).when(aaiResourcesMock).get(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, - "cloud-owner", "cloud-region-id", "tenant-id", "VUSCHGA1")); - - Optional auditList = - auditNova.auditVserversThroughRelationships("genericVnfId", "vfModuleName"); - - Assert.assertFalse(auditList.get().getAuditList().isEmpty()); - } - - - private String getJson(String filename) throws IOException { - return new String(Files.readAllBytes(Paths.get("src/test/resources/" + filename))); - } - - - -} 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 deleted file mode 100644 index c995064ab2..0000000000 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java +++ /dev/null @@ -1,296 +0,0 @@ -/*- - * ============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.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -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.objects.audit.AAIObjectAuditList; -import org.onap.so.openstack.utils.MsoHeatUtils; -import org.onap.so.openstack.utils.MsoNeutronUtils; -import org.skyscreamer.jsonassert.JSONAssert; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -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; -import com.woorea.openstack.quantum.model.Port; - - -@RunWith(MockitoJUnitRunner.Silent.class) -public class HeatStackAuditTest extends HeatStackAudit { - - @InjectMocks - private HeatStackAudit heatStackAudit = new HeatStackAudit(); - - @Mock - private MsoHeatUtils msoHeatUtilsMock; - - @Mock - private MsoNeutronUtils neutronUtilsMock; - - @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) - .setSerializationInclusion(Include.NON_NULL); - - private ObjectMapper stackObjectMapper = new ObjectMapper() - .configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true).setSerializationInclusion(Include.NON_NULL); - - private List> portList = new ArrayList<>(); - - @Before - public void setup() throws Exception { - resources = objectMapper.readValue(new File("src/test/resources/GetResources.json"), Resources.class); - Port neutronPort1 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort1.json"), Port.class); - doReturn(Optional.of(neutronPort1)).when(neutronUtilsMock) - .getNeutronPort("7ee06d9d-3d18-411c-9d3e-aec930f70413", cloudRegion, tenantId); - Port neutronPort2 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort2.json"), Port.class); - doReturn(Optional.of(neutronPort2)).when(neutronUtilsMock) - .getNeutronPort("27391d94-33af-474a-927d-d409249e8fd3", cloudRegion, tenantId); - Port neutronPort3 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort3.json"), Port.class); - doReturn(Optional.of(neutronPort3)).when(neutronUtilsMock) - .getNeutronPort("fdeedf37-c01e-4ab0-bdd6-8d5fc4913943", cloudRegion, tenantId); - Port neutronPort4 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort4.json"), Port.class); - doReturn(Optional.of(neutronPort4)).when(neutronUtilsMock) - .getNeutronPort("8d93f63e-e972-48c7-ad98-b2122da47315", cloudRegion, tenantId); - Port neutronPort5 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort5.json"), Port.class); - doReturn(Optional.of(neutronPort5)).when(neutronUtilsMock) - .getNeutronPort("0594a2f2-7ea4-42eb-abc2-48ea49677fca", cloudRegion, tenantId); - Port neutronPort6 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort6.json"), Port.class); - doReturn(Optional.of(neutronPort6)).when(neutronUtilsMock) - .getNeutronPort("00bb8407-650e-48b5-b919-33b88d6f8fe3", cloudRegion, tenantId); - - - portList.add(Optional.empty()); - portList.add(Optional.of(neutronPort1)); - portList.add(Optional.of(neutronPort2)); - portList.add(Optional.of(neutronPort3)); - portList.add(Optional.of(neutronPort4)); - portList.add(Optional.of(neutronPort5)); - portList.add(Optional.of(neutronPort6)); - } - - @Test - public void extract_proper_path_Test() { - Optional actualResult = extractStackPathFromHref( - "https://orchestration.com:8004/v1/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81"); - assertEquals("/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81", actualResult.get()); - } - - @Test - public void extract_proper_resources_path_Test() { - Optional actualResult = extractResourcePathFromHref( - "https://orchestration.com:8004/v1/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81"); - assertEquals("/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81/resources", actualResult.get()); - } - - @Test - public void extract_invalid_uri_Test() { - Optional 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 novaResources = resources.getList().stream().filter(p -> "OS::Nova::Server".equals(p.getType())) - .collect(Collectors.toList()); - - List resourceGroups = resources.getList().stream() - .filter(p -> "OS::Heat::ResourceGroup".equals(p.getType())).collect(Collectors.toList()); - - Resources service1QueryResponse = objectMapper - .readValue(new File("src/test/resources/Service1ResourceGroupResponse.json"), Resources.class); - doReturn(service1QueryResponse).when(msoHeatUtilsMock).executeHeatClientRequest( - "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz/31d0647a-6043-49a4-81b6-ccab29380672/resources", - cloudRegion, tenantId, Resources.class); - - Resources service2QueryResponse = objectMapper - .readValue(new File("src/test/resources/Service2ResourceGroupResponse.json"), Resources.class); - doReturn(service2QueryResponse).when(msoHeatUtilsMock).executeHeatClientRequest( - "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service2_port_0_subinterfaces-hlzdigtimzst/447a9b41-714e-434b-b1d0-6cce8d9f0f0c/resources", - cloudRegion, tenantId, Resources.class); - - - Stack service2StackQuerySubInt = - stackObjectMapper.readValue(new File("src/test/resources/Service2SubInterface0.json"), Stack.class); - doReturn(service2StackQuerySubInt).when(msoHeatUtilsMock).executeHeatClientRequest( - "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service2_port_0_subinterfaces-hlzdigtimzst-0-upfi5nhurk7y/f711be16-2654-4a09-b89d-0511fda20e81", - cloudRegion, tenantId, Stack.class); - Resources service2ResourceQuerySubInt = objectMapper - .readValue(new File("src/test/resources/Service2SubInterface1Resources.json"), Resources.class); - doReturn(service2ResourceQuerySubInt).when(msoHeatUtilsMock).executeHeatClientRequest( - "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service2_port_0_subinterfaces-hlzdigtimzst-0-upfi5nhurk7y/f711be16-2654-4a09-b89d-0511fda20e81/resources", - cloudRegion, tenantId, Resources.class); - - Stack service1StackQuerySubInt1 = - stackObjectMapper.readValue(new File("src/test/resources/Service1SubInterface0.json"), Stack.class); - doReturn(service1StackQuerySubInt1).when(msoHeatUtilsMock).executeHeatClientRequest( - "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-1-fmn5laetg5cs/0d9cd813-2ae1-46c0-9ebb-48081f6cffbb", - cloudRegion, tenantId, Stack.class); - Resources service1ResourceQuerySubInt1 = objectMapper - .readValue(new File("src/test/resources/Service1SubInterface0Resources.json"), Resources.class); - doReturn(service1ResourceQuerySubInt1).when(msoHeatUtilsMock).executeHeatClientRequest( - "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-1-fmn5laetg5cs/0d9cd813-2ae1-46c0-9ebb-48081f6cffbb/resources", - cloudRegion, tenantId, Resources.class); - - - Stack service1StackQuerySubInt2 = - stackObjectMapper.readValue(new File("src/test/resources/Service1SubInterface1.json"), Stack.class); - doReturn(service1StackQuerySubInt2).when(msoHeatUtilsMock).executeHeatClientRequest( - "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-0-yghihziaf36m/b7019dd0-2ee9-4447-bdef-ac25676b205a", - cloudRegion, tenantId, Stack.class); - Resources service1ResourceQuerySubInt2 = objectMapper - .readValue(new File("src/test/resources/Service1SubInterface1Resources.json"), Resources.class); - doReturn(service1ResourceQuerySubInt2).when(msoHeatUtilsMock).executeHeatClientRequest( - "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-0-yghihziaf36m/b7019dd0-2ee9-4447-bdef-ac25676b205a/resources", - cloudRegion, tenantId, Resources.class); - - Stack service1StackQuerySubInt3 = - stackObjectMapper.readValue(new File("src/test/resources/Service1SubInterface2.json"), Stack.class); - doReturn(service1StackQuerySubInt3).when(msoHeatUtilsMock).executeHeatClientRequest( - "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-2-y3ndsavmsymv/bd0fc728-cbde-4301-a581-db56f494675c", - cloudRegion, tenantId, Stack.class); - Resources service1ResourceQuerySubInt3 = objectMapper - .readValue(new File("src/test/resources/Service1SubInterface2Resources.json"), Resources.class); - doReturn(service1ResourceQuerySubInt3).when(msoHeatUtilsMock).executeHeatClientRequest( - "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-2-y3ndsavmsymv/bd0fc728-cbde-4301-a581-db56f494675c/resources", - cloudRegion, tenantId, Resources.class); - - Set vServersToAudit = heatStackAudit.createVserverSet(resources, novaResources, portList); - Set vserversWithSubInterfaces = - heatStackAudit.processSubInterfaces(cloudRegion, tenantId, resourceGroups, vServersToAudit); - - String actualValue = objectMapper.writeValueAsString(vserversWithSubInterfaces); - String expectedValue = getJson("ExpectedVserversToAudit.json"); - JSONAssert.assertEquals(expectedValue, actualValue, false); - } - - @Test - public void auditHeatStackNoServers_Test() throws Exception { - Resources getResource = objectMapper - .readValue(new File("src/test/resources/Service1ResourceGroupResponse.json"), Resources.class); - doReturn(getResource).when(msoHeatUtilsMock).queryStackResources(cloudRegion, tenantId, "heatStackName", 3); - - Optional actual = - heatStackAudit.auditHeatStack(cloudRegion, "cloudOwner", tenantId, "heatStackName"); - assertEquals(true, actual.get().getAuditList().isEmpty()); - } - - @Test - public void auditHeatStackNestedServers_Test() throws Exception { - Resources getResource = - objectMapper.readValue(new File("src/test/resources/GetNestedResources.json"), Resources.class); - List novaResources = getResource.getList().stream() - .filter(p -> "OS::Nova::Server".equals(p.getType())).collect(Collectors.toList()); - List resourceGroups = getResource.getList().stream() - .filter(p -> "OS::Heat::ResourceGroup".equals(p.getType())).collect(Collectors.toList()); - - doReturn(getResource).when(msoHeatUtilsMock).queryStackResources(cloudRegion, tenantId, "heatStackName", 3); - Set vServersToAudit = heatStackAudit.createVserverSet(resources, novaResources, portList); - Set vserversWithSubInterfaces = - heatStackAudit.processSubInterfaces(cloudRegion, tenantId, resourceGroups, vServersToAudit); - String actualValue = objectMapper.writeValueAsString(vserversWithSubInterfaces); - String expectedValue = getJson("NestedExpectedValue.json"); - JSONAssert.assertEquals(expectedValue, actualValue, false); - } - - - @Test - public void findInterfaceInformation_Test() { - List novaResources = resources.getList().stream().filter(p -> "OS::Nova::Server".equals(p.getType())) - .collect(Collectors.toList()); - Set 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("7ee06d9d-3d18-411c-9d3e-aec930f70413"); - ssc_1_trusted_port_0.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port"); - vServer1.getLInterfaces().getLInterface().add(ssc_1_trusted_port_0); - - LInterface ssc_1_svc2_port_0 = new LInterface(); - ssc_1_svc2_port_0.setInterfaceId("27391d94-33af-474a-927d-d409249e8fd3"); - ssc_1_svc2_port_0.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port"); - vServer1.getLInterfaces().getLInterface().add(ssc_1_svc2_port_0); - - LInterface ssc_1_mgmt_port_1 = new LInterface(); - ssc_1_mgmt_port_1.setInterfaceId("fdeedf37-c01e-4ab0-bdd6-8d5fc4913943"); - ssc_1_mgmt_port_1.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port"); - 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"); - ssc_1_mgmt_port_0.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port"); - vServer1.getLInterfaces().getLInterface().add(ssc_1_mgmt_port_0); - - LInterface ssc_1_svc1_port_0 = new LInterface(); - ssc_1_svc1_port_0.setInterfaceId("0594a2f2-7ea4-42eb-abc2-48ea49677fca"); - ssc_1_svc1_port_0.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port"); - vServer1.getLInterfaces().getLInterface().add(ssc_1_svc1_port_0); - - LInterface ssc_1_int_ha_port_0 = new LInterface(); - ssc_1_int_ha_port_0.setInterfaceId("00bb8407-650e-48b5-b919-33b88d6f8fe3"); - ssc_1_int_ha_port_0.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port"); - vServer1.getLInterfaces().getLInterface().add(ssc_1_int_ha_port_0); - - expectedVservers.add(vServer1); - - Set actualVservers = heatStackAudit.createVserverSet(resources, novaResources, portList); - - assertThat(actualVservers, sameBeanAs(expectedVservers)); - } - - private String getJson(String filename) throws IOException { - return new String(Files.readAllBytes(Paths.get("src/test/resources/" + filename))); - } -} diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateAAIInventoryTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateAAIInventoryTest.java deleted file mode 100644 index 8226f4fed8..0000000000 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateAAIInventoryTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/*- - * ============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.inventory.create; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import org.camunda.bpm.client.task.ExternalTask; -import org.hamcrest.Matchers; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.onap.so.audit.beans.AuditInventory; -import org.onap.so.client.aai.AAIObjectType; -import org.onap.so.client.aai.AAIResourcesClient; -import org.onap.so.client.aai.entities.uri.AAIResourceUri; -import org.onap.so.client.aai.entities.uri.AAIUriFactory; -import org.onap.so.objects.audit.AAIObjectAuditList; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class CreateAAIInventoryTest extends CreateAAIInventory { - - @InjectMocks - private CreateAAIInventory createAAIInventory = new CreateAAIInventory(); - - @Mock - private ExternalTask mockExternalTask; - - @Mock - private AAIResourcesClient mockClient; - - private ObjectMapper objectMapper = new ObjectMapper(); - - private AuditInventory auditInventory = new AuditInventory(); - - AAIObjectAuditList auditListSuccess; - - AAIObjectAuditList auditListFailure; - - AAIObjectAuditList missingSubInterfaces; - - @Before - public void setup() throws JsonParseException, JsonMappingException, IOException { - auditInventory.setCloudOwner("cloudOwner"); - auditInventory.setCloudRegion("cloudRegion"); - auditInventory.setTenantId("tenantId"); - auditInventory.setHeatStackName("stackName"); - MockitoAnnotations.initMocks(this); - auditListSuccess = objectMapper.readValue(new File("src/test/resources/ExpectedVServerFound.json"), - AAIObjectAuditList.class); - auditListFailure = objectMapper.readValue(new File("src/test/resources/Vserver2_Found_VServer1_Not_Found.json"), - AAIObjectAuditList.class); - missingSubInterfaces = objectMapper.readValue(new File("src/test/resources/AuditResultsMissSub.json"), - AAIObjectAuditList.class); - doReturn(auditInventory).when(mockExternalTask).getVariable("auditInventory"); - } - - @Test - public void determineAuditResult_Test() throws Exception { - boolean actual = createAAIInventory.didAuditFailVserverLInterfaces(auditListSuccess); - assertEquals(false, actual); - } - - @Test - public void determineAuditResult_Failure_Test() throws Exception { - boolean actual = createAAIInventory.didAuditFailVserverLInterfaces(auditListFailure); - assertEquals(true, actual); - } - - @Test - public void missing_Sub_Interfaces_Test() throws Exception { - AAIResourceUri aaiURI2 = AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, "cloudOwner", - "regionOne", "0422ffb57ba042c0800a29dc85ca70f8", "92272b67-d23f-42ca-87fa-7b06a9ec81f3", - "tsbc0005v_tsbc0005vm002_svc1_port_0", "tsbc0005v_tsbc0005vm002_subint_untrusted_svc1_81"); - AAIResourceUri aaiURI1 = AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, "cloudOwner", - "regionOne", "0422ffb57ba042c0800a29dc85ca70f8", "92272b67-d23f-42ca-87fa-7b06a9ec81f3", - "tsbc0005v_tsbc0005vm002_svc2_port_0", "tsbc0005v_tsbc0005vm002_subint_untrusted_svc2_103"); - ArgumentCaptor captor = ArgumentCaptor.forClass(Optional.class); - ArgumentCaptor uriCaptor = ArgumentCaptor.forClass(AAIResourceUri.class); - - createAAIInventory.setAaiClient(mockClient); - createAAIInventory.createInventory(missingSubInterfaces); - Mockito.verify(mockClient, times(2)).createIfNotExists(uriCaptor.capture(), captor.capture()); - - List capturedURI = uriCaptor.getAllValues(); - assertTrue(capturedURI.stream().anyMatch(item -> aaiURI1.build().toString().equals(item.build().toString()))); - assertTrue(capturedURI.stream().anyMatch(item -> aaiURI2.build().toString().equals(item.build().toString()))); - - - - } -} diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java deleted file mode 100644 index c4fa9ee2c5..0000000000 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * ============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.inventory.create; - -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -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.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider; -import org.onap.so.externaltasks.logging.AuditMDCSetup; -import org.onap.so.objects.audit.AAIObjectAudit; -import org.onap.so.objects.audit.AAIObjectAuditList; -import com.fasterxml.jackson.core.JsonProcessingException; - -public class CreateInventoryTaskTest { - - @Mock - ExternalTask externalTask; - - @Mock - CreateAAIInventory createAAIInventory; - - @Mock - ExternalTaskService externalTaskService; - - @Mock - private AuditMDCSetup mdcSetup; - - @InjectMocks - CreateInventoryTask inventoryTask; - - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void test_Runtime_Parse_Exception() { - doReturn(null).when(externalTask).getVariable("auditInventoryResult"); - inventoryTask.executeExternalTask(externalTask, externalTaskService); - Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure"); - } - - @Test - public void testExecuteExternalTask_InventoryException() throws InventoryException, JsonProcessingException { - AAIObjectAuditList object = new AAIObjectAuditList(); - AAIObjectAudit e = new AAIObjectAudit(); - e.setDoesObjectExist(true); - object.getAuditList().add(e); - GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider(); - doReturn(objectMapper.getMapper().writeValueAsString(e)).when(externalTask).getVariable("auditInventoryResult"); - Mockito.doThrow(InventoryException.class).when(createAAIInventory).createInventory(Mockito.any()); - inventoryTask.executeExternalTask(externalTask, externalTaskService); - Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure"); - } -} diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditDataServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditDataServiceTest.java new file mode 100644 index 0000000000..d5f8f865a8 --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditDataServiceTest.java @@ -0,0 +1,102 @@ +package org.onap.so.adapters.tasks.audit; + +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; +import java.util.ArrayList; +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.aai.domain.yang.Vserver; +import org.onap.so.adapters.tasks.audit.AuditDataService; +import org.onap.so.audit.beans.AuditInventory; +import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider; +import org.onap.so.db.request.beans.RequestProcessingData; +import org.onap.so.db.request.client.RequestsDbClient; +import org.onap.so.objects.audit.AAIObjectAudit; +import org.onap.so.objects.audit.AAIObjectAuditList; +import com.fasterxml.jackson.core.JsonProcessingException; + +@RunWith(MockitoJUnitRunner.Silent.class) +public class AuditDataServiceTest { + + @InjectMocks + AuditDataService auditDataService = new AuditDataService(); + + @Mock + protected RequestsDbClient requestsDbClient; + + AuditInventory auditInventory = new AuditInventory(); + + @Before + public void before() throws JsonProcessingException { + auditInventory.setCloudOwner("testCloudOwner"); + auditInventory.setCloudRegion("testLcpCloudRegionId"); + auditInventory.setHeatStackName("testVfModuleName1"); + auditInventory.setVfModuleId("testVnfModuleId"); + auditInventory.setTenantId("testTenantId"); + auditInventory.setGenericVnfId("testVnfId1"); + } + + @Test + public void testWriteStackDataToRequestDb() throws Exception { + Mockito.doReturn(new ArrayList()).when(requestsDbClient) + .getRequestProcessingDataByGroupingIdAndNameAndTag(Mockito.any(), Mockito.any(), Mockito.any()); + Mockito.doNothing().when(requestsDbClient).saveRequestProcessingData(Mockito.any()); + + AAIObjectAuditList auditList = new AAIObjectAuditList(); + auditList.setHeatStackName("testHeatStackName"); + AAIObjectAudit audit = new AAIObjectAudit(); + Vserver vserver = new Vserver(); + vserver.setVserverId("testVserverId"); + audit.setAaiObject(vserver); + auditList.getAuditList().add(audit); + + GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider(); + String auditListString = objectMapper.getMapper().writeValueAsString(auditList);; + + RequestProcessingData requestProcessingData = new RequestProcessingData(); + requestProcessingData.setSoRequestId(auditInventory.getMsoRequestId()); + requestProcessingData.setGroupingId(auditInventory.getVfModuleId()); + requestProcessingData.setName(auditInventory.getHeatStackName()); + requestProcessingData.setTag("AuditStackData"); + requestProcessingData.setValue(auditListString); + + auditDataService.writeStackDataToRequestDb(auditInventory, auditList); + Mockito.verify(requestsDbClient, Mockito.times(1)).saveRequestProcessingData(requestProcessingData); + } + + @Test + public void testGetStackDataToRequestDb() throws Exception { + AAIObjectAuditList auditList = new AAIObjectAuditList(); + auditList.setHeatStackName("testHeatStackName"); + AAIObjectAudit audit = new AAIObjectAudit(); + Vserver vserver = new Vserver(); + vserver.setVserverId("testVserverId"); + audit.setAaiObject(vserver); + auditList.getAuditList().add(audit); + GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider(); + String auditListString = objectMapper.getMapper().writeValueAsString(audit); + + List list = new ArrayList(); + RequestProcessingData requestProcessingData = new RequestProcessingData(); + requestProcessingData.setId(234321432); + requestProcessingData.setGroupingId("testVfModuleId"); + requestProcessingData.setName("heatStackName"); + requestProcessingData.setTag("AuditStackData"); + requestProcessingData.setValue(auditListString); + list.add(requestProcessingData); + + Mockito.doReturn(list).when(requestsDbClient).getRequestProcessingDataByGroupingIdAndNameAndTag(Mockito.any(), + Mockito.any(), Mockito.any()); + auditDataService.getStackDataFromRequestDb(auditInventory); + Mockito.verify(requestsDbClient, Mockito.times(1)).getRequestProcessingDataByGroupingIdAndNameAndTag( + "testVnfModuleId", "testVfModuleName1", "AuditStackData"); + } + +} diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditStackServiceDataTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditStackServiceDataTest.java new file mode 100644 index 0000000000..a10ab4b7df --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditStackServiceDataTest.java @@ -0,0 +1,191 @@ +/*- + * ============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.tasks.audit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.doReturn; +import java.io.File; +import java.io.IOException; +import java.util.Map; +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.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.so.adapters.tasks.audit.AuditCreateStackService; +import org.onap.so.adapters.tasks.audit.AuditDataService; +import org.onap.so.adapters.tasks.audit.AuditQueryStackService; +import org.onap.so.adapters.tasks.audit.HeatStackAudit; +import org.onap.so.audit.beans.AuditInventory; +import org.onap.so.logging.tasks.AuditMDCSetup; +import org.onap.so.objects.audit.AAIObjectAuditList; +import org.springframework.core.env.Environment; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class AuditStackServiceDataTest extends AuditCreateStackService { + + @InjectMocks + private AuditCreateStackService auditStackService = new AuditCreateStackService(); + + @InjectMocks + private AuditQueryStackService auditQueryStackService = new AuditQueryStackService(); + + @Mock + private HeatStackAudit heatStackAuditMock; + + @Mock + private Environment mockEnv; + + @Mock + private ExternalTask mockExternalTask; + + @Mock + private ExternalTaskService mockExternalTaskService; + + @Mock + private AuditDataService auditDataService; + + @Mock + private AuditMDCSetup mdcSetup; + + private ObjectMapper objectMapper = new ObjectMapper(); + + private AuditInventory auditInventory = new AuditInventory(); + + Optional auditListOptSuccess; + + Optional auditListOptFailure; + + @Before + public void setup() throws JsonParseException, JsonMappingException, IOException { + auditInventory.setCloudOwner("cloudOwner"); + auditInventory.setCloudRegion("cloudRegion"); + auditInventory.setTenantId("tenantId"); + auditInventory.setHeatStackName("stackName"); + MockitoAnnotations.initMocks(this); + + AAIObjectAuditList auditListSuccess = objectMapper + .readValue(new File("src/test/resources/ExpectedVServerFound.json"), AAIObjectAuditList.class); + auditListOptSuccess = Optional.of(auditListSuccess); + + AAIObjectAuditList auditListFailure = objectMapper.readValue( + new File("src/test/resources/Vserver2_Found_VServer1_Not_Found.json"), AAIObjectAuditList.class); + auditListOptFailure = Optional.of(auditListFailure); + String[] retrySequence = new String[8]; + retrySequence[0] = "1"; + retrySequence[1] = "1"; + retrySequence[2] = "2"; + retrySequence[3] = "3"; + retrySequence[4] = "5"; + retrySequence[5] = "8"; + retrySequence[6] = "13"; + retrySequence[7] = "20"; + doReturn(auditInventory).when(mockExternalTask).getVariable("auditInventory"); + doReturn("6000").when(mockEnv).getProperty("mso.workflow.topics.retryMultiplier", "6000"); + doReturn(retrySequence).when(mockEnv).getProperty("mso.workflow.topics.retrySequence", String[].class); + doReturn("aasdfasdf").when(mockExternalTask).getId(); + } + + @Test + public void execute_external_task_audit_success_Test() { + doReturn(auditListOptSuccess).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", + "stackName"); + auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); + ArgumentCaptor captor = ArgumentCaptor.forClass(Map.class); + ArgumentCaptor taskCaptor = ArgumentCaptor.forClass(ExternalTask.class); + Mockito.verify(mockExternalTaskService).complete(taskCaptor.capture(), captor.capture()); + Map actualMap = captor.getValue(); + assertEquals(true, actualMap.get("auditIsSuccessful")); + assertNotNull(actualMap.get("auditInventoryResult")); + } + + @Test + public void executeExternalTaskQueryAuditTest() throws JsonProcessingException { + doReturn(auditListOptSuccess).when(heatStackAuditMock).queryHeatStack("cloudOwner", "cloudRegion", "tenantId", + "stackName"); + Mockito.doNothing().when(auditDataService).writeStackDataToRequestDb(Mockito.any(AuditInventory.class), + Mockito.any(AAIObjectAuditList.class)); + auditQueryStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); + ArgumentCaptor captor = ArgumentCaptor.forClass(Map.class); + ArgumentCaptor taskCaptor = ArgumentCaptor.forClass(ExternalTask.class); + Mockito.verify(mockExternalTaskService).complete(taskCaptor.capture(), captor.capture()); + Mockito.verify(auditDataService).writeStackDataToRequestDb(Mockito.any(AuditInventory.class), + Mockito.any(AAIObjectAuditList.class)); + } + + @Test + public void execute_external_task_audit_first_failure_Test() { + doReturn(auditListOptFailure).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(auditListOptFailure).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(auditListOptFailure).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", + "stackName"); + doReturn(1).when(mockExternalTask).getRetries(); + auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); + ArgumentCaptor captor = ArgumentCaptor.forClass(Map.class); + ArgumentCaptor taskCaptor = ArgumentCaptor.forClass(ExternalTask.class); + Mockito.verify(mockExternalTaskService).complete(taskCaptor.capture(), captor.capture()); + Map actualMap = captor.getValue(); + assertEquals(false, actualMap.get("auditIsSuccessful")); + assertNotNull(actualMap.get("auditInventoryResult")); + } + + @Test + public void determineAuditResult_Test() throws Exception { + boolean actual = auditStackService.didCreateAuditFail(auditListOptSuccess); + assertEquals(false, actual); + } + + @Test + public void determineAuditResult_Failure_Test() throws Exception { + boolean actual = auditStackService.didCreateAuditFail(auditListOptFailure); + assertEquals(true, actual); + } +} diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditVServerTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditVServerTest.java new file mode 100644 index 0000000000..af4afd41a1 --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditVServerTest.java @@ -0,0 +1,433 @@ +/*- + * ============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 perservice2sions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.tasks.audit; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +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.VfModule; +import org.onap.aai.domain.yang.VfModules; +import org.onap.aai.domain.yang.Vserver; +import org.onap.so.adapters.tasks.audit.AuditVServer; +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 org.onap.so.objects.audit.AAIObjectAudit; +import org.onap.so.objects.audit.AAIObjectAuditList; +import org.skyscreamer.jsonassert.JSONAssert; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +@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(AAIObjectType.L_INTERFACE, + cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_trusted_port_0"); + + private AAIResourceUri ssc_1_service1_port_0_uri = AAIUriFactory.createResourceUri(AAIObjectType.L_INTERFACE, + cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_service1_port_0"); + + private AAIResourceUri ssc_1_mgmt_port_1_uri = AAIUriFactory.createResourceUri(AAIObjectType.L_INTERFACE, + cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_mgmt_port_1"); + + private AAIResourceUri ssc_1_mgmt_port_0_uri = AAIUriFactory.createResourceUri(AAIObjectType.L_INTERFACE, + cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_mgmt_port_0"); + + private AAIResourceUri ssc_1_service2_port_0_uri = AAIUriFactory.createResourceUri(AAIObjectType.L_INTERFACE, + cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_service2_port_0"); + + private AAIResourceUri ssc_1_int_ha_port_0_uri = AAIUriFactory.createResourceUri(AAIObjectType.L_INTERFACE, + cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_int_ha_port_0"); + + private AAIResourceUri test_port_1_uri = AAIUriFactory.createResourceUri(AAIObjectType.L_INTERFACE, cloudOwner, + cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4dz", "test_port_1"); + + private AAIResourceUri test_port_2_uri = AAIUriFactory.createResourceUri(AAIObjectType.L_INTERFACE, cloudOwner, + cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4dz", "test_port_2"); + + private AAIResourceUri service2_sub_1_uri = + AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, cloudOwner, cloudRegion, tenantId, + "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_service2_port_0", "service2_sub_interface_1"); + + private AAIResourceUri service1_sub_0_uri = + AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, cloudOwner, cloudRegion, tenantId, + "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_service1_port_0", "service1_sub_interface_1"); + + private AAIResourceUri service1_sub_1_uri = + AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, cloudOwner, cloudRegion, tenantId, + "3a4c2ca5-27b3-4ecc-98c5-06804867c4db", "ssc_1_service1_port_0", "service1_sub_interface_2"); + + + + private Set 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 service2_sub_interface_1 = new LInterface(); + LInterface ssc_1_service2_port_0 = new LInterface(); + LInterface ssc_1_mgmt_port_0 = new LInterface(); + LInterface ssc_1_mgmt_port_1 = new LInterface(); + LInterface service1_sub_interface_2 = new LInterface(); + LInterface service1_sub_interface_1 = new LInterface(); + LInterface ssc_1_service1_port_0 = new LInterface(); + LInterface ssc_1_trusted_port_0 = new LInterface(); + + + + @Before + public void setup() { + objectMapper.setSerializationInclusion(Include.NON_NULL); + 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("ssc_1_trusted_port_0"); + vServer1.getLInterfaces().getLInterface().add(ssc_1_trusted_port_0); + + + ssc_1_service1_port_0.setInterfaceId("1c56a24b-5f03-435a-850d-31cd4252de56"); + ssc_1_service1_port_0.setInterfaceName("ssc_1_service1_port_0"); + vServer1.getLInterfaces().getLInterface().add(ssc_1_service1_port_0); + ssc_1_service1_port_0.setLInterfaces(new LInterfaces()); + + + service1_sub_interface_1.setInterfaceId("0d9cd813-2ae1-46c0-9ebb-48081f6cffbb"); + service1_sub_interface_1.setInterfaceName("service1_sub_interface_1"); + ssc_1_service1_port_0.getLInterfaces().getLInterface().add(service1_sub_interface_1); + + + service1_sub_interface_2.setInterfaceId("b7019dd0-2ee9-4447-bdef-ac25676b205a"); + service1_sub_interface_2.setInterfaceName("service1_sub_interface_2"); + ssc_1_service1_port_0.getLInterfaces().getLInterface().add(service1_sub_interface_2); + + + ssc_1_mgmt_port_1.setInterfaceId("12afcd28-929f-4d80-8a5a-0833bfd5e20b"); + ssc_1_mgmt_port_1.setInterfaceName("ssc_1_mgmt_port_1"); + 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("ssc_1_mgmt_port_0"); + vServer1.getLInterfaces().getLInterface().add(ssc_1_mgmt_port_0); + + + ssc_1_service2_port_0.setLInterfaces(new LInterfaces()); + ssc_1_service2_port_0.setInterfaceId("13eddf95-4cf3-45f2-823a-2d890a6549b4"); + ssc_1_service2_port_0.setInterfaceName("ssc_1_service2_port_0"); + vServer1.getLInterfaces().getLInterface().add(ssc_1_service2_port_0); + + + service2_sub_interface_1.setInterfaceId("f711be16-2654-4a09-b89d-0511fda20e81"); + service2_sub_interface_1.setInterfaceName("service2_sub_interface_1"); + ssc_1_service2_port_0.getLInterfaces().getLInterface().add(service2_sub_interface_1); + + + ssc_1_int_ha_port_0.setInterfaceId("9cab2903-70f7-44fd-b681-491d6ae2adb8"); + ssc_1_int_ha_port_0.setInterfaceName("ssc_1_int_ha_port_0"); + 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("test_port_1"); + + + test_port_2.setInterfaceId("9cab2903-70f7-44fd-b681-491d6ae2adz2"); + test_port_2.setInterfaceName("test_port_2"); + + vServer2.getLInterfaces().getLInterface().add(test_port_1); + vServer2.getLInterfaces().getLInterface().add(test_port_2); + + vserversToAudit.add(vServer1); + vserversToAudit.add(vServer2); + } + + @Test + public void audit_Vserver_Empty_HashSet() throws JsonParseException, JsonMappingException, IOException { + Optional actual = + auditNova.auditVservers(new HashSet(), tenantId, cloudOwner, cloudRegion); + assertEquals(Optional.empty(), actual); + } + + @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)).when(aaiResourcesMock).get(LInterface.class, + ssc_1_trusted_port_0_uri); + doReturn(Optional.of(ssc_1_service1_port_0)).when(aaiResourcesMock).get(LInterface.class, + ssc_1_service1_port_0_uri); + doReturn(Optional.of(ssc_1_mgmt_port_1)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_1_uri); + doReturn(Optional.of(ssc_1_mgmt_port_0)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_0_uri); + doReturn(Optional.of(ssc_1_service2_port_0)).when(aaiResourcesMock).get(LInterface.class, + ssc_1_service2_port_0_uri); + doReturn(Optional.of(service2_sub_interface_1)).when(aaiResourcesMock).get(LInterface.class, + service1_sub_1_uri); + doReturn(Optional.of(ssc_1_int_ha_port_0)).when(aaiResourcesMock).get(LInterface.class, + ssc_1_int_ha_port_0_uri); + doReturn(Optional.of(test_port_1)).when(aaiResourcesMock).get(LInterface.class, test_port_1_uri); + doReturn(Optional.of(test_port_2)).when(aaiResourcesMock).get(LInterface.class, test_port_2_uri); + + doReturn(true).when(aaiResourcesMock).exists(service2_sub_1_uri); + doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri); + doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri); + + Optional actual = + auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + String actualString = objectMapper.writeValueAsString(actual.get()); + String expected = getJson("ExpectedVServerFound.json"); + JSONAssert.assertEquals(expected, actualString, false); + } + + @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)).when(aaiResourcesMock).get(LInterface.class, + ssc_1_trusted_port_0_uri); + doReturn(Optional.of(ssc_1_service1_port_0)).when(aaiResourcesMock).get(LInterface.class, + ssc_1_service1_port_0_uri); + doReturn(Optional.of(ssc_1_mgmt_port_1)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_1_uri); + doReturn(Optional.empty()).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_0_uri); + doReturn(Optional.of(ssc_1_service2_port_0)).when(aaiResourcesMock).get(LInterface.class, + ssc_1_service2_port_0_uri); + doReturn(Optional.of(ssc_1_int_ha_port_0)).when(aaiResourcesMock).get(LInterface.class, + ssc_1_int_ha_port_0_uri); + doReturn(Optional.of(test_port_1)).when(aaiResourcesMock).get(LInterface.class, test_port_1_uri); + doReturn(Optional.of(test_port_2)).when(aaiResourcesMock).get(LInterface.class, test_port_2_uri); + + doReturn(true).when(aaiResourcesMock).exists(service2_sub_1_uri); + doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri); + doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri); + + Optional actual = + auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + String actualString = objectMapper.writeValueAsString(actual.get()); + String expected = getJson("VServer_Found_network_Not_Found.json"); + JSONAssert.assertEquals(expected, actualString, false); + } + + @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)).when(aaiResourcesMock).get(LInterface.class, + ssc_1_trusted_port_0_uri); + doReturn(Optional.of(ssc_1_service1_port_0)).when(aaiResourcesMock).get(LInterface.class, + ssc_1_service1_port_0_uri); + doReturn(Optional.of(ssc_1_mgmt_port_1)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_1_uri); + doReturn(Optional.of(ssc_1_mgmt_port_0)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_0_uri); + doReturn(Optional.of(ssc_1_service2_port_0)).when(aaiResourcesMock).get(LInterface.class, + ssc_1_service2_port_0_uri); + doReturn(Optional.of(ssc_1_int_ha_port_0)).when(aaiResourcesMock).get(LInterface.class, + ssc_1_int_ha_port_0_uri); + doReturn(Optional.of(test_port_1)).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(service2_sub_1_uri); + doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri); + doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri); + Optional actual = + auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + String actualString = objectMapper.writeValueAsString(actual.get()); + String expected = getJson("VServer_Found_Network_Sec_Server_Not_Found.json"); + JSONAssert.assertEquals(expected, actualString, false); + } + + @Test + public void audit_Vserver_Not_Found_Test() throws JsonParseException, JsonMappingException, IOException { + doReturn(false).when(aaiResourcesMock).exists(vserverURI); + doReturn(false).when(aaiResourcesMock).exists(vserverURI2); + Optional actual = + auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + String actualString = objectMapper.writeValueAsString(actual.get()); + String expected = getJson("Vservers_Not_Found.json"); + JSONAssert.assertEquals(expected, actualString, false); + } + + @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)).when(aaiResourcesMock).get(LInterface.class, test_port_1_uri); + doReturn(Optional.of(test_port_2)).when(aaiResourcesMock).get(LInterface.class, test_port_2_uri); + Optional actual = + auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + String actualString = objectMapper.writeValueAsString(actual.get()); + String expected = getJson("Vserver2_Found_VServer1_Not_Found.json"); + JSONAssert.assertEquals(expected, actualString, false); + } + + + @Test + public void doesSubInterfaceExistinAAI_Test() { + AAIResourceUri subInterfaceURI = AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, cloudOwner, + cloudRegion, tenantId, "vserverId", "l-interface", "sub-interface"); + + assertEquals( + "/cloud-infrastructure/cloud-regions/cloud-region/cloudOwner/cloudRegion/tenants/tenant/tenantId/vservers/vserver/vserverId/l-interfaces/l-interface/l-interface/l-interfaces/l-interface/sub-interface", + subInterfaceURI.build().toString()); + } + + @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)).when(aaiResourcesMock).get(LInterface.class, + ssc_1_trusted_port_0_uri); + doReturn(Optional.of(ssc_1_service1_port_0)).when(aaiResourcesMock).get(LInterface.class, + ssc_1_service1_port_0_uri); + doReturn(Optional.of(ssc_1_mgmt_port_1)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_1_uri); + doReturn(Optional.of(ssc_1_mgmt_port_0)).when(aaiResourcesMock).get(LInterface.class, ssc_1_mgmt_port_0_uri); + doReturn(Optional.of(ssc_1_service2_port_0)).when(aaiResourcesMock).get(LInterface.class, + ssc_1_service2_port_0_uri); + doReturn(Optional.of(ssc_1_int_ha_port_0)).when(aaiResourcesMock).get(LInterface.class, + ssc_1_int_ha_port_0_uri); + doReturn(Optional.empty()).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(service2_sub_1_uri); + doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri); + doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri); + + doReturn(false).when(aaiResourcesMock).exists(vserverURI2); + Optional actual = + auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + String actualString = objectMapper.writeValueAsString(actual.get()); + String expected = getJson("VServer_Found_Sec_Server_Not_Found2.json"); + + JSONAssert.assertEquals(expected, actualString, false); + } + + @Test + public void testAuditVserversWithList() { + + AAIObjectAuditList auditList = new AAIObjectAuditList(); + AAIObjectAudit obj1 = new AAIObjectAudit(); + Vserver vserver = new Vserver(); + vserver.setVserverId("testVserverId"); + obj1.setAaiObject(vserver); + obj1.setResourceURI(AAIUriFactory + .createResourceUri(AAIObjectType.VSERVER, cloudOwner, cloudRegion, tenantId, "testVserverId").build()); + auditList.getAuditList().add(obj1); + + doReturn(false).when(aaiResourcesMock).exists(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner, + cloudRegion, tenantId, "testVserverId")); + + auditNova.auditVservers(auditList); + + Mockito.verify(aaiResourcesMock).exists(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner, + cloudRegion, tenantId, "testVserverId")); + + Assert.assertEquals(false, auditList.getAuditList().get(0).isDoesObjectExist()); + } + + @Test + public void testAuditVserversThroughRelationships() { + + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("id"); + + AAIResultWrapper wrapper = new AAIResultWrapper(vfModule); + + doReturn(Optional.of(wrapper)).when(aaiResourcesMock).getFirstWrapper(VfModules.class, VfModule.class, + AAIUriFactory.createResourceUri(AAIObjectPlurals.VF_MODULE, "genericVnfId").queryParam("vf-module-name", + "vfModuleName")); + + Optional auditList = + auditNova.auditVserversThroughRelationships("genericVnfId", "vfModuleName"); + + Assert.assertTrue(auditList.get().getAuditList().isEmpty()); + } + + @Test + public void testAuditVserversThroughRelationships_exists() throws IOException { + + String vfModule = getJson("vfModule.json"); + + AAIResultWrapper wrapper = new AAIResultWrapper(vfModule); + AAIResultWrapper vserverWrapper = new AAIResultWrapper(new Vserver()); + + doReturn(Optional.of(wrapper)).when(aaiResourcesMock).getFirstWrapper(VfModules.class, VfModule.class, + AAIUriFactory.createResourceUri(AAIObjectPlurals.VF_MODULE, "genericVnfId").queryParam("vf-module-name", + "vfModuleName")); + + doReturn(vserverWrapper).when(aaiResourcesMock).get(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, + "cloud-owner", "cloud-region-id", "tenant-id", "VUSCHGA1")); + + Optional auditList = + auditNova.auditVserversThroughRelationships("genericVnfId", "vfModuleName"); + + Assert.assertFalse(auditList.get().getAuditList().isEmpty()); + } + + + private String getJson(String filename) throws IOException { + return new String(Files.readAllBytes(Paths.get("src/test/resources/" + filename))); + } + + + +} diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/HeatStackAuditTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/HeatStackAuditTest.java new file mode 100644 index 0000000000..d1d0d96042 --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/HeatStackAuditTest.java @@ -0,0 +1,298 @@ +/*- + * ============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.tasks.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.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +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.adapters.tasks.audit.AuditVServer; +import org.onap.so.adapters.tasks.audit.HeatStackAudit; +import org.onap.so.objects.audit.AAIObjectAuditList; +import org.onap.so.openstack.utils.MsoHeatUtils; +import org.onap.so.openstack.utils.MsoNeutronUtils; +import org.skyscreamer.jsonassert.JSONAssert; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +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; +import com.woorea.openstack.quantum.model.Port; + + +@RunWith(MockitoJUnitRunner.Silent.class) +public class HeatStackAuditTest extends HeatStackAudit { + + @InjectMocks + private HeatStackAudit heatStackAudit = new HeatStackAudit(); + + @Mock + private MsoHeatUtils msoHeatUtilsMock; + + @Mock + private MsoNeutronUtils neutronUtilsMock; + + @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) + .setSerializationInclusion(Include.NON_NULL); + + private ObjectMapper stackObjectMapper = new ObjectMapper() + .configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true).setSerializationInclusion(Include.NON_NULL); + + private List> portList = new ArrayList<>(); + + @Before + public void setup() throws Exception { + resources = objectMapper.readValue(new File("src/test/resources/GetResources.json"), Resources.class); + Port neutronPort1 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort1.json"), Port.class); + doReturn(Optional.of(neutronPort1)).when(neutronUtilsMock) + .getNeutronPort("7ee06d9d-3d18-411c-9d3e-aec930f70413", cloudRegion, tenantId); + Port neutronPort2 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort2.json"), Port.class); + doReturn(Optional.of(neutronPort2)).when(neutronUtilsMock) + .getNeutronPort("27391d94-33af-474a-927d-d409249e8fd3", cloudRegion, tenantId); + Port neutronPort3 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort3.json"), Port.class); + doReturn(Optional.of(neutronPort3)).when(neutronUtilsMock) + .getNeutronPort("fdeedf37-c01e-4ab0-bdd6-8d5fc4913943", cloudRegion, tenantId); + Port neutronPort4 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort4.json"), Port.class); + doReturn(Optional.of(neutronPort4)).when(neutronUtilsMock) + .getNeutronPort("8d93f63e-e972-48c7-ad98-b2122da47315", cloudRegion, tenantId); + Port neutronPort5 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort5.json"), Port.class); + doReturn(Optional.of(neutronPort5)).when(neutronUtilsMock) + .getNeutronPort("0594a2f2-7ea4-42eb-abc2-48ea49677fca", cloudRegion, tenantId); + Port neutronPort6 = stackObjectMapper.readValue(new File("src/test/resources/NeutronPort6.json"), Port.class); + doReturn(Optional.of(neutronPort6)).when(neutronUtilsMock) + .getNeutronPort("00bb8407-650e-48b5-b919-33b88d6f8fe3", cloudRegion, tenantId); + + + portList.add(Optional.empty()); + portList.add(Optional.of(neutronPort1)); + portList.add(Optional.of(neutronPort2)); + portList.add(Optional.of(neutronPort3)); + portList.add(Optional.of(neutronPort4)); + portList.add(Optional.of(neutronPort5)); + portList.add(Optional.of(neutronPort6)); + } + + @Test + public void extract_proper_path_Test() { + Optional actualResult = extractStackPathFromHref( + "https://orchestration.com:8004/v1/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81"); + assertEquals("/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81", actualResult.get()); + } + + @Test + public void extract_proper_resources_path_Test() { + Optional actualResult = extractResourcePathFromHref( + "https://orchestration.com:8004/v1/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81"); + assertEquals("/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81/resources", actualResult.get()); + } + + @Test + public void extract_invalid_uri_Test() { + Optional 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 novaResources = resources.getList().stream().filter(p -> "OS::Nova::Server".equals(p.getType())) + .collect(Collectors.toList()); + + List resourceGroups = resources.getList().stream() + .filter(p -> "OS::Heat::ResourceGroup".equals(p.getType())).collect(Collectors.toList()); + + Resources service1QueryResponse = objectMapper + .readValue(new File("src/test/resources/Service1ResourceGroupResponse.json"), Resources.class); + doReturn(service1QueryResponse).when(msoHeatUtilsMock).executeHeatClientRequest( + "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz/31d0647a-6043-49a4-81b6-ccab29380672/resources", + cloudRegion, tenantId, Resources.class); + + Resources service2QueryResponse = objectMapper + .readValue(new File("src/test/resources/Service2ResourceGroupResponse.json"), Resources.class); + doReturn(service2QueryResponse).when(msoHeatUtilsMock).executeHeatClientRequest( + "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service2_port_0_subinterfaces-hlzdigtimzst/447a9b41-714e-434b-b1d0-6cce8d9f0f0c/resources", + cloudRegion, tenantId, Resources.class); + + + Stack service2StackQuerySubInt = + stackObjectMapper.readValue(new File("src/test/resources/Service2SubInterface0.json"), Stack.class); + doReturn(service2StackQuerySubInt).when(msoHeatUtilsMock).executeHeatClientRequest( + "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service2_port_0_subinterfaces-hlzdigtimzst-0-upfi5nhurk7y/f711be16-2654-4a09-b89d-0511fda20e81", + cloudRegion, tenantId, Stack.class); + Resources service2ResourceQuerySubInt = objectMapper + .readValue(new File("src/test/resources/Service2SubInterface1Resources.json"), Resources.class); + doReturn(service2ResourceQuerySubInt).when(msoHeatUtilsMock).executeHeatClientRequest( + "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service2_port_0_subinterfaces-hlzdigtimzst-0-upfi5nhurk7y/f711be16-2654-4a09-b89d-0511fda20e81/resources", + cloudRegion, tenantId, Resources.class); + + Stack service1StackQuerySubInt1 = + stackObjectMapper.readValue(new File("src/test/resources/Service1SubInterface0.json"), Stack.class); + doReturn(service1StackQuerySubInt1).when(msoHeatUtilsMock).executeHeatClientRequest( + "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-1-fmn5laetg5cs/0d9cd813-2ae1-46c0-9ebb-48081f6cffbb", + cloudRegion, tenantId, Stack.class); + Resources service1ResourceQuerySubInt1 = objectMapper + .readValue(new File("src/test/resources/Service1SubInterface0Resources.json"), Resources.class); + doReturn(service1ResourceQuerySubInt1).when(msoHeatUtilsMock).executeHeatClientRequest( + "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-1-fmn5laetg5cs/0d9cd813-2ae1-46c0-9ebb-48081f6cffbb/resources", + cloudRegion, tenantId, Resources.class); + + + Stack service1StackQuerySubInt2 = + stackObjectMapper.readValue(new File("src/test/resources/Service1SubInterface1.json"), Stack.class); + doReturn(service1StackQuerySubInt2).when(msoHeatUtilsMock).executeHeatClientRequest( + "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-0-yghihziaf36m/b7019dd0-2ee9-4447-bdef-ac25676b205a", + cloudRegion, tenantId, Stack.class); + Resources service1ResourceQuerySubInt2 = objectMapper + .readValue(new File("src/test/resources/Service1SubInterface1Resources.json"), Resources.class); + doReturn(service1ResourceQuerySubInt2).when(msoHeatUtilsMock).executeHeatClientRequest( + "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-0-yghihziaf36m/b7019dd0-2ee9-4447-bdef-ac25676b205a/resources", + cloudRegion, tenantId, Resources.class); + + Stack service1StackQuerySubInt3 = + stackObjectMapper.readValue(new File("src/test/resources/Service1SubInterface2.json"), Stack.class); + doReturn(service1StackQuerySubInt3).when(msoHeatUtilsMock).executeHeatClientRequest( + "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-2-y3ndsavmsymv/bd0fc728-cbde-4301-a581-db56f494675c", + cloudRegion, tenantId, Stack.class); + Resources service1ResourceQuerySubInt3 = objectMapper + .readValue(new File("src/test/resources/Service1SubInterface2Resources.json"), Resources.class); + doReturn(service1ResourceQuerySubInt3).when(msoHeatUtilsMock).executeHeatClientRequest( + "/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-2-y3ndsavmsymv/bd0fc728-cbde-4301-a581-db56f494675c/resources", + cloudRegion, tenantId, Resources.class); + + Set vServersToAudit = heatStackAudit.createVserverSet(resources, novaResources, portList); + Set vserversWithSubInterfaces = + heatStackAudit.processSubInterfaces(cloudRegion, tenantId, resourceGroups, vServersToAudit); + + String actualValue = objectMapper.writeValueAsString(vserversWithSubInterfaces); + String expectedValue = getJson("ExpectedVserversToAudit.json"); + JSONAssert.assertEquals(expectedValue, actualValue, false); + } + + @Test + public void auditHeatStackNoServers_Test() throws Exception { + Resources getResource = objectMapper + .readValue(new File("src/test/resources/Service1ResourceGroupResponse.json"), Resources.class); + doReturn(getResource).when(msoHeatUtilsMock).queryStackResources(cloudRegion, tenantId, "heatStackName", 3); + + Optional actual = + heatStackAudit.auditHeatStack(cloudRegion, "cloudOwner", tenantId, "heatStackName"); + assertEquals(true, actual.get().getAuditList().isEmpty()); + } + + @Test + public void auditHeatStackNestedServers_Test() throws Exception { + Resources getResource = + objectMapper.readValue(new File("src/test/resources/GetNestedResources.json"), Resources.class); + List novaResources = getResource.getList().stream() + .filter(p -> "OS::Nova::Server".equals(p.getType())).collect(Collectors.toList()); + List resourceGroups = getResource.getList().stream() + .filter(p -> "OS::Heat::ResourceGroup".equals(p.getType())).collect(Collectors.toList()); + + doReturn(getResource).when(msoHeatUtilsMock).queryStackResources(cloudRegion, tenantId, "heatStackName", 3); + Set vServersToAudit = heatStackAudit.createVserverSet(resources, novaResources, portList); + Set vserversWithSubInterfaces = + heatStackAudit.processSubInterfaces(cloudRegion, tenantId, resourceGroups, vServersToAudit); + String actualValue = objectMapper.writeValueAsString(vserversWithSubInterfaces); + String expectedValue = getJson("NestedExpectedValue.json"); + JSONAssert.assertEquals(expectedValue, actualValue, false); + } + + + @Test + public void findInterfaceInformation_Test() { + List novaResources = resources.getList().stream().filter(p -> "OS::Nova::Server".equals(p.getType())) + .collect(Collectors.toList()); + Set 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("7ee06d9d-3d18-411c-9d3e-aec930f70413"); + ssc_1_trusted_port_0.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port"); + vServer1.getLInterfaces().getLInterface().add(ssc_1_trusted_port_0); + + LInterface ssc_1_svc2_port_0 = new LInterface(); + ssc_1_svc2_port_0.setInterfaceId("27391d94-33af-474a-927d-d409249e8fd3"); + ssc_1_svc2_port_0.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port"); + vServer1.getLInterfaces().getLInterface().add(ssc_1_svc2_port_0); + + LInterface ssc_1_mgmt_port_1 = new LInterface(); + ssc_1_mgmt_port_1.setInterfaceId("fdeedf37-c01e-4ab0-bdd6-8d5fc4913943"); + ssc_1_mgmt_port_1.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port"); + 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"); + ssc_1_mgmt_port_0.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port"); + vServer1.getLInterfaces().getLInterface().add(ssc_1_mgmt_port_0); + + LInterface ssc_1_svc1_port_0 = new LInterface(); + ssc_1_svc1_port_0.setInterfaceId("0594a2f2-7ea4-42eb-abc2-48ea49677fca"); + ssc_1_svc1_port_0.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port"); + vServer1.getLInterfaces().getLInterface().add(ssc_1_svc1_port_0); + + LInterface ssc_1_int_ha_port_0 = new LInterface(); + ssc_1_int_ha_port_0.setInterfaceId("00bb8407-650e-48b5-b919-33b88d6f8fe3"); + ssc_1_int_ha_port_0.setInterfaceName("ibcx0026v_ibcx0026vm003_untrusted_port"); + vServer1.getLInterfaces().getLInterface().add(ssc_1_int_ha_port_0); + + expectedVservers.add(vServer1); + + Set actualVservers = heatStackAudit.createVserverSet(resources, novaResources, portList); + + assertThat(actualVservers, sameBeanAs(expectedVservers)); + } + + private String getJson(String filename) throws IOException { + return new String(Files.readAllBytes(Paths.get("src/test/resources/" + filename))); + } +} diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventoryTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventoryTest.java new file mode 100644 index 0000000000..e822f65072 --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateAAIInventoryTest.java @@ -0,0 +1,123 @@ +/*- + * ============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.tasks.inventory; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import org.camunda.bpm.client.task.ExternalTask; +import org.hamcrest.Matchers; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.so.adapters.tasks.inventory.CreateAAIInventory; +import org.onap.so.audit.beans.AuditInventory; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.uri.AAIResourceUri; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; +import org.onap.so.objects.audit.AAIObjectAuditList; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class CreateAAIInventoryTest extends CreateAAIInventory { + + @InjectMocks + private CreateAAIInventory createAAIInventory = new CreateAAIInventory(); + + @Mock + private ExternalTask mockExternalTask; + + @Mock + private AAIResourcesClient mockClient; + + private ObjectMapper objectMapper = new ObjectMapper(); + + private AuditInventory auditInventory = new AuditInventory(); + + AAIObjectAuditList auditListSuccess; + + AAIObjectAuditList auditListFailure; + + AAIObjectAuditList missingSubInterfaces; + + @Before + public void setup() throws JsonParseException, JsonMappingException, IOException { + auditInventory.setCloudOwner("cloudOwner"); + auditInventory.setCloudRegion("cloudRegion"); + auditInventory.setTenantId("tenantId"); + auditInventory.setHeatStackName("stackName"); + MockitoAnnotations.initMocks(this); + auditListSuccess = objectMapper.readValue(new File("src/test/resources/ExpectedVServerFound.json"), + AAIObjectAuditList.class); + auditListFailure = objectMapper.readValue(new File("src/test/resources/Vserver2_Found_VServer1_Not_Found.json"), + AAIObjectAuditList.class); + missingSubInterfaces = objectMapper.readValue(new File("src/test/resources/AuditResultsMissSub.json"), + AAIObjectAuditList.class); + doReturn(auditInventory).when(mockExternalTask).getVariable("auditInventory"); + } + + @Test + public void determineAuditResult_Test() throws Exception { + boolean actual = createAAIInventory.didAuditFailVserverLInterfaces(auditListSuccess); + assertEquals(false, actual); + } + + @Test + public void determineAuditResult_Failure_Test() throws Exception { + boolean actual = createAAIInventory.didAuditFailVserverLInterfaces(auditListFailure); + assertEquals(true, actual); + } + + @Test + public void missing_Sub_Interfaces_Test() throws Exception { + AAIResourceUri aaiURI2 = AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, "cloudOwner", + "regionOne", "0422ffb57ba042c0800a29dc85ca70f8", "92272b67-d23f-42ca-87fa-7b06a9ec81f3", + "tsbc0005v_tsbc0005vm002_svc1_port_0", "tsbc0005v_tsbc0005vm002_subint_untrusted_svc1_81"); + AAIResourceUri aaiURI1 = AAIUriFactory.createResourceUri(AAIObjectType.SUB_L_INTERFACE, "cloudOwner", + "regionOne", "0422ffb57ba042c0800a29dc85ca70f8", "92272b67-d23f-42ca-87fa-7b06a9ec81f3", + "tsbc0005v_tsbc0005vm002_svc2_port_0", "tsbc0005v_tsbc0005vm002_subint_untrusted_svc2_103"); + ArgumentCaptor captor = ArgumentCaptor.forClass(Optional.class); + ArgumentCaptor uriCaptor = ArgumentCaptor.forClass(AAIResourceUri.class); + + createAAIInventory.setAaiClient(mockClient); + createAAIInventory.createInventory(missingSubInterfaces); + Mockito.verify(mockClient, times(2)).createIfNotExists(uriCaptor.capture(), captor.capture()); + + List capturedURI = uriCaptor.getAllValues(); + assertTrue(capturedURI.stream().anyMatch(item -> aaiURI1.build().toString().equals(item.build().toString()))); + assertTrue(capturedURI.stream().anyMatch(item -> aaiURI2.build().toString().equals(item.build().toString()))); + + + + } +} diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTaskTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTaskTest.java new file mode 100644 index 0000000000..fc2baefcd5 --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/inventory/CreateInventoryTaskTest.java @@ -0,0 +1,83 @@ +/*- + * ============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.tasks.inventory; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +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.so.adapters.tasks.inventory.CreateAAIInventory; +import org.onap.so.adapters.tasks.inventory.CreateInventoryTask; +import org.onap.so.adapters.tasks.inventory.InventoryException; +import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider; +import org.onap.so.logging.tasks.AuditMDCSetup; +import org.onap.so.objects.audit.AAIObjectAudit; +import org.onap.so.objects.audit.AAIObjectAuditList; +import com.fasterxml.jackson.core.JsonProcessingException; + +public class CreateInventoryTaskTest { + + @Mock + ExternalTask externalTask; + + @Mock + CreateAAIInventory createAAIInventory; + + @Mock + ExternalTaskService externalTaskService; + + @InjectMocks + CreateInventoryTask inventoryTask; + + @Mock + private AuditMDCSetup mdcSetup; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void test_Runtime_Parse_Exception() { + doReturn(null).when(externalTask).getVariable("auditInventoryResult"); + inventoryTask.executeExternalTask(externalTask, externalTaskService); + Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure"); + } + + @Test + public void testExecuteExternalTask_InventoryException() throws InventoryException, JsonProcessingException { + AAIObjectAuditList object = new AAIObjectAuditList(); + AAIObjectAudit e = new AAIObjectAudit(); + e.setDoesObjectExist(true); + object.getAuditList().add(e); + GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider(); + doReturn(objectMapper.getMapper().writeValueAsString(e)).when(externalTask).getVariable("auditInventoryResult"); + Mockito.doThrow(InventoryException.class).when(createAAIInventory).createInventory(Mockito.any()); + inventoryTask.executeExternalTask(externalTask, externalTaskService); + Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure"); + } +} diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/PollServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/PollServiceTest.java new file mode 100644 index 0000000000..b5b0f5a8ef --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/PollServiceTest.java @@ -0,0 +1,82 @@ +package org.onap.so.adapters.tasks.orchestration; + +import org.camunda.bpm.client.task.ExternalTask; +import org.camunda.bpm.client.task.ExternalTaskService; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.eq; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.adapters.tasks.orchestration.PollService; +import org.onap.so.logging.tasks.AuditMDCSetup; +import org.onap.so.openstack.exceptions.MsoException; +import org.onap.so.openstack.utils.MsoHeatUtils; +import com.woorea.openstack.heat.model.Stack; + +@RunWith(MockitoJUnitRunner.class) +public class PollServiceTest { + + private String RESOURCE_PATH = "src/test/resources/__files/"; + + @Mock + private ExternalTask mockExternalTask; + + @Mock + private ExternalTaskService mockExternalTaskService; + + @Mock + private MsoHeatUtils msoHeatUtils; + + @Mock + private AuditMDCSetup mdcSetup; + + @InjectMocks + private PollService pollService; + + @Test + public void testExecuteExternalTask() throws MsoException, IOException { + String xmlString = + new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "/vnfAdapterTaskRequestCreate.xml"))); + + Mockito.when(mockExternalTask.getVariable("vnfAdapterTaskRequest")).thenReturn(xmlString); + Mockito.when(mockExternalTask.getVariable("PollRollbackStatus")).thenReturn(false); + Mockito.when(mockExternalTask.getVariable("stackId")).thenReturn("stackId/stack123"); + Mockito.when(msoHeatUtils.pollStackForStatus(eq(1), any(Stack.class), eq("CREATE_IN_PROGRESS"), eq("regionOne"), + eq("0422ffb57ba042c0800a29dc85ca70f8"), eq(false))).thenReturn(new Stack()); + // Mockito.doNothing().when(msoHeatUtils).postProcessStackCreate(Mockito.any(), Mockito.any(), Mockito.any(), + // Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); + + pollService.executeExternalTask(mockExternalTask, mockExternalTaskService); + + Mockito.verify(msoHeatUtils).pollStackForStatus(eq(1), any(Stack.class), eq("CREATE_IN_PROGRESS"), + eq("regionOne"), eq("0422ffb57ba042c0800a29dc85ca70f8"), eq(false)); + + } + + @Test + public void testExecuteExternalTask_rollback() throws MsoException, IOException { + String xmlString = + new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "/vnfAdapterTaskRequestCreate.xml"))); + + Mockito.when(mockExternalTask.getVariable("vnfAdapterTaskRequest")).thenReturn(xmlString); + Mockito.when(mockExternalTask.getVariable("PollRollbackStatus")).thenReturn(true); + Mockito.when(mockExternalTask.getVariable("stackId")).thenReturn("stackId/stack123"); + Mockito.when(msoHeatUtils.pollStackForStatus(eq(1), any(), eq("DELETE_IN_PROGRESS"), eq("regionOne"), + eq("0422ffb57ba042c0800a29dc85ca70f8"), eq(true))).thenReturn(new Stack()); + Mockito.doNothing().when(msoHeatUtils).postProcessStackDelete(Mockito.any()); + + + pollService.executeExternalTask(mockExternalTask, mockExternalTaskService); + + Mockito.verify(msoHeatUtils).pollStackForStatus(eq(1), any(), eq("DELETE_IN_PROGRESS"), eq("regionOne"), + eq("0422ffb57ba042c0800a29dc85ca70f8"), eq(true)); + + } + +} diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/RollbackServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/RollbackServiceTest.java new file mode 100644 index 0000000000..f7613909ec --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/RollbackServiceTest.java @@ -0,0 +1,82 @@ +package org.onap.so.adapters.tasks.orchestration; + +import static org.junit.Assert.assertEquals; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import javax.xml.ws.Holder; +import org.camunda.bpm.client.task.ExternalTask; +import org.camunda.bpm.client.task.ExternalTaskService; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.adapters.tasks.orchestration.RollbackService; +import org.onap.so.adapters.vnf.MsoVnfAdapterImpl; +import org.onap.so.adapters.vnf.exceptions.VnfException; +import org.onap.so.entity.MsoRequest; +import org.onap.so.logging.tasks.AuditMDCSetup; +import org.onap.so.openstack.beans.VnfRollback; +import org.onap.so.openstack.exceptions.MsoException; +import org.onap.so.openstack.utils.MsoHeatUtils; +import com.woorea.openstack.heat.model.Stack; + +@RunWith(MockitoJUnitRunner.class) +public class RollbackServiceTest { + + private String RESOURCE_PATH = "src/test/resources/__files/"; + + @Mock + private ExternalTask mockExternalTask; + + @Mock + private ExternalTaskService mockExternalTaskService; + + @Mock + private MsoVnfAdapterImpl vnfAdapterImpl; + + @Mock + private MsoHeatUtils msoHeatUtils; + + @Mock + private AuditMDCSetup mdcSetup; + + @InjectMocks + private RollbackService rollbackService; + + + @Test + public void findRequestTypeTest() throws IOException { + String payload = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "/vnfAdapterTaskRequestCreate.xml"))); + + Optional actual = rollbackService.findRequestType(payload); + + assertEquals("createVfModuleRequest", actual.get()); + } + + @Test + public void testExecuteExternalTask() throws VnfException, MsoException, IOException { + String payload = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "/vnfAdapterTaskRequestCreate.xml"))); + + Stack stack = new Stack(); + stack.setId("heatId"); + Mockito.when(mockExternalTask.getVariable("vnfAdapterTaskRequest")).thenReturn(payload); + Mockito.doNothing().when(vnfAdapterImpl).deleteVfModule(Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()); + Mockito.doNothing().when(mockExternalTaskService).complete(Mockito.any(), Mockito.any()); + + rollbackService.executeExternalTask(mockExternalTask, mockExternalTaskService); + + Mockito.verify(vnfAdapterImpl, Mockito.times(1)).deleteVfModule(Mockito.eq("regionOne"), + Mockito.eq("CloudOwner"), Mockito.eq("0422ffb57ba042c0800a29dc85ca70f8"), Mockito.eq("dummy_id"), + Mockito.any(String.class), Mockito.any(String.class), Mockito.any(), Mockito.any(), Mockito.any()); + Mockito.verify(mockExternalTaskService).complete(Mockito.eq(mockExternalTask), Mockito.any()); + + } + +} diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/StackServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/StackServiceTest.java new file mode 100644 index 0000000000..2f583b30a2 --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/orchestration/StackServiceTest.java @@ -0,0 +1,113 @@ +package org.onap.so.adapters.tasks.orchestration; + +import static org.junit.Assert.assertEquals; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import javax.xml.ws.Holder; +import org.camunda.bpm.client.task.ExternalTask; +import org.camunda.bpm.client.task.ExternalTaskService; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.adapters.tasks.orchestration.StackService; +import org.onap.so.adapters.vnf.MsoVnfAdapterImpl; +import org.onap.so.entity.MsoRequest; +import org.onap.so.logging.tasks.AuditMDCSetup; +import org.onap.so.openstack.beans.VnfRollback; +import org.onap.so.openstack.exceptions.MsoException; +import org.onap.so.openstack.utils.MsoHeatUtils; +import com.woorea.openstack.heat.model.Stack; +import org.onap.so.adapters.vnf.exceptions.VnfException; + +@RunWith(MockitoJUnitRunner.class) +public class StackServiceTest { + + private String RESOURCE_PATH = "src/test/resources/__files/"; + + @Mock + private ExternalTask mockExternalTask; + + @Mock + private ExternalTaskService mockExternalTaskService; + + @Mock + private MsoVnfAdapterImpl vnfAdapterImpl; + + @Mock + private MsoHeatUtils msoHeatUtils; + + @Mock + private AuditMDCSetup mdcSetup; + + @InjectMocks + private StackService stackService; + + @Test + public void findRequestTypeTest() throws IOException { + String payload = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "/vnfAdapterTaskRequestCreate.xml"))); + + Optional actual = stackService.findRequestType(payload); + + assertEquals("createVfModuleRequest", actual.get()); + } + + @Test + public void testExecuteExternalTask() throws VnfException, MsoException, IOException { + String payload = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "/vnfAdapterTaskRequestCreate.xml"))); + + Stack stack = new Stack(); + stack.setId("heatId"); + Mockito.when(mockExternalTask.getVariable("vnfAdapterTaskRequest")).thenReturn(payload); + Mockito.doNothing().when(vnfAdapterImpl).createVfModule(Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any(), Mockito.any(), Mockito.any()); + Mockito.doNothing().when(mockExternalTaskService).complete(Mockito.any(), Mockito.any()); + + stackService.executeExternalTask(mockExternalTask, mockExternalTaskService); + + Map paramsMap = new HashMap(); + paramsMap.put("vf_module_id", "985a468b-328b-4c2b-ad0e-b8f1e19501c4"); + paramsMap.put("vnf_id", "6640feba-55f6-4946-9694-4d9558c8870a"); + paramsMap.put("vnf_name", "Robot_VNF_For_Volume_Group"); + paramsMap.put("availability_zone_0", "AZ-MN02"); + paramsMap.put("environment_context", "General_Revenue-Bearing"); + paramsMap.put("user_directives", "{}"); + paramsMap.put("workload_context", ""); + paramsMap.put("vf_module_name", "dummy_id"); + paramsMap.put("vf_module_index", "0"); + paramsMap.put("sdnc_directives", + "{ \"attributes\": [ {\"attribute_name\": \"availability_zone_0\", \"attribute_value\": \"AZ-MN02\"}] }"); + + Map variables = new HashMap<>(); + variables.put("backout", true); + variables.put("WorkflowResponse", ""); + variables.put("OpenstackInvokeSuccess", true); + variables.put("stackId", null); + variables.put("openstackAdapterErrorMessage", null); + variables.put("PollRollbackStatus", false); + variables.put("rollbackPerformed", false); + variables.put("OpenstackRollbackSuccess", false); + variables.put("OpenstackPollSuccess", false); + + Mockito.verify(vnfAdapterImpl, Mockito.times(1)).createVfModule(Mockito.eq("regionOne"), + Mockito.eq("CloudOwner"), Mockito.eq("0422ffb57ba042c0800a29dc85ca70f8"), + Mockito.eq( + "Vf zrdm5bpxmc02092017-Service/Vf zrdm5bpxmc02092017-VF 0::VfZrdm5bpxmc02092017Vf..pxmc_base..module-0"), + Mockito.eq("1.0"), Mockito.eq("6640feba-55f6-4946-9694-4d9558c8870a"), Mockito.eq("dummy_id"), + Mockito.eq("985a468b-328b-4c2b-ad0e-b8f1e19501c4"), Mockito.eq(null), Mockito.eq(null), + Mockito.eq(null), Mockito.eq("074c64d0-7e13-4bcc-8bdb-ea922331102d"), Mockito.eq(paramsMap), + Mockito.eq(false), Mockito.eq(false), Mockito.eq(null), Mockito.any(), Mockito.any(), Mockito.any(), + Mockito.any()); + Mockito.verify(mockExternalTaskService).complete(Mockito.eq(mockExternalTask), Mockito.eq(variables)); + + } + +} -- cgit 1.2.3-korg