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.data.ServiceTemplate
31 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate
32 import org.onap.ccsdk.cds.controllerblueprints.core.logger
33 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
34 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
35 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
36 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
37 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
38 import kotlin.test.Test
39 import kotlin.test.assertNotNull
41 class ImperativeWorkflowExecutionServiceTest {
42 val log = logger(ImperativeWorkflowExecutionServiceTest::class)
46 mockkObject(BluePrintDependencyService)
47 every { BluePrintDependencyService.applicationContext.getBean(any()) } returns MockComponentFunction()
55 fun mockServiceTemplate(): ServiceTemplate {
56 return serviceTemplate("imperative-test", "1.0.0",
57 "brindasanth@onap.com", "tosca") {
60 nodeTemplate(mockNodeTemplateComponentScriptExecutor("resolve-config",
61 "cba.wt.imperative.test.ResolveConfig"))
62 nodeTemplate(mockNodeTemplateComponentScriptExecutor("activate-config",
63 "cba.wt.imperative.test.ActivateConfig"))
64 nodeTemplate(mockNodeTemplateComponentScriptExecutor("activate-config-rollback",
65 "cba.wt.imperative.test.ActivateConfigRollback"))
66 nodeTemplate(mockNodeTemplateComponentScriptExecutor("activate-licence",
67 "cba.wt.imperative.test.ActivateLicence"))
69 workflow("imperative-test-wf", "Test Imperative flow") {
70 step("resolve-config", "resolve-config", "") {
71 success("activate-config")
73 step("activate-config", "activate-config", "") {
74 success("activate-licence")
75 failure("activate-config-rollback")
77 step("activate-config-rollback", "activate-config-rollback", "")
78 step("activate-licence", "activate-licence", "")
81 nodeType(BluePrintTypes.nodeTypeComponentScriptExecutor())
86 fun testImperativeExecutionService() {
88 val serviceTemplate = mockServiceTemplate()
89 val bluePrintContext = BluePrintContext(serviceTemplate)
90 bluePrintContext.rootPath = normalizedPathName(".")
91 bluePrintContext.entryDefinition = "cba.imperative.test.ImperativeTestDefinitions.kt"
92 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("12345", bluePrintContext)
94 val executionServiceInput = JacksonUtils
95 .readValueFromClassPathFile("execution-input/imperative-test-input.json",
96 ExecutionServiceInput::class.java)!!
98 val bluePrintWorkFlowService = ImperativeBluePrintWorkflowService(NodeTemplateExecutionService())
99 val imperativeWorkflowExecutionService = ImperativeWorkflowExecutionService(bluePrintWorkFlowService)
100 val output = imperativeWorkflowExecutionService
101 .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())
102 assertNotNull(output)