diff options
Diffstat (limited to 'ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiServicesControllerTest.java')
-rw-r--r-- | ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiServicesControllerTest.java | 345 |
1 files changed, 343 insertions, 2 deletions
diff --git a/ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiServicesControllerTest.java b/ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiServicesControllerTest.java index b9ec3de..75e1a31 100644 --- a/ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiServicesControllerTest.java +++ b/ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiServicesControllerTest.java @@ -16,8 +16,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.sdnc.apps.ms.gra.GenericResourceMsApp; -import org.onap.sdnc.apps.ms.gra.data.ConfigServices; -import org.onap.sdnc.apps.ms.gra.data.ConfigServicesRepository; +import org.onap.sdnc.apps.ms.gra.data.*; import org.onap.sdnc.apps.ms.gra.swagger.model.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -37,6 +36,8 @@ public class ConfigApiServicesControllerTest { private final static String CONFIG_SERVICES_URL = "/config/GENERIC-RESOURCE-API:services/"; private final static String CONFIG_SERVICES_SERVICE_URL = "/config/GENERIC-RESOURCE-API:services/service/"; + private final static String CONFIG_CR_ARS_CR_AR_URL = "/config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/contrail-route-allotted-resource/"; + private final static String CONFIG_PM_CONFIGS_PM_CONFIG_URL = "/config/GENERIC-RESOURCE-API:port-mirror-configurations/port-mirror-configuration/"; @Autowired private MockMvc mvc; @@ -44,6 +45,12 @@ public class ConfigApiServicesControllerTest { @Autowired ConfigServicesRepository configServicesRepository; + @Autowired + ConfigContrailRouteAllottedResourcesRepository configContrailRouteAllottedResourcesRepository; + + @Autowired + ConfigPortMirrorConfigurationsRepository configPortMirrorConfigurationsRepository; + @BeforeClass public static void setUp() throws Exception { System.out.println("ConfigApiServicesControllerTest: Setting serviceLogicProperties, serviceLogicDirectory and sdnc.config.dir"); @@ -669,6 +676,312 @@ public class ConfigApiServicesControllerTest { assertEquals(1, configServicesRepository.count()); } + @Test + public void configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdPut() throws Exception { + // Clean up data + configPortMirrorConfigurationsRepository.deleteAll(); + + String content = readFileContent("src/test/resources/port-mirror-configuration-item.json"); + + // Test with no data + MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-2/") + .contentType(MediaType.APPLICATION_JSON).content(content)).andReturn(); + assertEquals(201, mvcResult.getResponse().getStatus()); + + // Test with existing port-mirror-configuration + // Load data + loadPortMirrorConfigurationData("src/test/resources/port-mirror-configuration-1.json"); + assertEquals(2, configPortMirrorConfigurationsRepository.count()); + + mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-2/") + .contentType(MediaType.APPLICATION_JSON).content(content)).andReturn(); + assertEquals(204, mvcResult.getResponse().getStatus()); + assertEquals(2, configPortMirrorConfigurationsRepository.count()); + + // Clean up data + configPortMirrorConfigurationsRepository.deleteAll(); + } + + @Test + public void configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdDelete() throws Exception { + // Clean up data + configPortMirrorConfigurationsRepository.deleteAll(); + + // Test with no data + MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-1/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + + assertEquals(204, mvcResult.getResponse().getStatus()); + assertEquals(0, configPortMirrorConfigurationsRepository.count()); + + // Load data + loadPortMirrorConfigurationData("src/test/resources/port-mirror-configuration-1.json"); + assertEquals(1, configPortMirrorConfigurationsRepository.count()); + + // Test with data + mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-1/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + + assertEquals(204, mvcResult.getResponse().getStatus()); + assertEquals(0, configPortMirrorConfigurationsRepository.count()); + } + + @Test + public void configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdGet() throws Exception { + // Clean up data + configPortMirrorConfigurationsRepository.deleteAll(); + + // Test with data + loadPortMirrorConfigurationData("src/test/resources/port-mirror-configuration-1.json"); + assert(configPortMirrorConfigurationsRepository.count() > 0); + + MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-1/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + assertEquals(200, mvcResult.getResponse().getStatus()); + + // Test with bad allotted-resource-id in input + mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"dummy/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + + assertEquals(404, mvcResult.getResponse().getStatus()); + + // Test with no data + configPortMirrorConfigurationsRepository.deleteAll(); + mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-1/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + + assertEquals(404, mvcResult.getResponse().getStatus()); + } + + @Test + public void configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdConfigurationDataPortMirrorConfigurationTopologyGet() throws Exception { + // Clean up data + configPortMirrorConfigurationsRepository.deleteAll(); + + // Test with data + loadPortMirrorConfigurationData("src/test/resources/port-mirror-configuration-1.json"); + assert(configPortMirrorConfigurationsRepository.count() > 0); + + MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-1/configuration-data/port-mirror-configuration-topology/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + assertEquals(200, mvcResult.getResponse().getStatus()); + + // Test with dummy allotted-resource-id + mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"dummy/configuration-data/port-mirror-configuration-topology/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + assertEquals(404, mvcResult.getResponse().getStatus()); + + // Test with no data + configPortMirrorConfigurationsRepository.deleteAll(); + mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_PM_CONFIGS_PM_CONFIG_URL+"pm-config-1/configuration-data/port-mirror-configuration-topology/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + assertEquals(404, mvcResult.getResponse().getStatus()); + } + + @Test + public void configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdPut() throws Exception { + // Clean up data + configContrailRouteAllottedResourcesRepository.deleteAll(); + + String content = readFileContent("src/test/resources/allotted-resource-item.json"); + + // Test with no data + MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_CR_ARS_CR_AR_URL+"ar2/") + .contentType(MediaType.APPLICATION_JSON).content(content)).andReturn(); + assertEquals(201, mvcResult.getResponse().getStatus()); + + // Test with existing allotted-resource + // Load data + configContrailRouteAllottedResourcesRepository.deleteAll(); + loadContrailRouteAllottedResourceData("src/test/resources/contrail-route-allotted-resource-1.json"); + assertEquals(1, configContrailRouteAllottedResourcesRepository.count()); + + mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_CR_ARS_CR_AR_URL+"ar2/") + .contentType(MediaType.APPLICATION_JSON).content(content)).andReturn(); + assertEquals(201, mvcResult.getResponse().getStatus()); + assertEquals(2, configContrailRouteAllottedResourcesRepository.count()); + + // Clean up data + configContrailRouteAllottedResourcesRepository.deleteAll(); + } + + @Test + public void configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdDelete() throws Exception { + // Clean up data + configContrailRouteAllottedResourcesRepository.deleteAll(); + + // Test with no data + MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_CR_ARS_CR_AR_URL+"ar1/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + + assertEquals(204, mvcResult.getResponse().getStatus()); + assertEquals(0, configContrailRouteAllottedResourcesRepository.count()); + + // Load data + loadContrailRouteAllottedResourceData("src/test/resources/contrail-route-allotted-resource-1.json"); + assertEquals(1, configContrailRouteAllottedResourcesRepository.count()); + + // Test with data + mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_CR_ARS_CR_AR_URL+"ar1/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + + assertEquals(204, mvcResult.getResponse().getStatus()); + assertEquals(0, configContrailRouteAllottedResourcesRepository.count()); + } + + @Test + public void configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdGet() throws Exception { + // Clean up data + configContrailRouteAllottedResourcesRepository.deleteAll(); + + // Test with data + loadContrailRouteAllottedResourceData("src/test/resources/contrail-route-allotted-resource-1.json"); + assert(configContrailRouteAllottedResourcesRepository.count() > 0); + + MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_CR_ARS_CR_AR_URL+"ar1/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + assertEquals(200, mvcResult.getResponse().getStatus()); + + // Test with bad allotted-resource-id in input + mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_CR_ARS_CR_AR_URL+"dummy/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + + assertEquals(404, mvcResult.getResponse().getStatus()); + + // Test with no data + configContrailRouteAllottedResourcesRepository.deleteAll(); + mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_CR_ARS_CR_AR_URL+"ar1/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + + assertEquals(404, mvcResult.getResponse().getStatus()); + } + + @Test + public void configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdAllottedResourceDataContrailRouteTopologyGet() throws Exception { + // Clean up data + configContrailRouteAllottedResourcesRepository.deleteAll(); + + // Test with data + loadContrailRouteAllottedResourceData("src/test/resources/contrail-route-allotted-resource-1.json"); + assert(configContrailRouteAllottedResourcesRepository.count() > 0); + + MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_CR_ARS_CR_AR_URL+"ar1/allotted-resource-data/contrail-route-topology/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + assertEquals(200, mvcResult.getResponse().getStatus()); + + // Test with dummy allotted-resource-id + mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_CR_ARS_CR_AR_URL+"dummy/allotted-resource-data/contrail-route-topology/").contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + assertEquals(404, mvcResult.getResponse().getStatus()); + + // Test with no data + configContrailRouteAllottedResourcesRepository.deleteAll(); + mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_CR_ARS_CR_AR_URL+"ar1/allotted-resource-data/contrail-route-topology/").contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + assertEquals(404, mvcResult.getResponse().getStatus()); + } + + @Test + public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdPut() throws Exception { + // Clean up data + configServicesRepository.deleteAll(); + + String content = readFileContent("src/test/resources/service1-vfmodule-item.json"); + + // Test with no data + MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/vf-1/") + .contentType(MediaType.APPLICATION_JSON).content(content)).andReturn(); + assertEquals(400, mvcResult.getResponse().getStatus()); + + // Test with existing service and vnf + // Load data + loadServicesData("src/test/resources/service1.json"); + assertEquals(1, configServicesRepository.count()); + + mvcResult = mvc.perform(MockMvcRequestBuilders.put(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/vf-1/") + .contentType(MediaType.APPLICATION_JSON).content(content)).andReturn(); + assertEquals(200, mvcResult.getResponse().getStatus()); + assertEquals(1, configServicesRepository.count()); + + // Clean up data + configServicesRepository.deleteAll(); + } + + @Test + public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdDelete() throws Exception { + // Clean up data + configServicesRepository.deleteAll(); + + // Test with no data + MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/269bda16-f40c-41a9-baef-e8905ab2b70e/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + + assertEquals(400, mvcResult.getResponse().getStatus()); + assertEquals(0, configServicesRepository.count()); + + // Load data + loadServicesData("src/test/resources/service1.json"); + assertEquals(1, configServicesRepository.count()); + + // Test with data + mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/269bda16-f40c-41a9-baef-e8905ab2b70e/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + + assertEquals(200, mvcResult.getResponse().getStatus()); + } + + @Test + public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdGet() throws Exception { + // Clean up data + configServicesRepository.deleteAll(); + + // Test with data + loadServicesData("src/test/resources/service1.json"); + assert(configServicesRepository.count() > 0); + + MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/269bda16-f40c-41a9-baef-e8905ab2b70e/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + + assertEquals(200, mvcResult.getResponse().getStatus()); + + // Test with bad vf-module-id in input + mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/dummyid/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + + assertEquals(404, mvcResult.getResponse().getStatus()); + + // Test with no data + configServicesRepository.deleteAll(); + mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/269bda16-f40c-41a9-baef-e8905ab2b70e/") + .contentType(MediaType.APPLICATION_JSON).content("")).andReturn(); + + assertEquals(404, mvcResult.getResponse().getStatus()); + } + + @Test + public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdVfModuleDataVfModuleTopologyGet() throws Exception { + // Clean up data + configServicesRepository.deleteAll(); + + // Test with data + loadServicesData("src/test/resources/service1.json"); + assert(configServicesRepository.count() > 0); + + MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/269bda16-f40c-41a9-baef-e8905ab2b70e/vf-module-data/vf-module-topology/").contentType(MediaType.APPLICATION_JSON) + .content("")).andReturn(); + assertEquals(200, mvcResult.getResponse().getStatus()); + + // Test with existing service and vnf but with dummy vf-module-id in input + configServicesRepository.deleteAll(); + mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/dummy/vf-module-data/vf-module-topology/").contentType(MediaType.APPLICATION_JSON) + .content("")).andReturn(); + assertEquals(404, mvcResult.getResponse().getStatus()); + + // Test with no data + configServicesRepository.deleteAll(); + mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/vnfs/vnf/fae319cc-68d6-496f-be1e-a09e133c71d4/vnf-data/vf-modules/vf-module/269bda16-f40c-41a9-baef-e8905ab2b70e/vf-module-data/vf-module-topology/").contentType(MediaType.APPLICATION_JSON) + .content("")).andReturn(); + assertEquals(404, mvcResult.getResponse().getStatus()); + } + private String readFileContent(String path) throws IOException { String content = new String(Files.readAllBytes(Paths.get(path))); return content; @@ -725,4 +1038,32 @@ public class ConfigApiServicesControllerTest { configServicesRepository.save(newService); } + private void loadContrailRouteAllottedResourceData(String path) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + String content = readFileContent(path); + GenericResourceApiContrailRouteAllottedResources allottedResources = objectMapper.readValue(content, GenericResourceApiContrailRouteAllottedResources.class); + + for (GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource allottedResource : allottedResources.getContrailRouteAllottedResource()) { + ConfigContrailRouteAllottedResources newContrailRouteAllottedResource = new ConfigContrailRouteAllottedResources(); + newContrailRouteAllottedResource.setAllottedResourceId(allottedResource.getAllottedResourceId()); + newContrailRouteAllottedResource.setArData(objectMapper.writeValueAsString(allottedResource.getAllottedResourceData())); + newContrailRouteAllottedResource.setAllottedResourceStatus(allottedResource.getAllottedResourceStatus()); + configContrailRouteAllottedResourcesRepository.save(newContrailRouteAllottedResource); + } + } + + private void loadPortMirrorConfigurationData(String path) throws IOException { + ObjectMapper objectMapper = new ObjectMapper(); + String content = readFileContent(path); + GenericResourceApiPortMirrorConfigurations pmConfigurations = objectMapper.readValue(content, GenericResourceApiPortMirrorConfigurations.class); + + for (GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration pmConfig : pmConfigurations.getPortMirrorConfiguration()) { + ConfigPortMirrorConfigurations newPmConfig = new ConfigPortMirrorConfigurations(); + newPmConfig.setConfigureationId(pmConfig.getConfigurationId()); + newPmConfig.setPmcData(objectMapper.writeValueAsString(pmConfig.getConfigurationData())); + newPmConfig.setPortMirrorConfigurationStatus(pmConfig.getConfigurationStatus()); + configPortMirrorConfigurationsRepository.save(newPmConfig); + } + } + }
\ No newline at end of file |