diff options
Diffstat (limited to 'adapters/mso-openstack-adapters/src/test/java')
42 files changed, 4295 insertions, 4262 deletions
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/BeansTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/BeansTest.java index 7aa86da237..ea9512bfa7 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/BeansTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/BeansTest.java @@ -36,55 +36,53 @@ import org.springframework.stereotype.Component; public class BeansTest { - private final PojoClassFilter filterTestClasses = new FilterTestClasses(); - - private final PojoClassFilter enumFilter = new FilterEnum(); - - private final PojoClassFilter noNestedClasses = new FilterTestNestedClasses(); - - - - @Test - public void pojoStructure() { - test("org.onap.so.adapters.network.async.client"); - test("org.onap.so.adapters.vnf.async.client"); - test("org.onap.so.adapters.network"); - test("org.onap.so.adapters.vnf"); - test("org.onap.so.adapters.valet"); - test("org.onap.so.adapters.valet.beans"); - test("org.onap.so.vdu.utils"); - } - - private void test(String pojoPackage) { - Validator validator = ValidatorBuilder.create() - .with(new NoStaticExceptFinalRule()) - .with(new SerializableMustHaveSerialVersionUIDRule()) - .with(new NoPublicFieldsExceptStaticFinalRule()) - .with(new SetterTester()) - .with(new GetterTester()) - .with(new ToStringTester()) - - .build(); - - - validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses,enumFilter,new FilterNonConcrete(), noNestedClasses, new FilterBeans()); - } - private static class FilterTestClasses implements PojoClassFilter { - public boolean include(PojoClass pojoClass) { - return !pojoClass.getSourcePath().contains("/test-classes/"); - } - } - - private static class FilterTestNestedClasses implements PojoClassFilter { - public boolean include(PojoClass pojoClass) { - return !pojoClass.isNestedClass(); - } - } - - private static class FilterBeans implements PojoClassFilter { - public boolean include(PojoClass pojoClass) { - return pojoClass.getAnnotations().stream().filter(o -> o instanceof Component).count() <= 0; - } - } + private final PojoClassFilter filterTestClasses = new FilterTestClasses(); + + private final PojoClassFilter enumFilter = new FilterEnum(); + + private final PojoClassFilter noNestedClasses = new FilterTestNestedClasses(); + + + + @Test + public void pojoStructure() { + test("org.onap.so.adapters.network.async.client"); + test("org.onap.so.adapters.vnf.async.client"); + test("org.onap.so.adapters.network"); + test("org.onap.so.adapters.vnf"); + test("org.onap.so.adapters.valet"); + test("org.onap.so.adapters.valet.beans"); + test("org.onap.so.vdu.utils"); + } + + private void test(String pojoPackage) { + Validator validator = ValidatorBuilder.create().with(new NoStaticExceptFinalRule()) + .with(new SerializableMustHaveSerialVersionUIDRule()).with(new NoPublicFieldsExceptStaticFinalRule()) + .with(new SetterTester()).with(new GetterTester()).with(new ToStringTester()) + + .build(); + + + validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses, enumFilter, new FilterNonConcrete(), + noNestedClasses, new FilterBeans()); + } + + private static class FilterTestClasses implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return !pojoClass.getSourcePath().contains("/test-classes/"); + } + } + + private static class FilterTestNestedClasses implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return !pojoClass.isNestedClass(); + } + } + + private static class FilterBeans implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return pojoClass.getAnnotations().stream().filter(o -> o instanceof Component).count() <= 0; + } + } } 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 index 1eaac18fb6..80b2a21419 100644 --- 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 @@ -23,12 +23,10 @@ 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; @@ -40,160 +38,165 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; 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 AuditStackServiceDataTest extends AuditCreateStackService { - @InjectMocks - private AuditCreateStackService auditStackService = new AuditCreateStackService(); - - @Mock - private HeatStackAudit heatStackAuditMock; - - @Mock - private Environment mockEnv; - - @Mock - private ExternalTask mockExternalTask; - - @Mock - private ExternalTaskService mockExternalTaskService; - - private ObjectMapper objectMapper = new ObjectMapper(); - - private AuditInventory auditInventory = new AuditInventory(); - - Optional<AAIObjectAuditList> auditListOptSuccess; - - Optional<AAIObjectAuditList> 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<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(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<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 - public void retry_sequence_calculation_Test() { - long firstRetry = auditStackService.calculateRetryDelay(8); - assertEquals(6000L, firstRetry); - long secondRetry = auditStackService.calculateRetryDelay(7); - assertEquals(6000L, secondRetry); - long thirdRetry = auditStackService.calculateRetryDelay(6); - assertEquals(12000L, thirdRetry); - long fourthRetry = auditStackService.calculateRetryDelay(5); - assertEquals(18000L, fourthRetry); - long fifthRetry = auditStackService.calculateRetryDelay(4); - assertEquals(30000L, fifthRetry); - long sixRetry = auditStackService.calculateRetryDelay(3); - assertEquals(48000L, sixRetry); - long seventhRetry = auditStackService.calculateRetryDelay(2); - assertEquals(78000L, seventhRetry); - long eigthRetry = auditStackService.calculateRetryDelay(1); - assertEquals(120000L, eigthRetry); - } - - @Test - public void retry_sequence_Test() { - long firstRetry = auditStackService.calculateRetryDelay(8); - assertEquals(6000L, firstRetry); - long secondRetry = auditStackService.calculateRetryDelay(7); - assertEquals(6000L, secondRetry); - long thirdRetry = auditStackService.calculateRetryDelay(6); - assertEquals(12000L, thirdRetry); - long fourthRetry = auditStackService.calculateRetryDelay(5); - assertEquals(18000L, fourthRetry); - long fifthRetry = auditStackService.calculateRetryDelay(4); - assertEquals(30000L, fifthRetry); - long sixRetry = auditStackService.calculateRetryDelay(3); - assertEquals(48000L, sixRetry); - long seventhRetry = auditStackService.calculateRetryDelay(2); - assertEquals(78000L, seventhRetry); - long eigthRetry = auditStackService.calculateRetryDelay(1); - assertEquals(120000L, eigthRetry); - } - - - @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); - } + @InjectMocks + private AuditCreateStackService auditStackService = new AuditCreateStackService(); + + @Mock + private HeatStackAudit heatStackAuditMock; + + @Mock + private Environment mockEnv; + + @Mock + private ExternalTask mockExternalTask; + + @Mock + private ExternalTaskService mockExternalTaskService; + + private ObjectMapper objectMapper = new ObjectMapper(); + + private AuditInventory auditInventory = new AuditInventory(); + + Optional<AAIObjectAuditList> auditListOptSuccess; + + Optional<AAIObjectAuditList> 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<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(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<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 + public void retry_sequence_calculation_Test() { + long firstRetry = auditStackService.calculateRetryDelay(8); + assertEquals(6000L, firstRetry); + long secondRetry = auditStackService.calculateRetryDelay(7); + assertEquals(6000L, secondRetry); + long thirdRetry = auditStackService.calculateRetryDelay(6); + assertEquals(12000L, thirdRetry); + long fourthRetry = auditStackService.calculateRetryDelay(5); + assertEquals(18000L, fourthRetry); + long fifthRetry = auditStackService.calculateRetryDelay(4); + assertEquals(30000L, fifthRetry); + long sixRetry = auditStackService.calculateRetryDelay(3); + assertEquals(48000L, sixRetry); + long seventhRetry = auditStackService.calculateRetryDelay(2); + assertEquals(78000L, seventhRetry); + long eigthRetry = auditStackService.calculateRetryDelay(1); + assertEquals(120000L, eigthRetry); + } + + @Test + public void retry_sequence_Test() { + long firstRetry = auditStackService.calculateRetryDelay(8); + assertEquals(6000L, firstRetry); + long secondRetry = auditStackService.calculateRetryDelay(7); + assertEquals(6000L, secondRetry); + long thirdRetry = auditStackService.calculateRetryDelay(6); + assertEquals(12000L, thirdRetry); + long fourthRetry = auditStackService.calculateRetryDelay(5); + assertEquals(18000L, fourthRetry); + long fifthRetry = auditStackService.calculateRetryDelay(4); + assertEquals(30000L, fifthRetry); + long sixRetry = auditStackService.calculateRetryDelay(3); + assertEquals(48000L, sixRetry); + long seventhRetry = auditStackService.calculateRetryDelay(2); + assertEquals(78000L, seventhRetry); + long eigthRetry = auditStackService.calculateRetryDelay(1); + assertEquals(120000L, eigthRetry); + } + + + @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 index f0fce4db45..d43dbd99f9 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 @@ -24,7 +24,6 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; - import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -34,7 +33,6 @@ import java.util.List; import java.util.Optional; import java.util.Set; import java.util.stream.Stream; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -51,7 +49,6 @@ 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; @@ -62,283 +59,311 @@ import com.woorea.openstack.heat.model.Resources; @RunWith(MockitoJUnitRunner.Silent.class) public class AuditVServerTest extends AuditVServer { - private ObjectMapper objectMapper = new ObjectMapper(); - - @InjectMocks - private AuditVServer auditNova = new AuditVServer(); - - @Mock - private AAIResourcesClient aaiResourcesMock; - - private String cloudOwner = "cloudOwner"; - private String cloudRegion = "cloudRegion"; - private String tenantId = "tenantId"; - - private AAIResourceUri vserverURI = AAIUriFactory.createResourceUri(AAIObjectType.VSERVER,cloudOwner, cloudRegion, - tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4db"); - - private AAIResourceUri vserverURI2 = AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, cloudOwner, cloudRegion, - tenantId, "3a4c2ca5-27b3-4ecc-98c5-06804867c4dz"); - - private AAIResourceUri ssc_1_trusted_port_0_uri = AAIUriFactory.createResourceUri(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<Vserver> vserversToAudit = new HashSet<>(); - - LInterface test_port_1 = new LInterface(); - LInterface test_port_2 = new LInterface(); - LInterface ssc_1_int_ha_port_0 = new LInterface(); - LInterface 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<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)).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<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 - 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<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 - 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<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_Vserver_Not_Found_Test() throws JsonParseException, JsonMappingException, IOException { - doReturn(false).when(aaiResourcesMock).exists(vserverURI); - doReturn(false).when(aaiResourcesMock).exists(vserverURI2); - 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)).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"); - - 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<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))); - } + 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<Vserver> vserversToAudit = new HashSet<>(); + + LInterface test_port_1 = new LInterface(); + LInterface test_port_2 = new LInterface(); + LInterface ssc_1_int_ha_port_0 = new LInterface(); + LInterface 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<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)).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<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 + 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<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 + 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<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_Vserver_Not_Found_Test() throws JsonParseException, JsonMappingException, IOException { + doReturn(false).when(aaiResourcesMock).exists(vserverURI); + doReturn(false).when(aaiResourcesMock).exists(vserverURI2); + 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)).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"); + + 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<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 e728cfd0d4..bc7ce53b8d 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 @@ -24,7 +24,6 @@ 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; @@ -35,7 +34,6 @@ 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; @@ -48,7 +46,6 @@ import org.onap.aai.domain.yang.Vserver; 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; @@ -61,191 +58,238 @@ 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<Optional<Port>> 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<String> 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<String> 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<String> actualResult = extractStackPathFromHref("orchestrn.com:8004/v18b44d60a6f94bdcb2738f9e//stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81"); - assertEquals(false, actualResult.isPresent()); - } - - @Test - public void createVserverSet_Test() throws Exception{ - List<Resource> novaResources = resources.getList().stream() - .filter(p -> "OS::Nova::Server".equals(p.getType())).collect(Collectors.toList()); - - List<Resource> resourceGroups = resources.getList().stream() - .filter(p -> "OS::Heat::ResourceGroup".equals(p.getType())).collect(Collectors.toList()); - - 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<Vserver> vServersToAudit = heatStackAudit.createVserverSet(resources, novaResources,portList); - Set<Vserver> 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<AAIObjectAuditList> 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<Resource> novaResources = getResource.getList().stream() - .filter(p -> "OS::Nova::Server".equals(p.getType())).collect(Collectors.toList()); - List<Resource> 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<Vserver> vServersToAudit = heatStackAudit.createVserverSet(resources, novaResources,portList); - Set<Vserver> 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<Resource> novaResources = resources.getList().stream() - .filter(p -> "OS::Nova::Server".equals(p.getType())).collect(Collectors.toList()); - Set<Vserver> expectedVservers = new HashSet<>(); - Vserver vServer1= new Vserver(); - vServer1.setVserverId("92272b67-d23f-42ca-87fa-7b06a9ec81f3"); - LInterfaces vServer1Linterfaces = new LInterfaces(); - vServer1.setLInterfaces(vServer1Linterfaces); - - LInterface ssc_1_trusted_port_0 = new LInterface(); - ssc_1_trusted_port_0.setInterfaceId("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<Vserver> 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))); - } + @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<Optional<Port>> 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<String> 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<String> 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<String> actualResult = extractStackPathFromHref( + "orchestrn.com:8004/v18b44d60a6f94bdcb2738f9e//stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81"); + assertEquals(false, actualResult.isPresent()); + } + + @Test + public void createVserverSet_Test() throws Exception { + List<Resource> novaResources = resources.getList().stream().filter(p -> "OS::Nova::Server".equals(p.getType())) + .collect(Collectors.toList()); + + List<Resource> resourceGroups = resources.getList().stream() + .filter(p -> "OS::Heat::ResourceGroup".equals(p.getType())).collect(Collectors.toList()); + + 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<Vserver> vServersToAudit = heatStackAudit.createVserverSet(resources, novaResources, portList); + Set<Vserver> 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<AAIObjectAuditList> 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<Resource> novaResources = getResource.getList().stream() + .filter(p -> "OS::Nova::Server".equals(p.getType())).collect(Collectors.toList()); + List<Resource> 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<Vserver> vServersToAudit = heatStackAudit.createVserverSet(resources, novaResources, portList); + Set<Vserver> 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<Resource> novaResources = resources.getList().stream().filter(p -> "OS::Nova::Server".equals(p.getType())) + .collect(Collectors.toList()); + Set<Vserver> expectedVservers = new HashSet<>(); + Vserver vServer1 = new Vserver(); + vServer1.setVserverId("92272b67-d23f-42ca-87fa-7b06a9ec81f3"); + LInterfaces vServer1Linterfaces = new LInterfaces(); + vServer1.setLInterfaces(vServer1Linterfaces); + + LInterface ssc_1_trusted_port_0 = new LInterface(); + ssc_1_trusted_port_0.setInterfaceId("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<Vserver> 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 index 4d34d18727..0fd2bd4b7f 100644 --- 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 @@ -24,13 +24,11 @@ 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; @@ -46,77 +44,79 @@ 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()))); - - - - } + @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()))); + + + + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/EmbeddedMariaDbConfig.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/EmbeddedMariaDbConfig.java index d552f8d893..66cee2d804 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/EmbeddedMariaDbConfig.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/EmbeddedMariaDbConfig.java @@ -19,6 +19,7 @@ */ package org.onap.so.adapters.msoopenstackadapters; + import ch.vorburger.exec.ManagedProcessException; import ch.vorburger.mariadb4j.DBConfigurationBuilder; import ch.vorburger.mariadb4j.springframework.MariaDB4jSpringService; @@ -40,21 +41,16 @@ public class EmbeddedMariaDbConfig { @Bean DataSource dataSource(MariaDB4jSpringService mariaDB4jSpringService, - @Value("${mariaDB4j.databaseName}") String databaseName, - @Value("${spring.datasource.username}") String datasourceUsername, - @Value("${spring.datasource.password}") String datasourcePassword, - @Value("${spring.datasource.driver-class-name}") String datasourceDriver) throws ManagedProcessException { - //Create our database with default root user and no password + @Value("${mariaDB4j.databaseName}") String databaseName, + @Value("${spring.datasource.username}") String datasourceUsername, + @Value("${spring.datasource.password}") String datasourcePassword, + @Value("${spring.datasource.driver-class-name}") String datasourceDriver) throws ManagedProcessException { + // Create our database with default root user and no password mariaDB4jSpringService.getDB().createDB(databaseName); DBConfigurationBuilder config = mariaDB4jSpringService.getConfiguration(); - return DataSourceBuilder - .create() - .username(datasourceUsername) - .password(datasourcePassword) - .url(config.getURL(databaseName)) - .driverClassName(datasourceDriver) - .build(); + return DataSourceBuilder.create().username(datasourceUsername).password(datasourcePassword) + .url(config.getURL(databaseName)).driverClassName(datasourceDriver).build(); } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/HealthCheckHandlerTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/HealthCheckHandlerTest.java index 4df9a7af6d..61a8f627a6 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/HealthCheckHandlerTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/HealthCheckHandlerTest.java @@ -21,9 +21,7 @@ package org.onap.so.adapters.msoopenstackadapters; import static org.junit.Assert.assertEquals; - import javax.ws.rs.core.Response; - import org.json.JSONException; import org.junit.Test; import org.onap.so.adapters.vnf.BaseRestTestUtils; @@ -33,15 +31,15 @@ import org.springframework.http.ResponseEntity; public class HealthCheckHandlerTest extends BaseRestTestUtils { - @Test - public void testHealthcheckVnf() throws JSONException { + @Test + public void testHealthcheckVnf() throws JSONException { + + HttpEntity<String> entity = new HttpEntity<String>(null, headers); - HttpEntity<String> entity = new HttpEntity<String>(null, headers); + ResponseEntity<String> response = + restTemplate.exchange(createURLWithPort("/manage/health"), HttpMethod.GET, entity, String.class); - ResponseEntity<String> response = restTemplate.exchange(createURLWithPort("/manage/health"), - HttpMethod.GET, entity, String.class); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + } - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - } - } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/TestRestTemplateFactory.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/TestRestTemplateFactory.java index be76a9e365..8d1dd8b69a 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/TestRestTemplateFactory.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/msoopenstackadapters/TestRestTemplateFactory.java @@ -22,7 +22,6 @@ package org.onap.so.adapters.msoopenstackadapters; import java.util.ArrayList; import java.util.List; - import org.onap.so.client.policy.JettisonStyleMapperProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -34,17 +33,18 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert @Configuration public class TestRestTemplateFactory { - @Autowired - private JettisonStyleMapperProvider objectMapper; + @Autowired + private JettisonStyleMapperProvider objectMapper; - @Bean("JettisonStyle") - public TestRestTemplate createRestTemplate() { - TestRestTemplate restTemplate = new TestRestTemplate("test", "test"); - List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); - MappingJackson2HttpMessageConverter jsonMessageConverter = new MappingJackson2HttpMessageConverter(); - jsonMessageConverter.setObjectMapper(objectMapper.getMapper()); - restTemplate.getRestTemplate().getMessageConverters().removeIf(m -> m.getClass().getName().equals(MappingJackson2HttpMessageConverter.class.getName())); - restTemplate.getRestTemplate().getMessageConverters().add(jsonMessageConverter); - return restTemplate; - } + @Bean("JettisonStyle") + public TestRestTemplate createRestTemplate() { + TestRestTemplate restTemplate = new TestRestTemplate("test", "test"); + List<HttpMessageConverter<?>> messageConverters = new ArrayList<>(); + MappingJackson2HttpMessageConverter jsonMessageConverter = new MappingJackson2HttpMessageConverter(); + jsonMessageConverter.setObjectMapper(objectMapper.getMapper()); + restTemplate.getRestTemplate().getMessageConverters() + .removeIf(m -> m.getClass().getName().equals(MappingJackson2HttpMessageConverter.class.getName())); + restTemplate.getRestTemplate().getMessageConverters().add(jsonMessageConverter); + return restTemplate; + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailPolicyRefSeqTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailPolicyRefSeqTest.java index 46bf21722c..dd59121a39 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailPolicyRefSeqTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailPolicyRefSeqTest.java @@ -21,16 +21,14 @@ package org.onap.so.adapters.network; import static org.junit.Assert.assertTrue; - import org.junit.Test; public class ContrailPolicyRefSeqTest { - @Test - public void ContrailPolicyRefSeqJson_Test() - { - ContrailPolicyRefSeq cprs = new ContrailPolicyRefSeq("majorVersion 1","minorVersion 0.02"); - assertTrue(cprs.toString().contains("majorVersion 1")); - assertTrue(cprs.toString().contains("minorVersion 0.02")); - } - + @Test + public void ContrailPolicyRefSeqJson_Test() { + ContrailPolicyRefSeq cprs = new ContrailPolicyRefSeq("majorVersion 1", "minorVersion 0.02"); + assertTrue(cprs.toString().contains("majorVersion 1")); + assertTrue(cprs.toString().contains("minorVersion 0.02")); + } + } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailPolicyRefTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailPolicyRefTest.java index 7a0f3d0551..e8e14417c0 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailPolicyRefTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailPolicyRefTest.java @@ -21,19 +21,17 @@ package org.onap.so.adapters.network; import static org.junit.Assert.assertTrue; - import org.junit.Test; public class ContrailPolicyRefTest { - @Test - public void ContrailPolicyRef_Test() - { - ContrailPolicyRef ref = new ContrailPolicyRef(); - ref.populate("majorVersion 1", "minorVersion 0.02"); - String strJson = ref.toJsonString(); - assertTrue(strJson.contains("majorVersion 1")); - assertTrue(strJson.contains("minorVersion 0.02")); - } - -}
\ No newline at end of file + @Test + public void ContrailPolicyRef_Test() { + ContrailPolicyRef ref = new ContrailPolicyRef(); + ref.populate("majorVersion 1", "minorVersion 0.02"); + String strJson = ref.toJsonString(); + assertTrue(strJson.contains("majorVersion 1")); + assertTrue(strJson.contains("minorVersion 0.02")); + } + +} diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailSubnetHostRouteTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailSubnetHostRouteTest.java index ca8a45e8dc..eb8395cd9b 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailSubnetHostRouteTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailSubnetHostRouteTest.java @@ -1,26 +1,20 @@ /* -* ============LICENSE_START======================================================= - * ONAP : SO - * ================================================================================ - * Copyright (C) 2018 TechMahindra - * ================================================================================ - * 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 + * ============LICENSE_START======================================================= ONAP : SO + * ================================================================================ Copyright (C) 2018 TechMahindra + * ================================================================================ 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 + * 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. + * 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.network; import static org.junit.Assert.assertEquals; - import org.junit.Test; import org.onap.so.openstack.beans.HostRoute; @@ -28,6 +22,7 @@ public class ContrailSubnetHostRouteTest { private ContrailSubnetHostRoute cshr = new ContrailSubnetHostRoute(); HostRoute hr = new HostRoute(); + @Test public void testContrailSubnetHostRoute() { diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailSubnetHostRoutesTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailSubnetHostRoutesTest.java index fd17c37e6d..eb8912f56d 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailSubnetHostRoutesTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/ContrailSubnetHostRoutesTest.java @@ -1,29 +1,22 @@ /* -* ============LICENSE_START======================================================= - * ONAP : SO - * ================================================================================ - * Copyright (C) 2018 TechMahindra - * ================================================================================ - * 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 + * ============LICENSE_START======================================================= ONAP : SO + * ================================================================================ Copyright (C) 2018 TechMahindra + * ================================================================================ 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 + * 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. + * 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.network; import static org.junit.Assert.*; - import java.util.List; - import org.junit.Test; public class ContrailSubnetHostRoutesTest { @@ -31,6 +24,7 @@ public class ContrailSubnetHostRoutesTest { ContrailSubnetHostRoutes cshr = new ContrailSubnetHostRoutes(); List<ContrailSubnetHostRoute> host_routes; StringBuilder buf = new StringBuilder(); + @Test public void testContrailSubnetHostRoutes() { cshr.setHost_routes(host_routes); diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MSONetworkAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MSONetworkAdapterImplTest.java index 7bfb8c1d76..4dcb7c8710 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MSONetworkAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MSONetworkAdapterImplTest.java @@ -27,13 +27,11 @@ import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.web.util.UriComponentsBuilder; - import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; - import static org.junit.Assert.assertEquals; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackDeleteNeutronNetwork; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackDeleteStack_200; @@ -57,419 +55,455 @@ import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenstackPost; public class MSONetworkAdapterImplTest extends BaseRestTestUtils { - public static final String NETWORK_ID = "43173f6a-d699-414b-888f-ab243dda6dfe"; - public static final String NETWORK_NAME = "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0"; + public static final String NETWORK_ID = "43173f6a-d699-414b-888f-ab243dda6dfe"; + public static final String NETWORK_NAME = "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0"; + + @Test + public void createNetworkByModelNameNeutronModeGetNetworkException() throws IOException { + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - @Test - public void createNetworkByModelNameNeutronModeGetNetworkException() throws IOException{ - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenstackGet(wireMockServer, "/mockPublicUrl/v2.0/networks", HttpStatus.SC_INTERNAL_SERVER_ERROR); - mockOpenstackGet(wireMockServer, "/mockPublicUrl/v2.0/networks",HttpStatus.SC_INTERNAL_SERVER_ERROR); + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/CreateNetwork_NEUTRON_Mode.xml"), uri, HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork_NEUTRON_Mode.xml"), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + @Test + public void createNetworkByModelNameNeutronModeCreateNetworkException() throws IOException { - @Test - public void createNetworkByModelNameNeutronModeCreateNetworkException() throws IOException{ + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetNeutronNetwork_404(wireMockServer, "dvspg-VCE_VPE-mtjnj40avbc"); - mockOpenStackGetNeutronNetwork_404(wireMockServer, "dvspg-VCE_VPE-mtjnj40avbc"); + mockOpenStackGetAllNeutronNetworks_404(wireMockServer); - mockOpenStackGetAllNeutronNetworks_404(wireMockServer); + mockOpenstackPost(wireMockServer, "/mockPublicUrl/v2.0/networks", HttpStatus.SC_INTERNAL_SERVER_ERROR); - mockOpenstackPost(wireMockServer, "/mockPublicUrl/v2.0/networks", HttpStatus.SC_INTERNAL_SERVER_ERROR); + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/CreateNetwork_NEUTRON_Mode.xml"), uri, HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork_NEUTRON_Mode.xml"), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + @Test + public void createNetworkByModelNameNeutronMode() throws IOException { - @Test - public void createNetworkByModelNameNeutronMode() throws IOException{ + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetNeutronNetwork_404(wireMockServer, "dvspg-VCE_VPE-mtjnj40avbc"); - mockOpenStackGetNeutronNetwork_404(wireMockServer, "dvspg-VCE_VPE-mtjnj40avbc"); + mockOpenStackGetAllNeutronNetworks_404(wireMockServer); - mockOpenStackGetAllNeutronNetworks_404(wireMockServer); + mockOpenStackPostNeutronNetwork_200(wireMockServer, "OpenstackCreateNeutronNetworkResponse.json"); - mockOpenStackPostNeutronNetwork_200(wireMockServer, "OpenstackCreateNeutronNetworkResponse.json"); + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/CreateNetwork_NEUTRON_Mode.xml"), uri, HttpMethod.POST); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + } - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork_NEUTRON_Mode.xml"), uri, HttpMethod.POST); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - } + @Test + public void createNetworkByModelNameAlreadyExistNeutronMode() throws IOException { - @Test - public void createNetworkByModelNameAlreadyExistNeutronMode() throws IOException{ + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetAllNeutronNetworks_200(wireMockServer, "OpenstackGetNeutronNetworks.json"); - mockOpenStackGetAllNeutronNetworks_200(wireMockServer, "OpenstackGetNeutronNetworks.json"); + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/CreateNetwork_NEUTRON_Mode.xml"), uri, HttpMethod.POST); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + } - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork_NEUTRON_Mode.xml"), uri, HttpMethod.POST); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - } + @Test + public void createNetworkByModelNameAlreadyExistNeutronModeFailIfExistTrue() throws IOException { - @Test - public void createNetworkByModelNameAlreadyExistNeutronModeFailIfExistTrue() throws IOException{ + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetAllNeutronNetworks_200(wireMockServer, "OpenstackGetNeutronNetworks.json"); - mockOpenStackGetAllNeutronNetworks_200(wireMockServer, "OpenstackGetNeutronNetworks.json"); + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/CreateNetwork_NEUTRON_Mode_Fail_If_Exist_True.xml"), uri, HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork_NEUTRON_Mode_Fail_If_Exist_True.xml"), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + @Test + public void createNetworkByModelNameHeatMode() throws IOException { - @Test - public void createNetworkByModelNameHeatMode() throws IOException{ + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStack_404(wireMockServer, "dvspg-VCE_VPE-mtjnj40avbc"); - mockOpenStackGetStack_404(wireMockServer, "dvspg-VCE_VPE-mtjnj40avbc"); + mockOpenStackPostStack_200(wireMockServer, "OpenstackResponse_Stack.json"); - mockOpenStackPostStack_200(wireMockServer, "OpenstackResponse_Stack.json"); + mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", + "dvspg-VCE_VPE-mtjnj40avbc/stackId"); - mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", "dvspg-VCE_VPE-mtjnj40avbc/stackId"); + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork.xml"), uri, HttpMethod.POST); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + } - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork.xml"), uri, HttpMethod.POST); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - } + @Test + public void createNetworkByModelNameAlreadyExistHeatMode() throws IOException { - @Test - public void createNetworkByModelNameAlreadyExistHeatMode() throws IOException{ + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackPostStack_200(wireMockServer, "OpenstackResponse_Stack.json"); - mockOpenStackPostStack_200(wireMockServer, "OpenstackResponse_Stack.json"); + mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", + "dvspg-VCE_VPE-mtjnj40avbc"); - mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", "dvspg-VCE_VPE-mtjnj40avbc"); + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork.xml"), uri, HttpMethod.POST); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + } - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork.xml"), uri, HttpMethod.POST); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - } + @Test + public void createNetworkByModelNameAlreadyExistHeatModeFailIfExistTrue() throws IOException { - @Test - public void createNetworkByModelNameAlreadyExistHeatModeFailIfExistTrue() throws IOException{ + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", + "dvspg-VCE_VPE-mtjnj40avbc"); - mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", "dvspg-VCE_VPE-mtjnj40avbc"); + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/CreateNetwork_Fail_If_Exist_True.xml"), uri, HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork_Fail_If_Exist_True.xml"), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + @Test + public void createNetworkByModelNameHeatModeQueryNetworkException() throws IOException { - @Test - public void createNetworkByModelNameHeatModeQueryNetworkException() throws IOException{ + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenstackGet(wireMockServer, "/mockPublicUrl/stacks/dvspg-VCE_VPE-mtjnj40avbc", + HttpStatus.SC_INTERNAL_SERVER_ERROR); - mockOpenstackGet(wireMockServer, "/mockPublicUrl/stacks/dvspg-VCE_VPE-mtjnj40avbc",HttpStatus.SC_INTERNAL_SERVER_ERROR); + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork.xml"), uri, HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork.xml"), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + @Test + public void createNetworkByModelNameHeatModeCreateNetworkException() throws IOException { - @Test - public void createNetworkByModelNameHeatModeCreateNetworkException() throws IOException{ + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStack_404(wireMockServer, "dvspg-VCE_VPE-mtjnj40avbc"); - mockOpenStackGetStack_404(wireMockServer, "dvspg-VCE_VPE-mtjnj40avbc"); + mockOpenstackPost(wireMockServer, "/mockPublicUrl/stacks", HttpStatus.SC_INTERNAL_SERVER_ERROR); - mockOpenstackPost(wireMockServer, "/mockPublicUrl/stacks",HttpStatus.SC_INTERNAL_SERVER_ERROR); + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork.xml"), uri, HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork.xml"), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + @Test + public void createNetworkByModelNameCloudSiteNotPresentError() throws IOException { - @Test - public void createNetworkByModelNameCloudSiteNotPresentError() throws IOException{ + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackPostStack_200(wireMockServer, "OpenstackResponse_Stack.json"); - mockOpenStackPostStack_200(wireMockServer, "OpenstackResponse_Stack.json"); + mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", + "dvspg-VCE_VPE-mtjnj40avbc"); - mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", "dvspg-VCE_VPE-mtjnj40avbc"); + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/CreateNetwork_InvalidCloudSiteId.xml"), uri, HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/CreateNetwork_InvalidCloudSiteId.xml"), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + @Test + public void deleteNetworkHeatModeSuccess() throws IOException { - @Test - public void deleteNetworkHeatModeSuccess() throws IOException{ + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackDeleteOrUpdateComplete_200(wireMockServer, "OpenstackResponse_Stack_DeleteComplete.json"); - mockOpenStackGetStackDeleteOrUpdateComplete_200(wireMockServer, "OpenstackResponse_Stack_DeleteComplete.json"); + mockOpenStackDeleteStack_200(wireMockServer); - mockOpenStackDeleteStack_200(wireMockServer); + mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", + "43173f6a-d699-414b-888f-ab243dda6dfe"); - mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", "43173f6a-d699-414b-888f-ab243dda6dfe"); + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = sendXMLRequest(inputStream("/DeleteNetwork.xml"), uri, HttpMethod.POST); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + } - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/DeleteNetwork.xml"), uri, HttpMethod.POST); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - } + @Test + public void deleteNetworkDeleteStackException() throws IOException { - @Test - public void deleteNetworkDeleteStackException() throws IOException{ + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackDeleteOrUpdateComplete_200(wireMockServer, "OpenstackResponse_Stack_DeleteComplete.json"); - mockOpenStackGetStackDeleteOrUpdateComplete_200(wireMockServer, "OpenstackResponse_Stack_DeleteComplete.json"); + mockOpenStackDeleteStack_500(wireMockServer); - mockOpenStackDeleteStack_500(wireMockServer); + mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", + "43173f6a-d699-414b-888f-ab243dda6dfe"); - mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", "43173f6a-d699-414b-888f-ab243dda6dfe"); + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = sendXMLRequest(inputStream("/DeleteNetwork.xml"), uri, HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/DeleteNetwork.xml"), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + @Test + public void deleteNetworkError() throws IOException { - @Test - public void deleteNetworkError() throws IOException{ + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackDeleteOrUpdateComplete_200(wireMockServer, "OpenstackResponse_Stack_DeleteComplete.json"); - mockOpenStackGetStackDeleteOrUpdateComplete_200(wireMockServer, "OpenstackResponse_Stack_DeleteComplete.json"); + mockOpenStackDeleteStack_200(wireMockServer); - mockOpenStackDeleteStack_200(wireMockServer); + mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", + "43173f6a-d699-414b-888f-ab243dda6dfe"); - mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", "43173f6a-d699-414b-888f-ab243dda6dfe"); + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/DeleteNetwork.xml").replace("mtn13", ""), uri, HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/DeleteNetwork.xml").replace("mtn13",""), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + @Test + public void deleteNetworkNeureonMode() throws IOException { - @Test - public void deleteNetworkNeureonMode() throws IOException{ + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetNeutronNetwork(wireMockServer, "GetNeutronNetwork.json", NETWORK_ID, HttpStatus.SC_OK); - mockOpenStackGetNeutronNetwork(wireMockServer, "GetNeutronNetwork.json",NETWORK_ID,HttpStatus.SC_OK); + mockOpenStackDeleteNeutronNetwork(wireMockServer, NETWORK_ID, HttpStatus.SC_OK); - mockOpenStackDeleteNeutronNetwork(wireMockServer, NETWORK_ID,HttpStatus.SC_OK); - - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/DeleteNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - } + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/DeleteNetwork.xml").replace("CONTRAIL30_BASIC", "CONTRAIL31_GNDIRECT"), + uri, HttpMethod.POST); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + } - @Test - public void deleteNetworkNeutronModeDeleteStackException() throws IOException{ + @Test + public void deleteNetworkNeutronModeDeleteStackException() throws IOException { - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetNeutronNetwork(wireMockServer, "GetNeutronNetwork.json",NETWORK_ID,HttpStatus.SC_OK); + mockOpenStackGetNeutronNetwork(wireMockServer, "GetNeutronNetwork.json", NETWORK_ID, HttpStatus.SC_OK); - mockOpenStackDeleteNeutronNetwork(wireMockServer, NETWORK_ID,HttpStatus.SC_INTERNAL_SERVER_ERROR); + mockOpenStackDeleteNeutronNetwork(wireMockServer, NETWORK_ID, HttpStatus.SC_INTERNAL_SERVER_ERROR); - //mockOpenStackGetStackCreated_200("OpenstackResponse_Stack_Created.json", NETWORK_ID); + // mockOpenStackGetStackCreated_200("OpenstackResponse_Stack_Created.json", NETWORK_ID); - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/DeleteNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/DeleteNetwork.xml").replace("CONTRAIL30_BASIC", "CONTRAIL31_GNDIRECT"), + uri, HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - @Test - public void updateNetworkNeutronModeSuccess() throws IOException{ + @Test + public void updateNetworkNeutronModeSuccess() throws IOException { - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetNeutronNetwork(wireMockServer, "GetNeutronNetwork.json",NETWORK_ID,HttpStatus.SC_OK); - mockOpenStackPutNeutronNetwork_200(wireMockServer, "OpenstackCreateNeutronNetworkResponse.json",NETWORK_ID); + mockOpenStackGetNeutronNetwork(wireMockServer, "GetNeutronNetwork.json", NETWORK_ID, HttpStatus.SC_OK); + mockOpenStackPutNeutronNetwork_200(wireMockServer, "OpenstackCreateNeutronNetworkResponse.json", NETWORK_ID); - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/UpdateNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - } + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/UpdateNetwork.xml").replace("CONTRAIL30_BASIC", "CONTRAIL31_GNDIRECT"), + uri, HttpMethod.POST); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + } - @Test - public void updateNetworkNeutronUpdateException() throws IOException{ + @Test + public void updateNetworkNeutronUpdateException() throws IOException { - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetNeutronNetwork(wireMockServer, "GetNeutronNetwork.json",NETWORK_ID,HttpStatus.SC_OK); - mockOpenStackPutNeutronNetwork(wireMockServer, NETWORK_ID,HttpStatus.SC_INTERNAL_SERVER_ERROR); + mockOpenStackGetNeutronNetwork(wireMockServer, "GetNeutronNetwork.json", NETWORK_ID, HttpStatus.SC_OK); + mockOpenStackPutNeutronNetwork(wireMockServer, NETWORK_ID, HttpStatus.SC_INTERNAL_SERVER_ERROR); - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/UpdateNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/UpdateNetwork.xml").replace("CONTRAIL30_BASIC", "CONTRAIL31_GNDIRECT"), + uri, HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - @Test - public void updateNetworkHeatUpdateException() throws IOException{ + @Test + public void updateNetworkHeatUpdateException() throws IOException { - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", NETWORK_NAME); + mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", NETWORK_NAME); - mockOpenStackPutStack(wireMockServer, NETWORK_ID,HttpStatus.SC_INTERNAL_SERVER_ERROR); + mockOpenStackPutStack(wireMockServer, NETWORK_ID, HttpStatus.SC_INTERNAL_SERVER_ERROR); - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/UpdateNetwork.xml"), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = sendXMLRequest(inputStream("/UpdateNetwork.xml"), uri, HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - @Test - public void updateNetworkHeatQueryException() throws IOException{ + @Test + public void updateNetworkHeatQueryException() throws IOException { - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStack_500(wireMockServer, NETWORK_NAME); + mockOpenStackGetStack_500(wireMockServer, NETWORK_NAME); - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/UpdateNetwork.xml"), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = sendXMLRequest(inputStream("/UpdateNetwork.xml"), uri, HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - @Test - public void updateNetworkHeatStackNotFound() throws IOException{ + @Test + public void updateNetworkHeatStackNotFound() throws IOException { - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStack_404(wireMockServer, NETWORK_NAME); + mockOpenStackGetStack_404(wireMockServer, NETWORK_NAME); - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/UpdateNetwork.xml"), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = sendXMLRequest(inputStream("/UpdateNetwork.xml"), uri, HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - @Test - public void updateNetworkNeutronQueryException() throws IOException{ + @Test + public void updateNetworkNeutronQueryException() throws IOException { - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetNeutronNetwork(wireMockServer, NETWORK_ID,HttpStatus.SC_INTERNAL_SERVER_ERROR); + mockOpenStackGetNeutronNetwork(wireMockServer, NETWORK_ID, HttpStatus.SC_INTERNAL_SERVER_ERROR); - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/UpdateNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/UpdateNetwork.xml").replace("CONTRAIL30_BASIC", "CONTRAIL31_GNDIRECT"), + uri, HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - @Test - public void updateNetworkNeutronStackNotFound() throws IOException{ + @Test + public void updateNetworkNeutronStackNotFound() throws IOException { - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetNeutronNetwork(wireMockServer, NETWORK_ID,HttpStatus.SC_NOT_FOUND); + mockOpenStackGetNeutronNetwork(wireMockServer, NETWORK_ID, HttpStatus.SC_NOT_FOUND); - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/UpdateNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/UpdateNetwork.xml").replace("CONTRAIL30_BASIC", "CONTRAIL31_GNDIRECT"), + uri, HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - @Test - public void queryNetworkHeatModesuccess() throws IOException{ + @Test + public void queryNetworkHeatModesuccess() throws IOException { - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", NETWORK_ID); + mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", NETWORK_ID); - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/QueryNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - } + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/QueryNetwork.xml").replace("CONTRAIL30_BASIC", "CONTRAIL31_GNDIRECT"), uri, + HttpMethod.POST); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + } - @Test - public void queryNetworkHeatModeQueryException() throws IOException{ + @Test + public void queryNetworkHeatModeQueryException() throws IOException { - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStack_500(wireMockServer, NETWORK_ID); + mockOpenStackGetStack_500(wireMockServer, NETWORK_ID); - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/QueryNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/QueryNetwork.xml").replace("CONTRAIL30_BASIC", "CONTRAIL31_GNDIRECT"), uri, + HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - @Test - public void queryNetworkNeutronModeSuccess() throws IOException{ + @Test + public void queryNetworkNeutronModeSuccess() throws IOException { - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetNeutronNetwork(wireMockServer, "GetNeutronNetwork.json",NETWORK_ID,HttpStatus.SC_OK); + mockOpenStackGetNeutronNetwork(wireMockServer, "GetNeutronNetwork.json", NETWORK_ID, HttpStatus.SC_OK); - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/QueryNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - } + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/QueryNetwork.xml").replace("CONTRAIL30_BASIC", "CONTRAIL31_GNDIRECT"), uri, + HttpMethod.POST); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + } - @Test - public void queryNetworkNeutronModeException() throws IOException{ + @Test + public void queryNetworkNeutronModeException() throws IOException { - mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetNeutronNetwork(wireMockServer, NETWORK_ID,HttpStatus.SC_INTERNAL_SERVER_ERROR); + mockOpenStackGetNeutronNetwork(wireMockServer, NETWORK_ID, HttpStatus.SC_INTERNAL_SERVER_ERROR); - String uri = "/services/NetworkAdapter"; - headers.set("X-ECOMP-RequestID", "123456789456127"); - ResponseEntity<String> response = sendXMLRequest(inputStream("/QueryNetwork.xml").replace("CONTRAIL30_BASIC","CONTRAIL31_GNDIRECT"), uri, HttpMethod.POST); - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } + String uri = "/services/NetworkAdapter"; + headers.set("X-ECOMP-RequestID", "123456789456127"); + ResponseEntity<String> response = + sendXMLRequest(inputStream("/QueryNetwork.xml").replace("CONTRAIL30_BASIC", "CONTRAIL31_GNDIRECT"), uri, + HttpMethod.POST); + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + } - public ResponseEntity<String> sendXMLRequest(String requestJson, String uriPath, HttpMethod reqMethod){ - headers.set("Accept", MediaType.APPLICATION_XML); - headers.set("Content-Type", MediaType.APPLICATION_XML); + public ResponseEntity<String> sendXMLRequest(String requestJson, String uriPath, HttpMethod reqMethod) { + headers.set("Accept", MediaType.APPLICATION_XML); + headers.set("Content-Type", MediaType.APPLICATION_XML); - UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(uriPath)); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(uriPath)); - HttpEntity<String> request = new HttpEntity<String>(requestJson, headers); - ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), - reqMethod, request, String.class); + HttpEntity<String> request = new HttpEntity<String>(requestJson, headers); + ResponseEntity<String> response = + restTemplate.exchange(builder.toUriString(), reqMethod, request, String.class); - return response; - } + return response; + } - public String inputStream(String JsonInput)throws IOException{ - JsonInput = "src/test/resources/" + JsonInput; - String input = new String(Files.readAllBytes(Paths.get(JsonInput))); - return input; - } + public String inputStream(String JsonInput) throws IOException { + JsonInput = "src/test/resources/" + JsonInput; + String input = new String(Files.readAllBytes(Paths.get(JsonInput))); + return input; + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MsoNetworkAdapterAsyncImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MsoNetworkAdapterAsyncImplTest.java index 21ca860b54..727f18902a 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MsoNetworkAdapterAsyncImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/MsoNetworkAdapterAsyncImplTest.java @@ -31,11 +31,9 @@ import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackDeleteOrU import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPostStacks_200; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPutPublicUrlStackByNameAndID_NETWORK2_200; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccessQueryNetwork; - import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; - import org.apache.http.HttpStatus; import org.junit.Test; import org.onap.so.adapters.vnf.BaseRestTestUtils; @@ -45,233 +43,224 @@ import org.onap.so.openstack.beans.Subnet; import org.springframework.beans.factory.annotation.Autowired; public class MsoNetworkAdapterAsyncImplTest extends BaseRestTestUtils { - @Autowired - MsoNetworkAdapterAsyncImpl impl; + @Autowired + MsoNetworkAdapterAsyncImpl impl; - @Test - public void healthCheckATest() { - MsoNetworkAdapterAsyncImpl mNAAimpl = new MsoNetworkAdapterAsyncImpl(); - mNAAimpl.healthCheckA(); - } + @Test + public void healthCheckATest() { + MsoNetworkAdapterAsyncImpl mNAAimpl = new MsoNetworkAdapterAsyncImpl(); + mNAAimpl.healthCheckA(); + } - @Test - public void rollbackNetworkATest() throws IOException { - wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")) - .withRequestBody(containing("tenantId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl")) - .withStatus(HttpStatus.SC_OK))); - wireMockServer.stubFor(post(urlPathEqualTo("/notificationUrl")) - .withRequestBody(containing("<completed>true</completed>")) - .willReturn(aResponse() - .withBody("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:net=\"http://org.onap.so/networkNotify\">\n" + - " <soapenv:Header/>\n" + - " <soapenv:Body>\n" + - " <net:rollbackNetworkNotificationResponse>\n" + - " </net:rollbackNetworkNotificationResponse>\n" + - " </soapenv:Body>\n" + - "</soapenv:Envelope>") - .withStatus(HttpStatus.SC_OK))); - NetworkRollback nrb = getNetworkRollback("mtn13"); - impl.rollbackNetworkA(nrb, "messageId", "http://localhost:"+wireMockPort+"/notificationUrl"); - } + @Test + public void rollbackNetworkATest() throws IOException { + wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl")) + .withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(post(urlPathEqualTo("/notificationUrl")) + .withRequestBody(containing("<completed>true</completed>")) + .willReturn(aResponse().withBody( + "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:net=\"http://org.onap.so/networkNotify\">\n" + + " <soapenv:Header/>\n" + " <soapenv:Body>\n" + + " <net:rollbackNetworkNotificationResponse>\n" + + " </net:rollbackNetworkNotificationResponse>\n" + " </soapenv:Body>\n" + + "</soapenv:Envelope>") + .withStatus(HttpStatus.SC_OK))); + NetworkRollback nrb = getNetworkRollback("mtn13"); + impl.rollbackNetworkA(nrb, "messageId", "http://localhost:" + wireMockPort + "/notificationUrl"); + } - @Test - public void rollbackNetworkATest_NotifyException() throws IOException { - wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")) - .withRequestBody(containing("tenantId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl")) - .withStatus(HttpStatus.SC_OK))); - wireMockServer.stubFor(post(urlPathEqualTo("/notificationUrl")) - .withRequestBody(containing("<completed>true</completed>")) - .willReturn(aResponse() - .withStatus(HttpStatus.SC_NOT_FOUND))); - NetworkRollback nrb = getNetworkRollback("mtn13"); - impl.rollbackNetworkA(nrb, "messageId", "http://localhost:"+wireMockPort+"/notificationUrl"); - } + @Test + public void rollbackNetworkATest_NotifyException() throws IOException { + wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl")) + .withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor( + post(urlPathEqualTo("/notificationUrl")).withRequestBody(containing("<completed>true</completed>")) + .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND))); + NetworkRollback nrb = getNetworkRollback("mtn13"); + impl.rollbackNetworkA(nrb, "messageId", "http://localhost:" + wireMockPort + "/notificationUrl"); + } - private NetworkRollback getNetworkRollback(String cloudId) { - NetworkRollback nrb = new NetworkRollback(); - nrb.setCloudId(cloudId); - nrb.setMsoRequest(new MsoRequest()); - nrb.setModelCustomizationUuid("3bdbb104-476c-483e-9f8b-c095b3d3068c"); - nrb.setNetworkCreated(true); - nrb.setNetworkId("networkId"); - nrb.setNetworkName("networkName"); - nrb.setNetworkStackId("networkStackId"); - nrb.setNetworkType("networkType"); - nrb.setNeutronNetworkId("neutronNetworkId"); - nrb.setPhysicalNetwork("physicalNetwork"); - nrb.setTenantId("tenantId"); - nrb.setVlans(new ArrayList<>()); - return nrb; - } + private NetworkRollback getNetworkRollback(String cloudId) { + NetworkRollback nrb = new NetworkRollback(); + nrb.setCloudId(cloudId); + nrb.setMsoRequest(new MsoRequest()); + nrb.setModelCustomizationUuid("3bdbb104-476c-483e-9f8b-c095b3d3068c"); + nrb.setNetworkCreated(true); + nrb.setNetworkId("networkId"); + nrb.setNetworkName("networkName"); + nrb.setNetworkStackId("networkStackId"); + nrb.setNetworkType("networkType"); + nrb.setNeutronNetworkId("neutronNetworkId"); + nrb.setPhysicalNetwork("physicalNetwork"); + nrb.setTenantId("tenantId"); + nrb.setVlans(new ArrayList<>()); + return nrb; + } - @Test - public void rollbackNetworkATestNetworkException() { - NetworkRollback nrb = getNetworkRollback("cloudId"); + @Test + public void rollbackNetworkATestNetworkException() { + NetworkRollback nrb = getNetworkRollback("cloudId"); - impl.rollbackNetworkA(nrb, "messageId", "http://localhost"); - } + impl.rollbackNetworkA(nrb, "messageId", "http://localhost"); + } - @Test - public void noRollbackNetworkATest() { - impl.rollbackNetworkA(null, "messageId", "http://localhost"); - } + @Test + public void noRollbackNetworkATest() { + impl.rollbackNetworkA(null, "messageId", "http://localhost"); + } - @Test - public void deleteNetworkATest() throws IOException { - wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")) - .withRequestBody(containing("tenantId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl")) - .withStatus(HttpStatus.SC_OK))); - wireMockServer.stubFor(post(urlPathEqualTo("/notificationUrl")) - .withRequestBody(containing("<completed>true</completed>")) - .willReturn(aResponse() - .withBody("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:net=\"http://org.onap.so/networkNotify\">\n" + - " <soapenv:Header/>\n" + - " <soapenv:Body>\n" + - " <net:deleteNetworkNotificationResponse>\n" + - " </net:deleteNetworkNotificationResponse>\n" + - " </soapenv:Body>\n" + - "</soapenv:Envelope>") - .withStatus(HttpStatus.SC_OK))); - impl.deleteNetworkA("mtn13", "tenantId", "networkType", "modelCustomizationUuid", "networkId", - "messageId", new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl"); - } + @Test + public void deleteNetworkATest() throws IOException { + wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl")) + .withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(post(urlPathEqualTo("/notificationUrl")) + .withRequestBody(containing("<completed>true</completed>")) + .willReturn(aResponse().withBody( + "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:net=\"http://org.onap.so/networkNotify\">\n" + + " <soapenv:Header/>\n" + " <soapenv:Body>\n" + + " <net:deleteNetworkNotificationResponse>\n" + + " </net:deleteNetworkNotificationResponse>\n" + " </soapenv:Body>\n" + + "</soapenv:Envelope>") + .withStatus(HttpStatus.SC_OK))); + impl.deleteNetworkA("mtn13", "tenantId", "networkType", "modelCustomizationUuid", "networkId", "messageId", + new MsoRequest(), "http://localhost:" + wireMockPort + "/notificationUrl"); + } - @Test - public void deleteNetworkATest_NotifyException() throws IOException { - wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")) - .withRequestBody(containing("tenantId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl")) - .withStatus(HttpStatus.SC_OK))); - wireMockServer.stubFor(post(urlPathEqualTo("/notificationUrl")) - .withRequestBody(containing("<completed>true</completed>")) - .willReturn(aResponse() - .withStatus(HttpStatus.SC_NOT_FOUND))); - impl.deleteNetworkA("mtn13", "tenantId", "networkType", "modelCustomizationUuid", "networkId", - "messageId", new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl"); - } + @Test + public void deleteNetworkATest_NotifyException() throws IOException { + wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl")) + .withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor( + post(urlPathEqualTo("/notificationUrl")).withRequestBody(containing("<completed>true</completed>")) + .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND))); + impl.deleteNetworkA("mtn13", "tenantId", "networkType", "modelCustomizationUuid", "networkId", "messageId", + new MsoRequest(), "http://localhost:" + wireMockPort + "/notificationUrl"); + } - @Test - public void deleteNetworkATest_NetworkException() { - impl.deleteNetworkA("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId", - "messageId", new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl"); - } + @Test + public void deleteNetworkATest_NetworkException() { + impl.deleteNetworkA("cloudSiteId", "tenantId", "networkType", "modelCustomizationUuid", "networkId", + "messageId", new MsoRequest(), "http://localhost:" + wireMockPort + "/notificationUrl"); + } - @Test - public void updateNetworkATest() throws IOException { - wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")) - .withRequestBody(containing("tenantId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl")) - .withStatus(HttpStatus.SC_OK))); - mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", "dvspg-VCE_VPE-mtjnj40avbc"); - mockOpenStackGetStackDeleteOrUpdateComplete_200(wireMockServer, "OpenstackResponse_Stack_UpdateComplete.json"); - mockOpenStackPutPublicUrlStackByNameAndID_NETWORK2_200(wireMockServer); - wireMockServer.stubFor(post(urlPathEqualTo("/notificationUrl")) - .withRequestBody(containing("updateNetworkNotification")) - .willReturn(aResponse() - .withBody("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:net=\"http://org.onap.so/networkNotify\">\n" + - " <soapenv:Header/>\n" + - " <soapenv:Body>\n" + - " <net:updateNetworkNotificationResponse>\n" + - " </net:updateNetworkNotificationResponse>\n" + - " </soapenv:Body>\n" + - "</soapenv:Envelope>") - .withStatus(HttpStatus.SC_OK))); - HashMap<String,String> networkParams = new HashMap<String,String>(); - networkParams.put("shared", "true"); - networkParams.put("external", "false"); - impl.updateNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", "dvspg-VCE_VPE-mtjnj40avbc", - "dvspg-VCE_VPE-mtjnj40avbc", "physicalNetworkName", new ArrayList<>(), new ArrayList<Subnet>(), networkParams, "messageId", - new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl"); - } + @Test + public void updateNetworkATest() throws IOException { + wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl")) + .withStatus(HttpStatus.SC_OK))); + mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", + "dvspg-VCE_VPE-mtjnj40avbc"); + mockOpenStackGetStackDeleteOrUpdateComplete_200(wireMockServer, "OpenstackResponse_Stack_UpdateComplete.json"); + mockOpenStackPutPublicUrlStackByNameAndID_NETWORK2_200(wireMockServer); + wireMockServer.stubFor(post(urlPathEqualTo("/notificationUrl")) + .withRequestBody(containing("updateNetworkNotification")) + .willReturn(aResponse().withBody( + "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:net=\"http://org.onap.so/networkNotify\">\n" + + " <soapenv:Header/>\n" + " <soapenv:Body>\n" + + " <net:updateNetworkNotificationResponse>\n" + + " </net:updateNetworkNotificationResponse>\n" + " </soapenv:Body>\n" + + "</soapenv:Envelope>") + .withStatus(HttpStatus.SC_OK))); + HashMap<String, String> networkParams = new HashMap<String, String>(); + networkParams.put("shared", "true"); + networkParams.put("external", "false"); + impl.updateNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", + "dvspg-VCE_VPE-mtjnj40avbc", "dvspg-VCE_VPE-mtjnj40avbc", "physicalNetworkName", new ArrayList<>(), + new ArrayList<Subnet>(), networkParams, "messageId", new MsoRequest(), + "http://localhost:" + wireMockPort + "/notificationUrl"); + } - @Test - public void updateNetworkATest_NotifyExcpetion() throws IOException { - wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")) - .withRequestBody(containing("tenantId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl")) - .withStatus(HttpStatus.SC_OK))); - mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", "dvspg-VCE_VPE-mtjnj40avbc"); - mockOpenStackGetStackDeleteOrUpdateComplete_200(wireMockServer, "OpenstackResponse_Stack_UpdateComplete.json"); - mockOpenStackPutPublicUrlStackByNameAndID_NETWORK2_200(wireMockServer); - HashMap<String,String> networkParams = new HashMap<String,String>(); - networkParams.put("shared", "true"); - networkParams.put("external", "false"); - impl.updateNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", "dvspg-VCE_VPE-mtjnj40avbc", - "dvspg-VCE_VPE-mtjnj40avbc", "physicalNetworkName", new ArrayList<>(), new ArrayList<>(), networkParams, "messageId", - new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl"); } + @Test + public void updateNetworkATest_NotifyExcpetion() throws IOException { + wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl")) + .withStatus(HttpStatus.SC_OK))); + mockOpenStackGetStackCreated_200(wireMockServer, "OpenstackResponse_Stack_Created.json", + "dvspg-VCE_VPE-mtjnj40avbc"); + mockOpenStackGetStackDeleteOrUpdateComplete_200(wireMockServer, "OpenstackResponse_Stack_UpdateComplete.json"); + mockOpenStackPutPublicUrlStackByNameAndID_NETWORK2_200(wireMockServer); + HashMap<String, String> networkParams = new HashMap<String, String>(); + networkParams.put("shared", "true"); + networkParams.put("external", "false"); + impl.updateNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", + "dvspg-VCE_VPE-mtjnj40avbc", "dvspg-VCE_VPE-mtjnj40avbc", "physicalNetworkName", new ArrayList<>(), + new ArrayList<>(), networkParams, "messageId", new MsoRequest(), + "http://localhost:" + wireMockPort + "/notificationUrl"); + } - @Test - public void updateNetworkATest_NetworkException() { - impl.updateNetworkA("cloudSiteId", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", "networkId", - "dvspg-VCE_VPE-mtjnj40avbc", "physicalNetworkName", new ArrayList<>(), new ArrayList<>(), new HashMap<String,String>(), "messageId", - new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl"); - } + @Test + public void updateNetworkATest_NetworkException() { + impl.updateNetworkA("cloudSiteId", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", + "networkId", "dvspg-VCE_VPE-mtjnj40avbc", "physicalNetworkName", new ArrayList<>(), new ArrayList<>(), + new HashMap<String, String>(), "messageId", new MsoRequest(), + "http://localhost:" + wireMockPort + "/notificationUrl"); + } - @Test - public void queryNetworkATest() throws IOException { - mockOpenStackResponseAccessQueryNetwork(wireMockServer, wireMockPort); - impl.queryNetworkA("mtn13", "tenantId", "networkId", "messageId", new MsoRequest(), - "http://localhost:"+wireMockPort+"/notificationUrl"); - } + @Test + public void queryNetworkATest() throws IOException { + mockOpenStackResponseAccessQueryNetwork(wireMockServer, wireMockPort); + impl.queryNetworkA("mtn13", "tenantId", "networkId", "messageId", new MsoRequest(), + "http://localhost:" + wireMockPort + "/notificationUrl"); + } - @Test - public void createNetworkATest() throws IOException { - wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")) - .withRequestBody(containing("tenantId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl")) - .withStatus(HttpStatus.SC_OK))); - wireMockServer.stubFor(post(urlPathEqualTo("/notificationUrl")) - .withRequestBody(containing("createNetworkNotification")) - .willReturn(aResponse() - .withBody("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:net=\"http://org.onap.so/networkNotify\">\n" + - " <soapenv:Header/>\n" + - " <soapenv:Body>\n" + - " <net:createNetworkNotificationResponse>\n" + - " </net:createNetworkNotificationResponse>\n" + - " </soapenv:Body>\n" + - "</soapenv:Envelope>") - .withStatus(HttpStatus.SC_OK))); - mockOpenStackGetStackCreatedVUSP_200(wireMockServer); - mockOpenStackPostStacks_200(wireMockServer); - mockOpenStackPostStacks_200(wireMockServer); - HashMap<String,String> networkParams = new HashMap<String,String>(); - impl.createNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0", - "physicalNetworkName", new ArrayList<>(), false, false, new ArrayList<>(), networkParams, "messageId", - new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl"); - } + @Test + public void createNetworkATest() throws IOException { + wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl")) + .withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(post(urlPathEqualTo("/notificationUrl")) + .withRequestBody(containing("createNetworkNotification")) + .willReturn(aResponse().withBody( + "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:net=\"http://org.onap.so/networkNotify\">\n" + + " <soapenv:Header/>\n" + " <soapenv:Body>\n" + + " <net:createNetworkNotificationResponse>\n" + + " </net:createNetworkNotificationResponse>\n" + " </soapenv:Body>\n" + + "</soapenv:Envelope>") + .withStatus(HttpStatus.SC_OK))); + mockOpenStackGetStackCreatedVUSP_200(wireMockServer); + mockOpenStackPostStacks_200(wireMockServer); + mockOpenStackPostStacks_200(wireMockServer); + HashMap<String, String> networkParams = new HashMap<String, String>(); + impl.createNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", + "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0", "physicalNetworkName", new ArrayList<>(), false, + false, new ArrayList<>(), networkParams, "messageId", new MsoRequest(), + "http://localhost:" + wireMockPort + "/notificationUrl"); + } - @Test - public void createNetworkATest_NotifyException() throws IOException { - wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")) - .withRequestBody(containing("tenantId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl")) - .withStatus(HttpStatus.SC_OK))); - mockOpenStackGetStackCreatedVUSP_200(wireMockServer); - mockOpenStackPostStacks_200(wireMockServer); - HashMap<String,String> networkParams = new HashMap<String,String>(); - networkParams.put("shared", "true"); - networkParams.put("external", "false"); - impl.createNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0", - "physicalNetworkName", new ArrayList<>(), false, false, new ArrayList<>(), networkParams, "messageId", - new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl"); - } + @Test + public void createNetworkATest_NotifyException() throws IOException { + wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFile("OpenstackResponse_Access.json", wireMockPort, "/mockPublicUrl")) + .withStatus(HttpStatus.SC_OK))); + mockOpenStackGetStackCreatedVUSP_200(wireMockServer); + mockOpenStackPostStacks_200(wireMockServer); + HashMap<String, String> networkParams = new HashMap<String, String>(); + networkParams.put("shared", "true"); + networkParams.put("external", "false"); + impl.createNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", + "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0", "physicalNetworkName", new ArrayList<>(), false, + false, new ArrayList<>(), networkParams, "messageId", new MsoRequest(), + "http://localhost:" + wireMockPort + "/notificationUrl"); + } - @Test - public void createNetworkATest_NetworkException() { - impl.createNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0", - "physicalNetworkName", new ArrayList<>(), false, false, new ArrayList<>(), new HashMap<String,String>(), "messageId", - new MsoRequest(), "http://localhost:"+wireMockPort+"/notificationUrl"); - } + @Test + public void createNetworkATest_NetworkException() { + impl.createNetworkA("mtn13", "tenantId", "networkType", "3bdbb104-476c-483e-9f8b-c095b3d3068c", + "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0", "physicalNetworkName", new ArrayList<>(), false, + false, new ArrayList<>(), new HashMap<String, String>(), "messageId", new MsoRequest(), + "http://localhost:" + wireMockPort + "/notificationUrl"); + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java index 97392adeef..1f4c205e7a 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/NetworkAdapterRestTest.java @@ -36,15 +36,12 @@ import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPublicUrlStackByI import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPublicUrlStackByName_200; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPutPublicUrlStackByNameAndID_200; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess; - import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; - import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; - import org.json.JSONException; import org.junit.Test; import org.onap.so.adapters.nwrest.CreateNetworkRequest; @@ -64,302 +61,306 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; - import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; public class NetworkAdapterRestTest extends BaseRestTestUtils { - @Autowired - private JettisonStyleMapperProvider jettisonTypeObjectMapper; - private static final String CLOUDSITE_ID = "mtn13"; - private static final String TENANT_ID = "ba38bc24a2ef4fb2ad2810c894f1938f"; - private static final String NETWORK_ID = "da886914-efb2-4917-b335-c8381528d90b"; - private static final String NETWORK_TYPE = "CONTRAIL30_BASIC"; - private static final String MODEL_CUSTOMIZATION_UUID = "3bdbb104-476c-483e-9f8b-c095b3d308ac"; - private static final String MSO_SERVICE_INSTANCE_ID = "05869d5f-47df-4b45-bbfc-4f03ce0a50bf"; - private static final String MSO_REQUEST_ID = "requestId"; - private static final String NETWORK_NAME = "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0"; - - @Test - public void testCreateNetwork() throws JSONException, JsonParseException, JsonMappingException, IOException { - - CreateNetworkRequest request = new CreateNetworkRequest(); - request.setBackout(true); - request.setSkipAAI(true); - request.setFailIfExists(false); - MsoRequest msoReq = new MsoRequest(); - String networkTechnology = "CONTRAIL"; - - msoReq.setRequestId(MSO_REQUEST_ID); - msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); - request.setMsoRequest(msoReq); - request.setCloudSiteId(CLOUDSITE_ID); - request.setTenantId(TENANT_ID); - request.setNetworkId(NETWORK_ID); - request.setNetworkName(NETWORK_NAME); - request.setNetworkType(NETWORK_TYPE); - request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID); - request.setNetworkTechnology(networkTechnology); - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - mockOpenStackPostPublicUrlWithBodyFile_200(wireMockServer); - - mockOpenStackGetStackCreatedVUSP_200(wireMockServer); - - mockOpenStackGetStackVUSP_404(wireMockServer); - - headers.add("Accept", MediaType.APPLICATION_JSON); - HttpEntity<CreateNetworkRequest> entity = new HttpEntity<CreateNetworkRequest>(request, headers); - ResponseEntity<CreateNetworkResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/networks"), HttpMethod.POST, entity, CreateNetworkResponse.class); - - CreateNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( - new File("src/test/resources/__files/CreateNetworkResponse.json"), CreateNetworkResponse.class); - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - assertThat(response.getBody(), sameBeanAs(expectedResponse)); - } - - @Test - public void testCreateNetwork_JSON() throws JSONException, JsonParseException, JsonMappingException, IOException { - - - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - mockOpenStackPostPublicUrlWithBodyFile_200(wireMockServer); - - mockOpenStackGetStackCreatedAppC_200(wireMockServer); - - mockOpenStackGetStackAppC_404(wireMockServer); - - headers.add("Content-Type", MediaType.APPLICATION_JSON); - headers.add("Accept", MediaType.APPLICATION_JSON); - - String request = readJsonFileAsString("src/test/resources/CreateNetwork.json"); - HttpEntity<String> entity = new HttpEntity<String>(request, headers); - - ResponseEntity<CreateNetworkResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/networks"), HttpMethod.POST, entity, CreateNetworkResponse.class); - - CreateNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( - new File("src/test/resources/__files/CreateNetworkResponse2.json"), CreateNetworkResponse.class); - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - assertThat(response.getBody(), sameBeanAs(expectedResponse)); - } - - - - @Test - public void testDeleteNetwork() throws IOException{ - - DeleteNetworkRequest request = new DeleteNetworkRequest(); - - MsoRequest msoReq = new MsoRequest(); - - msoReq.setRequestId(MSO_REQUEST_ID); - msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); - request.setMsoRequest(msoReq); - request.setCloudSiteId(CLOUDSITE_ID); - request.setTenantId(TENANT_ID); - request.setNetworkId(NETWORK_ID); - request.setNetworkType(NETWORK_TYPE); - request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID); - request.setNetworkStackId(NETWORK_ID); - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - mockOpenStackPublicUrlStackByID_200(wireMockServer, wireMockPort); - - mockOpenStackGetPublicUrlStackByNameAndID_204(wireMockServer, wireMockPort); - - mockOpenStackDeletePublicUrlStackByNameAndID_204(wireMockServer); - - headers.add("Accept", MediaType.APPLICATION_JSON); - - HttpEntity<DeleteNetworkRequest> entity = new HttpEntity<DeleteNetworkRequest>(request, headers); - - ResponseEntity<DeleteNetworkResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/networks/da886914-efb2-4917-b335-c8381528d90b"), HttpMethod.DELETE, entity, DeleteNetworkResponse.class); - - DeleteNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( - new File("src/test/resources/__files/DeleteNetworkResponse.json"), DeleteNetworkResponse.class); - - assertThat(response.getBody(), sameBeanAs(expectedResponse)); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - - } - - @Test - public void testRollbackNetwork() throws IOException { - - RollbackNetworkRequest request = new RollbackNetworkRequest(); - - MsoRequest msoReq = new MsoRequest(); - - msoReq.setRequestId(MSO_REQUEST_ID); - msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - mockOpenStackPublicUrlStackByID_200(wireMockServer, wireMockPort); - - mockOpenStackGetPublicUrlStackByNameAndID_204(wireMockServer, wireMockPort); - - mockOpenStackDeletePublicUrlStackByNameAndID_204(wireMockServer); - - headers.add("Accept", MediaType.APPLICATION_JSON); - - HttpEntity<RollbackNetworkRequest> entity = new HttpEntity<>(request, headers); - - ResponseEntity<RollbackNetworkResponse> response = restTemplate - .exchange(createURLWithPort("/services/rest/v1/networks/da886914-efb2-4917-b335-c8381528d90b/rollback"), - HttpMethod.DELETE, entity, RollbackNetworkResponse.class); - - RollbackNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper() - .readValue(new File("src/test/resources/__files/RollbackNetworkResponse.json"), RollbackNetworkResponse.class); - - assertThat(response.getBody(), sameBeanAs(expectedResponse)); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - - } - - @Test - public void testQueryNetwork_Exception() throws IOException{ - MsoRequest msoReq = new MsoRequest(); - msoReq.setRequestId(MSO_REQUEST_ID); - msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); - headers.add("Accept", MediaType.APPLICATION_JSON); - - HttpEntity<DeleteNetworkRequest> entity = new HttpEntity<DeleteNetworkRequest>(headers); - - ResponseEntity<QueryNetworkError> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/networks/da886914-efb2-4917-b335-c8381528d90b"), HttpMethod.GET, - entity, QueryNetworkError.class); - - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - - } - - @Test - public void testQueryNetwork() throws IOException{ - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_200(wireMockServer); - - headers.add("Accept", MediaType.APPLICATION_JSON); - HttpEntity<DeleteNetworkRequest> entity = new HttpEntity<DeleteNetworkRequest>(headers); - - ResponseEntity<QueryNetworkResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/networks/da886914-efb2-4917-b335-c8381528d90b"+"?cloudSiteId=" + CLOUDSITE_ID + "&tenantId=" + TENANT_ID - + "&aaiNetworkId=aaiNetworkId"), HttpMethod.GET, - entity, QueryNetworkResponse.class); - - assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value()); - - } - - @Test - public void testUpdateNetwork() throws IOException{ - - UpdateNetworkRequest request = new UpdateNetworkRequest(); - - MsoRequest msoReq = new MsoRequest(); - - msoReq.setRequestId(MSO_REQUEST_ID); - msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); - request.setMsoRequest(msoReq); - request.setCloudSiteId(CLOUDSITE_ID); - request.setTenantId(TENANT_ID); - request.setNetworkId(NETWORK_ID); - request.setNetworkName(NETWORK_NAME); - request.setNetworkType(NETWORK_TYPE); - request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID); - request.setNetworkStackId(NETWORK_ID); - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - mockOpenStackPublicUrlStackByName_200(wireMockServer, wireMockPort); - - mockOpenStackPublicUrlStackByID_200(wireMockServer, wireMockPort); - - mockOpenStackGetPublicUrlStackByNameAndID_200(wireMockServer, wireMockPort); - - mockOpenStackPutPublicUrlStackByNameAndID_200(wireMockServer); - - headers.add("Accept", MediaType.APPLICATION_JSON); - - HttpEntity<UpdateNetworkRequest> entity = new HttpEntity<UpdateNetworkRequest>(request, headers); - - ResponseEntity<UpdateNetworkResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/networks/da886914-efb2-4917-b335-c8381528d90b"), HttpMethod.PUT, entity, UpdateNetworkResponse.class); - - UpdateNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( - new File("src/test/resources/__files/UpdateNetworkResponse.json"), UpdateNetworkResponse.class); - - assertThat(response.getBody(), sameBeanAs(expectedResponse)); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - } - - @Test - public void testCreateNetworkCNRC_JSON() throws JSONException, JsonParseException, JsonMappingException, IOException { - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - mockOpenStackPostPublicUrlWithBodyFile_200(wireMockServer); - - mockOpenStackGetStackCreatedAppC_200(wireMockServer); - - mockOpenStackGetStackAppC_404(wireMockServer); - - headers.add("Content-Type", MediaType.APPLICATION_JSON); - headers.add("Accept", MediaType.APPLICATION_JSON); - - String request = readJsonFileAsString("src/test/resources/CreateNetwork3.json"); - HttpEntity<String> entity = new HttpEntity<String>(request, headers); - - ResponseEntity<CreateNetworkResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/networks"), HttpMethod.POST, entity, CreateNetworkResponse.class); - - CreateNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( - new File("src/test/resources/__files/CreateNetworkResponse3.json"), CreateNetworkResponse.class); - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - assertThat(response.getBody(), sameBeanAs(expectedResponse)); - } - - @Test - public void testCreateNetworkNC_Shared_JSON() throws JSONException, JsonParseException, JsonMappingException, IOException { - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - mockOpenStackPostPublicUrlWithBodyFile_200(wireMockServer); - - mockOpenStackGetStackCreatedAppC_200(wireMockServer); - - mockOpenStackGetStackAppC_404(wireMockServer); - - headers.add("Content-Type", MediaType.APPLICATION_JSON); - headers.add("Accept", MediaType.APPLICATION_JSON); - - String request = readJsonFileAsString("src/test/resources/CreateNetwork4.json"); - HttpEntity<String> entity = new HttpEntity<String>(request, headers); - - ResponseEntity<CreateNetworkResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/networks"), HttpMethod.POST, entity, CreateNetworkResponse.class); - - CreateNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( - new File("src/test/resources/__files/CreateNetworkResponse4.json"), CreateNetworkResponse.class); - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - assertThat(response.getBody(), sameBeanAs(expectedResponse)); - } - - @Override - protected String readJsonFileAsString(String fileLocation) throws JsonParseException, JsonMappingException, IOException{ - return new String(Files.readAllBytes(Paths.get(fileLocation))); - } + @Autowired + private JettisonStyleMapperProvider jettisonTypeObjectMapper; + private static final String CLOUDSITE_ID = "mtn13"; + private static final String TENANT_ID = "ba38bc24a2ef4fb2ad2810c894f1938f"; + private static final String NETWORK_ID = "da886914-efb2-4917-b335-c8381528d90b"; + private static final String NETWORK_TYPE = "CONTRAIL30_BASIC"; + private static final String MODEL_CUSTOMIZATION_UUID = "3bdbb104-476c-483e-9f8b-c095b3d308ac"; + private static final String MSO_SERVICE_INSTANCE_ID = "05869d5f-47df-4b45-bbfc-4f03ce0a50bf"; + private static final String MSO_REQUEST_ID = "requestId"; + private static final String NETWORK_NAME = "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0"; + + @Test + public void testCreateNetwork() throws JSONException, JsonParseException, JsonMappingException, IOException { + + CreateNetworkRequest request = new CreateNetworkRequest(); + request.setBackout(true); + request.setSkipAAI(true); + request.setFailIfExists(false); + MsoRequest msoReq = new MsoRequest(); + String networkTechnology = "CONTRAIL"; + + msoReq.setRequestId(MSO_REQUEST_ID); + msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); + request.setMsoRequest(msoReq); + request.setCloudSiteId(CLOUDSITE_ID); + request.setTenantId(TENANT_ID); + request.setNetworkId(NETWORK_ID); + request.setNetworkName(NETWORK_NAME); + request.setNetworkType(NETWORK_TYPE); + request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID); + request.setNetworkTechnology(networkTechnology); + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + mockOpenStackPostPublicUrlWithBodyFile_200(wireMockServer); + + mockOpenStackGetStackCreatedVUSP_200(wireMockServer); + + mockOpenStackGetStackVUSP_404(wireMockServer); + + headers.add("Accept", MediaType.APPLICATION_JSON); + HttpEntity<CreateNetworkRequest> entity = new HttpEntity<CreateNetworkRequest>(request, headers); + ResponseEntity<CreateNetworkResponse> response = restTemplate.exchange( + createURLWithPort("/services/rest/v1/networks"), HttpMethod.POST, entity, CreateNetworkResponse.class); + + CreateNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/CreateNetworkResponse.json"), CreateNetworkResponse.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + } + + @Test + public void testCreateNetwork_JSON() throws JSONException, JsonParseException, JsonMappingException, IOException { + + + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + mockOpenStackPostPublicUrlWithBodyFile_200(wireMockServer); + + mockOpenStackGetStackCreatedAppC_200(wireMockServer); + + mockOpenStackGetStackAppC_404(wireMockServer); + + headers.add("Content-Type", MediaType.APPLICATION_JSON); + headers.add("Accept", MediaType.APPLICATION_JSON); + + String request = readJsonFileAsString("src/test/resources/CreateNetwork.json"); + HttpEntity<String> entity = new HttpEntity<String>(request, headers); + + ResponseEntity<CreateNetworkResponse> response = restTemplate.exchange( + createURLWithPort("/services/rest/v1/networks"), HttpMethod.POST, entity, CreateNetworkResponse.class); + + CreateNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/CreateNetworkResponse2.json"), CreateNetworkResponse.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + } + + + + @Test + public void testDeleteNetwork() throws IOException { + + DeleteNetworkRequest request = new DeleteNetworkRequest(); + + MsoRequest msoReq = new MsoRequest(); + + msoReq.setRequestId(MSO_REQUEST_ID); + msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); + request.setMsoRequest(msoReq); + request.setCloudSiteId(CLOUDSITE_ID); + request.setTenantId(TENANT_ID); + request.setNetworkId(NETWORK_ID); + request.setNetworkType(NETWORK_TYPE); + request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID); + request.setNetworkStackId(NETWORK_ID); + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + mockOpenStackPublicUrlStackByID_200(wireMockServer, wireMockPort); + + mockOpenStackGetPublicUrlStackByNameAndID_204(wireMockServer, wireMockPort); + + mockOpenStackDeletePublicUrlStackByNameAndID_204(wireMockServer); + + headers.add("Accept", MediaType.APPLICATION_JSON); + + HttpEntity<DeleteNetworkRequest> entity = new HttpEntity<DeleteNetworkRequest>(request, headers); + + ResponseEntity<DeleteNetworkResponse> response = restTemplate.exchange( + createURLWithPort("/services/rest/v1/networks/da886914-efb2-4917-b335-c8381528d90b"), HttpMethod.DELETE, + entity, DeleteNetworkResponse.class); + + DeleteNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/DeleteNetworkResponse.json"), DeleteNetworkResponse.class); + + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + + } + + @Test + public void testRollbackNetwork() throws IOException { + + RollbackNetworkRequest request = new RollbackNetworkRequest(); + + MsoRequest msoReq = new MsoRequest(); + + msoReq.setRequestId(MSO_REQUEST_ID); + msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + mockOpenStackPublicUrlStackByID_200(wireMockServer, wireMockPort); + + mockOpenStackGetPublicUrlStackByNameAndID_204(wireMockServer, wireMockPort); + + mockOpenStackDeletePublicUrlStackByNameAndID_204(wireMockServer); + + headers.add("Accept", MediaType.APPLICATION_JSON); + + HttpEntity<RollbackNetworkRequest> entity = new HttpEntity<>(request, headers); + + ResponseEntity<RollbackNetworkResponse> response = restTemplate.exchange( + createURLWithPort("/services/rest/v1/networks/da886914-efb2-4917-b335-c8381528d90b/rollback"), + HttpMethod.DELETE, entity, RollbackNetworkResponse.class); + + RollbackNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/RollbackNetworkResponse.json"), RollbackNetworkResponse.class); + + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + + } + + @Test + public void testQueryNetwork_Exception() throws IOException { + MsoRequest msoReq = new MsoRequest(); + msoReq.setRequestId(MSO_REQUEST_ID); + msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); + headers.add("Accept", MediaType.APPLICATION_JSON); + + HttpEntity<DeleteNetworkRequest> entity = new HttpEntity<DeleteNetworkRequest>(headers); + + ResponseEntity<QueryNetworkError> response = restTemplate.exchange( + createURLWithPort("/services/rest/v1/networks/da886914-efb2-4917-b335-c8381528d90b"), HttpMethod.GET, + entity, QueryNetworkError.class); + + assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); + + } + + @Test + public void testQueryNetwork() throws IOException { + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackVfModule_200(wireMockServer); + + headers.add("Accept", MediaType.APPLICATION_JSON); + HttpEntity<DeleteNetworkRequest> entity = new HttpEntity<DeleteNetworkRequest>(headers); + + ResponseEntity<QueryNetworkResponse> response = restTemplate.exchange( + createURLWithPort("/services/rest/v1/networks/da886914-efb2-4917-b335-c8381528d90b" + "?cloudSiteId=" + + CLOUDSITE_ID + "&tenantId=" + TENANT_ID + "&aaiNetworkId=aaiNetworkId"), + HttpMethod.GET, entity, QueryNetworkResponse.class); + + assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value()); + + } + + @Test + public void testUpdateNetwork() throws IOException { + + UpdateNetworkRequest request = new UpdateNetworkRequest(); + + MsoRequest msoReq = new MsoRequest(); + + msoReq.setRequestId(MSO_REQUEST_ID); + msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); + request.setMsoRequest(msoReq); + request.setCloudSiteId(CLOUDSITE_ID); + request.setTenantId(TENANT_ID); + request.setNetworkId(NETWORK_ID); + request.setNetworkName(NETWORK_NAME); + request.setNetworkType(NETWORK_TYPE); + request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID); + request.setNetworkStackId(NETWORK_ID); + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + mockOpenStackPublicUrlStackByName_200(wireMockServer, wireMockPort); + + mockOpenStackPublicUrlStackByID_200(wireMockServer, wireMockPort); + + mockOpenStackGetPublicUrlStackByNameAndID_200(wireMockServer, wireMockPort); + + mockOpenStackPutPublicUrlStackByNameAndID_200(wireMockServer); + + headers.add("Accept", MediaType.APPLICATION_JSON); + + HttpEntity<UpdateNetworkRequest> entity = new HttpEntity<UpdateNetworkRequest>(request, headers); + + ResponseEntity<UpdateNetworkResponse> response = restTemplate.exchange( + createURLWithPort("/services/rest/v1/networks/da886914-efb2-4917-b335-c8381528d90b"), HttpMethod.PUT, + entity, UpdateNetworkResponse.class); + + UpdateNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/UpdateNetworkResponse.json"), UpdateNetworkResponse.class); + + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + } + + @Test + public void testCreateNetworkCNRC_JSON() + throws JSONException, JsonParseException, JsonMappingException, IOException { + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + mockOpenStackPostPublicUrlWithBodyFile_200(wireMockServer); + + mockOpenStackGetStackCreatedAppC_200(wireMockServer); + + mockOpenStackGetStackAppC_404(wireMockServer); + + headers.add("Content-Type", MediaType.APPLICATION_JSON); + headers.add("Accept", MediaType.APPLICATION_JSON); + + String request = readJsonFileAsString("src/test/resources/CreateNetwork3.json"); + HttpEntity<String> entity = new HttpEntity<String>(request, headers); + + ResponseEntity<CreateNetworkResponse> response = restTemplate.exchange( + createURLWithPort("/services/rest/v1/networks"), HttpMethod.POST, entity, CreateNetworkResponse.class); + + CreateNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/CreateNetworkResponse3.json"), CreateNetworkResponse.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + } + + @Test + public void testCreateNetworkNC_Shared_JSON() + throws JSONException, JsonParseException, JsonMappingException, IOException { + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + mockOpenStackPostPublicUrlWithBodyFile_200(wireMockServer); + + mockOpenStackGetStackCreatedAppC_200(wireMockServer); + + mockOpenStackGetStackAppC_404(wireMockServer); + + headers.add("Content-Type", MediaType.APPLICATION_JSON); + headers.add("Accept", MediaType.APPLICATION_JSON); + + String request = readJsonFileAsString("src/test/resources/CreateNetwork4.json"); + HttpEntity<String> entity = new HttpEntity<String>(request, headers); + + ResponseEntity<CreateNetworkResponse> response = restTemplate.exchange( + createURLWithPort("/services/rest/v1/networks"), HttpMethod.POST, entity, CreateNetworkResponse.class); + + CreateNetworkResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/CreateNetworkResponse4.json"), CreateNetworkResponse.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + } + + @Override + protected String readJsonFileAsString(String fileLocation) + throws JsonParseException, JsonMappingException, IOException { + return new String(Files.readAllBytes(Paths.get(fileLocation))); + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/exceptions/NetworkExceptionBeanTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/exceptions/NetworkExceptionBeanTest.java index a1e0a16819..01fbc308b9 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/exceptions/NetworkExceptionBeanTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/exceptions/NetworkExceptionBeanTest.java @@ -1,41 +1,35 @@ /* -* ============LICENSE_START======================================================= - * ONAP : SO - * ================================================================================ - * Copyright (C) 2018 TechMahindra - * ================================================================================ - * 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 + * ============LICENSE_START======================================================= ONAP : SO + * ================================================================================ Copyright (C) 2018 TechMahindra + * ================================================================================ 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 + * 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. + * 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.network.exceptions; import static org.junit.Assert.assertEquals; - import org.junit.Test; import org.onap.so.openstack.exceptions.MsoExceptionCategory; public class NetworkExceptionBeanTest { - - NetworkExceptionBean neb=new NetworkExceptionBean(); - MsoExceptionCategory msc=MsoExceptionCategory.INTERNAL; - - @Test - public void test() { - neb.setRolledBack(true); - neb.setMessage("message"); - neb.setCategory(msc); - assertEquals("message", neb.getMessage()); - assertEquals(msc, neb.getCategory()); - assertEquals(true, neb.isRolledBack()); - } + + NetworkExceptionBean neb = new NetworkExceptionBean(); + MsoExceptionCategory msc = MsoExceptionCategory.INTERNAL; + + @Test + public void test() { + neb.setRolledBack(true); + neb.setMessage("message"); + neb.setCategory(msc); + assertEquals("message", neb.getMessage()); + assertEquals(msc, neb.getCategory()); + assertEquals(true, neb.isRolledBack()); + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/exceptions/NetworkExceptionTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/exceptions/NetworkExceptionTest.java index bd5b07de1f..268d6b4c51 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/exceptions/NetworkExceptionTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/network/exceptions/NetworkExceptionTest.java @@ -1,50 +1,44 @@ /* -* ============LICENSE_START======================================================= - * ONAP : SO - * ================================================================================ - * Copyright (C) 2018 TechMahindra - * ================================================================================ - * 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 + * ============LICENSE_START======================================================= ONAP : SO + * ================================================================================ Copyright (C) 2018 TechMahindra + * ================================================================================ 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 + * 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. + * 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.network.exceptions; import static org.junit.Assert.assertEquals; - import org.junit.Test; import org.onap.so.openstack.exceptions.MsoException; import org.onap.so.openstack.exceptions.MsoExceptionCategory; -public class NetworkExceptionTest{ - - NetworkException ne=new NetworkException("msg"); - NetworkExceptionBean neb =new NetworkExceptionBean(); - MsoException msoException= new MsoException("msoException") { - private static final long serialVersionUID = 1L; - }; - MsoExceptionCategory msc=MsoExceptionCategory.INTERNAL; - NetworkException ne1=new NetworkException(msoException); - NetworkException ne2=new NetworkException(ne); - NetworkException ne3=new NetworkException("msg", ne); - NetworkException ne4=new NetworkException("msg", msoException); - NetworkException ne5=new NetworkException("msg", msc); - NetworkException ne6=new NetworkException("msg", msc, ne); - - @Test - public void test() { - ne.setFaultInfo(neb); - assertEquals(ne.getFaultInfo(), neb); - } +public class NetworkExceptionTest { + + NetworkException ne = new NetworkException("msg"); + NetworkExceptionBean neb = new NetworkExceptionBean(); + MsoException msoException = new MsoException("msoException") { + private static final long serialVersionUID = 1L; + }; + MsoExceptionCategory msc = MsoExceptionCategory.INTERNAL; + NetworkException ne1 = new NetworkException(msoException); + NetworkException ne2 = new NetworkException(ne); + NetworkException ne3 = new NetworkException("msg", ne); + NetworkException ne4 = new NetworkException("msg", msoException); + NetworkException ne5 = new NetworkException("msg", msc); + NetworkException ne6 = new NetworkException("msg", msc, ne); + + @Test + public void test() { + ne.setFaultInfo(neb); + assertEquals(ne.getFaultInfo(), neb); + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/MsoTenantAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/MsoTenantAdapterImplTest.java index df7e415724..b695a538bb 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/MsoTenantAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/MsoTenantAdapterImplTest.java @@ -20,9 +20,7 @@ package org.onap.so.adapters.tenant; import java.util.HashMap; - import javax.xml.ws.Holder; - import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; @@ -35,10 +33,10 @@ import org.onap.so.entity.MsoRequest; @RunWith(MockitoJUnitRunner.class) public class MsoTenantAdapterImplTest { - + @Mock - private CloudConfig cloudConfig; - + private CloudConfig cloudConfig; + @Spy @InjectMocks private MsoTenantAdapterImpl msoTenantAdapter; @@ -50,14 +48,14 @@ public class MsoTenantAdapterImplTest { @Test(expected = NullPointerException.class) public void createTenant() throws Exception { - msoTenantAdapter.createTenant("site", "tenant", new HashMap<>(), - true, true, new MsoRequest(), new Holder<String>(), new Holder<TenantRollback>()); + msoTenantAdapter.createTenant("site", "tenant", new HashMap<>(), true, true, new MsoRequest(), + new Holder<String>(), new Holder<TenantRollback>()); } @Test(expected = NullPointerException.class) public void queryTenant() throws Exception { - msoTenantAdapter.queryTenant("site", "tenant", new MsoRequest(), - new Holder<>(), new Holder<>(), new Holder<>()); + msoTenantAdapter.queryTenant("site", "tenant", new MsoRequest(), new Holder<>(), new Holder<>(), + new Holder<>()); } @Test(expected = NullPointerException.class) @@ -70,4 +68,4 @@ public class MsoTenantAdapterImplTest { msoTenantAdapter.rollbackTenant(new TenantRollback()); } -}
\ No newline at end of file +} diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/TenantAdapterRestTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/TenantAdapterRestTest.java index f24a5a5292..e481f0d03f 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/TenantAdapterRestTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/TenantAdapterRestTest.java @@ -36,15 +36,12 @@ import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPostTenantWithBod import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPostTenant_200; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPutRolesAdmin_200; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccessAdmin; - import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; - import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; - import org.junit.Ignore; import org.junit.Test; import org.onap.so.adapters.tenantrest.CreateTenantRequest; @@ -58,189 +55,186 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; - import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; public class TenantAdapterRestTest extends BaseRestTestUtils { - @Autowired - private JettisonStyleMapperProvider jettisonTypeObjectMapper; - - @Test - public void testCreateTenantCreated() throws JsonParseException, JsonMappingException, IOException { - - CreateTenantRequest request = new CreateTenantRequest(); - String cloudSiteId = "MTN13"; - String requestId = "62265093-277d-4388-9ba6-449838ade586"; - String serviceInstanceId = "4147e06f-1b89-49c5-b21f-4faf8dc9805a"; - String tenantName = "testingTenantName"; - boolean failIfExists = true; - boolean backout = true; - Map<String, String> metaData = new HashMap<>(); - metaData.put("key1", "value2"); - MsoRequest msoReq = new MsoRequest(); - msoReq.setRequestId(requestId); - msoReq.setServiceInstanceId(serviceInstanceId); - - request.setCloudSiteId(cloudSiteId); - request.setMsoRequest(msoReq); - request.setTenantName(tenantName); - request.setMetadata(metaData); - request.setBackout(backout); - request.setFailIfExists(failIfExists); - - mockOpenStackResponseAccessAdmin(wireMockServer, wireMockPort); - - mockOpenStackGetTenantByName_404(wireMockServer, tenantName); - - mockOpenStackPostTenantWithBodyFile_200(wireMockServer); - - mockOpenStackGetUser_200(wireMockServer, "m93945"); - - mockOpenStackGetRoles_200(wireMockServer, "OS-KSADM"); - - mockOpenStackPutRolesAdmin_200(wireMockServer, "OS-KSADM"); - - mockOpenStackPostMetadata_200(wireMockServer); - - headers.add("Accept", MediaType.APPLICATION_JSON); - HttpEntity<CreateTenantRequest> entity = new HttpEntity<CreateTenantRequest>(request, headers); - - ResponseEntity<CreateTenantResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/tenants"), HttpMethod.POST, - entity, CreateTenantResponse.class); - - CreateTenantResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( - new File("src/test/resources/__files/CreateTenantResponse_Created.json"), CreateTenantResponse.class); - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - assertThat(response.getBody(), sameBeanAs(expectedResponse)); - } - - @Test - public void testCreateTenantExists() throws JsonParseException, JsonMappingException, IOException { - - CreateTenantRequest request = new CreateTenantRequest(); - String cloudSiteId = "MTN13"; - String requestId = "62265093-277d-4388-9ba6-449838ade586"; - String serviceInstanceId = "4147e06f-1b89-49c5-b21f-4faf8dc9805a"; - String tenantName = "testingTenantName"; - boolean failIfExists = false; - boolean backout = true; - Map<String, String> metadata = new HashMap<>(); - - MsoRequest msoReq = new MsoRequest(); - msoReq.setRequestId(requestId); - msoReq.setServiceInstanceId(serviceInstanceId); - - request.setCloudSiteId(cloudSiteId); - request.setMsoRequest(msoReq); - request.setTenantName(tenantName); - request.setMetadata(metadata); - request.setBackout(backout); - request.setFailIfExists(failIfExists); - - mockOpenStackResponseAccessAdmin(wireMockServer, wireMockPort); - - mockOpenStackGetTenantByName_200(wireMockServer, tenantName); - - mockOpenStackPostTenant_200(wireMockServer); - - mockOpenStackGetMetadata_200(wireMockServer); - - headers.add("Accept", MediaType.APPLICATION_JSON); - HttpEntity<CreateTenantRequest> entity = new HttpEntity<CreateTenantRequest>(request, headers); - - ResponseEntity<CreateTenantResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/tenants"), HttpMethod.POST, - entity, CreateTenantResponse.class); - - CreateTenantResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( - new File("src/test/resources/__files/CreateTenantResponse_Exists.json"), CreateTenantResponse.class); - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - assertThat(response.getBody(), sameBeanAs(expectedResponse)); - } - - @Test - public void testDeleteTenant() throws IOException { - - DeleteTenantRequest request = new DeleteTenantRequest(); - String cloudSiteId = "mtn13"; - String tenantId = "tenantId"; - String requestId = "ra1"; - String serviceInstanceId = "sa1"; - - MsoRequest msoReq = new MsoRequest(); - msoReq.setRequestId(requestId); - msoReq.setServiceInstanceId(serviceInstanceId); - - request.setCloudSiteId(cloudSiteId); - request.setTenantId(tenantId); - request.setMsoRequest(msoReq); - - mockOpenStackResponseAccessAdmin(wireMockServer, wireMockPort); - - mockOpenStackGetTenantById_200(wireMockServer, tenantId); - - mockOpenStackDeleteTenantById_200(wireMockServer, tenantId); - - headers.add("Accept", MediaType.APPLICATION_JSON); - HttpEntity<DeleteTenantRequest> entity = new HttpEntity<DeleteTenantRequest>(request, headers); - - ResponseEntity<DeleteTenantResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/tenants/tenantId"), HttpMethod.DELETE, - entity, DeleteTenantResponse.class); - - DeleteTenantResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( - new File("src/test/resources/__files/DeleteTenantResponse_Success.json"), DeleteTenantResponse.class); - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - assertThat(response.getBody(), sameBeanAs(expectedResponse)); - } - - //@Ignore - @Test - public void testDeleteTenantFails() throws IOException { - - DeleteTenantRequest request = new DeleteTenantRequest(); - String cloudSiteId = "mtn13"; - String tenantId = "tenantId"; - String requestId = "ra1"; - String serviceInstanceId = "sa1"; - - MsoRequest msoReq = new MsoRequest(); - msoReq.setRequestId(requestId); - msoReq.setServiceInstanceId(serviceInstanceId); - - request.setCloudSiteId(cloudSiteId); - request.setTenantId(tenantId); - request.setMsoRequest(msoReq); - - mockOpenStackResponseAccessAdmin(wireMockServer, wireMockPort); - - mockOpenStackGetTenantById_404(wireMockServer, tenantId); - - headers.add("Accept", MediaType.APPLICATION_JSON); - HttpEntity<DeleteTenantRequest> entity = new HttpEntity<DeleteTenantRequest>(request, headers); - - ResponseEntity<DeleteTenantResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/tenants/tenantId"), HttpMethod.DELETE, - entity, DeleteTenantResponse.class); - - DeleteTenantResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( - new File("src/test/resources/__files/DeleteTenantResponse_Failed.json"), DeleteTenantResponse.class); - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - assertThat(response.getBody(), sameBeanAs(expectedResponse)); - } - - @Ignore - @Test - public void testQuaryTenant() { - - - - } + @Autowired + private JettisonStyleMapperProvider jettisonTypeObjectMapper; + + @Test + public void testCreateTenantCreated() throws JsonParseException, JsonMappingException, IOException { + + CreateTenantRequest request = new CreateTenantRequest(); + String cloudSiteId = "MTN13"; + String requestId = "62265093-277d-4388-9ba6-449838ade586"; + String serviceInstanceId = "4147e06f-1b89-49c5-b21f-4faf8dc9805a"; + String tenantName = "testingTenantName"; + boolean failIfExists = true; + boolean backout = true; + Map<String, String> metaData = new HashMap<>(); + metaData.put("key1", "value2"); + MsoRequest msoReq = new MsoRequest(); + msoReq.setRequestId(requestId); + msoReq.setServiceInstanceId(serviceInstanceId); + + request.setCloudSiteId(cloudSiteId); + request.setMsoRequest(msoReq); + request.setTenantName(tenantName); + request.setMetadata(metaData); + request.setBackout(backout); + request.setFailIfExists(failIfExists); + + mockOpenStackResponseAccessAdmin(wireMockServer, wireMockPort); + + mockOpenStackGetTenantByName_404(wireMockServer, tenantName); + + mockOpenStackPostTenantWithBodyFile_200(wireMockServer); + + mockOpenStackGetUser_200(wireMockServer, "m93945"); + + mockOpenStackGetRoles_200(wireMockServer, "OS-KSADM"); + + mockOpenStackPutRolesAdmin_200(wireMockServer, "OS-KSADM"); + + mockOpenStackPostMetadata_200(wireMockServer); + + headers.add("Accept", MediaType.APPLICATION_JSON); + HttpEntity<CreateTenantRequest> entity = new HttpEntity<CreateTenantRequest>(request, headers); + + ResponseEntity<CreateTenantResponse> response = restTemplate.exchange( + createURLWithPort("/services/rest/v1/tenants"), HttpMethod.POST, entity, CreateTenantResponse.class); + + CreateTenantResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/CreateTenantResponse_Created.json"), CreateTenantResponse.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + } + + @Test + public void testCreateTenantExists() throws JsonParseException, JsonMappingException, IOException { + + CreateTenantRequest request = new CreateTenantRequest(); + String cloudSiteId = "MTN13"; + String requestId = "62265093-277d-4388-9ba6-449838ade586"; + String serviceInstanceId = "4147e06f-1b89-49c5-b21f-4faf8dc9805a"; + String tenantName = "testingTenantName"; + boolean failIfExists = false; + boolean backout = true; + Map<String, String> metadata = new HashMap<>(); + + MsoRequest msoReq = new MsoRequest(); + msoReq.setRequestId(requestId); + msoReq.setServiceInstanceId(serviceInstanceId); + + request.setCloudSiteId(cloudSiteId); + request.setMsoRequest(msoReq); + request.setTenantName(tenantName); + request.setMetadata(metadata); + request.setBackout(backout); + request.setFailIfExists(failIfExists); + + mockOpenStackResponseAccessAdmin(wireMockServer, wireMockPort); + + mockOpenStackGetTenantByName_200(wireMockServer, tenantName); + + mockOpenStackPostTenant_200(wireMockServer); + + mockOpenStackGetMetadata_200(wireMockServer); + + headers.add("Accept", MediaType.APPLICATION_JSON); + HttpEntity<CreateTenantRequest> entity = new HttpEntity<CreateTenantRequest>(request, headers); + + ResponseEntity<CreateTenantResponse> response = restTemplate.exchange( + createURLWithPort("/services/rest/v1/tenants"), HttpMethod.POST, entity, CreateTenantResponse.class); + + CreateTenantResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/CreateTenantResponse_Exists.json"), CreateTenantResponse.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + } + + @Test + public void testDeleteTenant() throws IOException { + + DeleteTenantRequest request = new DeleteTenantRequest(); + String cloudSiteId = "mtn13"; + String tenantId = "tenantId"; + String requestId = "ra1"; + String serviceInstanceId = "sa1"; + + MsoRequest msoReq = new MsoRequest(); + msoReq.setRequestId(requestId); + msoReq.setServiceInstanceId(serviceInstanceId); + + request.setCloudSiteId(cloudSiteId); + request.setTenantId(tenantId); + request.setMsoRequest(msoReq); + + mockOpenStackResponseAccessAdmin(wireMockServer, wireMockPort); + + mockOpenStackGetTenantById_200(wireMockServer, tenantId); + + mockOpenStackDeleteTenantById_200(wireMockServer, tenantId); + + headers.add("Accept", MediaType.APPLICATION_JSON); + HttpEntity<DeleteTenantRequest> entity = new HttpEntity<DeleteTenantRequest>(request, headers); + + ResponseEntity<DeleteTenantResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v1/tenants/tenantId"), HttpMethod.DELETE, + entity, DeleteTenantResponse.class); + + DeleteTenantResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/DeleteTenantResponse_Success.json"), DeleteTenantResponse.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + } + + // @Ignore + @Test + public void testDeleteTenantFails() throws IOException { + + DeleteTenantRequest request = new DeleteTenantRequest(); + String cloudSiteId = "mtn13"; + String tenantId = "tenantId"; + String requestId = "ra1"; + String serviceInstanceId = "sa1"; + + MsoRequest msoReq = new MsoRequest(); + msoReq.setRequestId(requestId); + msoReq.setServiceInstanceId(serviceInstanceId); + + request.setCloudSiteId(cloudSiteId); + request.setTenantId(tenantId); + request.setMsoRequest(msoReq); + + mockOpenStackResponseAccessAdmin(wireMockServer, wireMockPort); + + mockOpenStackGetTenantById_404(wireMockServer, tenantId); + + headers.add("Accept", MediaType.APPLICATION_JSON); + HttpEntity<DeleteTenantRequest> entity = new HttpEntity<DeleteTenantRequest>(request, headers); + + ResponseEntity<DeleteTenantResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v1/tenants/tenantId"), HttpMethod.DELETE, + entity, DeleteTenantResponse.class); + + DeleteTenantResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/DeleteTenantResponse_Failed.json"), DeleteTenantResponse.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + } + + @Ignore + @Test + public void testQuaryTenant() { + + + + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantAlreadyExistsTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantAlreadyExistsTest.java index 6288dc9573..6e3312b1d3 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantAlreadyExistsTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantAlreadyExistsTest.java @@ -1,22 +1,17 @@ /* -* ============LICENSE_START======================================================= - * ONAP : SO - * ================================================================================ - * Copyright (C) 2018 TechMahindra - * ================================================================================ - * 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 + * ============LICENSE_START======================================================= ONAP : SO + * ================================================================================ Copyright (C) 2018 TechMahindra + * ================================================================================ 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 + * 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. + * 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.tenant.exceptions; @@ -24,9 +19,9 @@ import org.junit.Test; public class TenantAlreadyExistsTest { - @Test - public void test() { - TenantAlreadyExists tar= new TenantAlreadyExists("name", "cloudId", "tenantId"); - assert(tar!=null); - } + @Test + public void test() { + TenantAlreadyExists tar = new TenantAlreadyExists("name", "cloudId", "tenantId"); + assert (tar != null); + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantExceptionBeanTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantExceptionBeanTest.java index 178495105b..7314a9f1e2 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantExceptionBeanTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantExceptionBeanTest.java @@ -1,22 +1,17 @@ /* -* ============LICENSE_START======================================================= - * ONAP : SO - * ================================================================================ - * Copyright (C) 2018 TechMahindra - * ================================================================================ - * 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 + * ============LICENSE_START======================================================= ONAP : SO + * ================================================================================ Copyright (C) 2018 TechMahindra + * ================================================================================ 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 + * 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. + * 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.tenant.exceptions; @@ -27,21 +22,21 @@ import org.onap.so.openstack.exceptions.MsoExceptionCategory; public class TenantExceptionBeanTest { -@Mock -private MsoExceptionCategory mec; + @Mock + private MsoExceptionCategory mec; -@InjectMocks -private TenantExceptionBean teb; + @InjectMocks + private TenantExceptionBean teb; -@Test - public void test() { - teb =new TenantExceptionBean("message",mec); + @Test + public void test() { + teb = new TenantExceptionBean("message", mec); teb.setMessage("message"); teb.setCategory(MsoExceptionCategory.INTERNAL); teb.setCategory(MsoExceptionCategory.IO); teb.setCategory(MsoExceptionCategory.OPENSTACK); teb.setCategory(MsoExceptionCategory.USERDATA); - assert(teb.getMessage().equals("message")); - assert(teb.getCategory()!=null); - } + assert (teb.getMessage().equals("message")); + assert (teb.getCategory() != null); + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantExceptionTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantExceptionTest.java index 73614a3628..83eb1f1bdc 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantExceptionTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tenant/exceptions/TenantExceptionTest.java @@ -1,22 +1,17 @@ /* -* ============LICENSE_START======================================================= - * ONAP : SO - * ================================================================================ - * Copyright (C) 2018 TechMahindra - * ================================================================================ - * 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 + * ============LICENSE_START======================================================= ONAP : SO + * ================================================================================ Copyright (C) 2018 TechMahindra + * ================================================================================ 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 + * 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. + * 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.tenant.exceptions; @@ -26,24 +21,24 @@ import org.mockito.Mock; import org.onap.so.openstack.exceptions.MsoExceptionCategory; public class TenantExceptionTest { - - @Mock - private TenantExceptionBean teb; - - @Mock - private MsoExceptionCategory mec; - - @InjectMocks - private TenantException te; - - @Test - public void test() { - teb=new TenantExceptionBean("message"); - teb.setMessage("message"); - teb.setCategory(MsoExceptionCategory.INTERNAL); - te = new TenantException("message", mec); - te.setFaultInfo(teb); - assert(te.getFaultInfo()!=null); - assert(te.getFaultInfo().equals(teb)); - } + + @Mock + private TenantExceptionBean teb; + + @Mock + private MsoExceptionCategory mec; + + @InjectMocks + private TenantException te; + + @Test + public void test() { + teb = new TenantExceptionBean("message"); + teb.setMessage("message"); + teb.setCategory(MsoExceptionCategory.INTERNAL); + te = new TenantException("message", mec); + te.setFaultInfo(teb); + assert (te.getFaultInfo() != null); + assert (te.getFaultInfo().equals(teb)); + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/valet/ValetClientTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/valet/ValetClientTest.java index 0b83386ccc..61d2d08590 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/valet/ValetClientTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/valet/ValetClientTest.java @@ -27,9 +27,7 @@ import static org.onap.so.bpmn.mock.StubOpenStack.mockValetCreatePostResponse_20 import static org.onap.so.bpmn.mock.StubOpenStack.mockValetCreatePutResponse_200; import static org.onap.so.bpmn.mock.StubOpenStack.mockValetDeleteDeleteResponse_200; import static org.onap.so.bpmn.mock.StubOpenStack.mockValetRollbackPutRequest_200; - import java.io.File; - import org.apache.http.HttpStatus; import org.junit.Before; import org.junit.Test; @@ -40,77 +38,90 @@ import org.onap.so.adapters.valet.beans.ValetRollbackResponse; import org.onap.so.adapters.valet.beans.ValetUpdateResponse; import org.onap.so.adapters.vnf.BaseRestTestUtils; import org.springframework.beans.factory.annotation.Autowired; - import com.fasterxml.jackson.databind.ObjectMapper; public class ValetClientTest extends BaseRestTestUtils { - @Autowired - protected ValetClient client; - - private ObjectMapper mapper = new ObjectMapper(); - - @Before - public void init() { - client.baseUrl = "http://localhost:" + wireMockPort; - } - - @Test - public void testCallValetCreateRequest() throws Exception { - ValetCreateResponse vcr = mapper.readValue(new File("src/test/resources/__files/ValetCreateRequest.json"), ValetCreateResponse.class); - GenericValetResponse<ValetCreateResponse> expected = new GenericValetResponse<ValetCreateResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vcr); - - mockValetCreatePostResponse_200(wireMockServer, "requestId", mapper.writeValueAsString(vcr)); - - GenericValetResponse<ValetCreateResponse> actual = client.callValetCreateRequest("requestId", "regionId", "ownerId", "tenantId", "serviceInstanceId", "vnfId", "vnfName", "vfModuleId", "vfModuleName", "keystoneUrl", null); - - assertThat(actual, sameBeanAs(expected)); - } - - @Test - public void testCallValetUpdateRequest() throws Exception { - ValetUpdateResponse vur = mapper.readValue(new File("src/test/resources/__files/ValetCreateRequest.json"), ValetUpdateResponse.class); - GenericValetResponse<ValetUpdateResponse> expected = new GenericValetResponse<ValetUpdateResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vur); - - mockValetCreatePutResponse_200(wireMockServer, "requestId", mapper.writeValueAsString(vur)); - - GenericValetResponse<ValetUpdateResponse> actual = client.callValetUpdateRequest("requestId", "regionId", "ownerId", "tenantId", "serviceInstanceId", "vnfId", "vnfName", "vfModuleId", "vfModuleName", "keystoneUrl", null); - - assertThat(actual, sameBeanAs(expected)); - } - - @Test - public void testCallValetDeleteRequest() throws Exception { - ValetDeleteResponse vdr = mapper.readValue(new File("src/test/resources/__files/ValetDeleteRequest.json"), ValetDeleteResponse.class); - GenericValetResponse<ValetDeleteResponse> expected = new GenericValetResponse<ValetDeleteResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vdr); - - mockValetDeleteDeleteResponse_200(wireMockServer, "requestId", mapper.writeValueAsString(vdr)); - - GenericValetResponse<ValetDeleteResponse> actual = client.callValetDeleteRequest("requestId", "regionId", "ownerId", "tenantId", "vfModuleId", "vfModuleName"); - - assertThat(actual, sameBeanAs(expected)); - } - - @Test - public void testCallValetConfirmRequest() throws Exception { - ValetConfirmResponse vcr = new ValetConfirmResponse(); - GenericValetResponse<ValetConfirmResponse> expected = new GenericValetResponse<ValetConfirmResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vcr); - - mockValetConfirmPutRequest_200(wireMockServer, "requestId", "{}"); - - GenericValetResponse<ValetConfirmResponse> actual = client.callValetConfirmRequest("requestId", "stackId"); - - assertThat(actual, sameBeanAs(expected)); - } - - @Test - public void testCallValetRollbackRequest() throws Exception { - ValetRollbackResponse vrr = new ValetRollbackResponse(); - GenericValetResponse<ValetRollbackResponse> expected = new GenericValetResponse<ValetRollbackResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vrr); - - mockValetRollbackPutRequest_200(wireMockServer, "requestId", "{}"); - - GenericValetResponse<ValetRollbackResponse> actual = client.callValetRollbackRequest("requestId", "stackId", true, "error"); - - assertThat(actual, sameBeanAs(expected)); - } + @Autowired + protected ValetClient client; + + private ObjectMapper mapper = new ObjectMapper(); + + @Before + public void init() { + client.baseUrl = "http://localhost:" + wireMockPort; + } + + @Test + public void testCallValetCreateRequest() throws Exception { + ValetCreateResponse vcr = mapper.readValue(new File("src/test/resources/__files/ValetCreateRequest.json"), + ValetCreateResponse.class); + GenericValetResponse<ValetCreateResponse> expected = + new GenericValetResponse<ValetCreateResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vcr); + + mockValetCreatePostResponse_200(wireMockServer, "requestId", mapper.writeValueAsString(vcr)); + + GenericValetResponse<ValetCreateResponse> actual = + client.callValetCreateRequest("requestId", "regionId", "ownerId", "tenantId", "serviceInstanceId", + "vnfId", "vnfName", "vfModuleId", "vfModuleName", "keystoneUrl", null); + + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void testCallValetUpdateRequest() throws Exception { + ValetUpdateResponse vur = mapper.readValue(new File("src/test/resources/__files/ValetCreateRequest.json"), + ValetUpdateResponse.class); + GenericValetResponse<ValetUpdateResponse> expected = + new GenericValetResponse<ValetUpdateResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vur); + + mockValetCreatePutResponse_200(wireMockServer, "requestId", mapper.writeValueAsString(vur)); + + GenericValetResponse<ValetUpdateResponse> actual = + client.callValetUpdateRequest("requestId", "regionId", "ownerId", "tenantId", "serviceInstanceId", + "vnfId", "vnfName", "vfModuleId", "vfModuleName", "keystoneUrl", null); + + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void testCallValetDeleteRequest() throws Exception { + ValetDeleteResponse vdr = mapper.readValue(new File("src/test/resources/__files/ValetDeleteRequest.json"), + ValetDeleteResponse.class); + GenericValetResponse<ValetDeleteResponse> expected = + new GenericValetResponse<ValetDeleteResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vdr); + + mockValetDeleteDeleteResponse_200(wireMockServer, "requestId", mapper.writeValueAsString(vdr)); + + GenericValetResponse<ValetDeleteResponse> actual = client.callValetDeleteRequest("requestId", "regionId", + "ownerId", "tenantId", "vfModuleId", "vfModuleName"); + + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void testCallValetConfirmRequest() throws Exception { + ValetConfirmResponse vcr = new ValetConfirmResponse(); + GenericValetResponse<ValetConfirmResponse> expected = + new GenericValetResponse<ValetConfirmResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vcr); + + mockValetConfirmPutRequest_200(wireMockServer, "requestId", "{}"); + + GenericValetResponse<ValetConfirmResponse> actual = client.callValetConfirmRequest("requestId", "stackId"); + + assertThat(actual, sameBeanAs(expected)); + } + + @Test + public void testCallValetRollbackRequest() throws Exception { + ValetRollbackResponse vrr = new ValetRollbackResponse(); + GenericValetResponse<ValetRollbackResponse> expected = + new GenericValetResponse<ValetRollbackResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vrr); + + mockValetRollbackPutRequest_200(wireMockServer, "requestId", "{}"); + + GenericValetResponse<ValetRollbackResponse> actual = + client.callValetRollbackRequest("requestId", "stackId", true, "error"); + + assertThat(actual, sameBeanAs(expected)); + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vdu/mapper/VfModuleCustomizationToVduMapperTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vdu/mapper/VfModuleCustomizationToVduMapperTest.java index c982f8beb1..a9c57598b0 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vdu/mapper/VfModuleCustomizationToVduMapperTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vdu/mapper/VfModuleCustomizationToVduMapperTest.java @@ -21,7 +21,6 @@ package org.onap.so.adapters.vdu.mapper; import static org.assertj.core.api.Assertions.assertThat; - import com.google.common.collect.Lists; import java.util.List; import org.junit.Test; @@ -55,14 +54,13 @@ public class VfModuleCustomizationToVduMapperTest { VfModuleCustomization vfModuleCustomization = createVfModuleCustomization(); vfModuleCustomization.setHeatEnvironment(createHeatEnvironment(HEAT_ENV_NAME, HEAT_ENV_CONTENT)); VfModule vfModule = createVfModule(); - vfModule.setModuleHeatTemplate(createHeatTemplate( - MODULE_HEAT_TEMPLATE_NAME, MODULE_HEAT_TEMPLATE_BODY, - NESTED_TEMPLATE_NAME, NESTED_TEMPLATE_BODY)); + vfModule.setModuleHeatTemplate(createHeatTemplate(MODULE_HEAT_TEMPLATE_NAME, MODULE_HEAT_TEMPLATE_BODY, + NESTED_TEMPLATE_NAME, NESTED_TEMPLATE_BODY)); vfModuleCustomization.setVfModule(vfModule); // WHEN - VduModelInfo vduModelInfo = new VfModuleCustomizationToVduMapper() - .mapVfModuleCustomizationToVdu(vfModuleCustomization); + VduModelInfo vduModelInfo = + new VfModuleCustomizationToVduMapper().mapVfModuleCustomizationToVdu(vfModuleCustomization); // THEN assertThat(vduModelInfo.getModelCustomizationUUID()).isEqualTo(MODEL_CUSTOMIZATION_UUID); @@ -76,14 +74,13 @@ public class VfModuleCustomizationToVduMapperTest { VfModuleCustomization vfModuleCustomization = createVfModuleCustomization(); vfModuleCustomization.setVolumeHeatEnv(createHeatEnvironment(HEAT_ENV_NAME, HEAT_ENV_CONTENT)); VfModule vfModule = createVfModule(); - vfModule.setVolumeHeatTemplate(createHeatTemplate( - MODULE_HEAT_TEMPLATE_NAME, MODULE_HEAT_TEMPLATE_BODY, - NESTED_TEMPLATE_NAME, NESTED_TEMPLATE_BODY)); + vfModule.setVolumeHeatTemplate(createHeatTemplate(MODULE_HEAT_TEMPLATE_NAME, MODULE_HEAT_TEMPLATE_BODY, + NESTED_TEMPLATE_NAME, NESTED_TEMPLATE_BODY)); vfModuleCustomization.setVfModule(vfModule); // WHEN - VduModelInfo vduModelInfo = new VfModuleCustomizationToVduMapper() - .mapVfModuleCustVolumeToVdu(vfModuleCustomization); + VduModelInfo vduModelInfo = + new VfModuleCustomizationToVduMapper().mapVfModuleCustVolumeToVdu(vfModuleCustomization); // THEN assertThat(vduModelInfo.getModelCustomizationUUID()).isEqualTo(MODEL_CUSTOMIZATION_UUID); @@ -119,7 +116,7 @@ public class VfModuleCustomizationToVduMapperTest { } private HeatTemplate createHeatTemplate(String moduleHeatTemplateName, String moduleHeatTemplateBody, - String childTemplateName, String childTemplateBody) { + String childTemplateName, String childTemplateBody) { HeatTemplate heatTemplate = new HeatTemplate(); heatTemplate.setTemplateName(moduleHeatTemplateName); heatTemplate.setTemplateBody(moduleHeatTemplateBody); @@ -137,10 +134,10 @@ public class VfModuleCustomizationToVduMapperTest { private List<VduArtifact> createExpectedVduArtifacts() { return Lists.newArrayList( - new VduArtifact(MODULE_HEAT_TEMPLATE_NAME, MODULE_HEAT_TEMPLATE_BODY.getBytes(), - ArtifactType.MAIN_TEMPLATE), - new VduArtifact(NESTED_TEMPLATE_NAME, NESTED_TEMPLATE_BODY.getBytes(), ArtifactType.NESTED_TEMPLATE), - new VduArtifact(CLOUD_FILE_NAME, CLOUD_FILE_BODY.getBytes(), ArtifactType.TEXT_FILE), - new VduArtifact(HEAT_ENV_NAME, HEAT_ENV_CONTENT.getBytes(), ArtifactType.ENVIRONMENT)); + new VduArtifact(MODULE_HEAT_TEMPLATE_NAME, MODULE_HEAT_TEMPLATE_BODY.getBytes(), + ArtifactType.MAIN_TEMPLATE), + new VduArtifact(NESTED_TEMPLATE_NAME, NESTED_TEMPLATE_BODY.getBytes(), ArtifactType.NESTED_TEMPLATE), + new VduArtifact(CLOUD_FILE_NAME, CLOUD_FILE_BODY.getBytes(), ArtifactType.TEXT_FILE), + new VduArtifact(HEAT_ENV_NAME, HEAT_ENV_CONTENT.getBytes(), ArtifactType.ENVIRONMENT)); } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/AllTestsTestSuite.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/AllTestsTestSuite.java index f086653fea..a7bddd3ada 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/AllTestsTestSuite.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/AllTestsTestSuite.java @@ -19,14 +19,14 @@ */ package org.onap.so.adapters.vnf; -import org.junit.runner.RunWith; +import org.junit.runner.RunWith; import com.googlecode.junittoolbox.SuiteClasses; import com.googlecode.junittoolbox.WildcardPatternSuite; @RunWith(WildcardPatternSuite.class) @SuiteClasses("**/*Test.class") public class AllTestsTestSuite { - // the class remains empty, - // used only as a holder for the above annotations + // the class remains empty, + // used only as a holder for the above annotations } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java index b9edb68bb1..102d748d56 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java @@ -23,14 +23,11 @@ package org.onap.so.adapters.vnf; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; - import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; - import javax.ws.rs.core.MediaType; - import org.apache.http.HttpStatus; import org.junit.Before; import org.junit.Test; @@ -51,7 +48,6 @@ import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; import org.springframework.http.HttpHeaders; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; - import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; @@ -59,108 +55,111 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.github.tomakehurst.wiremock.WireMockServer; @RunWith(SpringRunner.class) -@SpringBootTest(classes = MsoOpenstackAdaptersApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@SpringBootTest(classes = MsoOpenstackAdaptersApplication.class, + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles("test") @AutoConfigureWireMock(port = 0) public abstract class BaseRestTestUtils { - @Value("${wiremock.server.port}") + @Value("${wiremock.server.port}") protected int wireMockPort; - - @Autowired - protected WireMockServer wireMockServer; - - @Autowired - CloudConfig cloudConfig; - - @Autowired - @Qualifier("JettisonStyle") - protected TestRestTemplate restTemplate; - - protected HttpHeaders headers = new HttpHeaders(); - - @LocalServerPort - private int port; - - public ObjectMapper mapper; - - public String orchestrator = "orchestrator"; - public String cloudEndpoint = "/v2.0"; - - - protected String readJsonFileAsString(String fileLocation) throws JsonParseException, JsonMappingException, IOException{ - ObjectMapper mapper = new ObjectMapper(); - JsonNode jsonNode = mapper.readTree(new File(fileLocation)); - return jsonNode.asText(); - } - - protected String createURLWithPort(String uri) { - return "http://localhost:" + port + uri; - } - - protected String readFile(String fileName) throws IOException { - try (BufferedReader br = new BufferedReader(new FileReader(fileName))) { - StringBuilder sb = new StringBuilder(); - String line = br.readLine(); - - while (line != null) { - sb.append(line); - sb.append("\n"); - line = br.readLine(); - } - return sb.toString(); - } - } - - /*** - * Before each test execution, updating IdentityUrl port value to the ramdom wireMockPort - * Since URL will be used as a rest call and required to be mocked in unit tests - */ - @Before - public void setUp() throws Exception { - wireMockServer.resetAll(); - mapper = new ObjectMapper(); - CloudIdentity identity = new CloudIdentity(); - identity.setId("MTN13"); - identity.setMsoId("m93945"); - identity.setMsoPass("93937EA01B94A10A49279D4572B48369"); - identity.setAdminTenant("admin"); - identity.setMemberRole("admin"); - identity.setTenantMetadata(new Boolean(true)); - identity.setIdentityUrl("http://localhost:" + wireMockPort + cloudEndpoint); - - identity.setIdentityAuthenticationType(AuthenticationType.USERNAME_PASSWORD); - - CloudSite cloudSite = new CloudSite(); - cloudSite.setId("MTN13"); - cloudSite.setCloudVersion("3.0"); - cloudSite.setClli("MDT13"); - cloudSite.setRegionId("mtn13"); - cloudSite.setOrchestrator(orchestrator); - identity.setIdentityServerType(ServerType.KEYSTONE); - cloudSite.setIdentityService(identity); - - wireMockServer.stubFor(get(urlPathEqualTo("/cloudSite/MTN13")).willReturn(aResponse() - .withBody(getBody(mapper.writeValueAsString(cloudSite),wireMockPort, "")) - .withHeader(org.apache.http.HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) - .withStatus(HttpStatus.SC_OK))); - wireMockServer.stubFor(get(urlPathEqualTo("/cloudSite/DEFAULT")).willReturn(aResponse() - .withBody(getBody(mapper.writeValueAsString(cloudSite),wireMockPort, "")) - .withHeader(org.apache.http.HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_JSON) - .withStatus(HttpStatus.SC_OK))); - wireMockServer.stubFor(get(urlPathEqualTo("/cloudIdentity/MTN13")).willReturn(aResponse() - .withBody(getBody(mapper.writeValueAsString(identity),wireMockPort, "")) - .withHeader(org.apache.http.HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_JSON) - .withStatus(HttpStatus.SC_OK))); - cloudConfig.getCloudSite("MTN13").get().getIdentityService().setIdentityUrl("http://localhost:" + wireMockPort + cloudEndpoint); - } - - protected static String getBody(String body, int port, String urlPath) throws IOException { - return body.replaceAll("port", "http://localhost:" + port + urlPath); - } - - @Test - public void testNothing(){ - - } + + @Autowired + protected WireMockServer wireMockServer; + + @Autowired + CloudConfig cloudConfig; + + @Autowired + @Qualifier("JettisonStyle") + protected TestRestTemplate restTemplate; + + protected HttpHeaders headers = new HttpHeaders(); + + @LocalServerPort + private int port; + + public ObjectMapper mapper; + + public String orchestrator = "orchestrator"; + public String cloudEndpoint = "/v2.0"; + + + protected String readJsonFileAsString(String fileLocation) + throws JsonParseException, JsonMappingException, IOException { + ObjectMapper mapper = new ObjectMapper(); + JsonNode jsonNode = mapper.readTree(new File(fileLocation)); + return jsonNode.asText(); + } + + protected String createURLWithPort(String uri) { + return "http://localhost:" + port + uri; + } + + protected String readFile(String fileName) throws IOException { + try (BufferedReader br = new BufferedReader(new FileReader(fileName))) { + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + + while (line != null) { + sb.append(line); + sb.append("\n"); + line = br.readLine(); + } + return sb.toString(); + } + } + + /*** + * Before each test execution, updating IdentityUrl port value to the ramdom wireMockPort Since URL will be used as + * a rest call and required to be mocked in unit tests + */ + @Before + public void setUp() throws Exception { + wireMockServer.resetAll(); + mapper = new ObjectMapper(); + CloudIdentity identity = new CloudIdentity(); + identity.setId("MTN13"); + identity.setMsoId("m93945"); + identity.setMsoPass("93937EA01B94A10A49279D4572B48369"); + identity.setAdminTenant("admin"); + identity.setMemberRole("admin"); + identity.setTenantMetadata(new Boolean(true)); + identity.setIdentityUrl("http://localhost:" + wireMockPort + cloudEndpoint); + + identity.setIdentityAuthenticationType(AuthenticationType.USERNAME_PASSWORD); + + CloudSite cloudSite = new CloudSite(); + cloudSite.setId("MTN13"); + cloudSite.setCloudVersion("3.0"); + cloudSite.setClli("MDT13"); + cloudSite.setRegionId("mtn13"); + cloudSite.setOrchestrator(orchestrator); + identity.setIdentityServerType(ServerType.KEYSTONE); + cloudSite.setIdentityService(identity); + + wireMockServer.stubFor(get(urlPathEqualTo("/cloudSite/MTN13")) + .willReturn(aResponse().withBody(getBody(mapper.writeValueAsString(cloudSite), wireMockPort, "")) + .withHeader(org.apache.http.HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlPathEqualTo("/cloudSite/DEFAULT")) + .willReturn(aResponse().withBody(getBody(mapper.writeValueAsString(cloudSite), wireMockPort, "")) + .withHeader(org.apache.http.HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlPathEqualTo("/cloudIdentity/MTN13")) + .willReturn(aResponse().withBody(getBody(mapper.writeValueAsString(identity), wireMockPort, "")) + .withHeader(org.apache.http.HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withStatus(HttpStatus.SC_OK))); + cloudConfig.getCloudSite("MTN13").get().getIdentityService() + .setIdentityUrl("http://localhost:" + wireMockPort + cloudEndpoint); + } + + protected static String getBody(String body, int port, String urlPath) throws IOException { + return body.replaceAll("port", "http://localhost:" + port + urlPath); + } + + @Test + public void testNothing() { + + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BpelRestClientTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BpelRestClientTest.java index 4b2fa8138a..883009216f 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BpelRestClientTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BpelRestClientTest.java @@ -21,33 +21,31 @@ package org.onap.so.adapters.vnf; import static org.junit.Assert.assertEquals; - import javax.inject.Provider; - import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.web.server.LocalServerPort; -public class BpelRestClientTest extends BaseRestTestUtils{ - - - @LocalServerPort - private int port; - @Autowired - private Provider<BpelRestClient> clientProvider; - - @Test - public void verifyPropertiesRead() { - BpelRestClient client = clientProvider.get(); - - assertEquals(5, client.getRetryCount()); - assertEquals(30, client.getConnectTimeout()); - assertEquals("test:test", client.getCredentials()); - assertEquals(30, client.getSocketTimeout()); - assertEquals("408, 429, 500, 502, 503, 504, 900", client.getRetryList()); - assertEquals(-15, client.getRetryInterval()); - - } +public class BpelRestClientTest extends BaseRestTestUtils { + + + @LocalServerPort + private int port; + @Autowired + private Provider<BpelRestClient> clientProvider; + + @Test + public void verifyPropertiesRead() { + BpelRestClient client = clientProvider.get(); + + assertEquals(5, client.getRetryCount()); + assertEquals(30, client.getConnectTimeout()); + assertEquals("test:test", client.getCredentials()); + assertEquals(30, client.getSocketTimeout()); + assertEquals("408, 429, 500, 502, 503, 504, 900", client.getRetryList()); + assertEquals(-15, client.getRetryInterval()); + + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterAsyncImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterAsyncImplTest.java index 02fbe2c530..46d9f89303 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterAsyncImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterAsyncImplTest.java @@ -29,10 +29,8 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess; - import java.util.HashMap; import java.util.Map; - import org.apache.http.HttpStatus; import org.junit.Rule; import org.junit.Test; @@ -43,110 +41,109 @@ import org.springframework.beans.factory.annotation.Autowired; public class MsoVnfAdapterAsyncImplTest extends BaseRestTestUtils { - @Autowired - MsoVnfAdapterAsyncImpl instance; - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Test - public void healthCheckVNFTest() { - instance.healthCheckA(); - } - - @Test - public void createVNFTest() throws Exception { - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_200(wireMockServer); - wireMockServer.stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")).withRequestBody - (containing("messageId")) - .willReturn(aResponse().withStatus(HttpStatus.SC_OK))); - - String vnfName = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"; - String notificationUrl = "http://localhost:"+wireMockPort+"/notify/adapterNotify/updateVnfNotificationRequest"; - instance.createVnfA("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", - "volumeGroupHeatStackId|1", new HashMap<String, Object>(), Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, "messageId", - msoRequest, notificationUrl); - - wireMockServer.verify(1,postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest"))); - } - - @Test - public void createVNFTest_Exception() throws Exception { - String notificationUrl = "http://localhost:"+wireMockPort+"/notify/adapterNotify/updateVnfNotificationRequest"; - instance.createVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD", - "volumeGroupHeatStackId|1", new HashMap<String, Object>(), Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, "messageId", - null, notificationUrl); - - wireMockServer.verify(1,postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest"))); - - } - - @Test - public void updateVnfTest() throws Exception{ - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - wireMockServer.stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")).withRequestBody - (containing("messageId")) - .willReturn(aResponse().withStatus(HttpStatus.SC_OK))); - String notificationUrl = "http://localhost:"+wireMockPort+"/notify/adapterNotify/updateVnfNotificationRequest"; - instance.updateVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD", - "volumeGroupHeatStackId|1", map, "messageId", msoRequest, - notificationUrl); - } - - @Test - public void updateVnfTest_Exception() throws Exception{ - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - wireMockServer.stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")).withRequestBody - (containing("messageId")) - .willReturn(aResponse().withStatus(HttpStatus.SC_OK))); - String notificationUrl = "http://localhost:"+wireMockPort+"/notify/adapterNotify/updateVnfNotificationRequest"; - instance.updateVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD", - "volumeGroupHeatStackId|1", map, "messageId", msoRequest, - notificationUrl); - wireMockServer.verify(1,postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest"))); - } - - @Test - public void queryVnfTest() { - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - instance.queryVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", "messageId", msoRequest, - "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest"); - } - - @Test - public void deleteVnfTest() { - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - instance.deleteVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", "messageId", msoRequest, - "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest"); - } - - @Test - public void rollbackVnfTest() { - VnfRollback vnfRollBack = new VnfRollback(); - vnfRollBack.setCloudSiteId("mdt1"); - vnfRollBack.setCloudOwner("CloudOwner"); - vnfRollBack.setTenantId("88a6ca3ee0394ade9403f075db23167e"); - vnfRollBack.setVnfId("ff5256d1-5a33-55df-13ab-12abad84e7ff"); - instance.rollbackVnfA(vnfRollBack, "messageId", - "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest"); - } + @Autowired + MsoVnfAdapterAsyncImpl instance; + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Test + public void healthCheckVNFTest() { + instance.healthCheckA(); + } + + @Test + public void createVNFTest() throws Exception { + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackVfModule_200(wireMockServer); + wireMockServer.stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")) + .withRequestBody(containing("messageId")).willReturn(aResponse().withStatus(HttpStatus.SC_OK))); + + String vnfName = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"; + String notificationUrl = + "http://localhost:" + wireMockPort + "/notify/adapterNotify/updateVnfNotificationRequest"; + instance.createVnfA("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", + "volumeGroupHeatStackId|1", new HashMap<String, Object>(), Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, + "messageId", msoRequest, notificationUrl); + + wireMockServer.verify(1, postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest"))); + } + + @Test + public void createVNFTest_Exception() throws Exception { + String notificationUrl = + "http://localhost:" + wireMockPort + "/notify/adapterNotify/updateVnfNotificationRequest"; + instance.createVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD", + "volumeGroupHeatStackId|1", new HashMap<String, Object>(), Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, + "messageId", null, notificationUrl); + + wireMockServer.verify(1, postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest"))); + + } + + @Test + public void updateVnfTest() throws Exception { + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + wireMockServer.stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")) + .withRequestBody(containing("messageId")).willReturn(aResponse().withStatus(HttpStatus.SC_OK))); + String notificationUrl = + "http://localhost:" + wireMockPort + "/notify/adapterNotify/updateVnfNotificationRequest"; + instance.updateVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD", + "volumeGroupHeatStackId|1", map, "messageId", msoRequest, notificationUrl); + } + + @Test + public void updateVnfTest_Exception() throws Exception { + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + wireMockServer.stubFor(post(urlPathEqualTo("/notify/adapterNotify/updateVnfNotificationRequest")) + .withRequestBody(containing("messageId")).willReturn(aResponse().withStatus(HttpStatus.SC_OK))); + String notificationUrl = + "http://localhost:" + wireMockPort + "/notify/adapterNotify/updateVnfNotificationRequest"; + instance.updateVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD", + "volumeGroupHeatStackId|1", map, "messageId", msoRequest, notificationUrl); + wireMockServer.verify(1, postRequestedFor(urlEqualTo("/notify/adapterNotify/updateVnfNotificationRequest"))); + } + + @Test + public void queryVnfTest() { + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + instance.queryVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", "messageId", msoRequest, + "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest"); + } + + @Test + public void deleteVnfTest() { + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + instance.deleteVnfA("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", "messageId", + msoRequest, "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest"); + } + + @Test + public void rollbackVnfTest() { + VnfRollback vnfRollBack = new VnfRollback(); + vnfRollBack.setCloudSiteId("mdt1"); + vnfRollBack.setCloudOwner("CloudOwner"); + vnfRollBack.setTenantId("88a6ca3ee0394ade9403f075db23167e"); + vnfRollBack.setVnfId("ff5256d1-5a33-55df-13ab-12abad84e7ff"); + instance.rollbackVnfA(vnfRollBack, "messageId", + "http://org.onap.so/notify/adapterNotify/updateVnfNotificationRequest"); + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java index e40aab9ba1..f314d32328 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfAdapterImplTest.java @@ -30,14 +30,11 @@ import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_ import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPutStack; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenstackGetWithResponse; - import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; - import javax.xml.ws.Holder; - import org.apache.http.HttpStatus; import org.junit.Before; import org.junit.Ignore; @@ -61,493 +58,510 @@ import org.onap.so.openstack.beans.VnfRollback; import org.onap.so.openstack.exceptions.MsoException; import org.onap.so.openstack.utils.MsoHeatUtils; import org.springframework.beans.factory.annotation.Autowired; - import com.github.tomakehurst.wiremock.client.WireMock; public class MsoVnfAdapterImplTest extends BaseRestTestUtils { - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Autowired - private MsoHeatUtils heatUtils; - - @Autowired - MsoVnfAdapterImpl instance; - - String vnfName = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"; - - @Test - @Ignore - public void healthCheckVNFTest() { - MsoVnfAdapterImpl instance = new MsoVnfAdapterImpl(); - instance.healthCheck(); - } - - @Test - public void createVnfTest() throws Exception { - StackInfo info = new StackInfo(); - info.setStatus(HeatStatus.CREATED); - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_200(wireMockServer); - - MsoRequest msoRequest = getMsoRequest(); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.createVfModule("MTN13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void createVnfTest_HeatStatusUpdating() throws Exception { - expectedException.expect(VnfAlreadyExists.class); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Stack_Updating_VfModule.json") - .withStatus(HttpStatus.SC_OK))); - - MsoRequest msoRequest = getMsoRequest(); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void createVnfTest_HeatStatusUpdated() throws Exception { - expectedException.expect(VnfAlreadyExists.class); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_StackId.json") - .withStatus(HttpStatus.SC_OK))); - - MsoRequest msoRequest = getMsoRequest(); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void createVnfTest_HeatStatusFailed() throws Exception { - expectedException.expect(VnfAlreadyExists.class); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Stack_Failed_VfModule.json") - .withStatus(HttpStatus.SC_OK))); - - MsoRequest msoRequest = getMsoRequest(); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void createVnfTest_HeatStatusCreated() throws Exception { - expectedException.expect(VnfAlreadyExists.class); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - mockOpenStackGetStackVfModule_200(wireMockServer); - - MsoRequest msoRequest = getMsoRequest(); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - - @Test - public void createVnfTest_ExceptionInGettingHeat() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = getMsoRequest(); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void createVnfTest_NestedHeatStatusNotFound() throws Exception { - expectedException.expect(VnfException.class); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_404(wireMockServer); - - MsoRequest msoRequest = getMsoRequest(); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void createVnfTest_ExceptionInGettingNestedHeat() throws Exception { - expectedException.expect(VnfException.class); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_404(wireMockServer); - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); - - MsoRequest msoRequest = getMsoRequest(); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void createVnfTest_NestedBaseHeatStatus_NotFound() throws Exception { - expectedException.expect(VnfException.class); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_404(wireMockServer); - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json") - .withStatus(HttpStatus.SC_OK))); - - MsoRequest msoRequest = getMsoRequest(); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void createVnfTest_ExceptionInGettingBaseNestedHeat() throws Exception { - expectedException.expect(VnfException.class); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_404(wireMockServer); - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")).willReturn(aResponse().withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK))); - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/baseVfHeatStackId")).willReturn(aResponse().withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); - - MsoRequest msoRequest = getMsoRequest(); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void createVnfTest_ExceptionInCreateStack() throws Exception { - expectedException.expect(VnfException.class); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_404(wireMockServer); - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")).willReturn(aResponse().withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK))); - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/baseVfHeatStackId")).willReturn(aResponse().withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK))); - - VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); - VfModule vfModule = new VfModule(); - vfModule.setIsBase(false); - - HeatTemplate heatTemplate = new HeatTemplate(); - heatTemplate.setTemplateBody(""); - heatTemplate.setTimeoutMinutes(200); - vfModule.setModuleHeatTemplate(heatTemplate); - vfModuleCustomization.setVfModule(vfModule); - - HeatEnvironment heatEnvironment = new HeatEnvironment(); - heatEnvironment.setEnvironment("ist"); - vfModuleCustomization.setHeatEnvironment(heatEnvironment); - - MsoRequest msoRequest = getMsoRequest(); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void createVnfTest_ModelCustUuidIsNull() throws Exception { - expectedException.expect(VnfException.class); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_404(wireMockServer); - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")).willReturn(aResponse().withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK))); - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/baseVfHeatStackId")).willReturn(aResponse().withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK))); - - VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); - VfModule vfModule = new VfModule(); - vfModule.setIsBase(false); - - HeatTemplate heatTemplate = new HeatTemplate(); - heatTemplate.setTemplateBody(""); - heatTemplate.setTimeoutMinutes(200); - vfModule.setModuleHeatTemplate(heatTemplate); - vfModuleCustomization.setVfModule(vfModule); - - HeatEnvironment heatEnvironment = new HeatEnvironment(); - heatEnvironment.setEnvironment("ist"); - vfModuleCustomization.setHeatEnvironment(heatEnvironment); - - VnfResource vnfResource = new VnfResource(); - vnfResource.setAicVersionMin("1"); - vnfResource.setAicVersionMin("3"); - - - MsoRequest msoRequest = getMsoRequest(); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "XVFMOD", - "volumeGroupHeatStackId", "baseVfHeatStackId", null, map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void createVnfTest_HeatEnvironment_ContainsParameters() throws Exception { - expectedException.expect(VnfException.class); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_404(wireMockServer); - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")).willReturn(aResponse().withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK))); - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/baseVfHeatStackId")).willReturn(aResponse().withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK))); - - MsoRequest msoRequest = getMsoRequest(); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - private MsoRequest getMsoRequest() { - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - return msoRequest; - } - - @Test - public void updateVnfTest_CloudSiteIdNotFound() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = getMsoRequest(); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.updateVfModule("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD", - "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId", - "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void updateVnfTest_HeatStackNotFound() throws Exception { - expectedException.expect(VnfNotFound.class); - MsoRequest msoRequest = getMsoRequest(); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.updateVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", - "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId", - "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void updateVnfTest_ExceptionInGettingNestedHeatStack() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = getMsoRequest(); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_200(wireMockServer); - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.updateVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", - "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId", - "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void updateVnfTest_NestedHeatStackNotFound() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = getMsoRequest(); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_200(wireMockServer); - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withStatus(HttpStatus.SC_NOT_FOUND))); - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.updateVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", - "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId", - "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void updateVnfTest_ExceptionInGettingNestedBaseHeatStack() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = getMsoRequest(); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_200(wireMockServer); - mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/volumeGroupHeatStackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_Created_VfModule.json"); - mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/baseVfHeatStackId",HttpStatus.SC_INTERNAL_SERVER_ERROR,"OpenstackResponse_Stack_Created_VfModule.json"); - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.updateVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", - "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId", - "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void updateVnfTest_NestedBaseHeatStackNotFound() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = getMsoRequest(); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_200(wireMockServer); - mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/volumeGroupHeatStackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_Created_VfModule.json"); - mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/baseVfHeatStackId",HttpStatus.SC_NOT_FOUND,"OpenstackResponse_Stack_Created_VfModule.json"); - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.updateVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", - "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId", - "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void updateVnfTest_MissingParams() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = getMsoRequest(); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_200(wireMockServer); - mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/volumeGroupHeatStackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_Created_VfModule.json"); - mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/baseVfHeatStackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_Created_VfModule.json"); - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.updateVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", - "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId", - "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void updateVnfTest_UpdateStackException() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = getMsoRequest(); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_200(wireMockServer); - mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/volumeGroupHeatStackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_Created_VfModule.json"); - mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/baseVfHeatStackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_Created_VfModule.json"); - - VfModuleCustomization vfModuleCustomization = getVfModuleCustomization(); - vfModuleCustomization.getVfModule().getModuleHeatTemplate().setParameters(new HashSet<>()); - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.updateVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", - "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId", - "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - public void updateVnfTest() throws Exception { - MsoRequest msoRequest = getMsoRequest(); - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/"+vnfName,HttpStatus.SC_OK,"OpenstackResponse_Stack_UpdateComplete.json"); - mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/volumeGroupHeatStackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_Created_VfModule.json"); - mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/baseVfHeatStackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_Created_VfModule.json"); - mockOpenStackPutStack(wireMockServer, "null/stackId", HttpStatus.SC_OK); - mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/null/stackId",HttpStatus.SC_OK,"OpenstackResponse_Stack_UpdateComplete.json"); - - VfModuleCustomization vfModuleCustomization = getVfModuleCustomization(); - vfModuleCustomization.getVfModule().getModuleHeatTemplate().setParameters(new HashSet<>()); - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - instance.updateVfModule("MTN13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", - "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId", - "b4ea86b4-253f-11e7-93ae-92361f002671", map, msoRequest, new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); - } - - @Test - @Ignore - public void deleteVnfTest() throws MsoException { - - Map<String, Object> outputs = new HashMap<>(); - outputs.put("Key1", "value1"); - when(heatUtils.queryStackForOutputs("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12")).thenReturn(outputs); - - MsoVnfAdapterImpl instance = new MsoVnfAdapterImpl(); - MsoRequest msoRequest = getMsoRequest(); - try { - instance.deleteVfModule("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest, - new Holder<Map<String, String>>()); - } catch (Exception e) { - - } - } - - private VfModuleCustomization getVfModuleCustomization() { - VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); - VfModule vfModule = new VfModule(); - vfModule.setIsBase(false); - - HeatTemplate heatTemplate = new HeatTemplate(); - heatTemplate.setTemplateBody(""); - heatTemplate.setTimeoutMinutes(200); - HeatTemplateParam heatTemplateParam = new HeatTemplateParam(); - heatTemplateParam.setParamAlias("ParamAlias"); - heatTemplateParam.setRequired(true); - heatTemplateParam.setParamName("test"); - Set set = new HashSet(); - set.add(heatTemplateParam); - heatTemplate.setParameters(set); - vfModule.setModuleHeatTemplate(heatTemplate); - vfModuleCustomization.setVfModule(vfModule); - - HeatEnvironment heatEnvironment = new HeatEnvironment(); - heatEnvironment.setEnvironment("parameters:ist"); - vfModuleCustomization.setHeatEnvironment(heatEnvironment); - return vfModuleCustomization; - } + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Autowired + private MsoHeatUtils heatUtils; + + @Autowired + MsoVnfAdapterImpl instance; + + String vnfName = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId"; + + @Test + @Ignore + public void healthCheckVNFTest() { + MsoVnfAdapterImpl instance = new MsoVnfAdapterImpl(); + instance.healthCheck(); + } + + @Test + public void createVnfTest() throws Exception { + StackInfo info = new StackInfo(); + info.setStatus(HeatStatus.CREATED); + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackVfModule_200(wireMockServer); + + MsoRequest msoRequest = getMsoRequest(); + + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.createVfModule("MTN13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", + "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, + Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), + new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + @Test + public void createVnfTest_HeatStatusUpdating() throws Exception { + expectedException.expect(VnfAlreadyExists.class); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + wireMockServer.stubFor(get( + urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_Stack_Updating_VfModule.json") + .withStatus(HttpStatus.SC_OK))); + + MsoRequest msoRequest = getMsoRequest(); + + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", + "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, + Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), + new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + @Test + public void createVnfTest_HeatStatusUpdated() throws Exception { + expectedException.expect(VnfAlreadyExists.class); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + wireMockServer.stubFor(get( + urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_StackId.json").withStatus(HttpStatus.SC_OK))); + + MsoRequest msoRequest = getMsoRequest(); + + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", + "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, + Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), + new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + @Test + public void createVnfTest_HeatStatusFailed() throws Exception { + expectedException.expect(VnfAlreadyExists.class); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + wireMockServer.stubFor(get( + urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_Stack_Failed_VfModule.json") + .withStatus(HttpStatus.SC_OK))); + + MsoRequest msoRequest = getMsoRequest(); + + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", + "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, + Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), + new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + @Test + public void createVnfTest_HeatStatusCreated() throws Exception { + expectedException.expect(VnfAlreadyExists.class); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + mockOpenStackGetStackVfModule_200(wireMockServer); + + MsoRequest msoRequest = getMsoRequest(); + + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", + "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, + Boolean.TRUE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), + new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + + @Test + public void createVnfTest_ExceptionInGettingHeat() throws Exception { + expectedException.expect(VnfException.class); + MsoRequest msoRequest = getMsoRequest(); + + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", + "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, + Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), + new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + @Test + public void createVnfTest_NestedHeatStatusNotFound() throws Exception { + expectedException.expect(VnfException.class); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackVfModule_404(wireMockServer); + + MsoRequest msoRequest = getMsoRequest(); + + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", + "VFMOD", "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, + Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), + new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + @Test + public void createVnfTest_ExceptionInGettingNestedHeat() throws Exception { + expectedException.expect(VnfException.class); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackVfModule_404(wireMockServer); + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); + + MsoRequest msoRequest = getMsoRequest(); + + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", + "VFMOD", "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, + Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), + new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + @Test + public void createVnfTest_NestedBaseHeatStatus_NotFound() throws Exception { + expectedException.expect(VnfException.class); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackVfModule_404(wireMockServer); + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK))); + + MsoRequest msoRequest = getMsoRequest(); + + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", + "VFMOD", "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, + Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), + new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + @Test + public void createVnfTest_ExceptionInGettingBaseNestedHeat() throws Exception { + expectedException.expect(VnfException.class); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackVfModule_404(wireMockServer); + wireMockServer + .stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")).willReturn(aResponse() + .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/baseVfHeatStackId")) + .willReturn(aResponse().withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); + + MsoRequest msoRequest = getMsoRequest(); + + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", + "VFMOD", "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, + Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), + new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + @Test + public void createVnfTest_ExceptionInCreateStack() throws Exception { + expectedException.expect(VnfException.class); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackVfModule_404(wireMockServer); + wireMockServer + .stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")).willReturn(aResponse() + .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/baseVfHeatStackId")).willReturn(aResponse() + .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK))); + + VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); + VfModule vfModule = new VfModule(); + vfModule.setIsBase(false); + + HeatTemplate heatTemplate = new HeatTemplate(); + heatTemplate.setTemplateBody(""); + heatTemplate.setTimeoutMinutes(200); + vfModule.setModuleHeatTemplate(heatTemplate); + vfModuleCustomization.setVfModule(vfModule); + + HeatEnvironment heatEnvironment = new HeatEnvironment(); + heatEnvironment.setEnvironment("ist"); + vfModuleCustomization.setHeatEnvironment(heatEnvironment); + + MsoRequest msoRequest = getMsoRequest(); + + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", + "VFMOD", "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, + Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), + new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + @Test + public void createVnfTest_ModelCustUuidIsNull() throws Exception { + expectedException.expect(VnfException.class); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackVfModule_404(wireMockServer); + wireMockServer + .stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")).willReturn(aResponse() + .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/baseVfHeatStackId")).willReturn(aResponse() + .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK))); + + VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); + VfModule vfModule = new VfModule(); + vfModule.setIsBase(false); + + HeatTemplate heatTemplate = new HeatTemplate(); + heatTemplate.setTemplateBody(""); + heatTemplate.setTimeoutMinutes(200); + vfModule.setModuleHeatTemplate(heatTemplate); + vfModuleCustomization.setVfModule(vfModule); + + HeatEnvironment heatEnvironment = new HeatEnvironment(); + heatEnvironment.setEnvironment("ist"); + vfModuleCustomization.setHeatEnvironment(heatEnvironment); + + VnfResource vnfResource = new VnfResource(); + vnfResource.setAicVersionMin("1"); + vnfResource.setAicVersionMin("3"); + + + MsoRequest msoRequest = getMsoRequest(); + + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", + "XVFMOD", "volumeGroupHeatStackId", "baseVfHeatStackId", null, map, Boolean.FALSE, Boolean.TRUE, + Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), + new Holder<VnfRollback>()); + } + + @Test + public void createVnfTest_HeatEnvironment_ContainsParameters() throws Exception { + expectedException.expect(VnfException.class); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackVfModule_404(wireMockServer); + wireMockServer + .stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")).willReturn(aResponse() + .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/baseVfHeatStackId")).willReturn(aResponse() + .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK))); + + MsoRequest msoRequest = getMsoRequest(); + + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", + "VFMOD", "volumeGroupHeatStackId", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, + Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), + new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + private MsoRequest getMsoRequest() { + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + return msoRequest; + } + + @Test + public void updateVnfTest_CloudSiteIdNotFound() throws Exception { + expectedException.expect(VnfException.class); + MsoRequest msoRequest = getMsoRequest(); + + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.updateVfModule("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", + "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", "vfModuleStackId", + "88a6ca3ee0394ade9403f075db23167e", map, msoRequest, new Holder<Map<String, String>>(), + new Holder<VnfRollback>()); + } + + @Test + public void updateVnfTest_HeatStackNotFound() throws Exception { + expectedException.expect(VnfNotFound.class); + MsoRequest msoRequest = getMsoRequest(); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.updateVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", + "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId", "88a6ca3ee0394ade9403f075db23167e", + map, msoRequest, new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + @Test + public void updateVnfTest_ExceptionInGettingNestedHeatStack() throws Exception { + expectedException.expect(VnfException.class); + MsoRequest msoRequest = getMsoRequest(); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackVfModule_200(wireMockServer); + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.updateVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", + "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId", "88a6ca3ee0394ade9403f075db23167e", + map, msoRequest, new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + @Test + public void updateVnfTest_NestedHeatStackNotFound() throws Exception { + expectedException.expect(VnfException.class); + MsoRequest msoRequest = getMsoRequest(); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackVfModule_200(wireMockServer); + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")).willReturn( + aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND))); + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.updateVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", + "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId", "88a6ca3ee0394ade9403f075db23167e", + map, msoRequest, new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + @Test + public void updateVnfTest_ExceptionInGettingNestedBaseHeatStack() throws Exception { + expectedException.expect(VnfException.class); + MsoRequest msoRequest = getMsoRequest(); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackVfModule_200(wireMockServer); + mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/volumeGroupHeatStackId", HttpStatus.SC_OK, + "OpenstackResponse_Stack_Created_VfModule.json"); + mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/baseVfHeatStackId", + HttpStatus.SC_INTERNAL_SERVER_ERROR, "OpenstackResponse_Stack_Created_VfModule.json"); + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.updateVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", + "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId", "88a6ca3ee0394ade9403f075db23167e", + map, msoRequest, new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + @Test + public void updateVnfTest_NestedBaseHeatStackNotFound() throws Exception { + expectedException.expect(VnfException.class); + MsoRequest msoRequest = getMsoRequest(); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackVfModule_200(wireMockServer); + mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/volumeGroupHeatStackId", HttpStatus.SC_OK, + "OpenstackResponse_Stack_Created_VfModule.json"); + mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/baseVfHeatStackId", HttpStatus.SC_NOT_FOUND, + "OpenstackResponse_Stack_Created_VfModule.json"); + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.updateVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", + "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId", "88a6ca3ee0394ade9403f075db23167e", + map, msoRequest, new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + @Test + public void updateVnfTest_MissingParams() throws Exception { + expectedException.expect(VnfException.class); + MsoRequest msoRequest = getMsoRequest(); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackVfModule_200(wireMockServer); + mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/volumeGroupHeatStackId", HttpStatus.SC_OK, + "OpenstackResponse_Stack_Created_VfModule.json"); + mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/baseVfHeatStackId", HttpStatus.SC_OK, + "OpenstackResponse_Stack_Created_VfModule.json"); + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.updateVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", + "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId", "88a6ca3ee0394ade9403f075db23167e", + map, msoRequest, new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + @Test + public void updateVnfTest_UpdateStackException() throws Exception { + expectedException.expect(VnfException.class); + MsoRequest msoRequest = getMsoRequest(); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackVfModule_200(wireMockServer); + mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/volumeGroupHeatStackId", HttpStatus.SC_OK, + "OpenstackResponse_Stack_Created_VfModule.json"); + mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/baseVfHeatStackId", HttpStatus.SC_OK, + "OpenstackResponse_Stack_Created_VfModule.json"); + + VfModuleCustomization vfModuleCustomization = getVfModuleCustomization(); + vfModuleCustomization.getVfModule().getModuleHeatTemplate().setParameters(new HashSet<>()); + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.updateVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", + "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId", "88a6ca3ee0394ade9403f075db23167e", + map, msoRequest, new Holder<Map<String, String>>(), new Holder<VnfRollback>()); + } + + @Test + public void updateVnfTest() throws Exception { + MsoRequest msoRequest = getMsoRequest(); + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/" + vnfName, HttpStatus.SC_OK, + "OpenstackResponse_Stack_UpdateComplete.json"); + mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/volumeGroupHeatStackId", HttpStatus.SC_OK, + "OpenstackResponse_Stack_Created_VfModule.json"); + mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/baseVfHeatStackId", HttpStatus.SC_OK, + "OpenstackResponse_Stack_Created_VfModule.json"); + mockOpenStackPutStack(wireMockServer, "null/stackId", HttpStatus.SC_OK); + mockOpenstackGetWithResponse(wireMockServer, "/mockPublicUrl/stacks/null/stackId", HttpStatus.SC_OK, + "OpenstackResponse_Stack_UpdateComplete.json"); + + VfModuleCustomization vfModuleCustomization = getVfModuleCustomization(); + vfModuleCustomization.getVfModule().getModuleHeatTemplate().setParameters(new HashSet<>()); + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + instance.updateVfModule("MTN13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", vnfName, "VFMOD", + "volumeGroupHeatStackId", "baseVfHeatStackId", "vfModuleStackId", + "b4ea86b4-253f-11e7-93ae-92361f002671", map, msoRequest, new Holder<Map<String, String>>(), + new Holder<VnfRollback>()); + } + + @Test + @Ignore + public void deleteVnfTest() throws MsoException { + + Map<String, Object> outputs = new HashMap<>(); + outputs.put("Key1", "value1"); + when(heatUtils.queryStackForOutputs("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12")) + .thenReturn(outputs); + + MsoVnfAdapterImpl instance = new MsoVnfAdapterImpl(); + MsoRequest msoRequest = getMsoRequest(); + try { + instance.deleteVfModule("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest, + new Holder<Map<String, String>>()); + } catch (Exception e) { + + } + } + + private VfModuleCustomization getVfModuleCustomization() { + VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); + VfModule vfModule = new VfModule(); + vfModule.setIsBase(false); + + HeatTemplate heatTemplate = new HeatTemplate(); + heatTemplate.setTemplateBody(""); + heatTemplate.setTimeoutMinutes(200); + HeatTemplateParam heatTemplateParam = new HeatTemplateParam(); + heatTemplateParam.setParamAlias("ParamAlias"); + heatTemplateParam.setRequired(true); + heatTemplateParam.setParamName("test"); + Set set = new HashSet(); + set.add(heatTemplateParam); + heatTemplate.setParameters(set); + vfModule.setModuleHeatTemplate(heatTemplate); + vfModuleCustomization.setVfModule(vfModule); + + HeatEnvironment heatEnvironment = new HeatEnvironment(); + heatEnvironment.setEnvironment("parameters:ist"); + vfModuleCustomization.setHeatEnvironment(heatEnvironment); + return vfModuleCustomization; + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImplTest.java index 0ace6e4249..3e5d4ad29a 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfCloudifyAdapterImplTest.java @@ -26,12 +26,9 @@ import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.junit.Assert.assertTrue; - import java.util.HashMap; import java.util.Map; - import javax.xml.ws.Holder; - import org.apache.http.HttpStatus; import org.junit.Before; import org.junit.Rule; @@ -46,102 +43,96 @@ import org.springframework.beans.factory.annotation.Autowired; public class MsoVnfCloudifyAdapterImplTest extends BaseRestTestUtils { - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - @Autowired - private MsoVnfCloudifyAdapterImpl instance; - - @Autowired - private CloudConfig cloudConfig; - - @Before - public void before() throws Exception { - super.setUp(); - CloudifyManager cloudifyManager = new CloudifyManager(); - cloudifyManager.setId("mtn13"); - cloudifyManager.setCloudifyUrl("http://localhost:"+wireMockPort+"/v2.0"); - cloudifyManager.setUsername("m93945"); - cloudifyManager.setPassword("93937EA01B94A10A49279D4572B48369"); - } - - @Test + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + @Autowired + private MsoVnfCloudifyAdapterImpl instance; + + @Autowired + private CloudConfig cloudConfig; + + @Before + public void before() throws Exception { + super.setUp(); + CloudifyManager cloudifyManager = new CloudifyManager(); + cloudifyManager.setId("mtn13"); + cloudifyManager.setCloudifyUrl("http://localhost:" + wireMockPort + "/v2.0"); + cloudifyManager.setUsername("m93945"); + cloudifyManager.setPassword("93937EA01B94A10A49279D4572B48369"); + } + + @Test public void queryVnfExceptionTest() throws Exception { MsoRequest msoRequest = new MsoRequest(); msoRequest.setRequestId("12345"); msoRequest.setServiceInstanceId("12345"); - Holder <Map <String, String>> outputs = new Holder<>(); - instance.queryVnf("siteid", "CloudOwner", "1234", "vfname", - msoRequest, new Holder<>(), new Holder<>(), new Holder<>(), - outputs); - + Holder<Map<String, String>> outputs = new Holder<>(); + instance.queryVnf("siteid", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>(), new Holder<>(), + new Holder<>(), outputs); + assertTrue(outputs.value.isEmpty()); } - @Test - public void queryVnfTest() throws Exception { - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse() - .withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse() - .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }") - .withStatus(HttpStatus.SC_OK))); - - wireMockServer.stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse() - .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ") - .withStatus(HttpStatus.SC_OK))); - - wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse() - .withBodyFile("OpenstackResponse_Access.json") - .withStatus(HttpStatus.SC_OK))); - - instance.queryVnf("mtn13", "CloudOwner", "1234", "vfname", - msoRequest, new Holder<>(), new Holder<>(), new Holder<>(), - new Holder<>()); - } - - @Test - public void deleteVfModuleTest_ExceptionWhileQueryDeployment() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - - instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>()); - } - - @Test - public void deleteVfModuleTest_ExceptionWhileDeleteDeployment() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse() - .withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse() - .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }") - .withStatus(HttpStatus.SC_OK))); - - wireMockServer.stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse() - .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ") - .withStatus(HttpStatus.SC_OK))); - - wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse() - .withBodyFile("OpenstackResponse_Access.json") - .withStatus(HttpStatus.SC_OK))); - - instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>()); - } - - @Test + @Test + public void queryVnfTest() throws Exception { + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")) + .willReturn(aResponse().withBody("{ \"id\": \"123\" }").withStatus(HttpStatus.SC_OK))); + + wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")) + .willReturn(aResponse().withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }") + .withStatus(HttpStatus.SC_OK))); + + wireMockServer.stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse() + .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ") + .withStatus(HttpStatus.SC_OK))); + + wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")) + .willReturn(aResponse().withBodyFile("OpenstackResponse_Access.json").withStatus(HttpStatus.SC_OK))); + + instance.queryVnf("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>(), new Holder<>(), + new Holder<>(), new Holder<>()); + } + + @Test + public void deleteVfModuleTest_ExceptionWhileQueryDeployment() throws Exception { + expectedException.expect(VnfException.class); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>()); + } + + @Test + public void deleteVfModuleTest_ExceptionWhileDeleteDeployment() throws Exception { + expectedException.expect(VnfException.class); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")) + .willReturn(aResponse().withBody("{ \"id\": \"123\" }").withStatus(HttpStatus.SC_OK))); + + wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")) + .willReturn(aResponse().withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }") + .withStatus(HttpStatus.SC_OK))); + + wireMockServer.stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse() + .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ") + .withStatus(HttpStatus.SC_OK))); + + wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")) + .willReturn(aResponse().withBodyFile("OpenstackResponse_Access.json").withStatus(HttpStatus.SC_OK))); + + instance.deleteVfModule("mtn13", "CloudOwner", "1234", "vfname", msoRequest, new Holder<>()); + } + + @Test public void deleteVnfVnfExceptionTest() throws Exception { - expectedException.expect(VnfException.class); + expectedException.expect(VnfException.class); MsoRequest msoRequest = new MsoRequest(); msoRequest.setRequestId("12345"); msoRequest.setServiceInstanceId("12345"); @@ -150,165 +141,169 @@ public class MsoVnfCloudifyAdapterImplTest extends BaseRestTestUtils { } - @Test - public void rollbackVnf() throws Exception { - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); + @Test + public void rollbackVnf() throws Exception { + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + VnfRollback vnfRollback = new VnfRollback(); + vnfRollback.setModelCustomizationUuid("1234"); + vnfRollback.setVfModuleStackId("2134"); + vnfRollback.setVnfId("123"); + vnfRollback.setModelCustomizationUuid("1234"); + + instance.rollbackVnf(vnfRollback); + } + + @Test + public void rollbackVnf_Created() throws Exception { + expectedException.expect(VnfException.class); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); VnfRollback vnfRollback = new VnfRollback(); vnfRollback.setModelCustomizationUuid("1234"); vnfRollback.setVfModuleStackId("2134"); vnfRollback.setVnfId("123"); vnfRollback.setModelCustomizationUuid("1234"); + vnfRollback.setVnfCreated(true); instance.rollbackVnf(vnfRollback); - } - - @Test - public void rollbackVnf_Created() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - - VnfRollback vnfRollback = new VnfRollback(); - vnfRollback.setModelCustomizationUuid("1234"); - vnfRollback.setVfModuleStackId("2134"); - vnfRollback.setVnfId("123"); - vnfRollback.setModelCustomizationUuid("1234"); - vnfRollback.setVnfCreated(true); - - instance.rollbackVnf(vnfRollback); - } - - @Test - public void createVfModuleVnfException() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - - instance.createVfModule("123", "CloudOwner", "123", "vf", "v1", "", "module-005", "", "create", "3245", "234", "123", new HashMap<>(), true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>()); - } - - @Test - public void createVfModule_ModelCustUuidIsNull() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - - instance.createVfModule("123", "CloudOwner", "123", "vf", "v1", "", "module-005", "", "create", "3245", "234", null, new - HashMap<>(), true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>()); - } - - @Test - public void createVfModule_CloudSiteIdNotFound() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - - instance.createVfModule("123", "CloudOwner", "123", "vf", "v1", "", "module-005", "", "create", "3245", "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", new HashMap<>(), true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>()); - } - - @Test - public void createVfModule_MsoCloudifyManagerNotFound() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - - instance.createVfModule("mtn13", "CloudOwner", "123", "vf", "v1", "", "module-005", "", "create", "3245", "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", new HashMap<>(), true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>()); - } - - @Test - public void createVfModule() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - - wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")).willReturn(aResponse() - .withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")).willReturn(aResponse() - .withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }") - .withStatus(HttpStatus.SC_OK))); - - wireMockServer.stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse() - .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ") - .withStatus(HttpStatus.SC_OK))); - - wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")).willReturn(aResponse() - .withBodyFile("OpenstackResponse_Access.json") - .withStatus(HttpStatus.SC_OK))); - - instance.createVfModule("mtn13", "CloudOwner", "123", "vf", "v1", "", "vfname", "", "create", "3245", "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", new HashMap<>(), true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>()); - } - - @Test - public void updateVfModuleVnfException() throws Exception { - expectedException.expect(VnfException.class); - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - - instance.updateVfModule("123", "CloudOwner", "1234", "fw", "v2", "vnf1", "create", "123", "12", "233", "234", new HashMap<>(), msoRequest, new Holder<>(), new Holder<>()); - } - - @Test - public void healthCheckVNFTest() { - instance.healthCheck(); - } - - @Test - public void createVnfTest() { - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - - Map<String, Object> map = new HashMap<>(); - map.put("key1", "value1"); - try { - instance.createVnf("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD", - "volumeGroupHeatStackId|1", map, - Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, msoRequest, new Holder<>(), new Holder<>(), - new Holder<>()); - } catch (Exception e) { - } - } - - @Test - public void updateVnfTest() { - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - - Map<String, Object> map = new HashMap<>(); - - map.put("key1", "value1"); - try { - instance.updateVnf("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD", - "volumeGroupHeatStackId|1", map, msoRequest, new Holder<>(), - new Holder<>()); - } catch (Exception e) { - - } - } - - @Test - public void deleteVnfTest() { - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId("12345"); - msoRequest.setServiceInstanceId("12345"); - try { - instance.deleteVnf("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest); - } catch (Exception e) { - - } - } + } + + @Test + public void createVfModuleVnfException() throws Exception { + expectedException.expect(VnfException.class); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + instance.createVfModule("123", "CloudOwner", "123", "vf", "v1", "", "module-005", "", "create", "3245", "234", + "123", new HashMap<>(), true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>()); + } + + @Test + public void createVfModule_ModelCustUuidIsNull() throws Exception { + expectedException.expect(VnfException.class); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + instance.createVfModule("123", "CloudOwner", "123", "vf", "v1", "", "module-005", "", "create", "3245", "234", + null, new HashMap<>(), true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>()); + } + + @Test + public void createVfModule_CloudSiteIdNotFound() throws Exception { + expectedException.expect(VnfException.class); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + instance.createVfModule("123", "CloudOwner", "123", "vf", "v1", "", "module-005", "", "create", "3245", "234", + "9b339a61-69ca-465f-86b8-1c72c582b8e8", new HashMap<>(), true, true, true, msoRequest, new Holder<>(), + new Holder<>(), new Holder<>()); + } + + @Test + public void createVfModule_MsoCloudifyManagerNotFound() throws Exception { + expectedException.expect(VnfException.class); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + instance.createVfModule("mtn13", "CloudOwner", "123", "vf", "v1", "", "module-005", "", "create", "3245", "234", + "9b339a61-69ca-465f-86b8-1c72c582b8e8", new HashMap<>(), true, true, true, msoRequest, new Holder<>(), + new Holder<>(), new Holder<>()); + } + + @Test + public void createVfModule() throws Exception { + expectedException.expect(VnfException.class); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname")) + .willReturn(aResponse().withBody("{ \"id\": \"123\" }").withStatus(HttpStatus.SC_OK))); + + wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/deployments/vfname/outputs")) + .willReturn(aResponse().withBody("{ \"deployment_id\": \"123\",\"outputs\":{\"abc\":\"abc\"} }") + .withStatus(HttpStatus.SC_OK))); + + wireMockServer.stubFor(get(urlMatching("/v2.0/api/v3/executions?.*")).willReturn(aResponse() + .withBody("{ \"items\": {\"id\": \"123\",\"workflow_id\":\"install\",\"status\":\"terminated\" } } ") + .withStatus(HttpStatus.SC_OK))); + + wireMockServer.stubFor(get(urlPathEqualTo("/v2.0/api/v3/tokens")) + .willReturn(aResponse().withBodyFile("OpenstackResponse_Access.json").withStatus(HttpStatus.SC_OK))); + + instance.createVfModule("mtn13", "CloudOwner", "123", "vf", "v1", "", "vfname", "", "create", "3245", "234", + "9b339a61-69ca-465f-86b8-1c72c582b8e8", new HashMap<>(), true, true, true, msoRequest, new Holder<>(), + new Holder<>(), new Holder<>()); + } + + @Test + public void updateVfModuleVnfException() throws Exception { + expectedException.expect(VnfException.class); + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + instance.updateVfModule("123", "CloudOwner", "1234", "fw", "v2", "vnf1", "create", "123", "12", "233", "234", + new HashMap<>(), msoRequest, new Holder<>(), new Holder<>()); + } + + @Test + public void healthCheckVNFTest() { + instance.healthCheck(); + } + + @Test + public void createVnfTest() { + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + Map<String, Object> map = new HashMap<>(); + map.put("key1", "value1"); + try { + instance.createVnf("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD", + "volumeGroupHeatStackId|1", map, Boolean.FALSE, Boolean.TRUE, Boolean.TRUE, msoRequest, + new Holder<>(), new Holder<>(), new Holder<>()); + } catch (Exception e) { + } + } + + @Test + public void updateVnfTest() { + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + + Map<String, Object> map = new HashMap<>(); + + map.put("key1", "value1"); + try { + instance.updateVnf("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "vSAMP12", "VFMOD", + "volumeGroupHeatStackId|1", map, msoRequest, new Holder<>(), new Holder<>()); + } catch (Exception e) { + + } + } + + @Test + public void deleteVnfTest() { + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId("12345"); + msoRequest.setServiceInstanceId("12345"); + try { + instance.deleteVnf("mdt1", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest); + } catch (Exception e) { + + } + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java index 507251bb80..9d13cc10a3 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java @@ -28,12 +28,9 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; - import java.util.HashMap; import java.util.Map; - import javax.xml.ws.Holder; - import org.apache.http.HttpStatus; import org.junit.Before; import org.junit.Rule; @@ -47,7 +44,7 @@ import org.onap.so.openstack.beans.StackInfo; import org.onap.so.openstack.exceptions.MsoException; import org.springframework.beans.factory.annotation.Autowired; -public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils{ +public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils { @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -59,17 +56,20 @@ public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils{ private static final String CREATE_STACK_RESPONSE = "{\"template_type\": \"TEST-template\", \"workload_id\": " + "\"workload-id\", \"template_response\": {\"stack\": {\"id\": \"TEST-stack\", \"links\": []}}}"; - private static final String UPDATE_STACK_RESPONSE = "{\"template_type\": \"heat\", \"workload_id\": " - + "\"workload-id\"}"; + private static final String UPDATE_STACK_RESPONSE = + "{\"template_type\": \"heat\", \"workload_id\": " + "\"workload-id\"}"; private static final String GET_CREATE_STACK_RESPONSE = "{\"template_type\": \"heat\", \"workload_id\": " + "\"workload-id\", \"workload_status\": \"CREATE_COMPLETE\"}"; private static final String GET_UPDATE_STACK_RESPONSE = "{\"template_type\": \"heat\", \"workload_id\": " + "\"workload-id\", \"workload_status\": \"UPDATE_COMPLETE\"}"; private static final String MULTICLOUD_CREATE_PATH = "/api/multicloud/v1/CloudOwner/MTN13/infra_workload"; - private static final String MULTICLOUD_UPDATE_PATH = "/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id"; - private static final String MULTICLOUD_GET_PATH_BY_NAME = "/api/multicloud/v1/CloudOwner/MTN13/infra_workload/vfname"; - private static final String MULTICLOUD_GET_PATH_BY_ID = "/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id"; + private static final String MULTICLOUD_UPDATE_PATH = + "/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id"; + private static final String MULTICLOUD_GET_PATH_BY_NAME = + "/api/multicloud/v1/CloudOwner/MTN13/infra_workload/vfname"; + private static final String MULTICLOUD_GET_PATH_BY_ID = + "/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id"; @Before public void before() throws Exception { @@ -92,41 +92,31 @@ public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils{ msoRequest.setRequestId("12345"); msoRequest.setServiceInstanceId("12345"); - wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_NAME)) - .willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withStatus(HttpStatus.SC_NOT_FOUND))); - - wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_ID)) - .inScenario("CREATE").whenScenarioStateIs("CREATING") - .willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBody(GET_CREATE_STACK_RESPONSE) - .withStatus(HttpStatus.SC_OK))); - - wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_ID)) - .inScenario("CREATE").whenScenarioStateIs("UPDATING") - .willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBody(GET_UPDATE_STACK_RESPONSE) - .withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_NAME)).willReturn( + aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND))); + + wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_ID)).inScenario("CREATE") + .whenScenarioStateIs("CREATING").willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(GET_CREATE_STACK_RESPONSE).withStatus(HttpStatus.SC_OK))); + + wireMockServer.stubFor(get(urlPathEqualTo(MULTICLOUD_GET_PATH_BY_ID)).inScenario("CREATE") + .whenScenarioStateIs("UPDATING").willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(GET_UPDATE_STACK_RESPONSE).withStatus(HttpStatus.SC_OK))); wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_CREATE_PATH)).inScenario("CREATE") - .willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile("MulticloudResponse_Stack_Create.json") - .withStatus(HttpStatus.SC_CREATED)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("MulticloudResponse_Stack_Create.json").withStatus(HttpStatus.SC_CREATED)) .willSetStateTo("CREATING")); - wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_UPDATE_PATH)).inScenario("CREATE") - .willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBody(UPDATE_STACK_RESPONSE) - .withStatus(HttpStatus.SC_ACCEPTED)) + wireMockServer.stubFor(post(urlPathEqualTo(MULTICLOUD_UPDATE_PATH)) + .inScenario("CREATE").willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(UPDATE_STACK_RESPONSE).withStatus(HttpStatus.SC_ACCEPTED)) .willSetStateTo("UPDATING")); try { - instance.createVfModule("MTN13", "CloudOwner", "123", "vf", "v1", "genericVnfId", "vfname", "vfModuleId", "create", null, "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", stackInputs, true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>()); + instance.createVfModule("MTN13", "CloudOwner", "123", "vf", "v1", "genericVnfId", "vfname", "vfModuleId", + "create", null, "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", stackInputs, true, true, true, + msoRequest, new Holder<>(), new Holder<>(), new Holder<>()); } catch (VnfException e) { fail("createVfModule success expected, failed with exception: " + e.toString()); } @@ -147,15 +137,18 @@ public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils{ msoRequest.setRequestId("12345"); msoRequest.setServiceInstanceId("12345"); - wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/vfname")).willReturn(aResponse() - //.withHeader() - .withBodyFile("MulticloudResponse_Stack.json") - .withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor( + get(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/vfname")).willReturn(aResponse() + // .withHeader() + .withBodyFile("MulticloudResponse_Stack.json").withStatus(HttpStatus.SC_OK))); try { - instance.createVfModule("MTN13", "CloudOwner", "123", "vf", "v1", "genericVnfId", "vfname", "vfModuleId", "create", null, "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", stackInputs, true, true, true, msoRequest, new Holder<>(), new Holder<>(), new Holder<>()); + instance.createVfModule("MTN13", "CloudOwner", "123", "vf", "v1", "genericVnfId", "vfname", "vfModuleId", + "create", null, "234", "9b339a61-69ca-465f-86b8-1c72c582b8e8", stackInputs, true, true, true, + msoRequest, new Holder<>(), new Holder<>(), new Holder<>()); } catch (VnfException e) { - assertTrue(e.toString().contains("Resource vfname already exists in owner/cloud/tenant CloudOwner/MTN13/123 with ID vfname/vfname")); + assertTrue(e.toString().contains( + "Resource vfname already exists in owner/cloud/tenant CloudOwner/MTN13/123 with ID vfname/vfname")); return; } fail("VnfAlreadyExists Exception expected!"); @@ -167,12 +160,11 @@ public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils{ msoRequest.setRequestId("12345"); msoRequest.setServiceInstanceId("12345"); - wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id")).willReturn(aResponse() - .withBodyFile("MulticloudResponse_Stack.json") - .withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id")) + .willReturn(aResponse().withBodyFile("MulticloudResponse_Stack.json").withStatus(HttpStatus.SC_OK))); - wireMockServer.stubFor(delete(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id")).willReturn(aResponse() - .withStatus(HttpStatus.SC_NO_CONTENT))); + wireMockServer.stubFor(delete(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id")) + .willReturn(aResponse().withStatus(HttpStatus.SC_NO_CONTENT))); instance.deleteVfModule("MTN13", "CloudOwner", "123", "workload-id", msoRequest, new Holder<>()); } @@ -183,11 +175,11 @@ public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils{ msoRequest.setRequestId("12345"); msoRequest.setServiceInstanceId("12345"); - wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id")).willReturn(aResponse() - .withBodyFile("MulticloudResponse_Stack.json") - .withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlPathEqualTo("/api/multicloud/v1/CloudOwner/MTN13/infra_workload/workload-id")) + .willReturn(aResponse().withBodyFile("MulticloudResponse_Stack.json").withStatus(HttpStatus.SC_OK))); - instance.queryVnf("MTN13", "CloudOwner", "123", "workload-id", msoRequest, new Holder<>(), new Holder<>(), new Holder<>(), new Holder<>()); + instance.queryVnf("MTN13", "CloudOwner", "123", "workload-id", msoRequest, new Holder<>(), new Holder<>(), + new Holder<>(), new Holder<>()); } // TODO Error Tests diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java index 50272dca20..be565deb9e 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfPluginAdapterImplTest.java @@ -27,12 +27,9 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_200; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackGetStackVfModule_404; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess; - import java.util.HashMap; import java.util.Map; - import javax.xml.ws.Holder; - import org.apache.http.HttpStatus; import org.junit.Rule; import org.junit.Test; @@ -58,9 +55,9 @@ public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils { MsoRequest msoRequest = getMsoRequest(); Map<String, Object> map = new HashMap<>(); map.put("key1", "value1"); - msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - "volumeGroupHeatStackId|1", "baseVfHeatStackId", null, map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), + msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", + vnfName, "", "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", null, map, Boolean.FALSE, + Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), new Holder<VnfRollback>()); } @@ -70,10 +67,10 @@ public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils { MsoRequest msoRequest = getMsoRequest(); Map<String, Object> map = new HashMap<>(); map.put("key1", "value1"); - msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - "volumeGroupHeatStackId|1", "baseVfHeatStackId", "88a6ca3ee0394ade9403f075db23167e", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); + msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", + vnfName, "", "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", + "88a6ca3ee0394ade9403f075db23167e", map, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, + new Holder<>(), new Holder<Map<String, String>>(), new Holder<VnfRollback>()); } @Test @@ -82,10 +79,10 @@ public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils { MsoRequest msoRequest = getMsoRequest(); Map<String, Object> map = new HashMap<>(); map.put("key1", "value1"); - msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - "volumeGroupHeatStackId|1", "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); + msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", + vnfName, "", "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", + "9b339a61-69ca-465f-86b8-1c72c582b8e8", map, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, + new Holder<>(), new Holder<Map<String, String>>(), new Holder<VnfRollback>()); } @Test @@ -96,10 +93,10 @@ public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils { MsoRequest msoRequest = getMsoRequest(); Map<String, Object> map = new HashMap<>(); map.put("key1", "value1"); - msoVnfPluginAdapter.createVfModule("MTN13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - null, "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); + msoVnfPluginAdapter.createVfModule("MTN13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", + vnfName, "", "VFMOD", null, "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map, + Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), + new Holder<Map<String, String>>(), new Holder<VnfRollback>()); } @Test @@ -109,10 +106,10 @@ public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils { MsoRequest msoRequest = getMsoRequest(); Map<String, Object> map = new HashMap<>(); map.put("key1", "value1"); - msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - "volumeGroupHeatStackId|1", "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); + msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", + vnfName, "", "VFMOD", "volumeGroupHeatStackId|1", "baseVfHeatStackId", + "9b339a61-69ca-465f-86b8-1c72c582b8e8", map, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, + new Holder<>(), new Holder<Map<String, String>>(), new Holder<VnfRollback>()); } @Test @@ -122,23 +119,22 @@ public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils { mockOpenStackGetStackVfModule_404(wireMockServer); wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/volumeGroupHeatStackId")) .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json") - .withStatus(HttpStatus.SC_OK))); + .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK))); MsoRequest msoRequest = getMsoRequest(); Map<String, Object> map = new HashMap<>(); map.put("key1", "value1"); - msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", vnfName, "", "VFMOD", - "volumeGroupHeatStackId", "baseVfHeatStackId", "9b339a61-69ca-465f-86b8-1c72c582b8e8", map, - Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, new Holder<>(), new Holder<Map<String, String>>(), - new Holder<VnfRollback>()); + msoVnfPluginAdapter.createVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vnf", "1", "", + vnfName, "", "VFMOD", "volumeGroupHeatStackId", "baseVfHeatStackId", + "9b339a61-69ca-465f-86b8-1c72c582b8e8", map, Boolean.FALSE, Boolean.TRUE, Boolean.FALSE, msoRequest, + new Holder<>(), new Holder<Map<String, String>>(), new Holder<VnfRollback>()); } @Test public void deleteVfModule_QueryVduException() throws Exception { expectedException.expect(VnfException.class); MsoRequest msoRequest = getMsoRequest(); - msoVnfPluginAdapter.deleteVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest, - new Holder<Map<String, String>>()); + msoVnfPluginAdapter.deleteVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", + msoRequest, new Holder<Map<String, String>>()); } @Test @@ -148,14 +144,14 @@ public class MsoVnfPluginAdapterImplTest extends BaseRestTestUtils { mockOpenStackGetStackVfModule_200(wireMockServer); wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/vSAMP12")) .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json") - .withStatus(HttpStatus.SC_OK))); - wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); + .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json").withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(delete( + urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); MsoRequest msoRequest = getMsoRequest(); - msoVnfPluginAdapter.deleteVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", msoRequest, - new Holder<Map<String, String>>()); + msoVnfPluginAdapter.deleteVfModule("mtn13", "CloudOwner", "88a6ca3ee0394ade9403f075db23167e", "vSAMP12", + msoRequest, new Holder<Map<String, String>>()); } private MsoRequest getMsoRequest() { diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/QueryTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/QueryTest.java index 232f5b3afe..7e7c130e33 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/QueryTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/QueryTest.java @@ -25,11 +25,8 @@ import static org.hamcrest.Matchers.hasProperty; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; - import java.util.Map; - import javax.xml.ws.Holder; - import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -48,64 +45,66 @@ import org.onap.so.openstack.utils.MsoHeatUtils; @RunWith(MockitoJUnitRunner.class) public class QueryTest { - - @Mock - private MsoHeatUtils heat; - @InjectMocks - private MsoVnfAdapterImpl vnfAdapter = new MsoVnfAdapterImpl(); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Test - public void testQueryCreatedVnf() throws VnfException, MsoException { - StackInfo info = new StackInfo("stackName", HeatStatus.CREATED); - when(heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(info); - String cloudId = "MT"; - String cloudOwner = "CloudOwner"; - String tenantId = "MSO_Test"; - String vnfName = "VNF_TEST1"; - Holder<Boolean> vnfExists = new Holder<>(); - Holder<String> vnfId = new Holder<>(); - Holder<VnfStatus> status = new Holder<>(); - Holder<Map<String, String>> outputs = new Holder<>(); - vnfAdapter.queryVnf(cloudId, cloudOwner, tenantId, vnfName, null, vnfExists, vnfId, status, outputs); + @Mock + private MsoHeatUtils heat; + @InjectMocks + private MsoVnfAdapterImpl vnfAdapter = new MsoVnfAdapterImpl(); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void testQueryCreatedVnf() throws VnfException, MsoException { + StackInfo info = new StackInfo("stackName", HeatStatus.CREATED); + when(heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(info); + String cloudId = "MT"; + String cloudOwner = "CloudOwner"; + String tenantId = "MSO_Test"; + String vnfName = "VNF_TEST1"; + Holder<Boolean> vnfExists = new Holder<>(); + Holder<String> vnfId = new Holder<>(); + Holder<VnfStatus> status = new Holder<>(); + Holder<Map<String, String>> outputs = new Holder<>(); + + vnfAdapter.queryVnf(cloudId, cloudOwner, tenantId, vnfName, null, vnfExists, vnfId, status, outputs); - assertTrue(vnfExists.value); - } + assertTrue(vnfExists.value); + } - @Test - public void testQueryNotFoundVnf() throws VnfException, MsoException { - StackInfo info = new StackInfo("stackName", HeatStatus.NOTFOUND); - when(heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(info); - String cloudId = "MT"; - String cloudOwner = "CloudOwner"; - String tenantId = "MSO_Test"; - String vnfName = "VNF_TEST1"; - Holder<Boolean> vnfExists = new Holder<>(); - Holder<String> vnfId = new Holder<>(); - Holder<VnfStatus> status = new Holder<>(); - Holder<Map<String, String>> outputs = new Holder<>(); + @Test + public void testQueryNotFoundVnf() throws VnfException, MsoException { + StackInfo info = new StackInfo("stackName", HeatStatus.NOTFOUND); + when(heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(info); + String cloudId = "MT"; + String cloudOwner = "CloudOwner"; + String tenantId = "MSO_Test"; + String vnfName = "VNF_TEST1"; + Holder<Boolean> vnfExists = new Holder<>(); + Holder<String> vnfId = new Holder<>(); + Holder<VnfStatus> status = new Holder<>(); + Holder<Map<String, String>> outputs = new Holder<>(); - vnfAdapter.queryVnf(cloudId, cloudOwner, tenantId, vnfName, null, vnfExists, vnfId, status, outputs); + vnfAdapter.queryVnf(cloudId, cloudOwner, tenantId, vnfName, null, vnfExists, vnfId, status, outputs); - assertFalse(vnfExists.value); - } + assertFalse(vnfExists.value); + } - @Test() - // @Ignore // 1802 merge - public void testQueryVnfWithException() throws VnfException, MsoException { - String cloudId = "MT"; - String cloudOwner = "CloudOwner"; - String tenantId = "MSO_Test"; - String vnfName = "VNF_TEST1"; - Holder<Boolean> vnfExists = new Holder<>(); - Holder<String> vnfId = new Holder<>(); - Holder<VnfStatus> status = new Holder<>(); - Holder<Map<String, String>> outputs = new Holder<>(); - thrown.expect(VnfException.class); - thrown.expectCause(hasProperty("context", is("QueryVNF"))); - when(heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())).thenThrow(new MsoOpenstackException(1, "test messsage", "test detail")); - vnfAdapter.queryVnf(cloudId, cloudOwner, tenantId, vnfName, null, vnfExists, vnfId, status, outputs); - } + @Test() + // @Ignore // 1802 merge + public void testQueryVnfWithException() throws VnfException, MsoException { + String cloudId = "MT"; + String cloudOwner = "CloudOwner"; + String tenantId = "MSO_Test"; + String vnfName = "VNF_TEST1"; + Holder<Boolean> vnfExists = new Holder<>(); + Holder<String> vnfId = new Holder<>(); + Holder<VnfStatus> status = new Holder<>(); + Holder<Map<String, String>> outputs = new Holder<>(); + thrown.expect(VnfException.class); + thrown.expectCause(hasProperty("context", is("QueryVNF"))); + when(heat.queryStack(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) + .thenThrow(new MsoOpenstackException(1, "test messsage", "test detail")); + vnfAdapter.queryVnf(cloudId, cloudOwner, tenantId, vnfName, null, vnfExists, vnfId, status, outputs); + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VfRollbackTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VfRollbackTest.java index a59de7695c..df2d798cda 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VfRollbackTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VfRollbackTest.java @@ -1,70 +1,66 @@ /* -* ============LICENSE_START======================================================= - * ONAP : SO - * ================================================================================ - * Copyright (C) 2018 TechMahindra - * ================================================================================ - * 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 + * ============LICENSE_START======================================================= ONAP : SO + * ================================================================================ Copyright (C) 2018 TechMahindra + * ================================================================================ 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 + * 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. + * 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.vnf; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertEquals; import org.junit.Test; + public class VfRollbackTest { - private VfRollback vfRollback = new VfRollback(); + private VfRollback vfRollback = new VfRollback(); + + @Test + public void test() { + vfRollback.setVnfId("vnfId"); + vfRollback.setTenantId("tenantId"); + vfRollback.setCloudSiteId("cloudId"); + vfRollback.setTenantCreated(true); + vfRollback.setVnfCreated(true); + vfRollback.setMsoRequest(null); + vfRollback.setVolumeGroupName("volumeGroupName"); + vfRollback.setVolumeGroupId("volumeGroupId"); + vfRollback.setRequestType("requestType"); + vfRollback.setVolumeGroupHeatStackId("volumeGroupHeatStackId"); + vfRollback.setBaseGroupHeatStackId("baseGroupHeatStackId"); + vfRollback.setIsBase(true); + vfRollback.setVfModuleStackId("vfModuleStackId"); + assert (vfRollback.getVnfId() != null); + assert (vfRollback.getTenantId() != null); + assert (vfRollback.getCloudSiteId() != null); + assert (vfRollback.getVolumeGroupName() != null); + assert (vfRollback.getVolumeGroupId() != null); + assert (vfRollback.getRequestType() != null); + assert (vfRollback.getVolumeGroupHeatStackId() != null); + assert (vfRollback.getBaseGroupHeatStackId() != null); + assert (vfRollback.getVfModuleStackId() != null); + assertEquals("vnfId", vfRollback.getVnfId()); + assertEquals("tenantId", vfRollback.getTenantId()); + assertEquals("cloudId", vfRollback.getCloudSiteId()); + assertEquals(true, vfRollback.getTenantCreated()); + assertEquals(true, vfRollback.getVnfCreated()); + assertEquals(null, vfRollback.getMsoRequest()); + assertEquals("volumeGroupName", vfRollback.getVolumeGroupName()); + assertEquals("volumeGroupId", vfRollback.getVolumeGroupId()); + assertEquals("requestType", vfRollback.getRequestType()); + assertEquals("volumeGroupHeatStackId", vfRollback.getVolumeGroupHeatStackId()); + assertEquals("baseGroupHeatStackId", vfRollback.getBaseGroupHeatStackId()); + assertEquals(true, vfRollback.isBase()); + assertEquals("vfModuleStackId", vfRollback.getVfModuleStackId()); + } - @Test - public void test() { - vfRollback.setVnfId("vnfId"); - vfRollback.setTenantId("tenantId"); - vfRollback.setCloudSiteId("cloudId"); - vfRollback.setTenantCreated(true); - vfRollback.setVnfCreated(true); - vfRollback.setMsoRequest(null); - vfRollback.setVolumeGroupName("volumeGroupName"); - vfRollback.setVolumeGroupId("volumeGroupId"); - vfRollback.setRequestType("requestType"); - vfRollback.setVolumeGroupHeatStackId("volumeGroupHeatStackId"); - vfRollback.setBaseGroupHeatStackId("baseGroupHeatStackId"); - vfRollback.setIsBase(true); - vfRollback.setVfModuleStackId("vfModuleStackId"); - assert(vfRollback.getVnfId() != null); - assert(vfRollback.getTenantId() != null); - assert(vfRollback.getCloudSiteId() != null); - assert(vfRollback.getVolumeGroupName() != null); - assert(vfRollback.getVolumeGroupId() != null); - assert(vfRollback.getRequestType() != null); - assert(vfRollback.getVolumeGroupHeatStackId() != null); - assert(vfRollback.getBaseGroupHeatStackId() != null); - assert(vfRollback.getVfModuleStackId() != null); - assertEquals("vnfId", vfRollback.getVnfId()); - assertEquals("tenantId", vfRollback.getTenantId()); - assertEquals("cloudId", vfRollback.getCloudSiteId()); - assertEquals(true, vfRollback.getTenantCreated()); - assertEquals(true, vfRollback.getVnfCreated()); - assertEquals(null, vfRollback.getMsoRequest()); - assertEquals("volumeGroupName", vfRollback.getVolumeGroupName()); - assertEquals("volumeGroupId", vfRollback.getVolumeGroupId()); - assertEquals("requestType", vfRollback.getRequestType()); - assertEquals("volumeGroupHeatStackId", vfRollback.getVolumeGroupHeatStackId()); - assertEquals("baseGroupHeatStackId", vfRollback.getBaseGroupHeatStackId()); - assertEquals(true, vfRollback.isBase()); - assertEquals("vfModuleStackId", vfRollback.getVfModuleStackId()); - } - - @Test - public void testtoString() { - assert(vfRollback.toString() != null); - } + @Test + public void testtoString() { + assert (vfRollback.toString() != null); + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VnfAdapterRestTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VnfAdapterRestTest.java index bf00faa41b..89adafd280 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VnfAdapterRestTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VnfAdapterRestTest.java @@ -42,7 +42,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; - import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; @@ -50,7 +49,6 @@ import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map; - import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; @@ -73,480 +71,477 @@ import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackPutStacks_200; import static org.onap.so.bpmn.mock.StubOpenStack.mockOpenStackResponseAccess; public class VnfAdapterRestTest extends BaseRestTestUtils { - - - @Autowired - private JettisonStyleMapperProvider jettisonTypeObjectMapper; - private static final String MESSAGE_ID = "62265093-277d-4388-9ba6-449838ade586-1517252396874"; - private static final String AAI_VNF_ID = "c93e0d34-5b63-45de-bbae-b0fe49dd3bd9"; - private static final String MSO_REQUEST_ID = "62265093-277d-4388-9ba6-449838ade586"; - private static final String MSO_SERVICE_INSTANCE_ID = "4147e06f-1b89-49c5-b21f-4faf8dc9805a"; - private static final String CLOUDSITE_ID = "mtn13"; - private static final String CLOUD_OWNER = "CloudOwner"; - private static final String TENANT_ID = "0422ffb57ba042c0800a29dc85ca70f8"; - private static final String VNF_TYPE = "MSOTADevInfra_vSAMP10a_Service/vSAMP10a 1"; - private static final String VNF_NAME = "MSO-DEV-VNF-1802-it3-pwt3-vSAMP10a-1XXX-Replace"; - private static final String VNF_VERSION = "1.0"; - private static final String VF_MODULE_ID = "1d48aaec-b7f3-4c24-ba4a-4e798ed3223c"; - private static final String VF_MODULE_NAME = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001"; - private static final String VF_MODULE_TYPE = "vSAMP10aDEV::PCM::module-2"; - private static final String MODEL_CUSTOMIZATION_UUID = "cb82ffd8-252a-11e7-93ae-92361f002671"; - private static final String BASE_VF_MODULE_ID = "3d7ff7b4-720b-4604-be0a-1974fc58ed96"; - // vfModuleParams specific variables - private static final String NETWORK_NAME = "Dev-vSAMP10a-ntwk-1802-pwt3-v6-Replace-1001"; - private static final String SERVER_NAME = "Dev-vSAMP10a-addon2-1802-pwt3-v6-Replace-1001"; - private static final String IMAGE = "ubuntu_14.04_IPv6"; - private static final String EXN_DIRECT_NET_FQDN = "direct"; - private static final String EXN_HSL_NET_FQDN = "hsl"; - private static final String AVAILABILITY_ZONE_0 = "nova"; - private static final String VF_MODULE_INDEX = "0"; - private static final String REQUEST_TYPE = ""; - - @Test - public void testCreateVfModule() throws JSONException, JsonParseException, JsonMappingException, IOException { - - CreateVfModuleRequest request = populateCreateVfModuleRequest(); - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - mockOpenStackGetStackVfModule_404(wireMockServer); - - mockOpenStackPostStacks_200(wireMockServer); - - mockOpenStackGetStackVfModule_200(wireMockServer); - - headers.add("Accept", MediaType.APPLICATION_JSON); - HttpEntity<CreateVfModuleRequest> entity = new HttpEntity<CreateVfModuleRequest>(request, headers); - - ResponseEntity<CreateVfModuleResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST, - entity, CreateVfModuleResponse.class); - - ResponseEntity<CreateVfModuleResponse> responseV2 = restTemplate.exchange( - createURLWithPort("/services/rest/v2/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST, - entity, CreateVfModuleResponse.class); - - CreateVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( - new File("src/test/resources/__files/CreateVfModuleResponse.json"), CreateVfModuleResponse.class); - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - assertThat(response.getBody(), sameBeanAs(expectedResponse)); - - assertEquals(Response.Status.OK.getStatusCode(), responseV2.getStatusCode().value()); - assertThat(responseV2.getBody(), sameBeanAs(expectedResponse)); - } - - @Test - public void testCreateVfModuleAsyncCall() throws Exception { - CreateVfModuleRequest request = populateCreateVfModuleRequest(); - request.setNotificationUrl( createURLWithPort("/mso/WorkflowMesssage")); - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - mockOpenStackGetStackVfModule_404(wireMockServer); - mockOpenStackPostStacks_200(wireMockServer); - mockOpenStackGetStackVfModule_200(wireMockServer); - - headers.add("Accept", MediaType.APPLICATION_JSON); - HttpEntity<CreateVfModuleRequest> entity = new HttpEntity<CreateVfModuleRequest>(request, headers); - - ResponseEntity<CreateVfModuleResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST, - entity, CreateVfModuleResponse.class); - - CreateVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( - new File("src/test/resources/__files/CreateVfModuleResponse.json"), CreateVfModuleResponse.class); - - assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); - } - - @Test - public void testCreateVfModuleWithEnableBridgeNull() - throws JSONException, JsonParseException, JsonMappingException, IOException { - - CreateVfModuleRequest request = new CreateVfModuleRequest(); - request.setBackout(true); - request.setSkipAAI(true); - request.setFailIfExists(false); - MsoRequest msoReq = new MsoRequest(); - boolean failIfExists = true; - Boolean enableBridge = null; - Map<String, Object> vfModuleParams = new HashMap<>(); - - - vfModuleParams.put("vf_module_id", VF_MODULE_ID); - vfModuleParams.put("vnf_id", AAI_VNF_ID); - vfModuleParams.put("network_name", NETWORK_NAME); - vfModuleParams.put("vnf_name", VNF_NAME); - vfModuleParams.put("environment_context", ""); - vfModuleParams.put("server_name", SERVER_NAME); - vfModuleParams.put("image", IMAGE); - vfModuleParams.put("workload_context", ""); - vfModuleParams.put("vf_module_index", VF_MODULE_INDEX); - vfModuleParams.put("vf_module_name", VF_MODULE_NAME); - vfModuleParams.put("availability_zone_0", AVAILABILITY_ZONE_0); - vfModuleParams.put("exn_direct_net_fqdn", EXN_DIRECT_NET_FQDN); - vfModuleParams.put("exn_hsl_net_fqdn", EXN_HSL_NET_FQDN); - - msoReq.setRequestId(MSO_REQUEST_ID); - msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); - request.setMsoRequest(msoReq); - request.setRequestType(REQUEST_TYPE); - request.setCloudSiteId(CLOUDSITE_ID); - request.setTenantId(TENANT_ID); - request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID); - request.setVnfId(AAI_VNF_ID); - request.setVnfVersion(VNF_VERSION); - request.setVfModuleId(VF_MODULE_ID); - request.setVfModuleName(VF_MODULE_NAME); - request.setBaseVfModuleId(BASE_VF_MODULE_ID); - request.setFailIfExists(failIfExists); - request.setEnableBridge(enableBridge); - request.setVfModuleParams(vfModuleParams); - request.setMessageId(MESSAGE_ID); - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - mockOpenStackGetStackVfModule_404(wireMockServer); - - mockOpenStackPostStacks_200(wireMockServer); - - mockOpenStackGetStackVfModule_200(wireMockServer); - - - headers.add("Accept", MediaType.APPLICATION_JSON); - HttpEntity<CreateVfModuleRequest> entity = new HttpEntity<CreateVfModuleRequest>(request, headers); - - ResponseEntity<CreateVfModuleResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST, - entity, CreateVfModuleResponse.class); - - CreateVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( - new File("src/test/resources/__files/CreateVfModuleResponse.json"), CreateVfModuleResponse.class); - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - assertThat(response.getBody(), sameBeanAs(expectedResponse)); - } - - @Test - public void testCreateVfModuleFail() throws IOException{ - - CreateVfModuleRequest request = new CreateVfModuleRequest(); - request.setBackout(true); - request.setSkipAAI(true); - request.setFailIfExists(false); - MsoRequest msoReq = new MsoRequest(); - boolean failIfExists = true; - boolean enableBridge = false; - Map<String, Object> vfModuleParams = new HashMap<>(); - - vfModuleParams.put("vf_module_id", VF_MODULE_ID); - vfModuleParams.put("vnf_id", AAI_VNF_ID); - vfModuleParams.put("network_name", NETWORK_NAME); - vfModuleParams.put("vnf_name", VNF_NAME); - vfModuleParams.put("environment_context", ""); - vfModuleParams.put("server_name", SERVER_NAME); - vfModuleParams.put("image", IMAGE); - vfModuleParams.put("workload_context", ""); - vfModuleParams.put("vf_module_index", VF_MODULE_INDEX); - vfModuleParams.put("vf_module_name", VF_MODULE_NAME); - vfModuleParams.put("availability_zone_0", AVAILABILITY_ZONE_0); - vfModuleParams.put("exn_direct_net_fqdn", EXN_DIRECT_NET_FQDN); - vfModuleParams.put("exn_hsl_net_fqdn", EXN_HSL_NET_FQDN); - - msoReq.setRequestId(MSO_REQUEST_ID); - msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); - request.setMsoRequest(msoReq); - request.setRequestType(REQUEST_TYPE); - request.setCloudSiteId(CLOUDSITE_ID); - request.setTenantId(TENANT_ID); - request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID); - request.setVnfId(AAI_VNF_ID); - request.setVnfType(VNF_TYPE); - request.setVnfVersion(VNF_VERSION); - request.setVfModuleId(VF_MODULE_ID); - request.setVfModuleName(VF_MODULE_NAME); - request.setVfModuleType(VF_MODULE_TYPE); - request.setBaseVfModuleStackId(BASE_VF_MODULE_ID); - request.setFailIfExists(failIfExists); - request.setEnableBridge(enableBridge); - request.setVfModuleParams(vfModuleParams); - request.setMessageId(MESSAGE_ID); - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - mockOpenStackGetStackVfModule_404(wireMockServer); - - mockOpenStackGetStacks_404(wireMockServer); - - mockOpenStackPostStacks_200(wireMockServer); - - mockOpenStackGetStackVfModule_200(wireMockServer); - - headers.add("Accept", MediaType.APPLICATION_JSON); - HttpEntity<CreateVfModuleRequest> entity = new HttpEntity<CreateVfModuleRequest>(request, headers); - - ResponseEntity<VfModuleExceptionResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST, - entity, VfModuleExceptionResponse.class); - - assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); - - mockOpenStackGetStacksWithBody_200(wireMockServer, "DELETE_IN_PROGRESS"); - - response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST, - entity, VfModuleExceptionResponse.class); - - assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); - - mockOpenStackGetStacksWithBody_200(wireMockServer, "DELETE_FAILED"); - - response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST, - entity, VfModuleExceptionResponse.class); - - assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); - - mockOpenStackGetStacksWithBody_200(wireMockServer, "UPDATE_COMPLETE"); - - response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST, - entity, VfModuleExceptionResponse.class); - - assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); - - mockOpenStackGetStacksWithBody_404(wireMockServer); - - response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), HttpMethod.POST, - entity, VfModuleExceptionResponse.class); - - assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); - - } - - @Test - public void testDeleteVfModule() throws IOException{ - - DeleteVfModuleRequest request = new DeleteVfModuleRequest(); - MsoRequest msoRequest = new MsoRequest(); - String vfModuleStackId = "stackId"; - - msoRequest.setRequestId(MSO_REQUEST_ID); - msoRequest.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); - request.setCloudSiteId(CLOUDSITE_ID); - request.setTenantId(TENANT_ID); - request.setVfModuleId(VF_MODULE_ID); - request.setVfModuleStackId(vfModuleStackId); - request.setVnfId(AAI_VNF_ID); - request.setMsoRequest(msoRequest); - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - mockOpenStackPostStacks_200(wireMockServer); - - mockOpenStackGetStacksStackId_404(wireMockServer); - - mockOpenStackGetPublicUrlStackByNameAndID_200(wireMockServer, wireMockPort); - - mockOpenStackDeletePublicUrlStackByNameAndID_204(wireMockServer); - - - headers.add("Accept", MediaType.APPLICATION_JSON); - HttpEntity<DeleteVfModuleRequest> entity = new HttpEntity<DeleteVfModuleRequest>(request, headers); - - ResponseEntity<DeleteVfModuleResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_ID), HttpMethod.DELETE, - entity, DeleteVfModuleResponse.class); - - ResponseEntity<DeleteVfModuleResponse> responseV2 = restTemplate.exchange( - createURLWithPort("/services/rest/v2/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_ID), HttpMethod.DELETE, - entity, DeleteVfModuleResponse.class); - - - DeleteVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( - new File("src/test/resources/__files/DeleteVfModuleResponse.json"), DeleteVfModuleResponse.class); - - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - assertThat(response.getBody(), sameBeanAs(expectedResponse)); - - assertEquals(Response.Status.OK.getStatusCode(), responseV2.getStatusCode().value()); - assertThat(responseV2.getBody(), sameBeanAs(expectedResponse)); - } - - @Test - public void testUpdateVfModule() throws IOException{ - - UpdateVfModuleRequest request = new UpdateVfModuleRequest(); - MsoRequest msoRequest = new MsoRequest(); - String vfModuleStackId = "vfModuleStackId"; - Boolean failIfExists = false; - Boolean backout = false; - msoRequest.setRequestId(MSO_REQUEST_ID); - msoRequest.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); - - Map<String, Object> vfModuleParams = new HashMap<>(); - - vfModuleParams.put("exn_direct_net_fqdn", EXN_DIRECT_NET_FQDN); - vfModuleParams.put("exn_hsl_net_fqdn", EXN_HSL_NET_FQDN); - - Map<String, String> vfModuleOutputs = new HashMap<String, String>(); - - vfModuleOutputs.put("output name", "output value"); - - request.setBackout(backout); - request.setCloudSiteId(CLOUDSITE_ID); - request.setFailIfExists(failIfExists); - request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID); - request.setMsoRequest(msoRequest); - request.setRequestType(REQUEST_TYPE); - request.setTenantId(TENANT_ID); - request.setVfModuleId(VF_MODULE_ID); - request.setVfModuleName(VF_MODULE_NAME); - request.setVfModuleStackId(vfModuleStackId); - request.setBackout(backout); - request.setVfModuleParams(vfModuleParams); - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - mockOpenStackGetStacksVfModuleWithLocationHeader_200(wireMockServer, wireMockPort); - - mockOpenStackGetStacksVfModule_200(wireMockServer, wireMockPort); - - mockOpenStackGetStacksBaseStack_200(wireMockServer, wireMockPort); - - mockOpenStackPutStacks_200(wireMockServer); - - UpdateVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( - new File("src/test/resources/__files/UpdateVfModuleResponse.json"), UpdateVfModuleResponse.class); - expectedResponse.setVfModuleOutputs(vfModuleOutputs); - - headers.add("Accept", MediaType.APPLICATION_JSON); - HttpEntity<UpdateVfModuleRequest> entity = new HttpEntity<UpdateVfModuleRequest>(request, headers); - - ResponseEntity<UpdateVfModuleResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_TYPE), HttpMethod.PUT, - entity, UpdateVfModuleResponse.class); - - ResponseEntity<UpdateVfModuleResponse> responseV2 = restTemplate.exchange( - createURLWithPort("/services/rest/v2/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_TYPE), HttpMethod.PUT, - entity, UpdateVfModuleResponse.class); - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - assertThat(response.getBody(), sameBeanAs(expectedResponse)); - - assertEquals(Response.Status.OK.getStatusCode(), responseV2.getStatusCode().value()); - assertThat(responseV2.getBody(), sameBeanAs(expectedResponse)); - - } - - @Test - public void testRollbackVfModule() throws IOException { - - - MsoRequest msoRequest = new MsoRequest(); - msoRequest.setRequestId(MSO_REQUEST_ID); - msoRequest.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); - - VfModuleRollback vfModuleRollback = new VfModuleRollback(AAI_VNF_ID, VF_MODULE_ID, - "StackId", false, TENANT_ID, CLOUD_OWNER, CLOUDSITE_ID, msoRequest, "messageId"); - - RollbackVfModuleRequest request = new RollbackVfModuleRequest(); - request.setVfModuleRollback(vfModuleRollback); - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - mockOpenStackGetStacksStackId_200(wireMockServer, wireMockPort); - - mockOpenStackDeleteStacks(wireMockServer); - - mockOpenStackGetStacksVUSP_404(wireMockServer); - - headers.add("Accept", MediaType.APPLICATION_JSON); - HttpEntity<RollbackVfModuleRequest> entity = new HttpEntity<RollbackVfModuleRequest>(request, headers); - - ResponseEntity<RollbackVfModuleResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_ID + "/rollback"), HttpMethod.DELETE, - entity, RollbackVfModuleResponse.class); - - RollbackVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( - new File("src/test/resources/__files/RollbackVfModuleResponse.json"),RollbackVfModuleResponse.class); - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - assertThat(response.getBody(), sameBeanAs(expectedResponse)); - - } - - @Ignore - @Test - public void testQueryVfModule() throws IOException{ - - String testUrl = createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_ID); - String testUri = UriBuilder.fromPath("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_ID ) - .host("localhost").port(wireMockPort).scheme("http") - //.queryParam("cloudSiteId", CLOUDSITE_ID).queryParam("tenantId", TENANT_ID) - .build().toString(); - System.out.println(testUri); - - mockOpenStackResponseAccess(wireMockServer, wireMockPort); - - - headers.add("Accept", MediaType.APPLICATION_JSON); - //HttpEntity entity = new HttpEntity(null, headers); - ResponseEntity<QueryVfModuleResponse> response = restTemplate.getForEntity(testUri, QueryVfModuleResponse.class); - //System.out.println(response); - - QueryVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( - new File("src/test/resources/__files/QueryVfModuleResponse.json"),QueryVfModuleResponse.class); - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - assertThat(response.getBody(), sameBeanAs(expectedResponse)); - } - - private CreateVfModuleRequest populateCreateVfModuleRequest(){ - CreateVfModuleRequest request = new CreateVfModuleRequest(); - request.setBackout(true); - request.setSkipAAI(true); - request.setFailIfExists(false); - MsoRequest msoReq = new MsoRequest(); - boolean failIfExists = true; - boolean enableBridge = false; - Map<String, Object> vfModuleParams = new HashMap<>(); - - vfModuleParams.put("vf_module_id", VF_MODULE_ID); - vfModuleParams.put("vnf_id", AAI_VNF_ID); - vfModuleParams.put("network_name", NETWORK_NAME); - vfModuleParams.put("vnf_name", VNF_NAME); - vfModuleParams.put("environment_context", ""); - vfModuleParams.put("server_name", SERVER_NAME); - vfModuleParams.put("image", IMAGE); - vfModuleParams.put("workload_context", ""); - vfModuleParams.put("vf_module_index", VF_MODULE_INDEX); - vfModuleParams.put("vf_module_name", VF_MODULE_NAME); - vfModuleParams.put("availability_zone_0", AVAILABILITY_ZONE_0); - vfModuleParams.put("exn_direct_net_fqdn", EXN_DIRECT_NET_FQDN); - vfModuleParams.put("exn_hsl_net_fqdn", EXN_HSL_NET_FQDN); - - msoReq.setRequestId(MSO_REQUEST_ID); - msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); - request.setMsoRequest(msoReq); - request.setRequestType(REQUEST_TYPE); - request.setCloudSiteId(CLOUDSITE_ID); - request.setTenantId(TENANT_ID); - request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID); - request.setVnfId(AAI_VNF_ID); - request.setVnfType(VNF_TYPE); - request.setVnfVersion(VNF_VERSION); - request.setVfModuleId(VF_MODULE_ID); - request.setVfModuleName(VF_MODULE_NAME); - request.setVfModuleType(VF_MODULE_TYPE); - request.setBaseVfModuleId(BASE_VF_MODULE_ID); - request.setFailIfExists(failIfExists); - request.setEnableBridge(enableBridge); - request.setVfModuleParams(vfModuleParams); - request.setMessageId(MESSAGE_ID); - - return request; - } + + + @Autowired + private JettisonStyleMapperProvider jettisonTypeObjectMapper; + private static final String MESSAGE_ID = "62265093-277d-4388-9ba6-449838ade586-1517252396874"; + private static final String AAI_VNF_ID = "c93e0d34-5b63-45de-bbae-b0fe49dd3bd9"; + private static final String MSO_REQUEST_ID = "62265093-277d-4388-9ba6-449838ade586"; + private static final String MSO_SERVICE_INSTANCE_ID = "4147e06f-1b89-49c5-b21f-4faf8dc9805a"; + private static final String CLOUDSITE_ID = "mtn13"; + private static final String CLOUD_OWNER = "CloudOwner"; + private static final String TENANT_ID = "0422ffb57ba042c0800a29dc85ca70f8"; + private static final String VNF_TYPE = "MSOTADevInfra_vSAMP10a_Service/vSAMP10a 1"; + private static final String VNF_NAME = "MSO-DEV-VNF-1802-it3-pwt3-vSAMP10a-1XXX-Replace"; + private static final String VNF_VERSION = "1.0"; + private static final String VF_MODULE_ID = "1d48aaec-b7f3-4c24-ba4a-4e798ed3223c"; + private static final String VF_MODULE_NAME = "DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001"; + private static final String VF_MODULE_TYPE = "vSAMP10aDEV::PCM::module-2"; + private static final String MODEL_CUSTOMIZATION_UUID = "cb82ffd8-252a-11e7-93ae-92361f002671"; + private static final String BASE_VF_MODULE_ID = "3d7ff7b4-720b-4604-be0a-1974fc58ed96"; + // vfModuleParams specific variables + private static final String NETWORK_NAME = "Dev-vSAMP10a-ntwk-1802-pwt3-v6-Replace-1001"; + private static final String SERVER_NAME = "Dev-vSAMP10a-addon2-1802-pwt3-v6-Replace-1001"; + private static final String IMAGE = "ubuntu_14.04_IPv6"; + private static final String EXN_DIRECT_NET_FQDN = "direct"; + private static final String EXN_HSL_NET_FQDN = "hsl"; + private static final String AVAILABILITY_ZONE_0 = "nova"; + private static final String VF_MODULE_INDEX = "0"; + private static final String REQUEST_TYPE = ""; + + @Test + public void testCreateVfModule() throws JSONException, JsonParseException, JsonMappingException, IOException { + + CreateVfModuleRequest request = populateCreateVfModuleRequest(); + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + mockOpenStackGetStackVfModule_404(wireMockServer); + + mockOpenStackPostStacks_200(wireMockServer); + + mockOpenStackGetStackVfModule_200(wireMockServer); + + headers.add("Accept", MediaType.APPLICATION_JSON); + HttpEntity<CreateVfModuleRequest> entity = new HttpEntity<CreateVfModuleRequest>(request, headers); + + ResponseEntity<CreateVfModuleResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), + HttpMethod.POST, entity, CreateVfModuleResponse.class); + + ResponseEntity<CreateVfModuleResponse> responseV2 = + restTemplate.exchange(createURLWithPort("/services/rest/v2/vnfs/" + AAI_VNF_ID + "/vf-modules"), + HttpMethod.POST, entity, CreateVfModuleResponse.class); + + CreateVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/CreateVfModuleResponse.json"), CreateVfModuleResponse.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + + assertEquals(Response.Status.OK.getStatusCode(), responseV2.getStatusCode().value()); + assertThat(responseV2.getBody(), sameBeanAs(expectedResponse)); + } + + @Test + public void testCreateVfModuleAsyncCall() throws Exception { + CreateVfModuleRequest request = populateCreateVfModuleRequest(); + request.setNotificationUrl(createURLWithPort("/mso/WorkflowMesssage")); + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + mockOpenStackGetStackVfModule_404(wireMockServer); + mockOpenStackPostStacks_200(wireMockServer); + mockOpenStackGetStackVfModule_200(wireMockServer); + + headers.add("Accept", MediaType.APPLICATION_JSON); + HttpEntity<CreateVfModuleRequest> entity = new HttpEntity<CreateVfModuleRequest>(request, headers); + + ResponseEntity<CreateVfModuleResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), + HttpMethod.POST, entity, CreateVfModuleResponse.class); + + CreateVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/CreateVfModuleResponse.json"), CreateVfModuleResponse.class); + + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); + } + + @Test + public void testCreateVfModuleWithEnableBridgeNull() + throws JSONException, JsonParseException, JsonMappingException, IOException { + + CreateVfModuleRequest request = new CreateVfModuleRequest(); + request.setBackout(true); + request.setSkipAAI(true); + request.setFailIfExists(false); + MsoRequest msoReq = new MsoRequest(); + boolean failIfExists = true; + Boolean enableBridge = null; + Map<String, Object> vfModuleParams = new HashMap<>(); + + + vfModuleParams.put("vf_module_id", VF_MODULE_ID); + vfModuleParams.put("vnf_id", AAI_VNF_ID); + vfModuleParams.put("network_name", NETWORK_NAME); + vfModuleParams.put("vnf_name", VNF_NAME); + vfModuleParams.put("environment_context", ""); + vfModuleParams.put("server_name", SERVER_NAME); + vfModuleParams.put("image", IMAGE); + vfModuleParams.put("workload_context", ""); + vfModuleParams.put("vf_module_index", VF_MODULE_INDEX); + vfModuleParams.put("vf_module_name", VF_MODULE_NAME); + vfModuleParams.put("availability_zone_0", AVAILABILITY_ZONE_0); + vfModuleParams.put("exn_direct_net_fqdn", EXN_DIRECT_NET_FQDN); + vfModuleParams.put("exn_hsl_net_fqdn", EXN_HSL_NET_FQDN); + + msoReq.setRequestId(MSO_REQUEST_ID); + msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); + request.setMsoRequest(msoReq); + request.setRequestType(REQUEST_TYPE); + request.setCloudSiteId(CLOUDSITE_ID); + request.setTenantId(TENANT_ID); + request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID); + request.setVnfId(AAI_VNF_ID); + request.setVnfVersion(VNF_VERSION); + request.setVfModuleId(VF_MODULE_ID); + request.setVfModuleName(VF_MODULE_NAME); + request.setBaseVfModuleId(BASE_VF_MODULE_ID); + request.setFailIfExists(failIfExists); + request.setEnableBridge(enableBridge); + request.setVfModuleParams(vfModuleParams); + request.setMessageId(MESSAGE_ID); + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + mockOpenStackGetStackVfModule_404(wireMockServer); + + mockOpenStackPostStacks_200(wireMockServer); + + mockOpenStackGetStackVfModule_200(wireMockServer); + + + headers.add("Accept", MediaType.APPLICATION_JSON); + HttpEntity<CreateVfModuleRequest> entity = new HttpEntity<CreateVfModuleRequest>(request, headers); + + ResponseEntity<CreateVfModuleResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), + HttpMethod.POST, entity, CreateVfModuleResponse.class); + + CreateVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/CreateVfModuleResponse.json"), CreateVfModuleResponse.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + } + + @Test + public void testCreateVfModuleFail() throws IOException { + + CreateVfModuleRequest request = new CreateVfModuleRequest(); + request.setBackout(true); + request.setSkipAAI(true); + request.setFailIfExists(false); + MsoRequest msoReq = new MsoRequest(); + boolean failIfExists = true; + boolean enableBridge = false; + Map<String, Object> vfModuleParams = new HashMap<>(); + + vfModuleParams.put("vf_module_id", VF_MODULE_ID); + vfModuleParams.put("vnf_id", AAI_VNF_ID); + vfModuleParams.put("network_name", NETWORK_NAME); + vfModuleParams.put("vnf_name", VNF_NAME); + vfModuleParams.put("environment_context", ""); + vfModuleParams.put("server_name", SERVER_NAME); + vfModuleParams.put("image", IMAGE); + vfModuleParams.put("workload_context", ""); + vfModuleParams.put("vf_module_index", VF_MODULE_INDEX); + vfModuleParams.put("vf_module_name", VF_MODULE_NAME); + vfModuleParams.put("availability_zone_0", AVAILABILITY_ZONE_0); + vfModuleParams.put("exn_direct_net_fqdn", EXN_DIRECT_NET_FQDN); + vfModuleParams.put("exn_hsl_net_fqdn", EXN_HSL_NET_FQDN); + + msoReq.setRequestId(MSO_REQUEST_ID); + msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); + request.setMsoRequest(msoReq); + request.setRequestType(REQUEST_TYPE); + request.setCloudSiteId(CLOUDSITE_ID); + request.setTenantId(TENANT_ID); + request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID); + request.setVnfId(AAI_VNF_ID); + request.setVnfType(VNF_TYPE); + request.setVnfVersion(VNF_VERSION); + request.setVfModuleId(VF_MODULE_ID); + request.setVfModuleName(VF_MODULE_NAME); + request.setVfModuleType(VF_MODULE_TYPE); + request.setBaseVfModuleStackId(BASE_VF_MODULE_ID); + request.setFailIfExists(failIfExists); + request.setEnableBridge(enableBridge); + request.setVfModuleParams(vfModuleParams); + request.setMessageId(MESSAGE_ID); + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + mockOpenStackGetStackVfModule_404(wireMockServer); + + mockOpenStackGetStacks_404(wireMockServer); + + mockOpenStackPostStacks_200(wireMockServer); + + mockOpenStackGetStackVfModule_200(wireMockServer); + + headers.add("Accept", MediaType.APPLICATION_JSON); + HttpEntity<CreateVfModuleRequest> entity = new HttpEntity<CreateVfModuleRequest>(request, headers); + + ResponseEntity<VfModuleExceptionResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), + HttpMethod.POST, entity, VfModuleExceptionResponse.class); + + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); + + mockOpenStackGetStacksWithBody_200(wireMockServer, "DELETE_IN_PROGRESS"); + + response = restTemplate.exchange(createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), + HttpMethod.POST, entity, VfModuleExceptionResponse.class); + + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); + + mockOpenStackGetStacksWithBody_200(wireMockServer, "DELETE_FAILED"); + + response = restTemplate.exchange(createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), + HttpMethod.POST, entity, VfModuleExceptionResponse.class); + + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); + + mockOpenStackGetStacksWithBody_200(wireMockServer, "UPDATE_COMPLETE"); + + response = restTemplate.exchange(createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), + HttpMethod.POST, entity, VfModuleExceptionResponse.class); + + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); + + mockOpenStackGetStacksWithBody_404(wireMockServer); + + response = restTemplate.exchange(createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules"), + HttpMethod.POST, entity, VfModuleExceptionResponse.class); + + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); + + } + + @Test + public void testDeleteVfModule() throws IOException { + + DeleteVfModuleRequest request = new DeleteVfModuleRequest(); + MsoRequest msoRequest = new MsoRequest(); + String vfModuleStackId = "stackId"; + + msoRequest.setRequestId(MSO_REQUEST_ID); + msoRequest.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); + request.setCloudSiteId(CLOUDSITE_ID); + request.setTenantId(TENANT_ID); + request.setVfModuleId(VF_MODULE_ID); + request.setVfModuleStackId(vfModuleStackId); + request.setVnfId(AAI_VNF_ID); + request.setMsoRequest(msoRequest); + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + mockOpenStackPostStacks_200(wireMockServer); + + mockOpenStackGetStacksStackId_404(wireMockServer); + + mockOpenStackGetPublicUrlStackByNameAndID_200(wireMockServer, wireMockPort); + + mockOpenStackDeletePublicUrlStackByNameAndID_204(wireMockServer); + + + headers.add("Accept", MediaType.APPLICATION_JSON); + HttpEntity<DeleteVfModuleRequest> entity = new HttpEntity<DeleteVfModuleRequest>(request, headers); + + ResponseEntity<DeleteVfModuleResponse> response = restTemplate.exchange( + createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_ID), + HttpMethod.DELETE, entity, DeleteVfModuleResponse.class); + + ResponseEntity<DeleteVfModuleResponse> responseV2 = restTemplate.exchange( + createURLWithPort("/services/rest/v2/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_ID), + HttpMethod.DELETE, entity, DeleteVfModuleResponse.class); + + + DeleteVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/DeleteVfModuleResponse.json"), DeleteVfModuleResponse.class); + + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + + assertEquals(Response.Status.OK.getStatusCode(), responseV2.getStatusCode().value()); + assertThat(responseV2.getBody(), sameBeanAs(expectedResponse)); + } + + @Test + public void testUpdateVfModule() throws IOException { + + UpdateVfModuleRequest request = new UpdateVfModuleRequest(); + MsoRequest msoRequest = new MsoRequest(); + String vfModuleStackId = "vfModuleStackId"; + Boolean failIfExists = false; + Boolean backout = false; + msoRequest.setRequestId(MSO_REQUEST_ID); + msoRequest.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); + + Map<String, Object> vfModuleParams = new HashMap<>(); + + vfModuleParams.put("exn_direct_net_fqdn", EXN_DIRECT_NET_FQDN); + vfModuleParams.put("exn_hsl_net_fqdn", EXN_HSL_NET_FQDN); + + Map<String, String> vfModuleOutputs = new HashMap<String, String>(); + + vfModuleOutputs.put("output name", "output value"); + + request.setBackout(backout); + request.setCloudSiteId(CLOUDSITE_ID); + request.setFailIfExists(failIfExists); + request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID); + request.setMsoRequest(msoRequest); + request.setRequestType(REQUEST_TYPE); + request.setTenantId(TENANT_ID); + request.setVfModuleId(VF_MODULE_ID); + request.setVfModuleName(VF_MODULE_NAME); + request.setVfModuleStackId(vfModuleStackId); + request.setBackout(backout); + request.setVfModuleParams(vfModuleParams); + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + mockOpenStackGetStacksVfModuleWithLocationHeader_200(wireMockServer, wireMockPort); + + mockOpenStackGetStacksVfModule_200(wireMockServer, wireMockPort); + + mockOpenStackGetStacksBaseStack_200(wireMockServer, wireMockPort); + + mockOpenStackPutStacks_200(wireMockServer); + + UpdateVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/UpdateVfModuleResponse.json"), UpdateVfModuleResponse.class); + expectedResponse.setVfModuleOutputs(vfModuleOutputs); + + headers.add("Accept", MediaType.APPLICATION_JSON); + HttpEntity<UpdateVfModuleRequest> entity = new HttpEntity<UpdateVfModuleRequest>(request, headers); + + ResponseEntity<UpdateVfModuleResponse> response = restTemplate.exchange( + createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_TYPE), + HttpMethod.PUT, entity, UpdateVfModuleResponse.class); + + ResponseEntity<UpdateVfModuleResponse> responseV2 = restTemplate.exchange( + createURLWithPort("/services/rest/v2/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_TYPE), + HttpMethod.PUT, entity, UpdateVfModuleResponse.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + + assertEquals(Response.Status.OK.getStatusCode(), responseV2.getStatusCode().value()); + assertThat(responseV2.getBody(), sameBeanAs(expectedResponse)); + + } + + @Test + public void testRollbackVfModule() throws IOException { + + + MsoRequest msoRequest = new MsoRequest(); + msoRequest.setRequestId(MSO_REQUEST_ID); + msoRequest.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); + + VfModuleRollback vfModuleRollback = new VfModuleRollback(AAI_VNF_ID, VF_MODULE_ID, "StackId", false, TENANT_ID, + CLOUD_OWNER, CLOUDSITE_ID, msoRequest, "messageId"); + + RollbackVfModuleRequest request = new RollbackVfModuleRequest(); + request.setVfModuleRollback(vfModuleRollback); + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + mockOpenStackGetStacksStackId_200(wireMockServer, wireMockPort); + + mockOpenStackDeleteStacks(wireMockServer); + + mockOpenStackGetStacksVUSP_404(wireMockServer); + + headers.add("Accept", MediaType.APPLICATION_JSON); + HttpEntity<RollbackVfModuleRequest> entity = new HttpEntity<RollbackVfModuleRequest>(request, headers); + + ResponseEntity<RollbackVfModuleResponse> response = restTemplate.exchange( + createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_ID + "/rollback"), + HttpMethod.DELETE, entity, RollbackVfModuleResponse.class); + + RollbackVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/RollbackVfModuleResponse.json"), RollbackVfModuleResponse.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + + } + + @Ignore + @Test + public void testQueryVfModule() throws IOException { + + String testUrl = createURLWithPort("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_ID); + String testUri = UriBuilder.fromPath("/services/rest/v1/vnfs/" + AAI_VNF_ID + "/vf-modules/" + VF_MODULE_ID) + .host("localhost").port(wireMockPort).scheme("http") + // .queryParam("cloudSiteId", CLOUDSITE_ID).queryParam("tenantId", TENANT_ID) + .build().toString(); + System.out.println(testUri); + + mockOpenStackResponseAccess(wireMockServer, wireMockPort); + + + headers.add("Accept", MediaType.APPLICATION_JSON); + // HttpEntity entity = new HttpEntity(null, headers); + ResponseEntity<QueryVfModuleResponse> response = + restTemplate.getForEntity(testUri, QueryVfModuleResponse.class); + // System.out.println(response); + + QueryVfModuleResponse expectedResponse = jettisonTypeObjectMapper.getMapper().readValue( + new File("src/test/resources/__files/QueryVfModuleResponse.json"), QueryVfModuleResponse.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), sameBeanAs(expectedResponse)); + } + + private CreateVfModuleRequest populateCreateVfModuleRequest() { + CreateVfModuleRequest request = new CreateVfModuleRequest(); + request.setBackout(true); + request.setSkipAAI(true); + request.setFailIfExists(false); + MsoRequest msoReq = new MsoRequest(); + boolean failIfExists = true; + boolean enableBridge = false; + Map<String, Object> vfModuleParams = new HashMap<>(); + + vfModuleParams.put("vf_module_id", VF_MODULE_ID); + vfModuleParams.put("vnf_id", AAI_VNF_ID); + vfModuleParams.put("network_name", NETWORK_NAME); + vfModuleParams.put("vnf_name", VNF_NAME); + vfModuleParams.put("environment_context", ""); + vfModuleParams.put("server_name", SERVER_NAME); + vfModuleParams.put("image", IMAGE); + vfModuleParams.put("workload_context", ""); + vfModuleParams.put("vf_module_index", VF_MODULE_INDEX); + vfModuleParams.put("vf_module_name", VF_MODULE_NAME); + vfModuleParams.put("availability_zone_0", AVAILABILITY_ZONE_0); + vfModuleParams.put("exn_direct_net_fqdn", EXN_DIRECT_NET_FQDN); + vfModuleParams.put("exn_hsl_net_fqdn", EXN_HSL_NET_FQDN); + + msoReq.setRequestId(MSO_REQUEST_ID); + msoReq.setServiceInstanceId(MSO_SERVICE_INSTANCE_ID); + request.setMsoRequest(msoReq); + request.setRequestType(REQUEST_TYPE); + request.setCloudSiteId(CLOUDSITE_ID); + request.setTenantId(TENANT_ID); + request.setModelCustomizationUuid(MODEL_CUSTOMIZATION_UUID); + request.setVnfId(AAI_VNF_ID); + request.setVnfType(VNF_TYPE); + request.setVnfVersion(VNF_VERSION); + request.setVfModuleId(VF_MODULE_ID); + request.setVfModuleName(VF_MODULE_NAME); + request.setVfModuleType(VF_MODULE_TYPE); + request.setBaseVfModuleId(BASE_VF_MODULE_ID); + request.setFailIfExists(failIfExists); + request.setEnableBridge(enableBridge); + request.setVfModuleParams(vfModuleParams); + request.setMessageId(MESSAGE_ID); + + return request; + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestTest.java index 20372b81d9..523a6903cc 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestTest.java @@ -56,9 +56,9 @@ public class VolumeAdapterRestTest extends VolumeGroupAdapterCommon { CreateVolumeGroupRequest request = buildCreateVfModuleRequest(); HttpEntity<CreateVolumeGroupRequest> entity = new HttpEntity<>(request, headers); - ResponseEntity<CreateVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/volume-groups"), HttpMethod.POST, - entity, CreateVolumeGroupResponse.class); + ResponseEntity<CreateVolumeGroupResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v1/volume-groups"), HttpMethod.POST, entity, + CreateVolumeGroupResponse.class); assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); } @@ -72,43 +72,43 @@ public class VolumeAdapterRestTest extends VolumeGroupAdapterCommon { request.setNotificationUrl("http://localhost:8080"); HttpEntity<CreateVolumeGroupRequest> entity = new HttpEntity<>(request, headers); - ResponseEntity<CreateVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/volume-groups"), HttpMethod.POST, - entity, CreateVolumeGroupResponse.class); + ResponseEntity<CreateVolumeGroupResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v1/volume-groups"), HttpMethod.POST, entity, + CreateVolumeGroupResponse.class); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); } @Test - public void testDeleteVNFVolumes() throws IOException { + public void testDeleteVNFVolumes() throws IOException { mockOpenStackResponseAccess(wireMockServer, wireMockPort); DeleteVolumeGroupRequest request = buildDeleteVolumeGroupRequest(); HttpEntity<DeleteVolumeGroupRequest> entity = new HttpEntity<>(request, headers); - ResponseEntity<DeleteVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/volume-groups/"+VOLUME_GROUP_ID), HttpMethod.DELETE, - entity, DeleteVolumeGroupResponse.class); + ResponseEntity<DeleteVolumeGroupResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v1/volume-groups/" + VOLUME_GROUP_ID), + HttpMethod.DELETE, entity, DeleteVolumeGroupResponse.class); assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); } @Test - public void testDeleteVNFVolumesAsync() throws IOException { + public void testDeleteVNFVolumesAsync() throws IOException { mockOpenStackResponseAccess(wireMockServer, wireMockPort); DeleteVolumeGroupRequest request = buildDeleteVolumeGroupRequest(); request.setNotificationUrl("http://localhost:8080"); HttpEntity<DeleteVolumeGroupRequest> entity = new HttpEntity<>(request, headers); - ResponseEntity<DeleteVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/volume-groups/"+VOLUME_GROUP_ID), HttpMethod.DELETE, - entity, DeleteVolumeGroupResponse.class); + ResponseEntity<DeleteVolumeGroupResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v1/volume-groups/" + VOLUME_GROUP_ID), + HttpMethod.DELETE, entity, DeleteVolumeGroupResponse.class); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); } @Test - public void testRollbackVNFVolumes() throws IOException { + public void testRollbackVNFVolumes() throws IOException { mockOpenStackResponseAccess(wireMockServer, wireMockPort); RollbackVolumeGroupRequest request = buildRollbackVolumeGroupRequest(); HttpEntity<RollbackVolumeGroupRequest> entity = new HttpEntity<>(request, headers); ResponseEntity<RollbackVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/volume-groups/"+VOLUME_GROUP_ID+"/rollback"), HttpMethod.DELETE, - entity, RollbackVolumeGroupResponse.class); + createURLWithPort("/services/rest/v1/volume-groups/" + VOLUME_GROUP_ID + "/rollback"), + HttpMethod.DELETE, entity, RollbackVolumeGroupResponse.class); assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); } @@ -119,13 +119,13 @@ public class VolumeAdapterRestTest extends VolumeGroupAdapterCommon { request.setNotificationUrl("http://localhost:8080"); HttpEntity<RollbackVolumeGroupRequest> entity = new HttpEntity<>(request, headers); ResponseEntity<RollbackVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/volume-groups/"+VOLUME_GROUP_ID+"/rollback"), HttpMethod.DELETE, - entity, RollbackVolumeGroupResponse.class); + createURLWithPort("/services/rest/v1/volume-groups/" + VOLUME_GROUP_ID + "/rollback"), + HttpMethod.DELETE, entity, RollbackVolumeGroupResponse.class); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); } @Test - public void testQueryVNFVolumes() throws IOException{ + public void testQueryVNFVolumes() throws IOException { mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackGetStacksWithBody_200(wireMockServer, "UPDATE_COMPLETE"); javax.ws.rs.core.UriBuilder builder = UriBuilder.fromPath("/services/rest/v1/volume-groups/" + VOLUME_GROUP_ID); @@ -135,24 +135,22 @@ public class VolumeAdapterRestTest extends VolumeGroupAdapterCommon { .queryParam("msoRequest.serviceInstanceId", MSO_SERVICE_INSTANCE_ID); ResponseEntity<QueryVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort(builder.build().toString()), HttpMethod.GET, - null,QueryVolumeGroupResponse.class); + createURLWithPort(builder.build().toString()), HttpMethod.GET, null, QueryVolumeGroupResponse.class); assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); } @Test - public void testQueryVNFVolumesError() throws IOException{ + public void testQueryVNFVolumesError() throws IOException { mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackGetStacksWithBody_200(wireMockServer, "UPDATE_COMPLETE"); javax.ws.rs.core.UriBuilder builder = UriBuilder.fromPath("/services/rest/v1/volume-groups/" + VOLUME_GROUP_ID); - builder.queryParam("tenantId", TENANT_ID) - .queryParam("volumeGroupStackId", VOUME_GROUP_NAME).queryParam("skipAAI", true) - .queryParam("msoRequest.requestId", MSO_REQUEST_ID) + builder.queryParam("tenantId", TENANT_ID).queryParam("volumeGroupStackId", VOUME_GROUP_NAME) + .queryParam("skipAAI", true).queryParam("msoRequest.requestId", MSO_REQUEST_ID) .queryParam("msoRequest.serviceInstanceId", MSO_SERVICE_INSTANCE_ID); - ResponseEntity<VolumeGroupExceptionResponse> response = restTemplate.exchange( - createURLWithPort(builder.build().toString()), HttpMethod.GET, - null,VolumeGroupExceptionResponse.class); + ResponseEntity<VolumeGroupExceptionResponse> response = + restTemplate.exchange(createURLWithPort(builder.build().toString()), HttpMethod.GET, null, + VolumeGroupExceptionResponse.class); assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); } @@ -160,13 +158,13 @@ public class VolumeAdapterRestTest extends VolumeGroupAdapterCommon { public void testUpdateVNFVolumes() throws IOException { mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackGetStacksWithBody_200(wireMockServer, "CREATE_COMPLETE"); - mockOpenStackPutStack(wireMockServer, VOUME_GROUP_NAME+"/stackId",200); + mockOpenStackPutStack(wireMockServer, VOUME_GROUP_NAME + "/stackId", 200); mockOpenStackGetStackWithBody_200(wireMockServer, "UPDATE_COMPLETE"); UpdateVolumeGroupRequest request = buildUpdateVolumeGroupRequest(); HttpEntity<UpdateVolumeGroupRequest> entity = new HttpEntity<>(request, headers); - ResponseEntity<UpdateVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/volume-groups/"+VOLUME_GROUP_ID), HttpMethod.PUT, - entity,UpdateVolumeGroupResponse.class); + ResponseEntity<UpdateVolumeGroupResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v1/volume-groups/" + VOLUME_GROUP_ID), + HttpMethod.PUT, entity, UpdateVolumeGroupResponse.class); assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); } @@ -174,14 +172,14 @@ public class VolumeAdapterRestTest extends VolumeGroupAdapterCommon { public void testUpdateVNFVolumesAsync() throws IOException { mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackGetStacksWithBody_200(wireMockServer, "CREATE_COMPLETE"); - mockOpenStackPutStack(wireMockServer, VOUME_GROUP_NAME+"/stackId",200); + mockOpenStackPutStack(wireMockServer, VOUME_GROUP_NAME + "/stackId", 200); mockOpenStackGetStackWithBody_200(wireMockServer, "UPDATE_COMPLETE"); UpdateVolumeGroupRequest request = buildUpdateVolumeGroupRequest(); request.setNotificationUrl("http://localhost:8080"); HttpEntity<UpdateVolumeGroupRequest> entity = new HttpEntity<>(request, headers); - ResponseEntity<UpdateVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v1/volume-groups/"+VOLUME_GROUP_ID), HttpMethod.PUT, - entity,UpdateVolumeGroupResponse.class); + ResponseEntity<UpdateVolumeGroupResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v1/volume-groups/" + VOLUME_GROUP_ID), + HttpMethod.PUT, entity, UpdateVolumeGroupResponse.class); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestV2Test.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestV2Test.java index abdc2609a1..fb4bec69ed 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestV2Test.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeAdapterRestV2Test.java @@ -55,9 +55,9 @@ public class VolumeAdapterRestV2Test extends VolumeGroupAdapterCommon { CreateVolumeGroupRequest request = buildCreateVfModuleRequest(); HttpEntity<CreateVolumeGroupRequest> entity = new HttpEntity<>(request, headers); - ResponseEntity<CreateVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v2/volume-groups"), HttpMethod.POST, - entity, CreateVolumeGroupResponse.class); + ResponseEntity<CreateVolumeGroupResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v2/volume-groups"), HttpMethod.POST, entity, + CreateVolumeGroupResponse.class); assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); } @@ -70,60 +70,60 @@ public class VolumeAdapterRestV2Test extends VolumeGroupAdapterCommon { CreateVolumeGroupRequest request = buildCreateVfModuleRequest(); request.setNotificationUrl("http://localhost:8080"); HttpEntity<CreateVolumeGroupRequest> entity = new HttpEntity<>(request, headers); - ResponseEntity<CreateVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v2/volume-groups"), HttpMethod.POST, - entity, CreateVolumeGroupResponse.class); + ResponseEntity<CreateVolumeGroupResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v2/volume-groups"), HttpMethod.POST, entity, + CreateVolumeGroupResponse.class); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); } @Test - public void testDeleteVNFVolumes() throws IOException { + public void testDeleteVNFVolumes() throws IOException { mockOpenStackResponseAccess(wireMockServer, wireMockPort); DeleteVolumeGroupRequest request = buildDeleteVolumeGroupRequest(); HttpEntity<DeleteVolumeGroupRequest> entity = new HttpEntity<>(request, headers); - ResponseEntity<DeleteVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v2/volume-groups/"+VOLUME_GROUP_ID), HttpMethod.DELETE, - entity, DeleteVolumeGroupResponse.class); + ResponseEntity<DeleteVolumeGroupResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v2/volume-groups/" + VOLUME_GROUP_ID), + HttpMethod.DELETE, entity, DeleteVolumeGroupResponse.class); assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); } @Test - public void testDeleteVNFVolumesAsync() throws IOException { + public void testDeleteVNFVolumesAsync() throws IOException { mockOpenStackResponseAccess(wireMockServer, wireMockPort); DeleteVolumeGroupRequest request = buildDeleteVolumeGroupRequest(); request.setNotificationUrl("http://localhost:8080"); HttpEntity<DeleteVolumeGroupRequest> entity = new HttpEntity<>(request, headers); - ResponseEntity<DeleteVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v2/volume-groups/"+VOLUME_GROUP_ID), HttpMethod.DELETE, - entity, DeleteVolumeGroupResponse.class); + ResponseEntity<DeleteVolumeGroupResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v2/volume-groups/" + VOLUME_GROUP_ID), + HttpMethod.DELETE, entity, DeleteVolumeGroupResponse.class); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); } @Test - public void testRollbackVNFVolumes() throws IOException { + public void testRollbackVNFVolumes() throws IOException { mockOpenStackResponseAccess(wireMockServer, wireMockPort); RollbackVolumeGroupRequest request = buildRollbackVolumeGroupRequest(); HttpEntity<RollbackVolumeGroupRequest> entity = new HttpEntity<>(request, headers); ResponseEntity<RollbackVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v2/volume-groups/"+VOLUME_GROUP_ID+"/rollback"), HttpMethod.DELETE, - entity, RollbackVolumeGroupResponse.class); + createURLWithPort("/services/rest/v2/volume-groups/" + VOLUME_GROUP_ID + "/rollback"), + HttpMethod.DELETE, entity, RollbackVolumeGroupResponse.class); assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); } @Test - public void testRollbackVNFVolumesAsync() throws IOException { + public void testRollbackVNFVolumesAsync() throws IOException { mockOpenStackResponseAccess(wireMockServer, wireMockPort); RollbackVolumeGroupRequest request = buildRollbackVolumeGroupRequest(); request.setNotificationUrl("http://localhost:8080"); HttpEntity<RollbackVolumeGroupRequest> entity = new HttpEntity<>(request, headers); ResponseEntity<RollbackVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v2/volume-groups/"+VOLUME_GROUP_ID+"/rollback"), HttpMethod.DELETE, - entity, RollbackVolumeGroupResponse.class); + createURLWithPort("/services/rest/v2/volume-groups/" + VOLUME_GROUP_ID + "/rollback"), + HttpMethod.DELETE, entity, RollbackVolumeGroupResponse.class); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); } @Test - public void testQueryVNFVolumes() throws IOException{ + public void testQueryVNFVolumes() throws IOException { mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackGetStacksWithBody_200(wireMockServer, "UPDATE_COMPLETE"); javax.ws.rs.core.UriBuilder builder = UriBuilder.fromPath("/services/rest/v2/volume-groups/" + VOLUME_GROUP_ID); @@ -133,37 +133,36 @@ public class VolumeAdapterRestV2Test extends VolumeGroupAdapterCommon { .queryParam("msoRequest.serviceInstanceId", MSO_SERVICE_INSTANCE_ID); ResponseEntity<QueryVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort(builder.build().toString()), HttpMethod.GET, - null,QueryVolumeGroupResponse.class); + createURLWithPort(builder.build().toString()), HttpMethod.GET, null, QueryVolumeGroupResponse.class); assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); } @Test - public void testQueryVNFVolumesError() throws IOException{ + public void testQueryVNFVolumesError() throws IOException { mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackGetStacksWithBody_200(wireMockServer, "UPDATE_COMPLETE"); javax.ws.rs.core.UriBuilder builder = UriBuilder.fromPath("/services/rest/v2/volume-groups/" + VOLUME_GROUP_ID); - builder.queryParam("tenantId", TENANT_ID) - .queryParam("volumeGroupStackId", VOUME_GROUP_NAME).queryParam("skipAAI", true) - .queryParam("msoRequest.requestId", MSO_REQUEST_ID) + builder.queryParam("tenantId", TENANT_ID).queryParam("volumeGroupStackId", VOUME_GROUP_NAME) + .queryParam("skipAAI", true).queryParam("msoRequest.requestId", MSO_REQUEST_ID) .queryParam("msoRequest.serviceInstanceId", MSO_SERVICE_INSTANCE_ID); - ResponseEntity<VolumeGroupExceptionResponse> response = restTemplate.exchange( - createURLWithPort(builder.build().toString()), HttpMethod.GET, - null,VolumeGroupExceptionResponse.class); + ResponseEntity<VolumeGroupExceptionResponse> response = + restTemplate.exchange(createURLWithPort(builder.build().toString()), HttpMethod.GET, null, + VolumeGroupExceptionResponse.class); assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); } + @Test public void testUpdateVNFVolumes() throws IOException { mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackGetStacksWithBody_200(wireMockServer, "CREATE_COMPLETE"); - mockOpenStackPutStack(wireMockServer, VOUME_GROUP_NAME+"/stackId",200); + mockOpenStackPutStack(wireMockServer, VOUME_GROUP_NAME + "/stackId", 200); mockOpenStackGetStackWithBody_200(wireMockServer, "UPDATE_COMPLETE"); UpdateVolumeGroupRequest request = buildUpdateVolumeGroupRequest(); HttpEntity<UpdateVolumeGroupRequest> entity = new HttpEntity<>(request, headers); - ResponseEntity<UpdateVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v2/volume-groups/"+VOLUME_GROUP_ID), HttpMethod.PUT, - entity,UpdateVolumeGroupResponse.class); + ResponseEntity<UpdateVolumeGroupResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v2/volume-groups/" + VOLUME_GROUP_ID), + HttpMethod.PUT, entity, UpdateVolumeGroupResponse.class); assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); } @@ -171,14 +170,14 @@ public class VolumeAdapterRestV2Test extends VolumeGroupAdapterCommon { public void testUpdateVNFVolumesAsync() throws IOException { mockOpenStackResponseAccess(wireMockServer, wireMockPort); mockOpenStackGetStacksWithBody_200(wireMockServer, "CREATE_COMPLETE"); - mockOpenStackPutStack(wireMockServer, VOUME_GROUP_NAME+"/stackId",200); + mockOpenStackPutStack(wireMockServer, VOUME_GROUP_NAME + "/stackId", 200); mockOpenStackGetStackWithBody_200(wireMockServer, "UPDATE_COMPLETE"); UpdateVolumeGroupRequest request = buildUpdateVolumeGroupRequest(); request.setNotificationUrl("http://localhost:8080"); HttpEntity<UpdateVolumeGroupRequest> entity = new HttpEntity<>(request, headers); - ResponseEntity<UpdateVolumeGroupResponse> response = restTemplate.exchange( - createURLWithPort("/services/rest/v2/volume-groups/"+VOLUME_GROUP_ID), HttpMethod.PUT, - entity,UpdateVolumeGroupResponse.class); + ResponseEntity<UpdateVolumeGroupResponse> response = + restTemplate.exchange(createURLWithPort("/services/rest/v2/volume-groups/" + VOLUME_GROUP_ID), + HttpMethod.PUT, entity, UpdateVolumeGroupResponse.class); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeGroupAdapterCommon.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeGroupAdapterCommon.java index d0d06aed6c..14fa1df6c9 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeGroupAdapterCommon.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/VolumeGroupAdapterCommon.java @@ -26,7 +26,6 @@ import org.onap.so.adapters.vnfrest.RollbackVolumeGroupRequest; import org.onap.so.adapters.vnfrest.UpdateVolumeGroupRequest; import org.onap.so.adapters.vnfrest.VolumeGroupRollback; import org.onap.so.entity.MsoRequest; - import java.util.HashMap; import java.util.Map; @@ -113,11 +112,11 @@ public class VolumeGroupAdapterCommon extends BaseRestTestUtils { } private Map<String, Object> getVolumeGroupParamsMap() { - Map<String, Object> volumeGroupParams = new HashMap<>(); - volumeGroupParams.put("fsb_volume_type_0","volume_type"); - volumeGroupParams.put("fsb_volume_image_name_1","vol_img_1"); - volumeGroupParams.put("fsb_volume_image_name_0","vol_img_0"); - volumeGroupParams.put("fsb_volume_size_0","100"); + Map<String, Object> volumeGroupParams = new HashMap<>(); + volumeGroupParams.put("fsb_volume_type_0", "volume_type"); + volumeGroupParams.put("fsb_volume_image_name_1", "vol_img_1"); + volumeGroupParams.put("fsb_volume_image_name_0", "vol_img_0"); + volumeGroupParams.put("fsb_volume_size_0", "100"); return volumeGroupParams; } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/bpmn/mock/StubOpenStack.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/bpmn/mock/StubOpenStack.java index de12f2cfbe..bb00700b60 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/bpmn/mock/StubOpenStack.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/bpmn/mock/StubOpenStack.java @@ -29,464 +29,484 @@ import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.put; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; - import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; - import org.apache.http.HttpStatus; - import com.github.tomakehurst.wiremock.WireMockServer; public class StubOpenStack { - private static final String NETWORK_NAME = "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0"; - private static final String NETWORK_ID = "da886914-efb2-4917-b335-c8381528d90b"; - private static final String NETWORK_NAME_2 = "stackname"; - private static final String NETWORK_ID_2 = "stackId"; - - public static void mockOpenStackResponseAccess(WireMockServer wireMockServer, int port) throws IOException { - wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(getBodyFromFile("OpenstackResponse_Access.json", port, "/mockPublicUrl")) - .withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackResponseAccessMulticloud(WireMockServer wireMockServer, int port) throws IOException { - wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(getBodyFromFile("OpenstackResponse_AccessMulticloud.json", port, "/mockPublicUrl")) - .withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackResponseAccessQueryNetwork(WireMockServer wireMockServer, int port) throws IOException { - wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")) - .withRequestBody(containing("tenantId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(getBodyFromFile("OpenstackResponse_Access_queryNetwork.json", port, "/mockPublicUrl")) - .withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackResponseAccessAdmin(WireMockServer wireMockServer, int port) throws IOException { - wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(getBodyFromFile("OpenstackResponse_Access_Admin.json", port, "/mockPublicUrl")) - .withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackPublicUrlStackByName_200(WireMockServer wireMockServer, int port) throws IOException { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME)).willReturn(aResponse() - .withHeader("X-Openstack-Request-Id", "openstackRquest") - .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/"+NETWORK_NAME) - .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, "/mockPublicUrl/stacks/" + NETWORK_NAME)) - .withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackPublicUrlStackByID_200(WireMockServer wireMockServer, int port) throws IOException { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_ID)).willReturn(aResponse() - .withHeader("X-Openstack-Request-Id", "openstackRquest") - .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/"+NETWORK_NAME) - .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, "/mockPublicUrl/stacks/" + NETWORK_NAME)) - .withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetPublicUrlStackByNameAndID_200(WireMockServer wireMockServer, int port) throws IOException { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME+"/"+NETWORK_ID)).willReturn(aResponse() - .withHeader("X-Openstack-Request-Id", "openstackRquest") - .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/"+NETWORK_NAME) - .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, "/mockPublicUrl/stacks/" + NETWORK_NAME)) - .withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetPublicUrlStackByNameAndID_204(WireMockServer wireMockServer, int port) throws IOException { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME+"/"+NETWORK_ID)).willReturn(aResponse() - .withHeader("X-Openstack-Request-Id", "openstackRquest") - .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/"+NETWORK_NAME+"/"+NETWORK_ID) - .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, "/mockPublicUrl/stacks/" + NETWORK_NAME)) - .withStatus(HttpStatus.SC_NOT_FOUND))); - } - - public static void mockOpenStackPutPublicUrlStackByNameAndID_200(WireMockServer wireMockServer) { - wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME+"/"+NETWORK_ID)).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackPutPublicUrlStackByNameAndID_NETWORK2_200(WireMockServer wireMockServer) { - wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME_2+"/"+NETWORK_ID_2)).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackDeletePublicUrlStackByNameAndID_204(WireMockServer wireMockServer) { - wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/"+NETWORK_NAME+"/"+NETWORK_ID)).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NO_CONTENT))); - } - - public static void mockOpenStackPostPublicUrlWithBodyFile_200(WireMockServer wireMockServer) { - wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Stack.json").withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetStackCreatedAppC_200(WireMockServer wireMockServer) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/APP-C-24595-T-IST-04AShared_untrusted_vDBE_net_3/stackId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Stack_Created.json").withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetStackAppC_404(WireMockServer wireMockServer) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/APP-C-24595-T-IST-04AShared_untrusted_vDBE_net_3")) - .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND))); - } - - public static void mockOpenStackGetStackCreatedVUSP_200(WireMockServer wireMockServer) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0/stackId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Stack_Created.json").withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetStackVUSP_404(WireMockServer wireMockServer) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0")) - .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND))); - } - - public static void mockOpenStackPostStack_200(WireMockServer wireMockServer, String filename) { - wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks")).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile(filename).withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackPostNeutronNetwork_200(WireMockServer wireMockServer, String filename) { - wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile(filename).withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackPutNeutronNetwork_200(WireMockServer wireMockServer, String filename,String networkId) { - wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+networkId)).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile(filename).withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackPutNeutronNetwork(WireMockServer wireMockServer, String networkId, int responseCode) { - wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+networkId)).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withStatus(responseCode))); - } - - public static void mockOpenStackGetAllNeutronNetworks_200(WireMockServer wireMockServer, String filename){ - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile(filename).withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetNeutronNetwork_404(WireMockServer wireMockServer, String networkName) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+networkName)).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withStatus(HttpStatus.SC_NOT_FOUND))); - } - - public static void mockOpenStackGetAllNeutronNetworks_404(WireMockServer wireMockServer) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withStatus(HttpStatus.SC_NOT_FOUND))); - } - - public static void mockOpenstackGetWithResponse(WireMockServer wireMockServer, String url,int responseCode, String responseFile) { - wireMockServer.stubFor(get(urlPathEqualTo(url)).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile(responseFile) - .withStatus(responseCode))); - } - - public static void mockOpenstackPostWithResponse(WireMockServer wireMockServer, String url,int responseCode, String responseFile) { - wireMockServer.stubFor(post(urlPathEqualTo(url)).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile(responseFile) - .withStatus(responseCode))); - } - - public static void mockOpenstackGet(WireMockServer wireMockServer, String url,int responseCode) { - wireMockServer.stubFor(get(urlPathEqualTo(url)).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withStatus(responseCode))); - } - - public static void mockOpenstackPost(WireMockServer wireMockServer, String url,int responseCode) { - wireMockServer.stubFor(post(urlPathEqualTo(url)).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withStatus(responseCode))); - } - - public static void mockOpenStackGetStackVfModule_200(WireMockServer wireMockServer) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json") - .withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetStackVfModule_404(WireMockServer wireMockServer) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withStatus(HttpStatus.SC_NOT_FOUND))); - } - - public static void mockOpenStackPostStacks_200(WireMockServer wireMockServer) { - wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Stack.json").withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetStacks_404(WireMockServer wireMockServer) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/3d7ff7b4-720b-4604-be0a-1974fc58ed96")) - .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND))); - } - - public static void mockOpenStackGetStacksWithBody_200(WireMockServer wireMockServer, String replaceWith) throws IOException { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(getBodyFromFileVnfAdapter(replaceWith)) - .withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetStackWithBody_200(WireMockServer wireMockServer, String replaceWith) throws IOException { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(getBodyFromFileVnfAdapter(replaceWith)) - .withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetStacksWithBody_404(WireMockServer wireMockServer) throws IOException { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(getBodyFromFileVnfAdapter(null)) - .withStatus(HttpStatus.SC_NOT_FOUND))); - } - - public static void mockOpenStackGetStacksStackId_404(WireMockServer wireMockServer) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/stackId")) - .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND))); - } - - public static void mockOpenStackGetStacksVfModule_200(WireMockServer wireMockServer, int port) throws IOException { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")).willReturn(aResponse() - .withHeader("X-Openstack-Request-Id", "openstackRquest") - .withBody(getBodyFromFile("OpenstackResponse_VnfStackId.json", port, "/mockPublicUrl/stacks/stackId")).withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetStacksVfModuleWithLocationHeader_200(WireMockServer wireMockServer, int port) throws IOException { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")).willReturn(aResponse() - .withHeader("X-Openstack-Request-Id", "openstackRquest") - .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001") - .withBody(getBodyFromFile("OpenstackResponse_VnfStackId.json", port, "/mockPublicUrl/stacks/stackId")).withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetStacksBaseStack_200(WireMockServer wireMockServer, int port) throws IOException { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/baseVfModuleStackId")).willReturn(aResponse() - .withHeader("X-Openstack-Request-Id", "openstackRquest") - .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/baseVfModuleStackId") - .withBody(getBodyFromFile("OpenstackResponse_VnfBaseStackId.json", port, "/mockPublicUrl/stacks/stackId")).withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackPutStacks_200(WireMockServer wireMockServer) { - wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackPutStack(WireMockServer wireMockServer, String networkId,int responseCode) { - wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/"+networkId)) - .willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withStatus(responseCode))); - } - - public static void mockOpenStackGetStacksStackId_200(WireMockServer wireMockServer, int port) throws IOException { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/StackId")).willReturn(aResponse() - .withHeader("X-Openstack-Request-Id", "openstackRquest") - .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/stackId") - .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, "/mockPublicUrl/stacks/stackId")).withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackDeleteStacks(WireMockServer wireMockServer) { - wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0/da886914-efb2-4917-b335-c8381528d90b")) - .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest"))); - } - - public static void mockOpenStackGetStacksVUSP_404(WireMockServer wireMockServer) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0/da886914-efb2-4917-b335-c8381528d90b")) - .willReturn(aResponse() - .withHeader("X-Openstack-Request-Id", "openstackRquest") - .withStatus(HttpStatus.SC_NOT_FOUND))); - } - - public static void mockOpenStackGetStackCreated_200(WireMockServer wireMockServer, String filename, String networkName) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + networkName)) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile(filename).withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetStack_404(WireMockServer wireMockServer, String networkName) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + networkName)) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withStatus(HttpStatus.SC_NOT_FOUND))); - } - - public static void mockOpenStackGetStack_500(WireMockServer wireMockServer, String networkName) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + networkName)) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); - } - - public static void mockOpenStackGetStackDeleteOrUpdateComplete_200(WireMockServer wireMockServer, String filename) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME_2 + "/" + NETWORK_ID_2)) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile(filename).withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetNeutronNetwork(WireMockServer wireMockServer, String filename,String networkId,int status) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+ networkId)) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile(filename).withStatus(status))); - } - - public static void mockOpenStackGetNeutronNetwork(WireMockServer wireMockServer, String networkId,int status) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/"+ networkId)) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withStatus(status))); - } - - public static void mockOpenStackDeleteStack_200(WireMockServer wireMockServer) { - wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME_2 + "/" + NETWORK_ID_2)) - .willReturn(aResponse().withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackDeleteStack_500(WireMockServer wireMockServer) { - wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME_2 + "/" + NETWORK_ID_2)) - .willReturn(aResponse().withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); - } - - public static void mockOpenStackDeleteNeutronNetwork(WireMockServer wireMockServer, String networkId,int responseCode) { - wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId)) - .willReturn(aResponse().withStatus(responseCode))); - } - - public static void mockOpenStackPostMetadata_200(WireMockServer wireMockServer) { - wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants/tenantId/metadata")).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Metadata.json").withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetMetadata_200(WireMockServer wireMockServer) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/tenantId/metadata")).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Metadata.json").withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackPostTenantWithBodyFile_200(WireMockServer wireMockServer) throws IOException { - wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants")) - .withRequestBody(equalToJson(readFile("src/test/resources/__files/OpenstackRequest_Tenant.json"))).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackPostTenant_200(WireMockServer wireMockServer) throws IOException { - wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetTenantByName_200(WireMockServer wireMockServer, String tenantName) { - wireMockServer.stubFor(get(urlEqualTo("/mockPublicUrl/tenants/?name=" + tenantName)).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetTenantByName_404(WireMockServer wireMockServer, String tenantName) { - wireMockServer.stubFor(get(urlEqualTo("/mockPublicUrl/tenants/?name=" + tenantName)).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND))); - } - - public static void mockOpenStackGetTenantById_200(WireMockServer wireMockServer, String tenantId) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetTenantById_404(WireMockServer wireMockServer, String tenantId) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND))); - } - - public static void mockOpenStackDeleteTenantById_200(WireMockServer wireMockServer, String tenantId) { - wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetUser_200(WireMockServer wireMockServer, String user) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/users/" + user)).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_User.json").withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackGetRoles_200(WireMockServer wireMockServer, String roleFor) { - wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/" + roleFor + "/roles")).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBodyFile("OpenstackResponse_Roles.json").withStatus(HttpStatus.SC_OK))); - } - - public static void mockOpenStackPutRolesAdmin_200(WireMockServer wireMockServer, String roleFor) { - wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/tenants/tenantId/users/msoId/roles/" + roleFor + "/admin")).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBody("").withStatus(HttpStatus.SC_OK))); - } - - public static void mockValetCreatePostResponse_200(WireMockServer wireMockServer, String requestId, String body) { - wireMockServer.stubFor(post(urlEqualTo("/api/valet/placement/v1/?requestId=" + requestId)) + private static final String NETWORK_NAME = "vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0"; + private static final String NETWORK_ID = "da886914-efb2-4917-b335-c8381528d90b"; + private static final String NETWORK_NAME_2 = "stackname"; + private static final String NETWORK_ID_2 = "stackId"; + + public static void mockOpenStackResponseAccess(WireMockServer wireMockServer, int port) throws IOException { + wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFile("OpenstackResponse_Access.json", port, "/mockPublicUrl")) + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackResponseAccessMulticloud(WireMockServer wireMockServer, int port) + throws IOException { + wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFile("OpenstackResponse_AccessMulticloud.json", port, "/mockPublicUrl")) + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackResponseAccessQueryNetwork(WireMockServer wireMockServer, int port) + throws IOException { + wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")).withRequestBody(containing("tenantId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFile("OpenstackResponse_Access_queryNetwork.json", port, "/mockPublicUrl")) + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackResponseAccessAdmin(WireMockServer wireMockServer, int port) throws IOException { + wireMockServer.stubFor(post(urlPathEqualTo("/v2.0/tokens")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFile("OpenstackResponse_Access_Admin.json", port, "/mockPublicUrl")) + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackPublicUrlStackByName_200(WireMockServer wireMockServer, int port) + throws IOException { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME)) + .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest") + .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/" + NETWORK_NAME) + .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, + "/mockPublicUrl/stacks/" + NETWORK_NAME)) + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackPublicUrlStackByID_200(WireMockServer wireMockServer, int port) throws IOException { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_ID)) + .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest") + .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/" + NETWORK_NAME) + .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, + "/mockPublicUrl/stacks/" + NETWORK_NAME)) + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetPublicUrlStackByNameAndID_200(WireMockServer wireMockServer, int port) + throws IOException { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME + "/" + NETWORK_ID)) + .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest") + .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/" + NETWORK_NAME) + .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, + "/mockPublicUrl/stacks/" + NETWORK_NAME)) + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetPublicUrlStackByNameAndID_204(WireMockServer wireMockServer, int port) + throws IOException { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME + "/" + NETWORK_ID)) + .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest") + .withHeader("location", + "http://localhost:" + port + "/mockPublicUrl/stacks/" + NETWORK_NAME + "/" + NETWORK_ID) + .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, + "/mockPublicUrl/stacks/" + NETWORK_NAME)) + .withStatus(HttpStatus.SC_NOT_FOUND))); + } + + public static void mockOpenStackPutPublicUrlStackByNameAndID_200(WireMockServer wireMockServer) { + wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME + "/" + NETWORK_ID)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackPutPublicUrlStackByNameAndID_NETWORK2_200(WireMockServer wireMockServer) { + wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME_2 + "/" + NETWORK_ID_2)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackDeletePublicUrlStackByNameAndID_204(WireMockServer wireMockServer) { + wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME + "/" + NETWORK_ID)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withStatus(HttpStatus.SC_NO_CONTENT))); + } + + public static void mockOpenStackPostPublicUrlWithBodyFile_200(WireMockServer wireMockServer) { + wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_Stack.json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetStackCreatedAppC_200(WireMockServer wireMockServer) { + wireMockServer.stubFor( + get(urlPathEqualTo("/mockPublicUrl/stacks/APP-C-24595-T-IST-04AShared_untrusted_vDBE_net_3/stackId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_Stack_Created.json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetStackAppC_404(WireMockServer wireMockServer) { + wireMockServer + .stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/APP-C-24595-T-IST-04AShared_untrusted_vDBE_net_3")) + .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND))); + } + + public static void mockOpenStackGetStackCreatedVUSP_200(WireMockServer wireMockServer) { + wireMockServer.stubFor( + get(urlPathEqualTo("/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0/stackId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_Stack_Created.json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetStackVUSP_404(WireMockServer wireMockServer) { + wireMockServer + .stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0")) + .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND))); + } + + public static void mockOpenStackPostStack_200(WireMockServer wireMockServer, String filename) { + wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBodyFile(filename).withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackPostNeutronNetwork_200(WireMockServer wireMockServer, String filename) { + wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBodyFile(filename).withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackPutNeutronNetwork_200(WireMockServer wireMockServer, String filename, + String networkId) { + wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId)).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBodyFile(filename).withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackPutNeutronNetwork(WireMockServer wireMockServer, String networkId, + int responseCode) { + wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(responseCode))); + } + + public static void mockOpenStackGetAllNeutronNetworks_200(WireMockServer wireMockServer, String filename) { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBodyFile(filename).withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetNeutronNetwork_404(WireMockServer wireMockServer, String networkName) { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkName)).willReturn( + aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND))); + } + + public static void mockOpenStackGetAllNeutronNetworks_404(WireMockServer wireMockServer) { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks")).willReturn( + aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND))); + } + + public static void mockOpenstackGetWithResponse(WireMockServer wireMockServer, String url, int responseCode, + String responseFile) { + wireMockServer.stubFor(get(urlPathEqualTo(url)).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBodyFile(responseFile).withStatus(responseCode))); + } + + public static void mockOpenstackPostWithResponse(WireMockServer wireMockServer, String url, int responseCode, + String responseFile) { + wireMockServer.stubFor(post(urlPathEqualTo(url)).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBodyFile(responseFile).withStatus(responseCode))); + } + + public static void mockOpenstackGet(WireMockServer wireMockServer, String url, int responseCode) { + wireMockServer.stubFor(get(urlPathEqualTo(url)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(responseCode))); + } + + public static void mockOpenstackPost(WireMockServer wireMockServer, String url, int responseCode) { + wireMockServer.stubFor(post(urlPathEqualTo(url)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(responseCode))); + } + + public static void mockOpenStackGetStackVfModule_200(WireMockServer wireMockServer) { + wireMockServer.stubFor(get( + urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_Stack_Created_VfModule.json") + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetStackVfModule_404(WireMockServer wireMockServer) { + wireMockServer.stubFor( + get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withStatus(HttpStatus.SC_NOT_FOUND))); + } + + public static void mockOpenStackPostStacks_200(WireMockServer wireMockServer) { + wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/stacks")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_Stack.json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetStacks_404(WireMockServer wireMockServer) { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/3d7ff7b4-720b-4604-be0a-1974fc58ed96")) + .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND))); + } + + public static void mockOpenStackGetStacksWithBody_200(WireMockServer wireMockServer, String replaceWith) + throws IOException { + wireMockServer.stubFor( + get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFileVnfAdapter(replaceWith)).withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetStackWithBody_200(WireMockServer wireMockServer, String replaceWith) + throws IOException { + wireMockServer.stubFor(get( + urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/stackId")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFileVnfAdapter(replaceWith)).withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetStacksWithBody_404(WireMockServer wireMockServer) throws IOException { + wireMockServer.stubFor( + get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(getBodyFromFileVnfAdapter(null)).withStatus(HttpStatus.SC_NOT_FOUND))); + } + + public static void mockOpenStackGetStacksStackId_404(WireMockServer wireMockServer) { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/stackId")) + .willReturn(aResponse().withStatus(HttpStatus.SC_NOT_FOUND))); + } + + public static void mockOpenStackGetStacksVfModule_200(WireMockServer wireMockServer, int port) throws IOException { + wireMockServer.stubFor(get(urlPathEqualTo( + "/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")) + .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest") + .withBody(getBodyFromFile("OpenstackResponse_VnfStackId.json", port, + "/mockPublicUrl/stacks/stackId")) + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetStacksVfModuleWithLocationHeader_200(WireMockServer wireMockServer, int port) + throws IOException { + wireMockServer.stubFor( + get(urlPathEqualTo("/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")) + .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest") + .withHeader("location", "http://localhost:" + port + + "/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001") + .withBody(getBodyFromFile("OpenstackResponse_VnfStackId.json", port, + "/mockPublicUrl/stacks/stackId")) + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetStacksBaseStack_200(WireMockServer wireMockServer, int port) throws IOException { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/baseVfModuleStackId")).willReturn(aResponse() + .withHeader("X-Openstack-Request-Id", "openstackRquest") + .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/baseVfModuleStackId") + .withBody( + getBodyFromFile("OpenstackResponse_VnfBaseStackId.json", port, "/mockPublicUrl/stacks/stackId")) + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackPutStacks_200(WireMockServer wireMockServer) { + wireMockServer.stubFor(put(urlPathEqualTo( + "/mockPublicUrl/stacks/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001/DEV-VF-1802-it3-pwt3-v6-vSAMP10a-addon2-Replace-1001")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackPutStack(WireMockServer wireMockServer, String networkId, int responseCode) { + wireMockServer.stubFor(put(urlPathEqualTo("/mockPublicUrl/stacks/" + networkId)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(responseCode))); + } + + public static void mockOpenStackGetStacksStackId_200(WireMockServer wireMockServer, int port) throws IOException { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/StackId")).willReturn(aResponse() + .withHeader("X-Openstack-Request-Id", "openstackRquest") + .withHeader("location", "http://localhost:" + port + "/mockPublicUrl/stacks/stackId") + .withBody(getBodyFromFile("OpenstackResponse_StackId.json", port, "/mockPublicUrl/stacks/stackId")) + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackDeleteStacks(WireMockServer wireMockServer) { + wireMockServer.stubFor(delete(urlPathEqualTo( + "/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0/da886914-efb2-4917-b335-c8381528d90b")) + .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest"))); + } + + public static void mockOpenStackGetStacksVUSP_404(WireMockServer wireMockServer) { + wireMockServer.stubFor(get(urlPathEqualTo( + "/mockPublicUrl/stacks/vUSP-23804-T-01-dpa2b_EVUSP-CORE-VIF-TSIG0_net_0/da886914-efb2-4917-b335-c8381528d90b")) + .willReturn(aResponse().withHeader("X-Openstack-Request-Id", "openstackRquest") + .withStatus(HttpStatus.SC_NOT_FOUND))); + } + + public static void mockOpenStackGetStackCreated_200(WireMockServer wireMockServer, String filename, + String networkName) { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + networkName)).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBodyFile(filename).withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetStack_404(WireMockServer wireMockServer, String networkName) { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + networkName)).willReturn( + aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND))); + } + + public static void mockOpenStackGetStack_500(WireMockServer wireMockServer, String networkName) { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + networkName)).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); + } + + public static void mockOpenStackGetStackDeleteOrUpdateComplete_200(WireMockServer wireMockServer, String filename) { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME_2 + "/" + NETWORK_ID_2)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile(filename) + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetNeutronNetwork(WireMockServer wireMockServer, String filename, String networkId, + int status) { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId)).willReturn( + aResponse().withHeader("Content-Type", "application/json").withBodyFile(filename).withStatus(status))); + } + + public static void mockOpenStackGetNeutronNetwork(WireMockServer wireMockServer, String networkId, int status) { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(status))); + } + + public static void mockOpenStackDeleteStack_200(WireMockServer wireMockServer) { + wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME_2 + "/" + NETWORK_ID_2)) + .willReturn(aResponse().withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackDeleteStack_500(WireMockServer wireMockServer) { + wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/stacks/" + NETWORK_NAME_2 + "/" + NETWORK_ID_2)) + .willReturn(aResponse().withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); + } + + public static void mockOpenStackDeleteNeutronNetwork(WireMockServer wireMockServer, String networkId, + int responseCode) { + wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/v2.0/networks/" + networkId)) + .willReturn(aResponse().withStatus(responseCode))); + } + + public static void mockOpenStackPostMetadata_200(WireMockServer wireMockServer) { + wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants/tenantId/metadata")) .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(body).withStatus(HttpStatus.SC_OK))); - } - - public static void mockValetCreatePutResponse_200(WireMockServer wireMockServer, String requestId, String body) { - wireMockServer.stubFor(put(urlEqualTo("/api/valet/placement/v1/?requestId=" + requestId)) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(body).withStatus(HttpStatus.SC_OK))); - } - - public static void mockValetDeleteDeleteResponse_200(WireMockServer wireMockServer, String requestId, String body) { - wireMockServer.stubFor(delete(urlEqualTo("/api/valet/placement/v1/?requestId=" + requestId)) + .withBodyFile("OpenstackResponse_Metadata.json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetMetadata_200(WireMockServer wireMockServer) { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/tenantId/metadata")) .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(body).withStatus(HttpStatus.SC_OK))); - } - - public static void mockValetConfirmPutRequest_200(WireMockServer wireMockServer, String requestId, String body) { - wireMockServer.stubFor(put(urlPathEqualTo("/api/valet/placement/v1/" + requestId + "/confirm/")) + .withBodyFile("OpenstackResponse_Metadata.json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackPostTenantWithBodyFile_200(WireMockServer wireMockServer) throws IOException { + wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants")) + .withRequestBody(equalToJson(readFile("src/test/resources/__files/OpenstackRequest_Tenant.json"))) .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(body).withStatus(HttpStatus.SC_OK))); - } - - public static void mockValetRollbackPutRequest_200(WireMockServer wireMockServer, String requestId, String body) { - wireMockServer.stubFor(put(urlPathEqualTo("/api/valet/placement/v1/" + requestId + "/rollback/")) + .withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackPostTenant_200(WireMockServer wireMockServer) throws IOException { + wireMockServer.stubFor(post(urlPathEqualTo("/mockPublicUrl/tenants")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetTenantByName_200(WireMockServer wireMockServer, String tenantName) { + wireMockServer.stubFor(get(urlEqualTo("/mockPublicUrl/tenants/?name=" + tenantName)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetTenantByName_404(WireMockServer wireMockServer, String tenantName) { + wireMockServer.stubFor(get(urlEqualTo("/mockPublicUrl/tenants/?name=" + tenantName)).willReturn( + aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND))); + } + + public static void mockOpenStackGetTenantById_200(WireMockServer wireMockServer, String tenantId) { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_Tenant.json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetTenantById_404(WireMockServer wireMockServer, String tenantId) { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)).willReturn( + aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_NOT_FOUND))); + } + + public static void mockOpenStackDeleteTenantById_200(WireMockServer wireMockServer, String tenantId) { + wireMockServer.stubFor(delete(urlPathEqualTo("/mockPublicUrl/tenants/" + tenantId)) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetUser_200(WireMockServer wireMockServer, String user) { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/users/" + user)) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBodyFile("OpenstackResponse_User.json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackGetRoles_200(WireMockServer wireMockServer, String roleFor) { + wireMockServer.stubFor(get(urlPathEqualTo("/mockPublicUrl/" + roleFor + "/roles")) .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody(body).withStatus(HttpStatus.SC_OK))); - } - - private static String getBodyFromFileVnfAdapter(String replaceWith) throws IOException { - String temp = readFile("src/test/resources/__files/OpenstackResponse_Stack_Created_VfModule.json"); - if (replaceWith == null) { - return temp; - } - return temp.replaceAll("CREATE_COMPLETE", replaceWith); - } - - private static String readFile(String fileName) throws IOException { - try (BufferedReader br = new BufferedReader(new FileReader(fileName))) { - StringBuilder sb = new StringBuilder(); - String line = br.readLine(); - - while (line != null) { - sb.append(line); - sb.append("\n"); - line = br.readLine(); - } - return sb.toString(); - } - } - - public static String getBodyFromFile(String fileName, int port, String urlPath) throws IOException { - return readFile("src/test/resources/__files/" + fileName).replaceAll("port", "http://localhost:" + port + urlPath); - } + .withBodyFile("OpenstackResponse_Roles.json").withStatus(HttpStatus.SC_OK))); + } + + public static void mockOpenStackPutRolesAdmin_200(WireMockServer wireMockServer, String roleFor) { + wireMockServer + .stubFor(put(urlPathEqualTo("/mockPublicUrl/tenants/tenantId/users/msoId/roles/" + roleFor + "/admin")) + .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("") + .withStatus(HttpStatus.SC_OK))); + } + + public static void mockValetCreatePostResponse_200(WireMockServer wireMockServer, String requestId, String body) { + wireMockServer + .stubFor(post(urlEqualTo("/api/valet/placement/v1/?requestId=" + requestId)).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody(body).withStatus(HttpStatus.SC_OK))); + } + + public static void mockValetCreatePutResponse_200(WireMockServer wireMockServer, String requestId, String body) { + wireMockServer.stubFor(put(urlEqualTo("/api/valet/placement/v1/?requestId=" + requestId)).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody(body).withStatus(HttpStatus.SC_OK))); + } + + public static void mockValetDeleteDeleteResponse_200(WireMockServer wireMockServer, String requestId, String body) { + wireMockServer + .stubFor(delete(urlEqualTo("/api/valet/placement/v1/?requestId=" + requestId)).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody(body).withStatus(HttpStatus.SC_OK))); + } + + public static void mockValetConfirmPutRequest_200(WireMockServer wireMockServer, String requestId, String body) { + wireMockServer.stubFor( + put(urlPathEqualTo("/api/valet/placement/v1/" + requestId + "/confirm/")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody(body).withStatus(HttpStatus.SC_OK))); + } + + public static void mockValetRollbackPutRequest_200(WireMockServer wireMockServer, String requestId, String body) { + wireMockServer.stubFor( + put(urlPathEqualTo("/api/valet/placement/v1/" + requestId + "/rollback/")).willReturn(aResponse() + .withHeader("Content-Type", "application/json").withBody(body).withStatus(HttpStatus.SC_OK))); + } + + private static String getBodyFromFileVnfAdapter(String replaceWith) throws IOException { + String temp = readFile("src/test/resources/__files/OpenstackResponse_Stack_Created_VfModule.json"); + if (replaceWith == null) { + return temp; + } + return temp.replaceAll("CREATE_COMPLETE", replaceWith); + } + + private static String readFile(String fileName) throws IOException { + try (BufferedReader br = new BufferedReader(new FileReader(fileName))) { + StringBuilder sb = new StringBuilder(); + String line = br.readLine(); + + while (line != null) { + sb.append(line); + sb.append("\n"); + line = br.readLine(); + } + return sb.toString(); + } + } + + public static String getBodyFromFile(String fileName, int port, String urlPath) throws IOException { + return readFile("src/test/resources/__files/" + fileName).replaceAll("port", + "http://localhost:" + port + urlPath); + } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java index 3c777e17cb..0787cef75d 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java @@ -1,17 +1,14 @@ /* * Copyright (C) 2018 Bell Canada. 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 + * 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 + * 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. + * 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. */ package org.onap.so.heatbridge; @@ -25,7 +22,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; - import java.io.File; import java.io.IOException; import java.nio.charset.Charset; @@ -35,7 +31,6 @@ import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Optional; - import org.apache.commons.io.FileUtils; import org.junit.Assert; import org.junit.Before; @@ -69,7 +64,6 @@ import org.openstack4j.model.network.NetworkType; import org.openstack4j.model.network.Port; import org.openstack4j.openstack.heat.domain.HeatResource; import org.openstack4j.openstack.heat.domain.HeatResource.Resources; - import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; @@ -86,14 +80,14 @@ public class HeatBridgeImplTest { private OpenstackClient osClient; private CloudIdentity cloudIdentity = new CloudIdentity(); - + @Mock private AAIResourcesClient resourcesClient; @Mock private AAISingleTransactionClient transaction; - private HeatBridgeImpl heatbridge; - + private HeatBridgeImpl heatbridge; + @Before public void setUp() throws HeatBridgeException, OpenstackClientException, BulkProcessFailed { @@ -108,7 +102,7 @@ public class HeatBridgeImplTest { String heatStackId = "1234567"; List<Resource> expectedResourceList = (List<Resource>) extractTestStackResources(); when(osClient.getStackBasedResources(heatStackId, HeatBridgeConstants.OS_DEFAULT_HEAT_NESTING)) - .thenReturn(expectedResourceList); + .thenReturn(expectedResourceList); // Act List<Resource> resourceList = heatbridge.queryNestedHeatStackResources(heatStackId); @@ -122,12 +116,12 @@ public class HeatBridgeImplTest { public void testExtractStackResourceIdsByResourceType() throws HeatBridgeException { // Arrange List<Resource> expectedResourceList = (List<Resource>) extractTestStackResources(); - List<String> expectedServerIds = Arrays.asList("43c2159b-2c04-46ac-bda5-594110cae2d3", - "7cff109a-b2b7-4933-97b4-ec44a8365568"); + List<String> expectedServerIds = + Arrays.asList("43c2159b-2c04-46ac-bda5-594110cae2d3", "7cff109a-b2b7-4933-97b4-ec44a8365568"); // Act - List<String> serverIds = heatbridge - .extractStackResourceIdsByResourceType(expectedResourceList, HeatBridgeConstants.OS_SERVER_RESOURCE_TYPE); + List<String> serverIds = heatbridge.extractStackResourceIdsByResourceType(expectedResourceList, + HeatBridgeConstants.OS_SERVER_RESOURCE_TYPE); // Assert assertEquals(expectedServerIds, serverIds); @@ -205,7 +199,7 @@ public class HeatBridgeImplTest { public void testUpdateVserversToAai() throws HeatBridgeException { // Arrange Server server1 = mock(Server.class); - + when(server1.getId()).thenReturn("test-server1-id"); when(server1.getHypervisorHostname()).thenReturn("test-hypervisor"); when(server1.getName()).thenReturn("test-server1-name"); @@ -234,16 +228,16 @@ public class HeatBridgeImplTest { // Act heatbridge.buildAddVserversToAaiAction("test-genericVnf-id", "test-vfModule-id", servers); - + // Assert ArgumentCaptor<AAIResourceUri> captor = ArgumentCaptor.forClass(AAIResourceUri.class); verify(transaction, times(2)).create(captor.capture(), any(Vserver.class)); - + List<AAIResourceUri> uris = captor.getAllValues(); - assertEquals(AAIUriFactory.createResourceUri( - AAIObjectType.VSERVER, CLOUD_OWNER, REGION_ID, TENANT_ID, server1.getId()), uris.get(0)); - assertEquals(AAIUriFactory.createResourceUri( - AAIObjectType.VSERVER, CLOUD_OWNER, REGION_ID, TENANT_ID, server2.getId()), uris.get(1)); + assertEquals(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, CLOUD_OWNER, REGION_ID, TENANT_ID, + server1.getId()), uris.get(0)); + assertEquals(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, CLOUD_OWNER, REGION_ID, TENANT_ID, + server2.getId()), uris.get(1)); } @@ -315,11 +309,10 @@ public class HeatBridgeImplTest { when(port.getMacAddress()).thenReturn("78:4f:43:68:e2:78"); when(port.getNetworkId()).thenReturn("890a203a-23gg-56jh-df67-731656a8f13a"); when(port.getDeviceId()).thenReturn("test-device-id"); - when(port.getVifDetails()) - .thenReturn(ImmutableMap.of(HeatBridgeConstants.OS_VLAN_NETWORK_KEY, "2345")); + when(port.getVifDetails()).thenReturn(ImmutableMap.of(HeatBridgeConstants.OS_VLAN_NETWORK_KEY, "2345")); String pfPciId = "0000:08:00.0"; when(port.getProfile()).thenReturn(ImmutableMap.of(HeatBridgeConstants.OS_PCI_SLOT_KEY, pfPciId, - HeatBridgeConstants.OS_PHYSICAL_NETWORK_KEY, "physical_network_id")); + HeatBridgeConstants.OS_PHYSICAL_NETWORK_KEY, "physical_network_id")); Network network = mock(Network.class); when(network.getId()).thenReturn("test-network-id"); @@ -351,8 +344,7 @@ public class HeatBridgeImplTest { private List<? extends Resource> extractTestStackResources() { List<HeatResource> stackResources = null; try { - stackResources = MAPPER.readValue(readTestResourceFile("stack-resources.json"), Resources.class) - .getList(); + stackResources = MAPPER.readValue(readTestResourceFile("stack-resources.json"), Resources.class).getList(); assertNotNull(stackResources); assertFalse(stackResources.isEmpty()); } catch (IOException e) { diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/vdu/utils/VduBlueprintTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/vdu/utils/VduBlueprintTest.java index b382b6bcf8..796d122505 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/vdu/utils/VduBlueprintTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/vdu/utils/VduBlueprintTest.java @@ -22,7 +22,6 @@ package org.onap.so.vdu.utils; import java.util.HashMap; import java.util.Map; - import org.junit.Assert; import org.junit.Before; import org.junit.Test; diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/vdu/utils/VduInfoTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/vdu/utils/VduInfoTest.java index 6331563362..7041c7e949 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/vdu/utils/VduInfoTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/vdu/utils/VduInfoTest.java @@ -22,7 +22,6 @@ package org.onap.so.vdu.utils; import java.util.HashMap; import java.util.Map; - import org.junit.Assert; import org.junit.Before; import org.junit.Test; |