diff options
author | Dan Timoney <dtimoney@att.com> | 2021-03-26 09:57:35 -0400 |
---|---|---|
committer | Dan Timoney <dtimoney@att.com> | 2021-03-26 09:57:35 -0400 |
commit | 3e68599d1433c0200d20332c6bda3b2cfcf2dd93 (patch) | |
tree | a4b78bf4ae416e41215751d8e6ab2cfc36e33064 /ms/generic-resource-api/src/test/java | |
parent | 32bcdd700561be5457bbc0658fc27a87e1419f36 (diff) |
Refactor CRUD to new table structure
Refactor operations on config tree to use new table structure
for service/network/vnf/vf-module data.
Change-Id: I2e673dfb7bd335e48a3bcf212399d021d37dd9ee
Issue-ID: SDNC-1481
Signed-off-by: Dan Timoney <dtimoney@att.com>
Diffstat (limited to 'ms/generic-resource-api/src/test/java')
2 files changed, 128 insertions, 73 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 75e1a31..e002a88 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 @@ -46,11 +46,23 @@ public class ConfigApiServicesControllerTest { ConfigServicesRepository configServicesRepository; @Autowired + ConfigNetworksRepository configNetworksRepository; + + @Autowired + ConfigVnfsRepository configVnfsRepository; + + @Autowired + ConfigVfModulesRepository configVfModulesRepository; + + @Autowired ConfigContrailRouteAllottedResourcesRepository configContrailRouteAllottedResourcesRepository; @Autowired ConfigPortMirrorConfigurationsRepository configPortMirrorConfigurationsRepository; + @Autowired + ServiceDataHelper serviceDataHelper; + @BeforeClass public static void setUp() throws Exception { System.out.println("ConfigApiServicesControllerTest: Setting serviceLogicProperties, serviceLogicDirectory and sdnc.config.dir"); @@ -65,7 +77,7 @@ public class ConfigApiServicesControllerTest { public void configGENERICRESOURCEAPIservicesDelete() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); // Load test data loadServicesData( "src/test/resources/service1.json"); @@ -86,7 +98,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesGet() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); // Test with data loadServicesData("src/test/resources/service1.json"); @@ -97,7 +109,7 @@ public class ConfigApiServicesControllerTest { assertEquals(200, mvcResult.getResponse().getStatus()); // Test with no data - configServicesRepository.deleteAll(); + clearServicesData(); mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_URL).contentType(MediaType.APPLICATION_JSON).content("")) .andReturn(); assertEquals(404, mvcResult.getResponse().getStatus()); @@ -106,7 +118,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesPost() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); String content = readFileContent("src/test/resources/service1.json"); @@ -123,14 +135,14 @@ public class ConfigApiServicesControllerTest { assertEquals(1, configServicesRepository.count()); // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); } @Test public void configGENERICRESOURCEAPIservicesPut() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); String content = readFileContent("src/test/resources/service1.json"); @@ -147,14 +159,14 @@ public class ConfigApiServicesControllerTest { assertEquals(1, configServicesRepository.count()); // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); } @Test public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdDelete() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); // Test with no data MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content("")) @@ -177,7 +189,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGet() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); // Test with data loadServicesData("src/test/resources/service1.json"); @@ -188,7 +200,7 @@ public class ConfigApiServicesControllerTest { assertEquals(200, mvcResult.getResponse().getStatus()); // Test with no data - configServicesRepository.deleteAll(); + clearServicesData(); mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/").contentType(MediaType.APPLICATION_JSON).content("")) .andReturn(); assertEquals(404, mvcResult.getResponse().getStatus()); @@ -197,7 +209,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdPost() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); String content = readFileContent("src/test/resources/service1-serviceitem.json"); @@ -214,14 +226,14 @@ public class ConfigApiServicesControllerTest { assertEquals(1, configServicesRepository.count()); // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); } @Test public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdPut() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); String content = readFileContent("src/test/resources/service1-serviceitem.json"); @@ -238,13 +250,13 @@ public class ConfigApiServicesControllerTest { assertEquals(1, configServicesRepository.count()); // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); } @Test public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataDelete() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); // Test with no data MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content("")) @@ -271,7 +283,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataGet() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); // Test with data loadServicesData("src/test/resources/service1.json"); @@ -282,7 +294,7 @@ public class ConfigApiServicesControllerTest { assertEquals(200, mvcResult.getResponse().getStatus()); // Test with no data - configServicesRepository.deleteAll(); + clearServicesData(); mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/").contentType(MediaType.APPLICATION_JSON).content("")) .andReturn(); assertEquals(404, mvcResult.getResponse().getStatus()); @@ -291,7 +303,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataPost() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); String content = readFileContent("src/test/resources/service1-servicedata.json"); @@ -320,13 +332,13 @@ public class ConfigApiServicesControllerTest { assertEquals(409, mvcResult.getResponse().getStatus()); // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); } @Test public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceDataPut() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); String content = readFileContent("src/test/resources/service1-servicedata.json"); @@ -354,13 +366,13 @@ public class ConfigApiServicesControllerTest { assertEquals(204, mvcResult.getResponse().getStatus()); // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); } @Test public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusDelete() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); // Test with no data MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content("")) @@ -385,7 +397,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusGet() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); // Test with data loadServicesData("src/test/resources/service1.json"); @@ -396,7 +408,7 @@ public class ConfigApiServicesControllerTest { assertEquals(200, mvcResult.getResponse().getStatus()); // Test with no data - configServicesRepository.deleteAll(); + clearServicesData(); mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-status/").contentType(MediaType.APPLICATION_JSON).content("")) .andReturn(); assertEquals(404, mvcResult.getResponse().getStatus()); @@ -405,7 +417,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusPost() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); String content = readFileContent("src/test/resources/service1-servicestatus.json"); @@ -433,13 +445,13 @@ public class ConfigApiServicesControllerTest { assertEquals(409, mvcResult.getResponse().getStatus()); // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); } @Test public void configGENERICRESOURCEAPIservicesGENERICRESOURCEAPIserviceServiceInstanceIdGENERICRESOURCEAPIserviceStatusPut() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); String content = readFileContent("src/test/resources/service1-servicestatus.json"); @@ -467,13 +479,13 @@ public class ConfigApiServicesControllerTest { assertEquals(204, mvcResult.getResponse().getStatus()); // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); } @Test public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataServiceTopologyGet() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); // Test with data loadServicesData("src/test/resources/service1.json"); @@ -484,7 +496,7 @@ public class ConfigApiServicesControllerTest { assertEquals(200, mvcResult.getResponse().getStatus()); // Test with no data - configServicesRepository.deleteAll(); + clearServicesData(); mvcResult = mvc.perform(MockMvcRequestBuilders.get(CONFIG_SERVICES_SERVICE_URL+"service1/service-data/service-topology/").contentType(MediaType.APPLICATION_JSON).content("")) .andReturn(); assertEquals(404, mvcResult.getResponse().getStatus()); @@ -493,7 +505,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdDelete() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); // Test with no data MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.delete("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/").contentType(MediaType.APPLICATION_JSON).content("")) @@ -511,28 +523,28 @@ public class ConfigApiServicesControllerTest { assertEquals(204, mvcResult.getResponse().getStatus()); assertEquals(1, configServicesRepository.count()); - configServicesRepository.deleteAll(); + clearServicesData(); loadVnfData("src/test/resources/vnf-data.json"); assertEquals(1, configServicesRepository.count()); mvcResult = mvc.perform(MockMvcRequestBuilders.delete("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c/").contentType(MediaType.APPLICATION_JSON).content("")) .andReturn(); assertEquals(404, mvcResult.getResponse().getStatus()); - configServicesRepository.deleteAll(); + clearServicesData(); createBadVnfData(true, true); assertEquals(1, configServicesRepository.count()); mvcResult = mvc.perform(MockMvcRequestBuilders.delete("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/").contentType(MediaType.APPLICATION_JSON).content("")) .andReturn(); assertEquals(404, mvcResult.getResponse().getStatus()); - configServicesRepository.deleteAll(); + clearServicesData(); createBadVnfData(false, false); assertEquals(1, configServicesRepository.count()); mvcResult = mvc.perform(MockMvcRequestBuilders.delete("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/").contentType(MediaType.APPLICATION_JSON).content("")) .andReturn(); assertEquals(404, mvcResult.getResponse().getStatus()); - configServicesRepository.deleteAll(); + clearServicesData(); createBadVnfData(false, true); assertEquals(1, configServicesRepository.count()); mvcResult = mvc.perform(MockMvcRequestBuilders.delete("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/").contentType(MediaType.APPLICATION_JSON).content("")) @@ -543,7 +555,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdGet() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); // Test with no data MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/").contentType(MediaType.APPLICATION_JSON).content("")) @@ -560,7 +572,7 @@ public class ConfigApiServicesControllerTest { .andReturn(); assertEquals(200, mvcResult.getResponse().getStatus()); - configServicesRepository.deleteAll(); + clearServicesData(); createBadVnfData(false, false); assertEquals(1, configServicesRepository.count()); mvcResult = mvc.perform(MockMvcRequestBuilders.get("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/").contentType(MediaType.APPLICATION_JSON).content("")) @@ -571,7 +583,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdPut() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); assertEquals(0, configServicesRepository.count()); MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/").contentType(MediaType.APPLICATION_JSON).content(readFileContent("src/test/resources/vnf-data.json"))) .andReturn(); @@ -587,7 +599,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyGet() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); // Test with no data MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.get("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/vnf-data/vnf-topology/").contentType(MediaType.APPLICATION_JSON).content("")) @@ -604,7 +616,7 @@ public class ConfigApiServicesControllerTest { .andReturn(); assertEquals(200, mvcResult.getResponse().getStatus()); - configServicesRepository.deleteAll(); + clearServicesData(); createBadVnfData(false, false); assertEquals(1, configServicesRepository.count()); mvcResult = mvc.perform(MockMvcRequestBuilders.get("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/vnf-data/vnf-topology/").contentType(MediaType.APPLICATION_JSON).content("")) @@ -615,7 +627,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfLevelOperStatusPut() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); assertEquals(0, configServicesRepository.count()); MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/vnf-data/vnf-level-oper-status/").contentType(MediaType.APPLICATION_JSON).content(readFileContent("src/test/resources/vnf-level-oper-status.json"))) .andReturn(); @@ -631,7 +643,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyOnapModelInformationPut() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); assertEquals(0, configServicesRepository.count()); MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/vnf-data/vnf-topology/onap-model-information/").contentType(MediaType.APPLICATION_JSON).content(readFileContent("src/test/resources/vnf-onap-model-info.json"))) .andReturn(); @@ -647,7 +659,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksPut() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); assertEquals(0, configServicesRepository.count()); MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/vnf-data/vnf-topology/vnf-resource-assignments/vnf-networks/").contentType(MediaType.APPLICATION_JSON).content(readFileContent("src/test/resources/vnf-vnf-networks.json"))) .andReturn(); @@ -663,7 +675,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksVnfNetworkNetworkRolePut() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); assertEquals(0, configServicesRepository.count()); MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.put("/config/GENERIC-RESOURCE-API:services/service/test-siid/service-data/vnfs/vnf/2a3bfc93-cd4c-4845-8919-434b2d999ada/vnf-data/vnf-topology/vnf-resource-assignments/vnf-networks/vnf-network/test-network-role/").contentType(MediaType.APPLICATION_JSON).content(readFileContent("src/test/resources/vnf-vnf-networks-network-role.json"))) .andReturn(); @@ -882,7 +894,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdPut() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); String content = readFileContent("src/test/resources/service1-vfmodule-item.json"); @@ -898,17 +910,17 @@ public class ConfigApiServicesControllerTest { 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(204, mvcResult.getResponse().getStatus()); assertEquals(1, configServicesRepository.count()); // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); } @Test public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdDelete() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); // 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/") @@ -931,7 +943,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdGet() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); // Test with data loadServicesData("src/test/resources/service1.json"); @@ -949,7 +961,7 @@ public class ConfigApiServicesControllerTest { assertEquals(404, mvcResult.getResponse().getStatus()); // Test with no data - configServicesRepository.deleteAll(); + clearServicesData(); 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(); @@ -959,7 +971,7 @@ public class ConfigApiServicesControllerTest { @Test public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdVfModuleDataVfModuleTopologyGet() throws Exception { // Clean up data - configServicesRepository.deleteAll(); + clearServicesData(); // Test with data loadServicesData("src/test/resources/service1.json"); @@ -970,13 +982,13 @@ public class ConfigApiServicesControllerTest { assertEquals(200, mvcResult.getResponse().getStatus()); // Test with existing service and vnf but with dummy vf-module-id in input - configServicesRepository.deleteAll(); + clearServicesData(); 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(); + clearServicesData(); 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()); @@ -992,6 +1004,13 @@ public class ConfigApiServicesControllerTest { .andReturn(); } + private void clearServicesData() { + configServicesRepository.deleteAll(); + configNetworksRepository.deleteAll(); + configVnfsRepository.deleteAll(); + configVfModulesRepository.deleteAll(); + } + private void loadServicesData(String path) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); String content = readFileContent(path); @@ -1000,24 +1019,19 @@ public class ConfigApiServicesControllerTest { for (GenericResourceApiServicemodelinfrastructureService service : services.getService()) { ConfigServices newService = new ConfigServices(); newService.setSvcInstanceId(service.getServiceInstanceId()); - newService.setSvcData(objectMapper.writeValueAsString(service.getServiceData())); newService.setServiceStatus(service.getServiceStatus()); - configServicesRepository.save(newService); + serviceDataHelper.saveService(newService, service.getServiceData()); } } private void loadVnfData(String path) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); String content = readFileContent(path); - GenericResourceApiServicedataServiceData svcData = new GenericResourceApiServicedataServiceData(); GenericResourceApiServicedataServicedataVnfsVnf vnfData = objectMapper.readValue(content, GenericResourceApiServicedataServicedataVnfsVnf.class); - svcData.setVnfs(new GenericResourceApiServicedataServicedataVnfs()); - svcData.getVnfs().setVnf(new ArrayList<>()); - svcData.getVnfs().addVnfItem(vnfData); - ConfigServices newService = new ConfigServices(); - newService.setSvcData(objectMapper.writeValueAsString(svcData)); - newService.setSvcInstanceId("test-siid"); + String svcInstanceId = "test-siid"; + ConfigServices newService = new ConfigServices(svcInstanceId); configServicesRepository.save(newService); + serviceDataHelper.saveVnf(svcInstanceId, vnfData, null); } private void createBadVnfData(boolean useNullSvc, boolean useNullVnfs) throws IOException { diff --git a/ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/OperationsApiControllerTest.java b/ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/OperationsApiControllerTest.java index 3c79e1d..6752d8c 100644 --- a/ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/OperationsApiControllerTest.java +++ b/ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/OperationsApiControllerTest.java @@ -52,6 +52,15 @@ public class OperationsApiControllerTest { ConfigServicesRepository configServicesRepository; @Autowired + ConfigNetworksRepository configNetworksRepository; + + @Autowired + ConfigVnfsRepository configVnfsRepository; + + @Autowired + ConfigVfModulesRepository configVfModulesRepository; + + @Autowired OperationalServicesRepository operationalServicesRepository; @Autowired @@ -63,6 +72,9 @@ public class OperationsApiControllerTest { @Autowired OperationalPortMirrorConfigurationsRepository operationalPortMirrorConfigurationsRepository; + @Autowired + ServiceDataHelper serviceDataHelper; + @BeforeClass public static void setUp() throws Exception { System.out.println("OperationsApiControllerTest: Setting serviceLogicProperties, serviceLogicDirectory and sdnc.config.dir"); @@ -119,7 +131,7 @@ public class OperationsApiControllerTest { public void operationsGENERICRESOURCEAPIserviceTopologyOperationAssignPost() throws Exception { // Remove any existing service data - configServicesRepository.deleteAll(); + clearServicesData(); operationalServicesRepository.deleteAll(); // Add invalid content @@ -141,14 +153,14 @@ public class OperationsApiControllerTest { @Test public void serviceTopologyOperationAsync() throws Exception { - configServicesRepository.deleteAll(); + clearServicesData(); GenericResourceApiVnfOperationInformationBodyparam inputParam = operationsApiController.getObjectMapper().get().readValue(readFileContent("src/test/resources/vnf-assign-rpc.json"), GenericResourceApiVnfOperationInformationBodyparam.class); operationsApiController.processAsyncVnfTopologyOperation("vnf-topology-operation",inputParam); loadVnfData("src/test/resources/vnf-data.json"); inputParam.getInput().getServiceInformation().setServiceInstanceId("98f189dd-2971-46f5-b4f1-1a9a323f39a4"); operationsApiController.processAsyncVnfTopologyOperation("vnf-topology-operation",inputParam); - configServicesRepository.deleteAll(); + clearServicesData(); } private void loadVnfData(String path) throws IOException { @@ -172,7 +184,7 @@ public class OperationsApiControllerTest { System.setProperty("serviceLogicDirectory", "src/test/resources/svclogic"); System.setProperty("sdnc.config.dir", "src/test/resources"); // Remove any existing service data - configServicesRepository.deleteAll(); + clearServicesData(); operationalServicesRepository.deleteAll(); // Load services data @@ -196,7 +208,7 @@ public class OperationsApiControllerTest { public void operationsGENERICRESOURCEAPIvnfTopologyOperationAssignPost() throws Exception { // Remove any existing service data - configServicesRepository.deleteAll(); + clearServicesData(); operationalServicesRepository.deleteAll(); // Load services data @@ -217,14 +229,22 @@ public class OperationsApiControllerTest { } @Test - public void operationsGENERICRESOURCEAPIvfModuleTopologyOperationAssignPost() throws Exception { + public void operationsGENERICRESOURCEAPIvfModuleTopologyOperationPost() throws Exception { // Remove any existing service data - configServicesRepository.deleteAll(); + clearServicesData(); operationalServicesRepository.deleteAll(); + assertEquals(0, configServicesRepository.count()); + assertEquals(0, configNetworksRepository.count()); + assertEquals(0, configVnfsRepository.count()); + assertEquals(0, configVfModulesRepository.count()); // Load services data - loadServicesData("src/test/resources/service1.json"); + loadServicesData("src/test/resources/service1-service_vnf.json"); + assertEquals(1, configServicesRepository.count()); + assertEquals(0, configNetworksRepository.count()); + assertEquals(1, configVnfsRepository.count()); + assertEquals(0, configVfModulesRepository.count()); // Add invalid content String content = readFileContent("src/test/resources/preload1-rpc-vfmodule.json"); @@ -237,9 +257,24 @@ public class OperationsApiControllerTest { mvcResult = mvc.perform(MockMvcRequestBuilders.post(VF_MODULE_TOPOLOGY_URL).contentType(MediaType.APPLICATION_JSON).content(content)) .andReturn(); assertEquals(200, mvcResult.getResponse().getStatus()); + assertEquals(1, configServicesRepository.count()); + assertEquals(0, configNetworksRepository.count()); + assertEquals(1, configVnfsRepository.count()); + assertEquals(1, configVfModulesRepository.count()); + + // Delete content + content = readFileContent("src/test/resources/vf-module-unassign-rpc.json"); + mvcResult = mvc.perform(MockMvcRequestBuilders.post(VF_MODULE_TOPOLOGY_URL).contentType(MediaType.APPLICATION_JSON).content(content)) + .andReturn(); + assertEquals(200, mvcResult.getResponse().getStatus()); + assertEquals(1, configServicesRepository.count()); + assertEquals(0, configNetworksRepository.count()); + assertEquals(1, configVnfsRepository.count()); + assertEquals(0, configVfModulesRepository.count()); } + @Test public void operationsGENERICRESOURCEAPIportMirrorConfigurationTopologyOperationAssignPost() throws Exception { @@ -271,7 +306,7 @@ public class OperationsApiControllerTest { public void operationsGENERICRESOURCEAPIvnfGetResourceRequestPost() throws Exception { // Remove any existing service data - configServicesRepository.deleteAll(); + clearServicesData(); operationalServicesRepository.deleteAll(); // Load services data @@ -305,9 +340,8 @@ public class OperationsApiControllerTest { for (GenericResourceApiServicemodelinfrastructureService service : services.getService()) { ConfigServices newService = new ConfigServices(); newService.setSvcInstanceId(service.getServiceInstanceId()); - newService.setSvcData(objectMapper.writeValueAsString(service.getServiceData())); newService.setServiceStatus(service.getServiceStatus()); - configServicesRepository.save(newService); + serviceDataHelper.saveService(newService, service.getServiceData()); } } @@ -325,6 +359,13 @@ public class OperationsApiControllerTest { } } + private void clearServicesData() { + configServicesRepository.deleteAll(); + configNetworksRepository.deleteAll(); + configVnfsRepository.deleteAll(); + configVfModulesRepository.deleteAll(); + } + private String readFileContent(String path) throws IOException { String content = new String(Files.readAllBytes(Paths.get(path))); return content; |