aboutsummaryrefslogtreecommitdiffstats
path: root/plans/so/integration-etsi-testing
diff options
context:
space:
mode:
authorwaqas.ikram <waqas.ikram@est.tech>2019-09-18 15:35:57 +0100
committerwaqas.ikram <waqas.ikram@est.tech>2019-09-18 15:35:59 +0100
commit8282312472138e981081b2239576ac3e75bce76e (patch)
treeae12f1c477572c660610a63a087f041dafba1f7f /plans/so/integration-etsi-testing
parentb8cb5a9d750d2bfeec274d1f955b73997a56bd52 (diff)
Adding delete endpoint for vnf
Change-Id: If982dcf160096329df2918a38afc41ee3f322085 Issue-ID: SO-2342 Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
Diffstat (limited to 'plans/so/integration-etsi-testing')
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/GenericVnfsController.java18
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java2
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java16
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java18
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestRestTemplateService.java5
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/OperationsController.java19
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProvider.java2
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java75
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/utils/ObjectUtils.java2
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java57
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/TestUtils.java6
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/deleteVnfInput.json46
12 files changed, 250 insertions, 16 deletions
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/GenericVnfsController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/GenericVnfsController.java
index 64284b5f..43fe47da 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/GenericVnfsController.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/GenericVnfsController.java
@@ -45,6 +45,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@@ -194,4 +195,21 @@ public class GenericVnfsController {
return ResponseEntity.ok(genericVnfs);
}
+ @DeleteMapping(value = "/generic-vnf/{vnf-id}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public ResponseEntity<?> deleteGenericVnf(@PathVariable("vnf-id") final String vnfId,
+ @RequestParam(name = "resource-version") final String resourceVersion, final HttpServletRequest request) {
+ LOGGER.info("Will delete GenericVnf for 'vnf-id': {} and 'resource-version': {}", vnfId, resourceVersion);
+
+ if (cacheServiceProvider.deleteGenericVnf(vnfId, resourceVersion)) {
+ LOGGER.info("Successfully delete GenericVnf from cache for 'vnf-id': {} and 'resource-version': {}", vnfId,
+ resourceVersion);
+ return ResponseEntity.noContent().build();
+ }
+
+ LOGGER.error("Unable to delete GenericVnf for 'vnf-id': {} and 'resource-version': {} ...", vnfId,
+ resourceVersion);
+ return getRequestErrorResponseEntity(request, GENERIC_VNF);
+
+ }
+
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java
index 8dd19cfa..901c2594 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java
@@ -47,5 +47,7 @@ public interface GenericVnfCacheServiceProvider extends Clearable {
List<GenericVnf> getGenericVnfs(final String selflink);
+ boolean deleteGenericVnf(final String vnfId, final String resourceVersion);
+
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java
index 81a74f25..3a12dfdc 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java
@@ -214,6 +214,22 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv
return Collections.emptyList();
}
+ @Override
+ public boolean deleteGenericVnf(final String vnfId, final String resourceVersion) {
+ final Optional<GenericVnf> optional = getGenericVnf(vnfId);
+ if (optional.isPresent()) {
+ final GenericVnf genericVnf = optional.get();
+ if (genericVnf.getResourceVersion() != null && genericVnf.getResourceVersion().equals(resourceVersion)) {
+ final Cache cache = getCache(GENERIC_VNF_CACHE.getName());
+ LOGGER.info("Will evict GenericVnf from cache with vnfId: {}", genericVnf.getVnfId());
+ cache.evict(vnfId);
+ return true;
+ }
+ }
+ LOGGER.error("Unable to find GenericVnf for vnfId: {} and resourceVersion: {} ...", vnfId, resourceVersion);
+ return false;
+ }
+
private Relationship getRelationship(final String relatedLink, final GenericVnf genericVnf) {
final Relationship relationShip = new Relationship();
relationShip.setRelatedTo(GENERIC_VNF);
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java
index dd749db4..711dcd11 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java
@@ -389,6 +389,24 @@ public class GenericVnfsControllerTest extends AbstractSpringBootTest {
assertEquals(VNF_ID, actualGenericVnf.getVnfId());
}
+ @Test
+ public void test_deleteGenericVnf_usingVnfIdAndResourceVersion_removedFromCache() throws Exception {
+
+ addCustomerServiceAndGenericVnf();
+
+ final Optional<GenericVnf> genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID);
+ assertTrue(genericVnfOptional.isPresent());
+ final GenericVnf genericVnf = genericVnfOptional.get();
+
+ final String genericVnfDeleteUrl =
+ getUrl(GENERIC_VNF_URL, genericVnf.getVnfId()) + "?resource-version=" + genericVnf.getResourceVersion();
+
+ final ResponseEntity<Void> responseEntity =
+ testRestTemplateService.invokeHttpDelete(genericVnfDeleteUrl, Void.class);
+ assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode());
+
+ }
+
private void addCustomerServiceAndGenericVnf() throws Exception, IOException {
final ResponseEntity<Void> customerResponse =
testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer(), Void.class);
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestRestTemplateService.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestRestTemplateService.java
index 018c056a..e49e6d49 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestRestTemplateService.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestRestTemplateService.java
@@ -52,6 +52,11 @@ public class TestRestTemplateService {
return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, clazz);
}
+ public <T> ResponseEntity<T> invokeHttpDelete(final String url, final Class<T> clazz) {
+ final HttpEntity<?> request = new HttpEntity<>(getHttpHeaders());
+ return restTemplate.exchange(url, HttpMethod.DELETE, request, clazz);
+ }
+
public <T> ResponseEntity<T> invokeHttpPost(final String url, final Object obj, final Class<T> clazz) {
final HttpEntity<?> httpEntity = getHttpEntity(obj);
return restTemplate.exchange(url, HttpMethod.POST, httpEntity, clazz);
diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/OperationsController.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/OperationsController.java
index 2d901c42..88970e74 100644
--- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/OperationsController.java
+++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/OperationsController.java
@@ -19,9 +19,12 @@
*/
package org.onap.so.sdncsimulator.controller;
+import static org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration.DELETEVNFINSTANCE;
import static org.onap.so.sdncsimulator.utils.Constants.OPERATIONS_URL;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.MediaType;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
+import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestinformationRequestInformation;
import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
import org.onap.so.sdncsimulator.models.InputRequest;
@@ -96,7 +99,8 @@ public class OperationsController {
return ResponseEntity.badRequest().build();
}
- final Output output = cacheServiceProvider.putVnfOperationInformation(apiVnfOperationInformation);
+ final Output output = getOutput(apiVnfOperationInformation);
+
final OutputRequest outputRequest = new OutputRequest(output);
if (output.getResponseCode().equals(HttpStatus.OK.toString())) {
@@ -109,4 +113,17 @@ public class OperationsController {
}
+ private Output getOutput(final GenericResourceApiVnfOperationInformation apiVnfOperationInformation) {
+ final GenericResourceApiRequestinformationRequestInformation requestInformation =
+ apiVnfOperationInformation.getRequestInformation();
+ if (requestInformation != null) {
+ final GenericResourceApiRequestActionEnumeration requestAction = requestInformation.getRequestAction();
+ if (DELETEVNFINSTANCE.equals(requestAction)) {
+ LOGGER.info("RequestAction: {} will delete vnf instance from cache ...", requestAction);
+ return cacheServiceProvider.deleteVnfOperationInformation(apiVnfOperationInformation);
+ }
+ }
+ return cacheServiceProvider.putVnfOperationInformation(apiVnfOperationInformation);
+ }
+
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProvider.java
index 97dc7b11..5b32b91f 100644
--- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProvider.java
+++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProvider.java
@@ -39,6 +39,8 @@ public interface ServiceOperationsCacheServiceProvider {
Output putVnfOperationInformation(final GenericResourceApiVnfOperationInformation apiVnfOperationInformation);
+ Output deleteVnfOperationInformation(final GenericResourceApiVnfOperationInformation apiVnfOperationInformation);
+
void clearAll();
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java
index d5e991a8..616a56c4 100644
--- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java
+++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java
@@ -78,6 +78,7 @@ import org.springframework.stereotype.Service;
public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServiceProvider
implements ServiceOperationsCacheServiceProvider {
+ private static final String EMPTY_STRING = "";
private static final Logger LOGGER = LoggerFactory.getLogger(ServiceOperationsCacheServiceProviderimpl.class);
@Autowired
@@ -89,7 +90,7 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ
public Output putServiceOperationInformation(final GenericResourceApiServiceOperationInformation input) {
final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
- final String svcRequestId = requestHeader != null ? requestHeader.getSvcRequestId() : null;
+ final String svcRequestId = getSvcRequestId(requestHeader);
final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId())) {
@@ -140,7 +141,7 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ
final GenericResourceApiVnfinformationVnfInformation vnfInformation = input.getVnfInformation();
final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
- final String svcRequestId = requestHeader != null ? requestHeader.getSvcRequestId() : null;
+ final String svcRequestId = getSvcRequestId(requestHeader);
if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null
&& isValid(vnfInformation.getVnfId())) {
@@ -187,6 +188,55 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ
}
@Override
+ public Output deleteVnfOperationInformation(final GenericResourceApiVnfOperationInformation input) {
+ final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
+ final GenericResourceApiVnfinformationVnfInformation vnfInformation = input.getVnfInformation();
+
+ final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
+ final String svcRequestId = getSvcRequestId(requestHeader);
+
+ if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null
+ && isValid(vnfInformation.getVnfId())) {
+ final String serviceInstanceId = serviceInformation.getServiceInstanceId();
+ final String vnfId = vnfInformation.getVnfId();
+ final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
+ getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
+ if (optional.isPresent()) {
+ final GenericResourceApiServicemodelinfrastructureService service = optional.get();
+ final GenericResourceApiServicedataServiceData serviceData = service.getServiceData();
+ if (serviceData != null) {
+ final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = getVnfs(serviceData);
+ final Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfInstanceOptional =
+ getExistingVnf(vnfId, vnfsList);
+
+ if (vnfInstanceOptional.isPresent()) {
+ vnfsList.removeIf(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId));
+
+ return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.OK.toString())
+ .responseMessage(EMPTY_STRING).svcRequestId(svcRequestId)
+ .serviceResponseInformation(
+ new GenericResourceApiInstanceReference().instanceId(serviceInstanceId))
+ .vnfResponseInformation(new GenericResourceApiInstanceReference().instanceId(vnfId));
+ }
+
+ }
+ }
+ LOGGER.error(
+ "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
+ serviceInstanceId);
+
+ }
+ LOGGER.error("Unable to remove vnf instance from cache due to invalid input: {}... ", input);
+ return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString())
+ .responseMessage("Unable to remove vnf").svcRequestId(svcRequestId);
+
+ }
+
+ private String getSvcRequestId(final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader) {
+ return requestHeader != null ? requestHeader.getSvcRequestId() : null;
+ }
+
+ @Override
public void clearAll() {
clearCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
}
@@ -228,9 +278,7 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ
private Optional<GenericResourceApiServicedataServicedataVnfsVnf> getExistingVnf(final String vnfId,
final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList) {
- final Optional<GenericResourceApiServicedataServicedataVnfsVnf> optional =
- vnfsList.stream().filter(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId)).findFirst();
- return optional;
+ return vnfsList.stream().filter(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId)).findFirst();
}
private List<GenericResourceApiServicedataServicedataVnfsVnf> getVnfs(
@@ -313,17 +361,13 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ
apiServicedataServiceData.serviceLevelOperStatus(getServiceLevelOperStatus(input));
final GenericResourceApiServicestatusServiceStatus serviceStatus =
- getServiceStatus(getSvcAction(input.getSdncRequestHeader()), getAction(input.getRequestInformation()),
- HttpStatus.OK.toString());
+ getServiceStatus(getSvcAction(input.getSdncRequestHeader()),
+ getRequestAction(input.getRequestInformation()), HttpStatus.OK.toString());
return new GenericResourceApiServicemodelinfrastructureService().serviceData(apiServicedataServiceData)
.serviceStatus(serviceStatus).serviceInstanceId(serviceInstanceId);
}
- private String getAction(final GenericResourceApiRequestinformationRequestInformation input) {
- return getString(input.getRequestAction(), "");
- }
-
private String getSvcAction(final GenericResourceApiSdncrequestheaderSdncRequestHeader input) {
return input != null ? getStringOrNull(input.getSvcAction()) : null;
}
@@ -333,7 +377,7 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ
return new GenericResourceApiServicestatusServiceStatus().finalIndicator(YES)
.rpcAction(GenericResourceApiRpcActionEnumeration.fromValue(rpcAction))
.rpcName(SERVICE_TOPOLOGY_OPERATION).responseTimestamp(LocalDateTime.now().toString())
- .responseCode(responseCode).requestStatus(SYNCCOMPLETE).responseMessage("").action(action);
+ .responseCode(responseCode).requestStatus(SYNCCOMPLETE).responseMessage(EMPTY_STRING).action(action);
}
private GenericResourceApiOperStatusData getServiceLevelOperStatus(
@@ -351,7 +395,12 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ
}
private String getRequestAction(final GenericResourceApiRequestinformationRequestInformation input) {
- return input != null ? getStringOrNull(input.getRequestAction()) : null;
+ return getRequestAction(input, EMPTY_STRING);
+ }
+
+ private String getRequestAction(final GenericResourceApiRequestinformationRequestInformation input,
+ final String defaultValue) {
+ return input != null ? getString(input.getRequestAction(), defaultValue) : defaultValue;
}
private GenericResourceApiServicetopologyServiceTopology getServiceTopology(
diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/utils/ObjectUtils.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/utils/ObjectUtils.java
index 833da414..b4d6da38 100644
--- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/utils/ObjectUtils.java
+++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/utils/ObjectUtils.java
@@ -33,7 +33,7 @@ public class ObjectUtils {
return getString(obj, null);
}
- public static String getString(final Object obj, String defaultValue) {
+ public static String getString(final Object obj, final String defaultValue) {
return obj != null ? obj.toString() : defaultValue;
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java
index b1ede082..a338283c 100644
--- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java
+++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java
@@ -20,11 +20,13 @@
package org.onap.so.sdncsimulator.controller;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.onap.so.sdncsimulator.controller.TestUtils.getInvalidRequestInput;
import static org.onap.so.sdncsimulator.controller.TestUtils.getRequestInput;
import static org.onap.so.sdncsimulator.controller.TestUtils.getVnfRequestInput;
+import static org.onap.so.sdncsimulator.controller.TestUtils.getVnfRequestWithRequestActionDeleteVnfInput;
import static org.onap.so.sdncsimulator.controller.TestUtils.getVnfRequestWithSvcActionActivateInput;
import java.util.Optional;
import org.junit.After;
@@ -306,6 +308,61 @@ public class OperationsControllerTest {
}
+ @Test
+ public void test_postVnfOperationInformation_successfullyRemoveVnfFromExistingServiceInCache() throws Exception {
+ final HttpEntity<?> httpEntity = new HttpEntity<>(getRequestInput(), getHttpHeaders());
+ final ResponseEntity<OutputRequest> responseEntity =
+ restTemplate.exchange(getUrl(), HttpMethod.POST, httpEntity, OutputRequest.class);
+
+ assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
+
+ final HttpEntity<?> httpAddVnfEntity = new HttpEntity<>(getVnfRequestInput(), getHttpHeaders());
+ final ResponseEntity<OutputRequest> responseAddVnfEntity =
+ restTemplate.exchange(getVnfUrl(), HttpMethod.POST, httpAddVnfEntity, OutputRequest.class);
+ assertEquals(HttpStatus.OK, responseAddVnfEntity.getStatusCode());
+
+ Optional<GenericResourceApiServicemodelinfrastructureService> serviceOptional =
+ cacheServiceProvider.getGenericResourceApiServicemodelinfrastructureService(SERVICE_INSTANCE_ID);
+ assertTrue(serviceOptional.isPresent());
+
+ GenericResourceApiServicemodelinfrastructureService service = serviceOptional.get();
+ assertNotNull(service.getServiceInstanceId());
+ assertNotNull(service.getServiceData().getVnfs().getVnf());
+ assertNotNull(service.getServiceData());
+ assertNotNull(service.getServiceData().getVnfs());
+ assertNotNull(service.getServiceData().getVnfs().getVnf());
+ assertFalse(service.getServiceData().getVnfs().getVnf().isEmpty());
+
+ final HttpEntity<?> httpRemoveVnfEntity =
+ new HttpEntity<>(getVnfRequestWithRequestActionDeleteVnfInput(), getHttpHeaders());
+ final ResponseEntity<OutputRequest> responseRemoveVnfEntity =
+ restTemplate.exchange(getVnfUrl(), HttpMethod.POST, httpRemoveVnfEntity, OutputRequest.class);
+ assertEquals(HttpStatus.OK, responseRemoveVnfEntity.getStatusCode());
+
+ final OutputRequest actualOutputRequest = responseRemoveVnfEntity.getBody();
+ assertNotNull(actualOutputRequest);
+ assertNotNull(actualOutputRequest.getOutput());
+
+ final Output actualObject = actualOutputRequest.getOutput();
+
+ assertEquals(HttpStatus.OK.toString(), actualObject.getResponseCode());
+ assertEquals(Constants.YES, actualObject.getAckFinalIndicator());
+ assertEquals(VNF_SVC_REQUEST_ID, actualObject.getSvcRequestId());
+
+ serviceOptional =
+ cacheServiceProvider.getGenericResourceApiServicemodelinfrastructureService(SERVICE_INSTANCE_ID);
+ assertTrue(serviceOptional.isPresent());
+
+ service = serviceOptional.get();
+ assertNotNull(service.getServiceInstanceId());
+ assertNotNull(service.getServiceData().getVnfs().getVnf());
+ assertNotNull(service.getServiceData());
+ assertNotNull(service.getServiceData().getVnfs());
+ assertNotNull(service.getServiceData().getVnfs().getVnf());
+ assertTrue(service.getServiceData().getVnfs().getVnf().isEmpty());
+
+
+ }
private HttpHeaders getHttpHeaders() {
return TestUtils.getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername());
diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/TestUtils.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/TestUtils.java
index 220ec7d3..b43ecf4c 100644
--- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/TestUtils.java
+++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/TestUtils.java
@@ -45,7 +45,7 @@ public class TestUtils {
public static String getVnfRequestInput() throws IOException {
return getFileAsString(getFile("test-data/vnfInput.json").toPath());
}
-
+
public static String getVnfRequestWithSvcActionActivateInput() throws IOException {
return getFileAsString(getFile("test-data/activateVnfInput.json").toPath());
}
@@ -54,6 +54,10 @@ public class TestUtils {
return getFileAsString(getFile("test-data/InvalidInput.json").toPath());
}
+ public static String getVnfRequestWithRequestActionDeleteVnfInput() throws IOException {
+ return getFileAsString(getFile("test-data/deleteVnfInput.json").toPath());
+ }
+
public static String getFileAsString(final Path path) throws IOException {
return new String(Files.readAllBytes(path));
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/deleteVnfInput.json b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/deleteVnfInput.json
new file mode 100644
index 00000000..dda16b5d
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/deleteVnfInput.json
@@ -0,0 +1,46 @@
+{
+ "input": {
+ "request-information": {
+ "request-action": "DeleteVnfInstance",
+ "source": "MSO",
+ "request-id": "1a545ea9-2a5e-4df9-9c73-529b1d0b2012"
+ },
+ "sdnc-request-header": {
+ "svc-request-id": "8fd2622b-01fc-424d-bfc8-f48bcd64e546",
+ "svc-notification-url": "http://so-bpmn-infra.onap:8081/mso/WorkflowMessage/SDNCCallback/fd40ea09-3245-476a-b6ff-58cb042edb9d",
+ "svc-action": "UNASSIGN"
+ },
+ "service-information": {
+ "onap-model-information": {
+ "model-name": "Sol004Zip4Service",
+ "model-version": "1.0",
+ "model-uuid": "99d59273-4450-4034-9141-027f0c1a807a",
+ "model-invariant-uuid": "51672777-9b8d-4e5e-b488-5f9092e03a82"
+ },
+ "subscription-service-type": "vCPE",
+ "service-id": "ccece8fe-13da-456a-baf6-41b3a4a2bc2b",
+ "global-customer-id": "NordixDemoCustomer",
+ "service-instance-id": "ccece8fe-13da-456a-baf6-41b3a4a2bc2b"
+ },
+ "vnf-information": {
+ "onap-model-information": {
+ "model-name": "Sol004Zip3VSP",
+ "model-version": "1.0",
+ "model-customization-uuid": "50a90cd7-a84e-4ee1-b5ba-bfa5a26f5e15",
+ "model-uuid": "84b9649a-4eb9-4967-9abe-e8702f55518b",
+ "model-invariant-uuid": "b0f14066-2b65-40d2-b5a4-c8f2116fb5fc"
+ },
+ "vnf-id": "dfd02fb5-d7fb-4aac-b3c4-cd6b60058701",
+ "vnf-name": "EsyVnfInstantiationTest2",
+ "vnf-type": "Sol004Zip4Service/Sol004Zip3VSP 0"
+ },
+ "vnf-request-input": {
+ "aic-cloud-region": "nordixcloud",
+ "cloud-owner": "CloudOwner",
+ "tenant": "693c7729b2364a26a3ca602e6f66187d",
+ "vnf-network-instance-group-ids": [],
+ "vnf-input-parameters": {},
+ "vnf-name": "EsyVnfInstantiationTest2"
+ }
+ }
+} \ No newline at end of file