summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java4
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java35
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/NetworkDeleteValidator.java34
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java3
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidatorListenerRunner.java9
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/ServiceInstanceDeleteValidator.java38
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java34
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java33
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/NetworkDeleteValidatorTest.java73
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/ServiceInstanceDeleteValidatorTest.java88
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VnfDeleteValidatorTest.java67
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VolumeGroupDeleteValidatorTest.java69
12 files changed, 480 insertions, 7 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
index f1e8e711c4..418ba05abf 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java
@@ -40,6 +40,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpStatus;
+import org.onap.logging.filter.base.ErrorCode;
import org.onap.so.apihandler.common.CommonConstants;
import org.onap.so.apihandler.common.ErrorNumbers;
import org.onap.so.apihandler.common.RequestClientParameter;
@@ -56,7 +57,6 @@ import org.onap.so.db.catalog.client.CatalogDbClient;
import org.onap.so.db.request.beans.InfraActiveRequests;
import org.onap.so.db.request.client.RequestsDbClient;
import org.onap.so.exceptions.ValidationException;
-import org.onap.logging.filter.base.ErrorCode;
import org.onap.so.logger.MessageEnum;
import org.onap.so.serviceinstancebeans.CloudConfiguration;
import org.onap.so.serviceinstancebeans.ModelInfo;
@@ -823,7 +823,7 @@ public class ServiceInstances extends AbstractRestHandler {
sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri);
action = handleReplaceInstance(action, sir);
- requestValidatorListenerRunner.runValidations(requestUri, instanceIdMap, sir, queryParams);
+ requestValidatorListenerRunner.runValidations(requestUri, instanceIdMap, sir, queryParams, action);
String requestScope = requestHandlerUtils.deriveRequestScope(action, sir, requestUri);
InfraActiveRequests currentActiveReq =
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java
index fee7a3a8f4..4e3d8736c2 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java
@@ -9,6 +9,7 @@ import org.onap.aai.domain.yang.Tenant;
import org.onap.aai.domain.yang.VfModule;
import org.onap.aai.domain.yang.VolumeGroup;
import org.onap.so.apihandlerinfra.infra.rest.exception.AAIEntityNotFound;
+import org.onap.so.client.aai.AAIObjectPlurals;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.AAIResourcesClient;
import org.onap.so.client.aai.entities.AAIResultWrapper;
@@ -76,6 +77,40 @@ public class AAIDataRetrieval {
});
}
+
+ public boolean isVolumeGroupRelatedToVFModule(String volumeGroupId) {
+ return this.getAaiResourcesClient().exists(AAIUriFactory
+ .createResourceUri(AAIObjectType.VOLUME_GROUP, volumeGroupId).relatedTo(AAIObjectPlurals.VF_MODULE));
+ }
+
+ public boolean isVnfRelatedToVolumes(String vnfId) {
+ return this.getAaiResourcesClient().exists(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)
+ .relatedTo(AAIObjectPlurals.VOLUME_GROUP));
+ }
+
+ public boolean isNetworkRelatedToModules(String networkId) {
+ return this.getAaiResourcesClient().exists(AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId)
+ .relatedTo(AAIObjectPlurals.VF_MODULE));
+ }
+
+ public boolean isServiceRelatedToNetworks(String serviceInstanceId) {
+ return this.getAaiResourcesClient()
+ .exists(AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
+ .relatedTo(AAIObjectPlurals.L3_NETWORK));
+ }
+
+ public boolean isServiceRelatedToGenericVnf(String serviceInstanceId) {
+ return this.getAaiResourcesClient()
+ .exists(AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
+ .relatedTo(AAIObjectPlurals.GENERIC_VNF));
+ }
+
+ public boolean isServiceRelatedToConfiguration(String serviceInstanceId) {
+ return this.getAaiResourcesClient()
+ .exists(AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)
+ .relatedTo(AAIObjectPlurals.CONFIGURATION));
+ }
+
public Service getService(String serviceId) {
return this.getAaiResourcesClient()
.get(Service.class, AAIUriFactory.createResourceUri(AAIObjectType.SERVICE, serviceId)).orElseGet(() -> {
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/NetworkDeleteValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/NetworkDeleteValidator.java
new file mode 100644
index 0000000000..f75897dda1
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/NetworkDeleteValidator.java
@@ -0,0 +1,34 @@
+package org.onap.so.apihandlerinfra.infra.rest.validators;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.regex.Pattern;
+import org.onap.so.apihandlerinfra.Action;
+import org.onap.so.apihandlerinfra.Actions;
+import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval;
+import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+
+
+public class NetworkDeleteValidator implements RequestValidator {
+
+ @Autowired
+ AAIDataRetrieval aaiDataRetrieval;
+
+ @Override
+ public boolean shouldRunFor(String requestUri, ServiceInstancesRequest request, Actions action) {
+ return Pattern.compile("[Vv][5-8]/serviceInstances/[^/]+/networks/[^/]+").matcher(requestUri).matches()
+ && action.equals(Action.deleteInstance);
+
+ }
+
+ @Override
+ public Optional<String> validate(Map<String, String> instanceIdMap, ServiceInstancesRequest request,
+ Map<String, String> queryParams) {
+ if (aaiDataRetrieval.isNetworkRelatedToModules(instanceIdMap.get("networkInstanceId"))) {
+ return Optional.of("Cannot delete network it is still related to existing vf-modules");
+ } else {
+ return Optional.empty();
+ }
+ }
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java
index 4aa60152dd..1dea57ad9c 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java
@@ -22,6 +22,7 @@ package org.onap.so.apihandlerinfra.infra.rest.validators;
import java.util.Map;
import java.util.Optional;
+import org.onap.so.apihandlerinfra.Actions;
import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
public interface RequestValidator {
@@ -32,7 +33,7 @@ public interface RequestValidator {
*
* @return
*/
- public boolean shouldRunFor(String uri, ServiceInstancesRequest request);
+ public boolean shouldRunFor(String uri, ServiceInstancesRequest request, Actions action);
public Optional<String> validate(Map<String, String> instanceIdMap, ServiceInstancesRequest request,
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidatorListenerRunner.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidatorListenerRunner.java
index d689c6b7a5..3aba39b501 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidatorListenerRunner.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidatorListenerRunner.java
@@ -28,6 +28,7 @@ import java.util.Optional;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import org.javatuples.Pair;
+import org.onap.so.apihandlerinfra.Actions;
import org.onap.so.apihandlerinfra.exceptions.ApiException;
import org.onap.so.apihandlerinfra.exceptions.ValidateException;
import org.onap.so.listener.ListenerRunner;
@@ -50,10 +51,10 @@ public class RequestValidatorListenerRunner extends ListenerRunner {
}
public boolean runValidations(String requestURI, Map<String, String> instanceIdMap, ServiceInstancesRequest request,
- Map<String, String> queryParams) throws ApiException {
+ Map<String, String> queryParams, Actions action) throws ApiException {
logger.info("Running local validations");
List<Pair<String, Optional<String>>> results =
- runValidations(requestValidators, instanceIdMap, request, queryParams, requestURI);
+ runValidations(requestValidators, instanceIdMap, request, queryParams, requestURI, action);
if (!results.isEmpty()) {
throw new ValidateException("Failed Validations:\n"
+ results.stream().map(item -> String.format("%s: %s", item.getValue0(), item.getValue1().get()))
@@ -66,10 +67,10 @@ public class RequestValidatorListenerRunner extends ListenerRunner {
protected List<Pair<String, Optional<String>>> runValidations(List<? extends RequestValidator> validators,
Map<String, String> instanceIdMap, ServiceInstancesRequest request, Map<String, String> queryParams,
- String requestURI) {
+ String requestURI, Actions action) {
List<? extends RequestValidator> filtered =
- filterListeners(validators, (item -> item.shouldRunFor(requestURI, request)));
+ filterListeners(validators, (item -> item.shouldRunFor(requestURI, request, action)));
List<Pair<String, Optional<String>>> results = new ArrayList<>();
filtered.forEach(item -> results
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/ServiceInstanceDeleteValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/ServiceInstanceDeleteValidator.java
new file mode 100644
index 0000000000..0c7ba65cf4
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/ServiceInstanceDeleteValidator.java
@@ -0,0 +1,38 @@
+package org.onap.so.apihandlerinfra.infra.rest.validators;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.regex.Pattern;
+import org.onap.so.apihandlerinfra.Action;
+import org.onap.so.apihandlerinfra.Actions;
+import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval;
+import org.onap.so.listener.Skip;
+import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+
+@Skip
+public class ServiceInstanceDeleteValidator implements RequestValidator {
+
+ @Autowired
+ AAIDataRetrieval aaiDataRetrieval;
+
+ @Override
+ public boolean shouldRunFor(String requestUri, ServiceInstancesRequest request, Actions action) {
+ return Pattern.compile("[Vv][5-8]/serviceInstances/[^/]+").matcher(requestUri).matches()
+ && action.equals(Action.deleteInstance);
+ }
+
+ @Override
+ public Optional<String> validate(Map<String, String> instanceIdMap, ServiceInstancesRequest request,
+ Map<String, String> queryParams) {
+ if (aaiDataRetrieval.isServiceRelatedToGenericVnf(instanceIdMap.get("serviceInstanceId"))) {
+ return Optional.of("Cannot delete service it is still related to existing vf-modules");
+ } else if (aaiDataRetrieval.isServiceRelatedToNetworks(instanceIdMap.get("serviceInstanceId"))) {
+ return Optional.of("Cannot delete service it is still related to existing networks");
+ } else if (aaiDataRetrieval.isServiceRelatedToConfiguration(instanceIdMap.get("serviceInstanceId"))) {
+ return Optional.of("Cannot delete service it is still related to existing configurations");
+ } else {
+ return Optional.empty();
+ }
+ }
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java
new file mode 100644
index 0000000000..d54e60d153
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VnfDeleteValidator.java
@@ -0,0 +1,34 @@
+package org.onap.so.apihandlerinfra.infra.rest.validators;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.regex.Pattern;
+import org.onap.so.apihandlerinfra.Action;
+import org.onap.so.apihandlerinfra.Actions;
+import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval;
+import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+
+
+public class VnfDeleteValidator implements RequestValidator {
+
+ @Autowired
+ AAIDataRetrieval aaiDataRetrieval;
+
+ @Override
+ public boolean shouldRunFor(String requestUri, ServiceInstancesRequest request, Actions action) {
+ return Pattern.compile("[Vv][5-8]/serviceInstances/[^/]+/vnfs/[^/]+").matcher(requestUri).matches()
+ && action.equals(Action.deleteInstance);
+ }
+
+ @Override
+ public Optional<String> validate(Map<String, String> instanceIdMap, ServiceInstancesRequest request,
+ Map<String, String> queryParams) {
+ if (aaiDataRetrieval.isVnfRelatedToVolumes(instanceIdMap.get("vnfInstanceId"))) {
+ return Optional.of("Cannot delete vnf it is still related to existing volume groups");
+ } else {
+ return Optional.empty();
+ }
+ }
+
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java
new file mode 100644
index 0000000000..f010d47f70
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java
@@ -0,0 +1,33 @@
+package org.onap.so.apihandlerinfra.infra.rest.validators;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.regex.Pattern;
+import org.onap.so.apihandlerinfra.Action;
+import org.onap.so.apihandlerinfra.Actions;
+import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval;
+import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
+import org.springframework.beans.factory.annotation.Autowired;
+
+public class VolumeGroupDeleteValidator implements RequestValidator {
+
+ @Autowired
+ AAIDataRetrieval aaiDataRetrieval;
+
+ @Override
+ public boolean shouldRunFor(String requestUri, ServiceInstancesRequest request, Actions action) {
+ return Pattern.compile("[Vv][5-8]/serviceInstances/[^/]+/volumeGroups/[^/]+").matcher(requestUri).matches()
+ && action.equals(Action.deleteInstance);
+ }
+
+ @Override
+ public Optional<String> validate(Map<String, String> instanceIdMap, ServiceInstancesRequest request,
+ Map<String, String> queryParams) {
+ if (aaiDataRetrieval.isVolumeGroupRelatedToVFModule(instanceIdMap.get("volumeGroupInstanceId"))) {
+ return Optional.of("Cannot delete volume group it is related to existing vf-modules");
+ } else {
+ return Optional.empty();
+ }
+ }
+
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/NetworkDeleteValidatorTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/NetworkDeleteValidatorTest.java
new file mode 100644
index 0000000000..7780f0ee2b
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/NetworkDeleteValidatorTest.java
@@ -0,0 +1,73 @@
+package org.onap.so.apihandlerinfra.infra.rest.validator;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.apihandlerinfra.Action;
+import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval;
+import org.onap.so.apihandlerinfra.infra.rest.validators.NetworkDeleteValidator;
+import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class NetworkDeleteValidatorTest {
+
+
+ @InjectMocks
+ @Spy
+ private NetworkDeleteValidator networkValidator;
+
+ @Mock
+ private AAIDataRetrieval aaiDataRetrieval;
+
+ private Map<String, String> instanceIdMap = new HashMap<>();
+
+ @Test
+ public void validateURIMatchTest() {
+ assertEquals(true, networkValidator.shouldRunFor("v8/serviceInstances/uasdfasdf/networks/asdfasdf",
+ new ServiceInstancesRequest(), Action.deleteInstance));
+ }
+
+ @Test
+ public void validateURINotMatchTest() {
+ assertEquals(false, networkValidator.shouldRunFor("v8/serviceInstances/uasdfasdf/vnfs/asdfasdf",
+ new ServiceInstancesRequest(), Action.deleteInstance));
+ }
+
+ @Test
+ public void validateURINotMatch2Test() {
+ assertEquals(false, networkValidator.shouldRunFor("v8/serviceInstances/uasdfasdf/networks/asdfasdf/update",
+ new ServiceInstancesRequest(), Action.deleteInstance));
+ }
+
+ @Test
+ public void validateURINotMatchActionTest() {
+ assertEquals(false, networkValidator.shouldRunFor("v8/serviceInstances/uasdfasdf/networks/asdfasdf",
+ new ServiceInstancesRequest(), Action.createInstance));
+ }
+
+ @Test
+ public void validateSuccessTest() {
+ instanceIdMap.put("networkInstanceId", "1");
+ when(aaiDataRetrieval.isNetworkRelatedToModules("1")).thenReturn(false);
+ Optional<String> result = networkValidator.validate(instanceIdMap, null, null);
+ assertEquals(false, result.isPresent());
+ }
+
+ @Test
+ public void validateFailureTest() {
+ instanceIdMap.put("networkInstanceId", "1");
+ when(aaiDataRetrieval.isNetworkRelatedToModules("1")).thenReturn(true);
+ Optional<String> result = networkValidator.validate(instanceIdMap, null, null);
+ assertEquals(true, result.isPresent());
+ }
+
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/ServiceInstanceDeleteValidatorTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/ServiceInstanceDeleteValidatorTest.java
new file mode 100644
index 0000000000..c334d522b6
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/ServiceInstanceDeleteValidatorTest.java
@@ -0,0 +1,88 @@
+package org.onap.so.apihandlerinfra.infra.rest.validator;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.apihandlerinfra.Action;
+import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval;
+import org.onap.so.apihandlerinfra.infra.rest.validators.ServiceInstanceDeleteValidator;
+import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class ServiceInstanceDeleteValidatorTest {
+
+
+ @InjectMocks
+ @Spy
+ private ServiceInstanceDeleteValidator serviceValidator;
+
+ @Mock
+ private AAIDataRetrieval aaiDataRetrieval;
+
+ private Map<String, String> instanceIdMap = new HashMap<>();
+
+ @Test
+ public void validateURIMatchTest() {
+ assertEquals(true, serviceValidator.shouldRunFor("v8/serviceInstances/uasdfasdf", new ServiceInstancesRequest(),
+ Action.deleteInstance));
+ }
+
+ @Test
+ public void validateURINotMatchTest() {
+ assertEquals(false, serviceValidator.shouldRunFor("v8/serviceInstances/uasdfasdf/vnfs/asdfasdf",
+ new ServiceInstancesRequest(), Action.deleteInstance));
+ }
+
+ @Test
+ public void validateURINotMatch2Test() {
+ assertEquals(false, serviceValidator.shouldRunFor("v8/serviceInstances/uasdfasdf/update",
+ new ServiceInstancesRequest(), Action.deleteInstance));
+ }
+
+ @Test
+ public void validateSuccessTest() {
+ instanceIdMap.put("serviceInstanceId", "1");
+ when(aaiDataRetrieval.isServiceRelatedToGenericVnf("1")).thenReturn(false);
+ when(aaiDataRetrieval.isServiceRelatedToNetworks("1")).thenReturn(false);
+ when(aaiDataRetrieval.isServiceRelatedToConfiguration("1")).thenReturn(false);
+ Optional<String> result = serviceValidator.validate(instanceIdMap, null, null);
+ assertEquals(false, result.isPresent());
+ }
+
+ @Test
+ public void validateFailureVnfTest() {
+ instanceIdMap.put("serviceInstanceId", "1");
+ when(aaiDataRetrieval.isServiceRelatedToGenericVnf("1")).thenReturn(true);
+ Optional<String> result = serviceValidator.validate(instanceIdMap, null, null);
+ assertEquals(true, result.isPresent());
+ }
+
+ @Test
+ public void validateFailureNetworksTest() {
+ instanceIdMap.put("serviceInstanceId", "1");
+ when(aaiDataRetrieval.isServiceRelatedToGenericVnf("1")).thenReturn(false);
+ when(aaiDataRetrieval.isServiceRelatedToNetworks("1")).thenReturn(true);
+ Optional<String> result = serviceValidator.validate(instanceIdMap, null, null);
+ assertEquals(true, result.isPresent());
+ }
+
+ @Test
+ public void validateFailureConfigurationTest() {
+ instanceIdMap.put("serviceInstanceId", "1");
+ when(aaiDataRetrieval.isServiceRelatedToGenericVnf("1")).thenReturn(false);
+ when(aaiDataRetrieval.isServiceRelatedToNetworks("1")).thenReturn(false);
+ when(aaiDataRetrieval.isServiceRelatedToConfiguration("1")).thenReturn(true);
+ Optional<String> result = serviceValidator.validate(instanceIdMap, null, null);
+ assertEquals(true, result.isPresent());
+ }
+
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VnfDeleteValidatorTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VnfDeleteValidatorTest.java
new file mode 100644
index 0000000000..d4f57d3146
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VnfDeleteValidatorTest.java
@@ -0,0 +1,67 @@
+package org.onap.so.apihandlerinfra.infra.rest.validator;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.apihandlerinfra.Action;
+import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval;
+import org.onap.so.apihandlerinfra.infra.rest.validators.VnfDeleteValidator;
+import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class VnfDeleteValidatorTest {
+
+
+ @InjectMocks
+ @Spy
+ private VnfDeleteValidator vnfValidator;
+
+ @Mock
+ private AAIDataRetrieval aaiDataRetrieval;
+
+ private Map<String, String> instanceIdMap = new HashMap<>();
+
+ @Test
+ public void validateURIMatchTest() {
+ assertEquals(true, vnfValidator.shouldRunFor("v8/serviceInstances/uasdfasdf/vnfs/asdfasdf",
+ new ServiceInstancesRequest(), Action.deleteInstance));
+ }
+
+ @Test
+ public void validateURINotMatchTest() {
+ assertEquals(false, vnfValidator.shouldRunFor("v8/serviceInstances/uasdfasdf/vnfs/asdfasdf/replace",
+ new ServiceInstancesRequest(), Action.deleteInstance));
+ }
+
+ @Test
+ public void validateURINotMatch2Test() {
+ assertEquals(false, vnfValidator.shouldRunFor("v8/serviceInstances/uasdfasdf", new ServiceInstancesRequest(),
+ Action.deleteInstance));
+ }
+
+ @Test
+ public void validateSuccessTest() {
+ instanceIdMap.put("vnfInstanceId", "1");
+ when(aaiDataRetrieval.isVnfRelatedToVolumes("1")).thenReturn(false);
+ Optional<String> result = vnfValidator.validate(instanceIdMap, null, null);
+ assertEquals(false, result.isPresent());
+ }
+
+ @Test
+ public void validateFailureVnfTest() {
+ instanceIdMap.put("vnfInstanceId", "1");
+ when(aaiDataRetrieval.isVnfRelatedToVolumes("1")).thenReturn(true);
+ Optional<String> result = vnfValidator.validate(instanceIdMap, null, null);
+ assertEquals(true, result.isPresent());
+ }
+
+}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VolumeGroupDeleteValidatorTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VolumeGroupDeleteValidatorTest.java
new file mode 100644
index 0000000000..3d81ee66c9
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VolumeGroupDeleteValidatorTest.java
@@ -0,0 +1,69 @@
+package org.onap.so.apihandlerinfra.infra.rest.validator;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.apihandlerinfra.Action;
+import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval;
+import org.onap.so.apihandlerinfra.infra.rest.validators.VolumeGroupDeleteValidator;
+import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
+
+
+@RunWith(MockitoJUnitRunner.class)
+public class VolumeGroupDeleteValidatorTest {
+
+
+ @InjectMocks
+ @Spy
+ private VolumeGroupDeleteValidator volumeGroupDeleteValidator;
+
+ @Mock
+ private AAIDataRetrieval aaiDataRetrieval;
+
+ private Map<String, String> instanceIdMap = new HashMap<>();
+
+ @Test
+ public void validateURIMatchTest() {
+ assertEquals(true, volumeGroupDeleteValidator.shouldRunFor("v8/serviceInstances/uasdfasdf/volumeGroups/uuid",
+ new ServiceInstancesRequest(), Action.deleteInstance));
+ }
+
+ @Test
+ public void validateURINotMatchTest() {
+ assertEquals(false,
+ volumeGroupDeleteValidator.shouldRunFor(
+ "v8/serviceInstances/uasdfasdf/vnfs/asdfasdf/volumeGroups/uuid/replace",
+ new ServiceInstancesRequest(), Action.deleteInstance));
+ }
+
+ @Test
+ public void validateURINotMatch2Test() {
+ assertEquals(false, volumeGroupDeleteValidator.shouldRunFor("v8/serviceInstances/uasdfasdf/vnfs/uuid",
+ new ServiceInstancesRequest(), Action.deleteInstance));
+ }
+
+ @Test
+ public void validateSuccessTest() {
+ instanceIdMap.put("volumeGroupInstanceId", "1");
+ when(aaiDataRetrieval.isVolumeGroupRelatedToVFModule("1")).thenReturn(false);
+ Optional<String> result = volumeGroupDeleteValidator.validate(instanceIdMap, null, null);
+ assertEquals(false, result.isPresent());
+ }
+
+ @Test
+ public void validateFailureVnfTest() {
+ instanceIdMap.put("volumeGroupInstanceId", "1");
+ when(aaiDataRetrieval.isVolumeGroupRelatedToVFModule("1")).thenReturn(true);
+ Optional<String> result = volumeGroupDeleteValidator.validate(instanceIdMap, null, null);
+ assertEquals(true, result.isPresent());
+ }
+
+}