Same Service names under two different Customers 97/28997/2
authorChittaranjan Sardar <chittaranjan.sardar@amdocs.com>
Wed, 24 Jan 2018 07:27:55 +0000 (12:57 +0530)
committerChittaranjan Sardar <chittaranjan.sardar@amdocs.com>
Wed, 24 Jan 2018 10:00:39 +0000 (15:30 +0530)
SO is not allowing to create services with same name with in different customers.

Change-Id: I2ce83f3d6c8d999f88154a1ac50330a8b6d50118
Issue-ID: SO-382
Signed-off-by: Chittaranjan Sardar <chittaranjan.sardar@amdocs.com>
bpmn/MSOCommonBPMN/src/main/groovy/org/openecomp/mso/bpmn/common/scripts/GenericGetService.groovy
bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/GenericGetServiceTest.java
bpmn/MSOCommonBPMN/src/test/resources/__files/GenericFlows/getSIUrlByNameMultiCustomer.xml [new file with mode: 0644]
bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/CreateGenericALaCarteServiceInstanceTest.java

index 14f9135..cfc5171 100644 (file)
 \r
 package org.openecomp.mso.bpmn.common.scripts\r
 \r
-import static org.apache.commons.lang3.StringUtils.*\r
-\r
-import org.apache.commons.lang3.*\r
+import org.apache.commons.lang3.StringEscapeUtils\r
 import org.camunda.bpm.engine.delegate.BpmnError\r
 import org.camunda.bpm.engine.runtime.Execution\r
 import org.openecomp.mso.rest.APIResponse\r
 import org.springframework.web.util.UriUtils\r
 \r
+import static org.apache.commons.lang3.StringUtils.isBlank\r
+\r
 \r
 /**\r
  * This class supports the GenericGetService Sub Flow.\r
@@ -301,7 +301,9 @@ class GenericGetService extends AbstractServiceTaskProcessor{
                        if(responseCode == 200){\r
                                utils.log("DEBUG", "  Query for Service Instance Url Received a Good Response Code", isDebugEnabled)\r
                                execution.setVariable("GENGS_SuccessIndicator", true)\r
-                               if(utils.nodeExists(aaiResponse, "result-data")){\r
+                               String globalCustomerId = execution.getVariable("GENGS_globalCustomerId")\r
+                               boolean nodeExists = isBlank(globalCustomerId) ? utils.nodeExists(aaiResponse, "result-data") : hasCustomerServiceInstance(aaiResponse, globalCustomerId)\r
+                               if(nodeExists){\r
                                        utils.log("DEBUG", "Query for Service Instance Url Response Does Contain Data" , isDebugEnabled)\r
                                        execution.setVariable("GENGS_FoundIndicator", true)\r
                                        String resourceLink = utils.getNodeText1(aaiResponse, "resource-link")\r
@@ -439,4 +441,30 @@ class GenericGetService extends AbstractServiceTaskProcessor{
                utils.log("DEBUG", " *** COMPLETED GenericGetService GetServiceObject Process*** ", isDebugEnabled)\r
        }\r
 \r
+       /**\r
+        * An utility method which check whether a service(by name) is already present within a globalCustomerId or not.\r
+        * @param jsonResponse raw response received from AAI by searching ServiceInstance by Name.\r
+        * @param globalCustomerId\r
+        * @return {@code true} if globalCustomerId is found at 6th position within "resource-link", {@code false} in any other cases.\r
+        */\r
+       public boolean hasCustomerServiceInstance(String aaiResponse, final String globalCustomerId) {\r
+               if (isBlank(aaiResponse)) {\r
+                       return false\r
+               }\r
+               aaiResponse = utils.removeXmlNamespaces(aaiResponse)\r
+               ArrayList<String> linksArray = utils.getMultNodeObjects(aaiResponse, "resource-link")\r
+               if (linksArray == null || linksArray.size() == 0) {\r
+                       return false\r
+               }\r
+               for (String resourceLink : linksArray) {\r
+                       int custStart = resourceLink.indexOf("customer/")\r
+                       int custEnd = resourceLink.indexOf("/service-subscriptions/")\r
+                       String receivedCustomerId = resourceLink.substring(custStart + 9, custEnd)\r
+                       if (globalCustomerId.equals(receivedCustomerId)) {\r
+                               return true\r
+                       }\r
+               }\r
+               return false\r
+       }\r
+\r
 }
\ No newline at end of file
index b117283..82cceb0 100644 (file)
@@ -482,6 +482,61 @@ public class GenericGetServiceTest extends WorkflowTest {
                assertEquals(expectedWorkflowException, workflowException);\r
        }\r
 \r
+    @Test\r
+    @Deployment(resources = {"subprocess/GenericGetService.bpmn"})\r
+    public void testGenericGetService_success_serviceInstance_byNameServicePresent() throws Exception{\r
+\r
+        MockNodeQueryServiceInstanceByName("1604-MVM-26", "GenericFlows/getSIUrlByNameMultiCustomer.xml");\r
+        MockGetServiceInstance("XyCorporation", "123456789", "MIS%252F1604%252F0026%252FSW_INTERNET", "GenericFlows/getServiceInstance.xml");\r
+\r
+        Map<String, String> variables = new HashMap<String, String>();\r
+        setVariablesInstance(variables, null, "1604-MVM-26", "XyCorporation", null);\r
+\r
+        WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericGetService", variables);\r
+        waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());\r
+\r
+        String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "GENGS_SuccessIndicator");\r
+        String found = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "GENGS_FoundIndicator");\r
+        String resourceLink = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "GENGS_resourceLink");\r
+        String response = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "WorkflowResponse");\r
+        String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "WorkflowException");\r
+        String siUrlResponseCode = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "GENGS_obtainSIUrlResponseCode");\r
+\r
+        assertEquals("true", successIndicator);\r
+        assertEquals("true", found);\r
+               assertNotNull(resourceLink);\r
+        assertNotNull(response);\r
+        assertEquals("200", siUrlResponseCode);\r
+        assertEquals(null, workflowException);\r
+    }\r
+\r
+       @Test\r
+       @Deployment(resources = {"subprocess/GenericGetService.bpmn"})\r
+       public void testGenericGetService_success_serviceInstance_byNameServiceNotPresent() throws Exception{\r
+\r
+               MockNodeQueryServiceInstanceByName("1604-MVM-26", "GenericFlows/getSIUrlByNameMultiCustomer.xml");\r
+               MockGetServiceInstance("CorporationNotPresent", "123456789", "MIS%252F1604%252F0026%252FSW_INTERNET", "GenericFlows/getServiceInstance.xml");\r
+\r
+               Map<String, String> variables = new HashMap<String, String>();\r
+               setVariablesInstance(variables, null, "1604-MVM-26", "CorporationNotPresent", null);\r
+\r
+               WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "GenericGetService", variables);\r
+               waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());\r
+\r
+               String successIndicator = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "GENGS_SuccessIndicator");\r
+               String found = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "GENGS_FoundIndicator");\r
+               String resourceLink = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "GENGS_resourceLink");\r
+               String response = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "WorkflowResponse");\r
+               String workflowException = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "WorkflowException");\r
+               String siUrlResponseCode = BPMNUtil.getVariable(processEngineRule, "GenericGetService", "GENGS_obtainSIUrlResponseCode");\r
+\r
+               assertEquals("true", successIndicator);\r
+               assertEquals("false", found);\r
+               assertEquals(null, resourceLink);\r
+               assertEquals("  ", response);\r
+               assertEquals("200", siUrlResponseCode);\r
+               assertEquals(null, workflowException);\r
+       }\r
 \r
        private void setVariablesInstance(Map<String, String> variables, String siId, String siName, String globalCustId, String serviceType) {\r
                variables.put("isDebugLogEnabled", "true");\r
diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/GenericFlows/getSIUrlByNameMultiCustomer.xml b/bpmn/MSOCommonBPMN/src/test/resources/__files/GenericFlows/getSIUrlByNameMultiCustomer.xml
new file mode 100644 (file)
index 0000000..fce47fc
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<search-results xmlns="http://org.openecomp.aai.inventory/v11">
+    <result-data>
+        <resource-type>service-instance</resource-type>
+        <resource-link>/aai/v11/business/customers/customer/AbcBank/service-subscriptions/service-subscription/ABC-ST/service-instances/service-instance/MIS%252F1604%252F0026%252FSW_INTERNET</resource-link>
+    </result-data>
+    <result-data>
+        <resource-type>service-instance</resource-type>
+        <resource-link>/aai/v11/business/customers/customer/XyCorporation/service-subscriptions/service-subscription/XY-ST/service-instances/service-instance/MIS%252F1604%252F0026%252FSW_INTERNET</resource-link>
+    </result-data>
+</search-results>
\ No newline at end of file
index 21c0091..571db76 100644 (file)
@@ -79,8 +79,8 @@ public class CreateGenericALaCarteServiceInstanceTest extends WorkflowTest {
                MockGetCustomer("MCBH-1610", "CreateServiceInstance/createServiceInstance_queryGlobalCustomerId_AAIResponse_Success.xml");
                MockPutServiceInstance("MCBH-1610", "viprsvc", "RaaTest-1-id", "");
                MockGetServiceInstance("MCBH-1610", "viprsvc", "RaaTest-1-id", "GenericFlows/getServiceInstance.xml");
-               MockNodeQueryServiceInstanceByName("RAATest-1", "");
-               MockNodeQueryServiceInstanceById("RaaTest-1-id", "");
+               MockNodeQueryServiceInstanceByName("RAATest-1", null);
+               MockNodeQueryServiceInstanceById("RaaTest-1-id", null);
                //SDNC
                mockSDNCAdapter(200);
                //DB