3c740725e4df04a42205a77991f1d91f98423020
[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.Before
21 import org.junit.Test
22 import org.junit.runner.RunWith
23 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
24 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
25 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
26 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
27 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService
28 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
29 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
30 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
31 import org.springframework.beans.factory.annotation.Autowired
32 import org.springframework.context.ApplicationContext
33 import org.springframework.test.context.ContextConfiguration
34 import org.springframework.test.context.junit4.SpringRunner
35 import kotlin.test.assertEquals
36 import kotlin.test.assertFailsWith
37 import kotlin.test.assertNotNull
38
39
40 @RunWith(SpringRunner::class)
41 @ContextConfiguration(classes = [WorkflowServiceConfiguration::class])
42 class BluePrintWorkflowExecutionServiceImplTest {
43
44     @Autowired
45     lateinit var applicationContext: ApplicationContext
46
47     @Autowired
48     lateinit var bluePrintWorkflowExecutionService: BluePrintWorkflowExecutionService<ExecutionServiceInput, ExecutionServiceOutput>
49
50     @Before
51     fun init() {
52         BluePrintDependencyService.inject(applicationContext)
53     }
54
55     @Test
56     fun testBluePrintWorkflowExecutionService() {
57         runBlocking {
58             val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
59                 "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
60
61             val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json",
62                 ExecutionServiceInput::class.java)!!
63
64             val executionServiceOutput = bluePrintWorkflowExecutionService
65                 .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())
66
67             assertNotNull(executionServiceOutput, "failed to get response")
68             assertEquals(BluePrintConstants.STATUS_SUCCESS, executionServiceOutput.status.message,
69                 "failed to get successful response")
70         }
71     }
72
73     @Test
74     fun `Blueprint fails on missing workflowName-parameters with a useful message`() {
75         assertFailsWith(exceptionClass = BluePrintProcessorException::class) {
76             runBlocking {
77                 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
78                     "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
79                 //service input will have a mislabeled input params, we are expecting to get an error when that happens with a useful error message
80                 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input-missing-resource_assignment_request.json",
81                     ExecutionServiceInput::class.java)!!
82
83                 val executionServiceOutput = bluePrintWorkflowExecutionService
84                     .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())
85             }
86         }
87     }
88
89 }