diff options
Diffstat (limited to 'adapters/mso-openstack-adapters/src/test/java')
-rw-r--r-- | adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java (renamed from adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditCreateStackServiceTest.java) | 83 | ||||
-rw-r--r-- | adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java | 251 | ||||
-rw-r--r-- | adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java | 95 | ||||
-rw-r--r-- | adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateAAIInventoryTest.java | 122 |
4 files changed, 336 insertions, 215 deletions
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditCreateStackServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java index bcf126d887..29e672a4a6 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditCreateStackServiceTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java @@ -20,16 +20,24 @@ package org.onap.so.adapters.audit; +import static org.hamcrest.CoreMatchers.isA; 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.Arrays; +import java.util.Collection; +import java.util.Map; import java.util.Optional; import org.camunda.bpm.client.task.ExternalTask; import org.camunda.bpm.client.task.ExternalTaskService; +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; @@ -39,48 +47,76 @@ import org.onap.so.audit.beans.AuditInventory; import org.springframework.core.env.Environment; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; -public class AuditCreateStackServiceTest extends AuditCreateStackService { +public class AuditStackServiceDataTest extends AuditStackServiceData { @InjectMocks - AuditCreateStackService auditStackService = new AuditCreateStackService(); + private AuditStackServiceData auditStackService = new AuditStackServiceData(); @Mock - HeatStackAudit heatStackAuditMock; + private HeatStackAudit heatStackAuditMock; @Mock - Environment mockEnv; + private Environment mockEnv; @Mock - ExternalTask mockExternalTask; + private ExternalTask mockExternalTask; @Mock - ExternalTaskService mockExternalTaskService; + private ExternalTaskService mockExternalTaskService; - AuditInventory auditInventory = new AuditInventory(); + private ObjectMapper objectMapper = new ObjectMapper(); + + private AuditInventory auditInventory = new AuditInventory(); + Optional<AAIObjectAuditList> auditListOptSuccess; + + Optional<AAIObjectAuditList> auditListOptFailure; + @Before - public void setup() { + 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(true).when(heatStackAuditMock).auditHeatStackCreate("cloudRegion", "cloudOwner", "tenantId", "stackName"); + doReturn(auditListOptSuccess).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", "stackName"); auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); - Mockito.verify(mockExternalTaskService).complete(mockExternalTask); + ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class); + ArgumentCaptor<ExternalTask> 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 execute_external_task_audit_first_failure_Test() { - doReturn(false).when(heatStackAuditMock).auditHeatStackCreate("cloudRegion", "cloudOwner", "tenantId", "stackName"); + doReturn(auditListOptFailure).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", "stackName"); doReturn(null).when(mockExternalTask).getRetries(); auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); Mockito.verify(mockExternalTaskService).handleFailure(mockExternalTask, @@ -90,7 +126,7 @@ public class AuditCreateStackServiceTest extends AuditCreateStackService { @Test public void execute_external_task_audit_intermediate_failure_Test() { - doReturn(false).when(heatStackAuditMock).auditHeatStackCreate("cloudRegion", "cloudOwner", "tenantId", "stackName"); + doReturn(auditListOptFailure).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", "stackName"); doReturn(6).when(mockExternalTask).getRetries(); auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); Mockito.verify(mockExternalTaskService).handleFailure(mockExternalTask, @@ -101,11 +137,15 @@ public class AuditCreateStackServiceTest extends AuditCreateStackService { @Test public void execute_external_task_audit_final_failure_Test() { - doReturn(false).when(heatStackAuditMock).auditHeatStackCreate("cloudRegion", "cloudOwner", "tenantId", "stackName"); + doReturn(auditListOptFailure).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", "stackName"); doReturn(1).when(mockExternalTask).getRetries(); auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); - Mockito.verify(mockExternalTaskService).handleBpmnError(mockExternalTask, - "AuditAAIInventoryFailure", "Number of Retries Exceeded auditing inventory"); + ArgumentCaptor<Map> captor = ArgumentCaptor.forClass(Map.class); + ArgumentCaptor<ExternalTask> 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 @@ -147,4 +187,17 @@ public class AuditCreateStackServiceTest extends AuditCreateStackService { long eigthRetry = auditStackService.calculateRetryDelay(1); assertEquals(120000L, eigthRetry); } + + + @Test + public void determineAuditResult_Test() throws Exception{ + boolean actual = auditStackService.didAuditFail(auditListOptSuccess); + assertEquals(false, actual); + } + + @Test + public void determineAuditResult_Failure_Test() throws Exception{ + boolean actual = auditStackService.didAuditFail(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 index 9176b58de8..f0fce4db45 100644 --- 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 @@ -13,7 +13,7 @@ * 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 + * See the License for the specific language governing perservice2sions and * limitations under the License. * ============LICENSE_END========================================================= */ @@ -27,6 +27,8 @@ import static org.mockito.Mockito.verify; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.HashSet; import java.util.List; import java.util.Optional; @@ -48,7 +50,9 @@ 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.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; @@ -58,6 +62,8 @@ import com.woorea.openstack.heat.model.Resources; @RunWith(MockitoJUnitRunner.Silent.class) public class AuditVServerTest extends AuditVServer { + private ObjectMapper objectMapper = new ObjectMapper(); + @InjectMocks private AuditVServer auditNova = new AuditVServer(); @@ -74,46 +80,43 @@ public class AuditVServerTest extends AuditVServer { private AAIResourceUri vserverURI2 = AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4dz"); - private AAIResourceUri ssc_1_trusted_port_0_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.L_INTERFACE, - cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db").queryParam("interface-id", "dec8bdc7-5718-41dc-bfbb-561ff6eeb81c"); - - private AAIResourceUri ssc_1_service1_port_0_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.L_INTERFACE, - cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db").queryParam("interface-id", "1c56a24b-5f03-435a-850d-31cd4252de56"); + private AAIResourceUri ssc_1_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_mgmt_port_1_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.L_INTERFACE, - cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db").queryParam("interface-id", "12afcd28-929f-4d80-8a5a-0833bfd5e20b"); + private AAIResourceUri ssc_1_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_0_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.L_INTERFACE, - cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db").queryParam("interface-id", "80baec42-ffae-425f-ad8c-3f7b2c24bfff"); + private AAIResourceUri ssc_1_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_service2_port_0_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.L_INTERFACE, - cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db").queryParam("interface-id", "13eddf95-4cf3-45f2-823a-2d890a6549b4"); + private AAIResourceUri ssc_1_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_int_ha_port_0_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.L_INTERFACE, - cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db").queryParam("interface-id", "9cab2903-70f7-44fd-b681-491d6ae2adb8"); + private AAIResourceUri 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 test_port_1_uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.L_INTERFACE, - cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4dz").queryParam("interface-id", "9cab2903-70f7-44fd-b681-491d6ae2adz1"); + private AAIResourceUri 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(AAIObjectPlurals.L_INTERFACE, - cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4dz").queryParam("interface-id", "9cab2903-70f7-44fd-b681-491d6ae2adz2"); - - + 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(AAIObjectPlurals.SUB_L_INTERFACE, - cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db","interface-name").queryParam("interface-id", "f711be16-2654-4a09-b89d-0511fda20e81"); + 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(AAIObjectPlurals.SUB_L_INTERFACE, - cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db","interface-name").queryParam("interface-id", "0d9cd813-2ae1-46c0-9ebb-48081f6cffbb"); + 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(AAIObjectPlurals.SUB_L_INTERFACE, - cloudOwner, cloudRegion, tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db","interface-name").queryParam("interface-id", "b7019dd0-2ee9-4447-bdef-ac25676b205a"); + 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<Vserver> vserversToAudit = new HashSet<>(); + private Set<Vserver> vserversToAudit = new HashSet<>(); LInterface test_port_1 = new LInterface(); LInterface test_port_2 = new LInterface(); @@ -126,22 +129,12 @@ public class AuditVServerTest extends AuditVServer { LInterface service1_sub_interface_1 = new LInterface(); LInterface ssc_1_service1_port_0 = new LInterface(); LInterface ssc_1_trusted_port_0 = new LInterface(); - - LInterfaces test_port_1_plural = new LInterfaces(); - LInterfaces test_port_2_plural = new LInterfaces(); - LInterfaces ssc_1_int_ha_port_0_plural = new LInterfaces(); - LInterfaces service2_sub_interface_1_plural = new LInterfaces(); - LInterfaces ssc_1_service2_port_0_plural = new LInterfaces(); - LInterfaces ssc_1_mgmt_port_0_plural = new LInterfaces(); - LInterfaces ssc_1_mgmt_port_1_plural = new LInterfaces(); - LInterfaces service1_sub_interface_2_plural = new LInterfaces(); - LInterfaces service1_sub_interface_1_plural = new LInterfaces(); - LInterfaces ssc_1_service1_port_0_plural = new LInterfaces(); - LInterfaces ssc_1_trusted_port_0_plural = new LInterfaces(); + @Before public void setup() { + objectMapper.setSerializationInclusion(Include.NON_NULL); auditNova.setAaiClient(aaiResourcesMock); Vserver vServer1= new Vserver(); @@ -150,109 +143,97 @@ public class AuditVServerTest extends AuditVServer { vServer1.setLInterfaces(vServer1Linterfaces); ssc_1_trusted_port_0.setInterfaceId("dec8bdc7-5718-41dc-bfbb-561ff6eeb81c"); - ssc_1_trusted_port_0.setInterfaceName("interface-name"); + 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("interface-name"); + 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("interface-name"); + 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("interface-name"); + 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("interface-name"); + 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.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("interface-name"); + test_port_1.setInterfaceName("test_port_1"); test_port_2.setInterfaceId("9cab2903-70f7-44fd-b681-491d6ae2adz2"); - test_port_2.setInterfaceName("interface-name"); + 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_port_1_plural.getLInterface().add(test_port_1); - test_port_2_plural.getLInterface().add(test_port_2); - ssc_1_int_ha_port_0_plural.getLInterface().add(ssc_1_int_ha_port_0); - ssc_1_service2_port_0_plural.getLInterface().add(ssc_1_service2_port_0); - ssc_1_mgmt_port_0_plural.getLInterface().add(ssc_1_mgmt_port_0); - ssc_1_mgmt_port_1_plural.getLInterface().add(ssc_1_mgmt_port_1); - ssc_1_service1_port_0_plural.getLInterface().add(ssc_1_service1_port_0); - ssc_1_trusted_port_0_plural.getLInterface().add(ssc_1_trusted_port_0); - } @Test public void audit_Vserver_Empty_HashSet() throws JsonParseException, JsonMappingException, IOException { - boolean exists = auditNova.auditAllVserversDoExist(new HashSet<Vserver>(), tenantId, cloudOwner, cloudRegion); - assertEquals(false, exists); - - boolean doNotExist = auditNova.auditAllVserversDoNotExist(new HashSet<Vserver>(), tenantId, cloudOwner, cloudRegion); - assertEquals(true, doNotExist); + Optional<AAIObjectAuditList> actual = auditNova.auditVservers(new HashSet<Vserver>(), 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_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_trusted_port_0_uri); - doReturn(Optional.of(ssc_1_service1_port_0_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_service1_port_0_uri); - doReturn(Optional.of(ssc_1_mgmt_port_1_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_mgmt_port_1_uri); - doReturn(Optional.of(ssc_1_mgmt_port_0_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_mgmt_port_0_uri); - doReturn(Optional.of(ssc_1_service2_port_0_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_service2_port_0_uri); - doReturn(Optional.of(ssc_1_int_ha_port_0_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_int_ha_port_0_uri); - doReturn(Optional.of(test_port_1_plural)).when(aaiResourcesMock).get(LInterfaces.class,test_port_1_uri); - doReturn(Optional.of(test_port_2_plural)).when(aaiResourcesMock).get(LInterfaces.class,test_port_2_uri); + doReturn(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); - boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); - assertEquals(true, exists); - - boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); - assertEquals(false, doNotExist); + Optional<AAIObjectAuditList> actual = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + String actualString = objectMapper.writeValueAsString(actual.get()); + String expected = getJson("ExpectedVServerFound.json"); + JSONAssert.assertEquals(expected,actualString, false); } @Test @@ -260,24 +241,23 @@ public class AuditVServerTest extends AuditVServer { throws JsonParseException, JsonMappingException, IOException { doReturn(true).when(aaiResourcesMock).exists(vserverURI); doReturn(true).when(aaiResourcesMock).exists(vserverURI2); - doReturn(Optional.of(ssc_1_trusted_port_0_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_trusted_port_0_uri); - doReturn(Optional.of(ssc_1_service1_port_0_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_service1_port_0_uri); - doReturn(Optional.of(ssc_1_mgmt_port_1_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_mgmt_port_1_uri); - doReturn(Optional.empty()).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_mgmt_port_0_uri); - doReturn(Optional.of(ssc_1_service2_port_0_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_service2_port_0_uri); - doReturn(Optional.of(ssc_1_int_ha_port_0_plural)).when(aaiResourcesMock).get(LInterfaces.class,ssc_1_int_ha_port_0_uri); - doReturn(Optional.of(test_port_1_plural)).when(aaiResourcesMock).get(LInterfaces.class,test_port_1_uri); - doReturn(Optional.of(test_port_2_plural)).when(aaiResourcesMock).get(LInterfaces.class,test_port_2_uri); + doReturn(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); - boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); - assertEquals(false, exists); - - boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); - assertEquals(false, doNotExist); + Optional<AAIObjectAuditList> 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 @@ -285,70 +265,81 @@ public class AuditVServerTest extends AuditVServer { throws JsonParseException, JsonMappingException, IOException { doReturn(true).when(aaiResourcesMock).exists(vserverURI); doReturn(true).when(aaiResourcesMock).exists(vserverURI2); - doReturn(Optional.of(ssc_1_trusted_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_trusted_port_0_uri); - doReturn(Optional.of(ssc_1_service1_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_service1_port_0_uri); - doReturn(Optional.of(ssc_1_mgmt_port_1_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_mgmt_port_1_uri); - doReturn(Optional.of(ssc_1_mgmt_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_mgmt_port_0_uri); - doReturn(Optional.of(ssc_1_service2_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_service2_port_0_uri); - doReturn(Optional.of(ssc_1_int_ha_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_int_ha_port_0_uri); - doReturn(Optional.of(test_port_1_plural)).when(aaiResourcesMock).get(LInterface.class,test_port_1_uri); + doReturn(Optional.of(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); - boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); - assertEquals(false, exists); - - boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); - assertEquals(false, doNotExist); + Optional<AAIObjectAuditList> 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_Vservers_Not_Found_Test() throws JsonParseException, JsonMappingException, IOException { + public void audit_Vserver_Not_Found_Test() throws JsonParseException, JsonMappingException, IOException { doReturn(false).when(aaiResourcesMock).exists(vserverURI); doReturn(false).when(aaiResourcesMock).exists(vserverURI2); - - boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); - assertEquals(false, exists); - - boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); - assertEquals(true, doNotExist); + Optional<AAIObjectAuditList> 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_plural)).when(aaiResourcesMock).get(LInterface.class,test_port_1_uri); - doReturn(Optional.of(test_port_2_plural)).when(aaiResourcesMock).get(LInterface.class,test_port_2_uri); - boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); - assertEquals(false, exists); + 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<AAIObjectAuditList> 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"); - boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); - assertEquals(false, doNotExist); + 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_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_trusted_port_0_uri); - doReturn(Optional.of(ssc_1_service1_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_service1_port_0_uri); - doReturn(Optional.of(ssc_1_mgmt_port_1_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_mgmt_port_1_uri); - doReturn(Optional.of(ssc_1_mgmt_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_mgmt_port_0_uri); - doReturn(Optional.of(ssc_1_service2_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_service2_port_0_uri); - doReturn(Optional.of(ssc_1_int_ha_port_0_plural)).when(aaiResourcesMock).get(LInterface.class,ssc_1_int_ha_port_0_uri); - doReturn(Optional.of(test_port_1_plural)).when(aaiResourcesMock).get(LInterface.class,test_port_1_uri); - doReturn(Optional.of(test_port_2_plural)).when(aaiResourcesMock).get(LInterface.class,test_port_2_uri); + doReturn(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); - boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); - assertEquals(false, exists); - - boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); - assertEquals(false, doNotExist); + doReturn(false).when(aaiResourcesMock).exists(vserverURI2); + Optional<AAIObjectAuditList> 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); } + + 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 index 987e4cf76d..a7744a2ea7 100644 --- 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 @@ -26,6 +26,9 @@ 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; @@ -46,6 +49,7 @@ 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; @@ -74,9 +78,9 @@ public class HeatStackAuditTest extends HeatStackAudit { private Resources resources = new Resources(); - private ObjectMapper objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + 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); + private ObjectMapper stackObjectMapper = new ObjectMapper().configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true).setSerializationInclusion(Include.NON_NULL); private List<Optional<Port>> portList = new ArrayList<>(); @@ -131,62 +135,7 @@ public class HeatStackAuditTest extends HeatStackAudit { List<Resource> resourceGroups = resources.getList().stream() .filter(p -> "OS::Heat::ResourceGroup".equals(p.getType())).collect(Collectors.toList()); - - Set<Vserver> expectedVservers = new HashSet<>(); - Vserver vServer1= new Vserver(); - vServer1.setVserverId("92272b67-d23f-42ca-87fa-7b06a9ec81f3"); - LInterfaces vServer1Linterfaces = new LInterfaces(); - vServer1.setLInterfaces(vServer1Linterfaces); - - LInterface ssc_1_trusted_port_0 = new LInterface(); - ssc_1_trusted_port_0.setInterfaceId("7ee06d9d-3d18-411c-9d3e-aec930f70413"); - vServer1.getLInterfaces().getLInterface().add(ssc_1_trusted_port_0); - - - - LInterface ssc_1_mgmt_port_1 = new LInterface(); - ssc_1_mgmt_port_1.setInterfaceId("fdeedf37-c01e-4ab0-bdd6-8d5fc4913943"); - vServer1.getLInterfaces().getLInterface().add(ssc_1_mgmt_port_1); - - LInterface ssc_1_mgmt_port_0 = new LInterface(); - ssc_1_mgmt_port_0.setInterfaceId("8d93f63e-e972-48c7-ad98-b2122da47315"); - vServer1.getLInterfaces().getLInterface().add(ssc_1_mgmt_port_0); - - LInterface ssc_1_service2_port_0 = new LInterface(); - ssc_1_service2_port_0.setLInterfaces(new LInterfaces()); - ssc_1_service2_port_0.setInterfaceId("0594a2f2-7ea4-42eb-abc2-48ea49677fca"); - vServer1.getLInterfaces().getLInterface().add(ssc_1_service2_port_0); - - LInterface service2_sub_interface_1 = new LInterface(); - service2_sub_interface_1.setInterfaceId("2bbfa345-33bb-495a-94b2-fb514ee1cffc"); - ssc_1_service2_port_0.getLInterfaces().getLInterface().add(service2_sub_interface_1); - - LInterface ssc_1_int_ha_port_0 = new LInterface(); - ssc_1_int_ha_port_0.setInterfaceId("00bb8407-650e-48b5-b919-33b88d6f8fe3"); - vServer1.getLInterfaces().getLInterface().add(ssc_1_int_ha_port_0); - - - LInterface ssc_1_service1_port_0 = new LInterface(); - ssc_1_service1_port_0.setInterfaceId("27391d94-33af-474a-927d-d409249e8fd3"); - vServer1.getLInterfaces().getLInterface().add(ssc_1_service1_port_0); - ssc_1_service1_port_0.setLInterfaces(new LInterfaces()); - - LInterface service1_sub_interface_0 = new LInterface(); - service1_sub_interface_0.setInterfaceId("d54dfd09-75c6-4e04-b204-909455b8f933"); - ssc_1_service1_port_0.getLInterfaces().getLInterface().add(service1_sub_interface_0); - - LInterface service1_sub_interface_1 = new LInterface(); - service1_sub_interface_1.setInterfaceId("f7a998c0-8939-4b07-bf4a-0862e9c325e1"); - ssc_1_service1_port_0.getLInterfaces().getLInterface().add(service1_sub_interface_1); - - LInterface service1_sub_interface_2 = new LInterface(); - service1_sub_interface_2.setInterfaceId("621c1fea-60b8-44ee-aede-c01b8b1aaa70"); - ssc_1_service1_port_0.getLInterfaces().getLInterface().add(service1_sub_interface_2); - - expectedVservers.add(vServer1); - - 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); @@ -219,20 +168,18 @@ public class HeatStackAuditTest extends HeatStackAudit { Set<Vserver> vserversWithSubInterfaces = heatStackAudit.processSubInterfaces(cloudRegion,tenantId,resourceGroups, vServersToAudit); String actualValue = objectMapper.writeValueAsString(vserversWithSubInterfaces); - String expectedValue = objectMapper.writeValueAsString(expectedVservers); - + String expectedValue = getJson("ExpectedVserversToAudit.json"); + System.out.println(actualValue); 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"); - boolean actual = heatStackAudit.auditHeatStackCreate(cloudRegion, "cloudOwner", tenantId, "heatStackName"); - assertEquals(true, actual); + Optional<AAIObjectAuditList> actual = heatStackAudit.auditHeatStack(cloudRegion, "cloudOwner", tenantId, "heatStackName"); + assertEquals(true, actual.get().getAuditList().isEmpty()); } @@ -248,26 +195,32 @@ public class HeatStackAuditTest extends HeatStackAudit { 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_service1_port_0 = new LInterface(); - ssc_1_service1_port_0.setInterfaceId("27391d94-33af-474a-927d-d409249e8fd3"); - vServer1.getLInterfaces().getLInterface().add(ssc_1_service1_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_service2_port_0 = new LInterface(); - ssc_1_service2_port_0.setInterfaceId("0594a2f2-7ea4-42eb-abc2-48ea49677fca"); - vServer1.getLInterfaces().getLInterface().add(ssc_1_service2_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); @@ -277,5 +230,7 @@ public class HeatStackAuditTest extends HeatStackAudit { 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 new file mode 100644 index 0000000000..4d34d18727 --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateAAIInventoryTest.java @@ -0,0 +1,122 @@ +/*- + * ============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.adapters.audit.AAIObjectAuditList; +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 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<Optional> captor = ArgumentCaptor.forClass(Optional.class); + ArgumentCaptor<AAIResourceUri> uriCaptor = ArgumentCaptor.forClass(AAIResourceUri.class); + + createAAIInventory.setAaiClient(mockClient); + createAAIInventory.createInventory(missingSubInterfaces); + Mockito.verify(mockClient,times(2)).createIfNotExists(uriCaptor.capture(),captor.capture()); + + List<AAIResourceUri> 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()))); + + + + } +} |