aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/so-bpmn-tasks
diff options
context:
space:
mode:
authorSangalang, Felix <felix.sangalang@att.com>2019-06-16 12:00:36 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-06-16 12:00:42 -0400
commit9990df8b87bdc0d3de175b8d56fc6920595e3129 (patch)
tree9e4b1ad5ff695c365846ee3c1790aecbbe8328e4 /bpmn/so-bpmn-tasks
parentc12bd8acf7bbc266b14851b50728e9d24d53b5b8 (diff)
Validate ServiceInstance name using createNodesUri
Validate ServiceInstance name using createNodesUri. Change-Id: I5194dd933dc98064888250bc9a38e6ee9716fc01 Issue-ID: SO-2024 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'bpmn/so-bpmn-tasks')
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java13
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java5
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java9
-rw-r--r--bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIServiceInstanceResourcesTest.java24
4 files changed, 47 insertions, 4 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java
index 57dbec3ad7..e3540ecc58 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java
@@ -107,8 +107,12 @@ public class AAICreateTasks {
public void createServiceInstance(BuildingBlockExecution execution) {
try {
+ Boolean alaCarte = execution.getVariable(A_LA_CARTE);
ServiceInstance serviceInstance =
extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
+ if (Boolean.TRUE.equals(alaCarte) && aaiSIResources.checkInstanceServiceNameInUse(serviceInstance)) {
+ throw new DuplicateNameException("service-instance", serviceInstance.getServiceInstanceName());
+ }
Customer customer = execution.getGeneralBuildingBlock().getCustomer();
aaiSIResources.createServiceInstance(serviceInstance, customer);
} catch (Exception ex) {
@@ -327,7 +331,8 @@ public class AAICreateTasks {
ServiceInstance serviceInstance =
extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID);
- if (alaCarte != null && alaCarte && aaiNetworkResources.checkNetworkNameInUse(l3network.getNetworkName())) {
+ if (Boolean.TRUE.equals(alaCarte)
+ && aaiNetworkResources.checkNetworkNameInUse(l3network.getNetworkName())) {
throw new DuplicateNameException("l3Network", l3network.getNetworkName());
}
// set default to false. ToBe updated by SDNC
@@ -386,7 +391,7 @@ public class AAICreateTasks {
InstanceGroup instanceGroup = serviceInstance.getCollection().getInstanceGroup();
// set name generated for NetworkCollection/NetworkCollectionInstanceGroup in previous step of the BB flow
instanceGroup.setInstanceGroupName(execution.getVariable(NETWORK_COLLECTION_NAME));
- if (alaCarte != null && alaCarte
+ if (Boolean.TRUE.equals(alaCarte)
&& aaiInstanceGroupResources.checkInstanceGroupNameInUse(instanceGroup.getInstanceGroupName())) {
throw new DuplicateNameException("instance-group", instanceGroup.getInstanceGroupName());
}
@@ -508,7 +513,7 @@ public class AAICreateTasks {
try {
Boolean alaCarte = execution.getVariable(A_LA_CARTE);
Configuration configuration = extractPojosForBB.extractByKey(execution, ResourceKey.CONFIGURATION_ID);
- if (alaCarte != null && alaCarte
+ if (Boolean.TRUE.equals(alaCarte)
&& aaiConfigurationResources.checkConfigurationNameInUse(configuration.getConfigurationName())) {
throw new DuplicateNameException("configuration", configuration.getConfigurationName());
}
@@ -524,7 +529,7 @@ public class AAICreateTasks {
ServiceInstance serviceInstance =
extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID);
- if (alaCarte != null && alaCarte
+ if (Boolean.TRUE.equals(alaCarte)
&& aaiInstanceGroupResources.checkInstanceGroupNameInUse(instanceGroup.getInstanceGroupName())) {
throw new DuplicateNameException("instance-group", instanceGroup.getInstanceGroupName());
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java
index f84afbe4a2..c41f3fa56c 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIServiceInstanceResources.java
@@ -157,5 +157,10 @@ public class AAIServiceInstanceResources {
injectionHelper.getAaiClient().update(serviceInstanceURI, aaiServiceInstance);
}
+ public boolean checkInstanceServiceNameInUse(ServiceInstance serviceInstance) {
+ AAIResourceUri uriSI = AAIUriFactory.createNodesUri(AAIObjectPlurals.SERVICE_INSTANCE)
+ .queryParam("service-instance-name", serviceInstance.getServiceInstanceName());
+ return injectionHelper.getAaiClient().exists(uriSI);
+ }
}
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java
index 5868eb8fc4..b889493d2e 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasksTest.java
@@ -123,12 +123,21 @@ public class AAICreateTasksTest extends BaseTaskTest {
@Test
public void createServiceInstanceTest() throws Exception {
+ doReturn(false).when(aaiServiceInstanceResources).checkInstanceServiceNameInUse(serviceInstance);
doNothing().when(aaiServiceInstanceResources).createServiceInstance(serviceInstance, customer);
aaiCreateTasks.createServiceInstance(execution);
verify(aaiServiceInstanceResources, times(1)).createServiceInstance(serviceInstance, customer);
}
@Test
+ public void createServiceInstanceNameInUseExceptionTest() throws Exception {
+ expectedException.expect(BpmnError.class);
+ doReturn(true).when(aaiServiceInstanceResources).checkInstanceServiceNameInUse(serviceInstance);
+ execution.setVariable("aLaCarte", Boolean.TRUE);
+ aaiCreateTasks.createServiceInstance(execution);
+ }
+
+ @Test
public void createServiceInstanceExceptionTest() throws Exception {
expectedException.expect(BpmnError.class);
diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIServiceInstanceResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIServiceInstanceResourcesTest.java
index 14df832754..ea98ee0169 100644
--- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIServiceInstanceResourcesTest.java
+++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIServiceInstanceResourcesTest.java
@@ -21,8 +21,11 @@
package org.onap.so.client.orchestration;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
@@ -43,8 +46,10 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity;
import org.onap.so.bpmn.servicedecomposition.bbobjects.Project;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription;
+import org.onap.so.client.aai.AAIObjectPlurals;
import org.onap.so.client.aai.AAIResourcesClient;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
import org.onap.so.client.aai.mapper.AAIObjectMapper;
import org.onap.so.db.catalog.beans.OrchestrationStatus;
@@ -186,4 +191,23 @@ public class AAIServiceInstanceResourcesTest extends TestDataSetup {
verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class),
any(org.onap.aai.domain.yang.ServiceInstance.class));
}
+
+ @Test
+ public void checkInstanceServiceNameInUseTrueTest() throws Exception {
+ AAIResourceUri uri = AAIUriFactory.createNodesUri(AAIObjectPlurals.SERVICE_INSTANCE)
+ .queryParam("service-instance-name", serviceInstance.getServiceInstanceName());
+ doReturn(true).when(MOCK_aaiResourcesClient).exists(eq(uri));
+ boolean nameInUse = aaiServiceInstanceResources.checkInstanceServiceNameInUse(serviceInstance);
+ assertTrue(nameInUse);
+ }
+
+ @Test
+ public void checkInstanceServiceNameInUseFalseTest() throws Exception {
+ AAIResourceUri uri = AAIUriFactory.createNodesUri(AAIObjectPlurals.SERVICE_INSTANCE)
+ .queryParam("service-instance-name", serviceInstance.getServiceInstanceName());
+ doReturn(false).when(MOCK_aaiResourcesClient).exists(eq(uri));
+ boolean nameInUse = aaiServiceInstanceResources.checkInstanceServiceNameInUse(serviceInstance);
+ assertFalse(nameInUse);
+ }
+
}