2 * Copyright © 2019 IBM.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.ccsdk.cds.blueprintsprocessor.services.workflow
20 import io.mockk.mockkObject
21 import io.mockk.unmockkAll
22 import kotlinx.coroutines.runBlocking
23 import org.junit.After
24 import org.junit.Before
26 import org.junit.runner.RunWith
27 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
28 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
29 import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.mock.MockComponentFunction
30 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
31 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
32 import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintWorkflowExecutionService
33 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
34 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
35 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
36 import org.springframework.beans.factory.annotation.Autowired
37 import org.springframework.test.context.ContextConfiguration
38 import org.springframework.test.context.junit4.SpringRunner
39 import kotlin.test.assertEquals
40 import kotlin.test.assertFailsWith
41 import kotlin.test.assertNotNull
44 @RunWith(SpringRunner::class)
45 @ContextConfiguration(classes = [WorkflowServiceConfiguration::class])
46 class BluePrintWorkflowExecutionServiceImplTest {
49 lateinit var bluePrintWorkflowExecutionService: BluePrintWorkflowExecutionService<ExecutionServiceInput, ExecutionServiceOutput>
53 mockkObject(BluePrintDependencyService)
54 every { BluePrintDependencyService.applicationContext.getBean(any()) } returns MockComponentFunction()
63 fun testBluePrintWorkflowExecutionService() {
65 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
66 "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
68 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json",
69 ExecutionServiceInput::class.java)!!
71 val executionServiceOutput = bluePrintWorkflowExecutionService
72 .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())
74 assertNotNull(executionServiceOutput, "failed to get response")
75 assertEquals(BluePrintConstants.STATUS_SUCCESS, executionServiceOutput.status.message,
76 "failed to get successful response")
81 fun testImperativeBluePrintWorkflowExecutionService() {
83 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
84 "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
86 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/imperative-test-input.json",
87 ExecutionServiceInput::class.java)!!
89 val executionServiceOutput = bluePrintWorkflowExecutionService
90 .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())
92 assertNotNull(executionServiceOutput, "failed to get response")
93 assertEquals(BluePrintConstants.STATUS_SUCCESS, executionServiceOutput.status.message,
94 "failed to get successful response")
99 fun `Blueprint fails on missing workflowName-parameters with a useful message`() {
100 assertFailsWith(exceptionClass = BluePrintProcessorException::class) {
102 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
103 "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
104 //service input will have a mislabeled input params, we are expecting to get an error when that happens with a useful error message
105 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input-missing-resource_assignment_request.json",
106 ExecutionServiceInput::class.java)!!
108 val executionServiceOutput = bluePrintWorkflowExecutionService
109 .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())