better errMsg for request block missing 79/91479/2
authorOleg Mitsura <oleg.mitsura@amdocs.com>
Mon, 15 Jul 2019 20:42:17 +0000 (16:42 -0400)
committerOleg Mitsura <oleg.mitsura@amdocs.com>
Mon, 15 Jul 2019 20:45:22 +0000 (16:45 -0400)
Issue-Id: CCSDK-1486

Signed-off-by: Oleg Mitsura <oleg.mitsura@amdocs.com>
Change-Id: I44881a149a1cb5fd6dda2cf682352f92fba45e0d

ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/test/resources/execution-input/resource-assignment-input-missing-resource_assignment_request.json [new file with mode: 0644]

index 8ae128d..fcf0558 100644 (file)
@@ -44,6 +44,10 @@ open class BluePrintWorkflowExecutionServiceImpl(
         val workflowName = executionServiceInput.actionIdentifiers.actionName
 
         // Assign Workflow inputs
+        //check if request structure exists
+        if (!executionServiceInput.payload.has("$workflowName-request")) {
+            throw BluePrintProcessorException("Input request missing the expected '$workflowName-request' block!")
+        }
         val input = executionServiceInput.payload.get("$workflowName-request")
         bluePrintRuntimeService.assignWorkflowInputs(workflowName, input)
 
@@ -80,4 +84,4 @@ open class BluePrintWorkflowExecutionServiceImpl(
         return executionServiceOutput
     }
 
-}
\ No newline at end of file
+}
index 59be940..c15c054 100644 (file)
@@ -22,6 +22,7 @@ import org.junit.runner.RunWith
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
@@ -29,6 +30,7 @@ import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.test.context.ContextConfiguration
 import org.springframework.test.context.junit4.SpringRunner
 import kotlin.test.assertEquals
+import kotlin.test.assertFailsWith
 import kotlin.test.assertNotNull
 
 
@@ -43,18 +45,33 @@ class BluePrintWorkflowExecutionServiceImplTest {
     fun testBluePrintWorkflowExecutionService() {
         runBlocking {
             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
-                    "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+                "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
 
             val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json",
-                    ExecutionServiceInput::class.java)!!
-
+                ExecutionServiceInput::class.java)!!
 
             val executionServiceOutput = bluePrintWorkflowExecutionService
-                    .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())
+                .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())
 
             assertNotNull(executionServiceOutput, "failed to get response")
             assertEquals(BluePrintConstants.STATUS_SUCCESS, executionServiceOutput.status.message,
-                    "failed to get successful response")
+                "failed to get successful response")
+        }
+    }
+
+    @Test
+    fun `Blueprint fails on missing workflowName-parameters with a useful message`() {
+        assertFailsWith(exceptionClass = BluePrintProcessorException::class) {
+            runBlocking {
+                val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
+                    "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+                //service input will have a mislabeled input params, we are expecting to get an error when that happens with a useful error message
+                val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input-missing-resource_assignment_request.json",
+                    ExecutionServiceInput::class.java)!!
+
+                val executionServiceOutput = bluePrintWorkflowExecutionService
+                    .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())
+            }
         }
     }
 
diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/resources/execution-input/resource-assignment-input-missing-resource_assignment_request.json b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/resources/execution-input/resource-assignment-input-missing-resource_assignment_request.json
new file mode 100644 (file)
index 0000000..a44e171
--- /dev/null
@@ -0,0 +1,23 @@
+{
+  "commonHeader": {
+    "originatorId": "System",
+    "requestId": "1234",
+    "subRequestId": "1234-12234"
+  },
+  "actionIdentifiers": {
+    "blueprintName": "baseconfiguration",
+    "blueprintVersion": "1.0.0",
+    "actionName": "resource-assignment",
+    "mode": "sync"
+  },
+  "payload": {
+    "resource-assignment-mislabeled-request": {
+      "resource-assignment-properties": {
+        "request-id": "1234",
+        "action-name": "resource-assignment",
+        "scope-type": "vnf-type",
+        "hostname": "localhost"
+      }
+    }
+  }
+}