summaryrefslogtreecommitdiffstats
path: root/ms/generic-resource-api/src/test/java
diff options
context:
space:
mode:
authorCheung, Pat (kc1472) <kc1472@att.com>2021-01-11 22:37:56 +0000
committerCheung, Pat (kc1472) <kc1472@att.com>2021-01-11 22:37:56 +0000
commite71c86c428806b55076c1687bb180176f87e6a23 (patch)
tree20503887e1d42ade76d279dc3ec5a46321a8f174 /ms/generic-resource-api/src/test/java
parent32ce2c60bd58043c18d87f7b14427aa573e700f6 (diff)
sdnc-apps update
Fixing delete operation issue and add junit config and operation tests Issue-ID: SDNC-1429 Signed-off-by: Cheung, Pat (kc1472) <kc1472@att.com> Change-Id: I2e72db0db899ca52cbfd7910d8fb55be4cf05749
Diffstat (limited to 'ms/generic-resource-api/src/test/java')
-rw-r--r--ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiServicesControllerTest.java345
-rw-r--r--ms/generic-resource-api/src/test/java/org/onap/sdnc/apps/ms/gra/controllers/OperationsApiControllerTest.java109
2 files changed, 448 insertions, 6 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
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 60dc811..3d24b22 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
@@ -13,10 +13,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.ConfigPreloadDataRepository;
-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.OperationalServicesRepository;
+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;
@@ -39,6 +36,10 @@ public class OperationsApiControllerTest {
private final static String SERVICE_TOPOLOGY_URL = "/operations/GENERIC-RESOURCE-API:service-topology-operation/";
private final static String NETWORK_TOPOLOGY_URL = "/operations/GENERIC-RESOURCE-API:network-topology-operation/";
private final static String VNF_TOPOLOGY_URL = "/operations/GENERIC-RESOURCE-API:vnf-topology-operation/";
+ private final static String VF_MODULE_TOPOLOGY_URL = "/operations/GENERIC-RESOURCE-API:vf-module-topology-operation/";
+ private final static String PORT_MIRROR_TOPOLOGY_URL = "/operations/GENERIC-RESOURCE-API:port-mirror-topology-operation/";
+ private final static String VNF_GET_RESOURCE_REQUEST_URL = "/operations/GENERIC-RESOURCE-API:vnf-get-resource-request/";
+ private final static String POLICY_UPDATE_NOTIFY_URL = "/operations/GENERIC-RESOURCE-API:policy-update-notify-operation/";
@Autowired
@@ -56,6 +57,12 @@ public class OperationsApiControllerTest {
@Autowired
OperationsApiController operationsApiController;
+ @Autowired
+ ConfigPortMirrorConfigurationsRepository configPortMirrorConfigurationsRepository;
+
+ @Autowired
+ OperationalPortMirrorConfigurationsRepository operationalPortMirrorConfigurationsRepository;
+
@BeforeClass
public static void setUp() throws Exception {
System.out.println("OperationsApiControllerTest: Setting serviceLogicProperties, serviceLogicDirectory and sdnc.config.dir");
@@ -206,6 +213,86 @@ public class OperationsApiControllerTest {
}
+ @Test
+ public void operationsGENERICRESOURCEAPIvfModuleTopologyOperationAssignPost() throws Exception {
+
+ // Remove any existing service data
+ configServicesRepository.deleteAll();
+ operationalServicesRepository.deleteAll();
+
+ // Load services data
+ loadServicesData("src/test/resources/service1.json");
+
+ // Add invalid content
+ String content = readFileContent("src/test/resources/preload1-rpc-vfmodule.json");
+ MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(VF_MODULE_TOPOLOGY_URL).contentType(MediaType.APPLICATION_JSON).content(content))
+ .andReturn();
+ assertEquals(200, mvcResult.getResponse().getStatus());
+
+ // Add valid content
+ content = readFileContent("src/test/resources/vf-module-assign-rpc.json");
+ mvcResult = mvc.perform(MockMvcRequestBuilders.post(VF_MODULE_TOPOLOGY_URL).contentType(MediaType.APPLICATION_JSON).content(content))
+ .andReturn();
+ assertEquals(200, mvcResult.getResponse().getStatus());
+
+ }
+
+ @Test
+ public void operationsGENERICRESOURCEAPIportMirrorConfigurationTopologyOperationAssignPost() throws Exception {
+
+ // Remove any existing service data
+ configPortMirrorConfigurationsRepository.deleteAll();
+ operationalPortMirrorConfigurationsRepository.deleteAll();
+
+ // Load port-mirror-configuration data
+ loadPortMirrorConfigurationData("src/test/resources/port-mirror-configuration-1.json");
+
+ // Load services data
+ loadServicesData("src/test/resources/service1.json");
+
+ // Add invalid content for request input
+ String content = readFileContent("src/test/resources/preload1-rpc-vfmodule.json");
+ MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(PORT_MIRROR_TOPOLOGY_URL).contentType(MediaType.APPLICATION_JSON).content(content))
+ .andReturn();
+ assertEquals(200, mvcResult.getResponse().getStatus());
+
+ // Add valid content
+ content = readFileContent("src/test/resources/port-mirror-assign-rpc.json");
+ mvcResult = mvc.perform(MockMvcRequestBuilders.post(PORT_MIRROR_TOPOLOGY_URL).contentType(MediaType.APPLICATION_JSON).content(content))
+ .andReturn();
+ assertEquals(200, mvcResult.getResponse().getStatus());
+
+ }
+
+ @Test
+ public void operationsGENERICRESOURCEAPIvnfGetResourceRequestPost() throws Exception {
+
+ // Remove any existing service data
+ configServicesRepository.deleteAll();
+ operationalServicesRepository.deleteAll();
+
+ // Load services data
+ loadServicesData("src/test/resources/service9.json");
+
+ // Add valid content
+ String content = readFileContent("src/test/resources/vnf-get-resource-request-rpc.json");
+ String expected = readFileContent("src/test/resources/vnf-get-resource-request-expected.json");
+ MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(VNF_GET_RESOURCE_REQUEST_URL).contentType(MediaType.APPLICATION_JSON).content(content))
+ .andReturn();
+ assertEquals(200, mvcResult.getResponse().getStatus());
+ assertEquals(expected, mvcResult.getResponse().getContentAsString());
+
+ }
+ @Test
+ public void operationsGENERICRESOURCEAPIpolicyUpdateNotifyOperationPost() throws Exception {
+
+ // Add valid content
+ String content = readFileContent("src/test/resources/policy-update-notify-rpc.json");
+ MvcResult mvcResult = mvc.perform(MockMvcRequestBuilders.post(POLICY_UPDATE_NOTIFY_URL).contentType(MediaType.APPLICATION_JSON).content(content))
+ .andReturn();
+ assertEquals(200, mvcResult.getResponse().getStatus());
+ }
+
private void loadServicesData(String path) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
@@ -221,6 +308,20 @@ public class OperationsApiControllerTest {
}
}
+ 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);
+ }
+ }
+
private String readFileContent(String path) throws IOException {
String content = new String(Files.readAllBytes(Paths.get(path)));
return content;