aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/test
diff options
context:
space:
mode:
authorSmokowski, Steven <steve.smokowski@att.com>2020-03-30 13:22:32 -0400
committerBenjamin, Max (mb388a) <mb388a@att.com>2020-03-30 13:22:34 -0400
commit32b6e452ab34939da6eb7ee23ea18244cff147ac (patch)
tree36f57b4d0f7f78ecfaaa9fff75a595be86254ad4 /mso-api-handlers/mso-api-handler-infra/src/test
parentdf5f83eef26b23a5381e134ff50f89b340376596 (diff)
Add validations to prevent out of order deletes
Add validations to prevent out of order deletes Add additional junits to all validations Remove tests that are not longer needed Issue-ID: SO-2772 Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com> Change-Id: I00b8490691181bc1e95da25c73e0f215e1c2b0e2
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/test')
-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
4 files changed, 297 insertions, 0 deletions
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());
+ }
+
+}