From 7eabc157204d2b027ac1a699dd0c3b5b18e117fb Mon Sep 17 00:00:00 2001 From: Oleg Mitsura Date: Mon, 15 Jul 2019 16:42:17 -0400 Subject: better errMsg for request block missing Issue-Id: CCSDK-1486 Signed-off-by: Oleg Mitsura Change-Id: I44881a149a1cb5fd6dda2cf682352f92fba45e0d --- .../BluePrintWorkflowExecutionServiceImpl.kt | 6 ++++- .../BluePrintWorkflowExecutionServiceImplTest.kt | 27 ++++++++++++++++++---- ...-input-missing-resource_assignment_request.json | 23 ++++++++++++++++++ 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 ms/blueprintsprocessor/modules/services/workflow-service/src/test/resources/execution-input/resource-assignment-input-missing-resource_assignment_request.json diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt index 8ae128d4b..fcf0558c7 100644 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImpl.kt @@ -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 +} diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt index 59be9406e..c15c054db 100644 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/BluePrintWorkflowExecutionServiceImplTest.kt @@ -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 index 000000000..a44e171a3 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/resources/execution-input/resource-assignment-input-missing-resource_assignment_request.json @@ -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" + } + } + } +} -- cgit 1.2.3-korg