From db82751c50a962ff3d731b89837f747aac71d72f Mon Sep 17 00:00:00 2001 From: David Stilwell Date: Thu, 19 Nov 2020 16:56:21 -0500 Subject: add support for service-toplogy GET Changes made: 1. add method for ServiceTopologyGet(), added junit test case Issue-ID: SDNC-1422 Change-Id: I770ff1fe9dbab7b06c2df4eb24d3e39eb3fa5cc9 Signed-off-by: David Stilwell --- .../ms/gra/controllers/ConfigApiController.java | 29 ++++++++++++++++++++++ .../ConfigApiServicesControllerTest.java | 20 +++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'ms/generic-resource-api') diff --git a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiController.java b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiController.java index 26b6dcf..581f0c7 100644 --- a/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiController.java +++ b/ms/generic-resource-api/src/main/java/org/onap/sdnc/apps/ms/gra/controllers/ConfigApiController.java @@ -1502,4 +1502,33 @@ public class ConfigApiController implements ConfigApi { .filter(targetVnf -> targetVnf.getVnfId().equals(vnfId)) .findFirst(); } + + @Override + public ResponseEntity configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataServiceTopologyGet(String serviceInstanceId) throws RestApplicationException, RestProtocolException { + GenericResourceApiServicetopologyServiceTopology serviceTopology = null; + GenericResourceApiServicedataServiceData serviceData = null; + + List services = configServicesRepository.findBySvcInstanceId(serviceInstanceId); + if ((services == null) || (services.isEmpty())) { + throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value()); + } + + try { + if ( services.get(0).getSvcData().isEmpty()) { + throw new RestProtocolException("data-missing", "No service-data entry found", HttpStatus.NOT_FOUND.value()); + } else { + serviceData = objectMapper.readValue(services.get(0).getSvcData(), GenericResourceApiServicedataServiceData.class); + serviceTopology = serviceData.getServiceTopology(); + } + if (serviceTopology == null) { + throw new RestProtocolException("data-missing", "No service-topology entry found", HttpStatus.NOT_FOUND.value()); + } + return new ResponseEntity<>(serviceTopology, HttpStatus.OK); + } catch (JsonProcessingException e) { + log.error("Could not parse service data", e); + throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value()); + } + + } + } 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 7bcfefe..b9ec3de 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 @@ -463,6 +463,26 @@ public class ConfigApiServicesControllerTest { configServicesRepository.deleteAll(); } + @Test + public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataServiceTopologyGet() 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/service-topology/").contentType(MediaType.APPLICATION_JSON).content("")) + .andReturn(); + assertEquals(200, mvcResult.getResponse().getStatus()); + + // Test with no data + configServicesRepository.deleteAll(); + 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()); + } + @Test public void configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdDelete() throws Exception { // Clean up data -- cgit 1.2.3-korg