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
19 import kotlinx.coroutines.runBlocking
20 import org.junit.Before
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
40 @RunWith(SpringRunner::class)
41 @ContextConfiguration(classes = [WorkflowServiceConfiguration::class])
42 class BluePrintWorkflowExecutionServiceImplTest {
45 lateinit var applicationContext: ApplicationContext
48 lateinit var bluePrintWorkflowExecutionService: BluePrintWorkflowExecutionService<ExecutionServiceInput, ExecutionServiceOutput>
52 BluePrintDependencyService.inject(applicationContext)
56 fun testBluePrintWorkflowExecutionService() {
58 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
59 "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
61 val executionServiceInput = JacksonUtils.readValueFromClassPathFile("execution-input/resource-assignment-input.json",
62 ExecutionServiceInput::class.java)!!
64 val executionServiceOutput = bluePrintWorkflowExecutionService
65 .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())
67 assertNotNull(executionServiceOutput, "failed to get response")
68 assertEquals(BluePrintConstants.STATUS_SUCCESS, executionServiceOutput.status.message,
69 "failed to get successful response")
74 fun `Blueprint fails on missing workflowName-parameters with a useful message`() {
75 assertFailsWith(exceptionClass = BluePrintProcessorException::class) {
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)!!
83 val executionServiceOutput = bluePrintWorkflowExecutionService
84 .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())