Removed slashes and added catch block 53/71953/1
authorBrittany Plummer (bp896r) <bp896r@att.com>
Tue, 6 Nov 2018 14:51:10 +0000 (09:51 -0500)
committerBrittany Plummer (bp896r) <bp896r@att.com>
Tue, 6 Nov 2018 14:51:10 +0000 (09:51 -0500)
Issue-ID: SO-1183
Change-Id: Ib8581393d782f078fc844cf96cbf7a0228133581
Signed-off-by: Brittany Plummer (bp896r) <bp896r@att.com>
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOut.java
bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/ConfigurationScaleOutTest.java
bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientResponseIncorrectPath.json [new file with mode: 0644]

index d13c5db..58dd5a1 100644 (file)
@@ -95,10 +95,13 @@ public class ConfigurationScaleOut {
                                        for (Map.Entry<String,String> entry : param.entrySet()) {
                                                key = entry.getKey();
                                                paramValue = entry.getValue();
-                                               configScaleOutParam = JsonPath.parse(sdncVfModuleQueryResponse).read(paramValue);
-                                               if(configScaleOutParam != null){
-                                                       paramsMap.put(key, configScaleOutParam);
+                                               try{
+                                                       configScaleOutParam = JsonPath.parse(sdncVfModuleQueryResponse).read(paramValue);
+                                               }catch(ClassCastException e){
+                                                       configScaleOutParam = null;
+                                                       msoLogger.warnSimple("Incorrect JSON path. Path points to object rather than value causing: ", e);
                                                }
+                                               paramsMap.put(key, configScaleOutParam);
                                        }
                                }
                        }
@@ -107,7 +110,6 @@ public class ConfigurationScaleOut {
                        configPayload.setConfigurationParameters(paramsMap);
                        configPayload.setRequestParameters(requestParameters);
                        configScaleOutPayloadString = mapper.writeValueAsString(configPayload);
-                       configScaleOutPayloadString = configScaleOutPayloadString.replaceAll("\"", "\\\\\"");
                        
                        execution.setVariable(ACTION, actionCategory);
                        execution.setVariable(MSO_REQUEST_ID, gBBInput.getRequestContext().getMsoRequestId());
index dabdc68..8577de2 100644 (file)
@@ -79,9 +79,9 @@ public class ConfigurationScaleOutTest extends BaseTaskTest {
                controllerSelectionReference.setActionCategory("testAction");
                controllerSelectionReference.setVnfType("testVnfType");
                String sdncResponse =  new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNCClientGetResponse.json")));
-               String expectedPayload = "{\\\"request-parameters\\\":{\\\"vnf-host-ip-address\\\":\\\"10.222.22.2\\\","
-                               + "\\\"vf-module-id\\\":\\\"testVfModuleId1\\\"},\\\"configuration-parameters\\\""
-                               + ":{\\\"vnf-id\\\":\\\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\\\",\\\"availability-zone\\\":\\\"AZ-MN02\\\"}}";
+               String expectedPayload = "{\"request-parameters\":{\"vnf-host-ip-address\":\"10.222.22.2\","
+                               + "\"vf-module-id\":\"testVfModuleId1\"},\"configuration-parameters\""
+                               + ":{\"vnf-id\":\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\",\"availability-zone\":\"AZ-MN02\"}}";
                execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), sdncResponse);
                
                doReturn(controllerSelectionReference).when(catalogDbClient).getControllerSelectionReferenceByVnfTypeAndActionCategory(genericVnf.getVnfType(), Action.ConfigScaleOut.toString());
@@ -101,9 +101,9 @@ public class ConfigurationScaleOutTest extends BaseTaskTest {
                Action action = Action.ConfigScaleOut;
                String vnfId = genericVnf.getVnfId();
                String controllerType = "testType";
-               String payload = "{\\\"request-parameters\\\":{\\\"vnf-host-ip-address\\\":\\\"10.222.22.2\\\","
-                               + "\\\"vf-module-id\\\":\\\"testVfModuleId1\\\"},\\\"configuration-parameters\\\""
-                               + ":{\\\"vnf-id\\\":\\\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\\\",\\\"availability-zone\\\":\\\"AZ-MN02\\\"}}";
+               String payload = "{\"request-parameters\":{\"vnf-host-ip-address\":\"10.222.22.2\","
+                               + "\"vf-module-id\":\"testVfModuleId1\"},\"configuration-parameters\""
+                               + ":{\"vnf-id\":\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\",\"availability-zone\":\"AZ-MN02\"}}";
                HashMap<String, String> payloadInfo = new HashMap<String, String>();
                payloadInfo.put("vnfName", "testVnfName");
                payloadInfo.put("vfModuleId", "testVfModuleId");
@@ -121,5 +121,29 @@ public class ConfigurationScaleOutTest extends BaseTaskTest {
                configurationScaleOut.callAppcClient(execution);
                verify(appCClient, times(1)).runAppCCommand(action, msoRequestId, vnfId, Optional.of(payload), payloadInfo, controllerType);
        }
+       @Test
+       public void setParamsForConfigurationScaleOutBadPathTest() throws Exception {
+               ControllerSelectionReference controllerSelectionReference = new ControllerSelectionReference();
+               controllerSelectionReference.setControllerName("testName");
+               controllerSelectionReference.setActionCategory("testAction");
+               controllerSelectionReference.setVnfType("testVnfType");
+               String sdncResponse =  new String(Files.readAllBytes(Paths.get("src/test/resources/__files/SDNCClientResponseIncorrectPath.json")));
+               String expectedPayload = "{\"request-parameters\":{\"vnf-host-ip-address\":\"10.222.22.2\","
+                               + "\"vf-module-id\":\"testVfModuleId1\"},\"configuration-parameters\""
+                               + ":{\"vnf-id\":\"66dac89b-2a5b-4cb9-b22e-a7e4488fb3db\",\"availability-zone\":null}}";
+               execution.setVariable("SDNCQueryResponse_" + vfModule.getVfModuleId(), sdncResponse);
+               
+               doReturn(controllerSelectionReference).when(catalogDbClient).getControllerSelectionReferenceByVnfTypeAndActionCategory(genericVnf.getVnfType(), Action.ConfigScaleOut.toString());
+               
+               configurationScaleOut.setParamsForConfigurationScaleOut(execution);
+               
+               assertEquals(genericVnf.getVnfId(), execution.getVariable("vnfId"));
+               assertEquals(genericVnf.getVnfName(), execution.getVariable("vnfName"));
+               assertEquals("ConfigScaleOut", execution.getVariable("action"));
+               assertEquals(requestContext.getMsoRequestId(), execution.getVariable("msoRequestId"));
+               assertEquals(controllerSelectionReference.getControllerName(), execution.getVariable("controllerType"));
+               assertEquals(vfModule.getVfModuleId(), execution.getVariable("vfModuleId"));
+               assertEquals(expectedPayload, execution.getVariable("payload"));
+       }
 
 }
diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientResponseIncorrectPath.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/SDNCClientResponseIncorrectPath.json
new file mode 100644 (file)
index 0000000..7e263b4
--- /dev/null
@@ -0,0 +1,29 @@
+{
+  "vnf-topology": {
+    "tenant": "0422ffb57ba042c0800a29dc85ca70f8",
+    "vnf-topology-identifier-structure": {
+      "vnf-id": "66dac89b-2a5b-4cb9-b22e-a7e4488fb3db",
+      "vnf-type": "InfraMSO_vSAMP10a_Service/InfraMSO_vSAMP10a-2 0",
+      "vnf-name": "MSO-DEV-VNF-1806HF1-InfraMSO_vSAMP10a-1XXX-GR_21"
+    },
+    "aic-clli": "AUSTTXGR",
+    "vnf-resource-assignments": {
+      "availability-zones": {
+        "availability-zone": [
+               {
+                       "test":"AZ-MN02"
+               }
+        ],
+        "max-count": 1
+      }
+    },
+    "aic-cloud-region": "mtn6",
+    "onap-model-information": {
+      "model-customization-uuid": "034226ae-879a-46b5-855c-d02babcb6cb6",
+      "model-uuid": "cb79c25f-b30d-4d95-afb5-97be4021f3db",
+      "model-invariant-uuid": "e93d3a7a-446d-486b-ae48-d474a9156064",
+      "model-name": "InfraMSO_vSAMP10a-2",
+      "model-version": "1.0"
+    }
+  }
+}
\ No newline at end of file