c15c054db3939108d7bc304f186507844d81301e
[ccsdk/cds.git] /
1 /*
2  *  Copyright © 2019 IBM.
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16
17 package org.onap.ccsdk.cds.blueprintsprocessor.services.workflow
18
19 import kotlinx.coroutines.runBlocking
20 import org.junit.Test
21 import org.junit.runner.RunWith
22 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
23 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
24 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
25 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
26 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService
27 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
28 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
29 import org.springframework.beans.factory.annotation.Autowired
30 import org.springframework.test.context.ContextConfiguration
31 import org.springframework.test.context.junit4.SpringRunner
32 import kotlin.test.assertEquals
33 import kotlin.test.assertFailsWith
34 import kotlin.test.assertNotNull
35
36
37 @RunWith(SpringRunner::class)
38 @ContextConfiguration(classes = [WorkflowServiceConfiguration::class])
39 class BluePrintWorkflowExecutionServiceImplTest {
40
41     @Autowired
42     lateinit var bluePrintWorkflowExecutionService: BluePrintWorkflowExecutionService<ExecutionServiceInput, ExecutionServiceOutput>
43
44     @Test
45     fun testBluePrintWorkflowExecutionService() {
46         runBlocking {
47             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
48                 "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
49
50             val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json",
51                 ExecutionServiceInput::class.java)!!
52
53             val executionServiceOutput = bluePrintWorkflowExecutionService
54                 .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())
55
56             assertNotNull(executionServiceOutput, "failed to get response")
57             assertEquals(BluePrintConstants.STATUS_SUCCESS, executionServiceOutput.status.message,
58                 "failed to get successful response")
59         }
60     }
61
62     @Test
63     fun `Blueprint fails on missing workflowName-parameters with a useful message`() {
64         assertFailsWith(exceptionClass = BluePrintProcessorException::class) {
65             runBlocking {
66                 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
67                     "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
68                 //service input will have a mislabeled input params, we are expecting to get an error when that happens with a useful error message
69                 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input-missing-resource_assignment_request.json",
70                     ExecutionServiceInput::class.java)!!
71
72                 val executionServiceOutput = bluePrintWorkflowExecutionService
73                     .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())
74             }
75         }
76     }
77
78 }