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
25 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
26 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.nodeTypeComponentScriptExecutor
27 import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.mock.MockComponentFunction
28 import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.mock.mockNodeTemplateComponentScriptExecutor
29 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
30 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate
31 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
32 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
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 kotlin.test.Test
37 import kotlin.test.assertNotNull
39 class ImperativeWorkflowExecutionServiceTest {
43 mockkObject(BluePrintDependencyService)
44 every { BluePrintDependencyService.applicationContext.getBean(any()) } returns MockComponentFunction()
53 fun testImperativeExecutionService() {
55 val serviceTemplate = serviceTemplate("imperative-test", "1.0.0",
56 "brindasanth@onap.com", "tosca") {
59 nodeTemplate(mockNodeTemplateComponentScriptExecutor("resolve-config",
60 "cba.wt.imperative.test.ResolveConfig"))
61 nodeTemplate(mockNodeTemplateComponentScriptExecutor("activate-config",
62 "cba.wt.imperative.test.ActivateConfig"))
63 nodeTemplate(mockNodeTemplateComponentScriptExecutor("activate-config-rollback",
64 "cba.wt.imperative.test.ActivateConfigRollback"))
65 nodeTemplate(mockNodeTemplateComponentScriptExecutor("activate-licence",
66 "cba.wt.imperative.test.ActivateLicence"))
68 workflow("test-wf", "Test Imperative flow") {
69 step("resolve-config", "resolve-config", "") {
70 success("activate-config")
72 step("activate-config", "activate-config", "") {
73 success("activate-licence")
74 failure("activate-config-rollback")
76 step("activate-config-rollback", "activate-config-rollback", "")
77 step("activate-licence", "activate-licence", "")
80 nodeType(BluePrintTypes.nodeTypeComponentScriptExecutor())
83 val bluePrintContext = BluePrintContext(serviceTemplate)
84 bluePrintContext.rootPath = normalizedPathName(".")
85 bluePrintContext.entryDefinition = "cba.imperative.test.ImperativeTestDefinitions.kt"
86 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("12345", bluePrintContext)
88 val executionServiceInput = JacksonUtils
89 .readValueFromClassPathFile("execution-input/imperative-test-input.json",
90 ExecutionServiceInput::class.java)!!
92 val bluePrintWorkFlowService = ImperativeBluePrintWorkflowService(NodeTemplateExecutionService())
93 val imperativeWorkflowExecutionService = ImperativeWorkflowExecutionService(bluePrintWorkFlowService)
94 val output = imperativeWorkflowExecutionService
95 .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())