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
21 import io.mockk.mockkObject
22 import io.mockk.unmockkAll
23 import kotlinx.coroutines.runBlocking
24 import org.junit.After
25 import org.junit.Before
26 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
27 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.nodeTypeComponentScriptExecutor
28 import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.mock.MockComponentFunction
29 import org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.mock.mockNodeTemplateComponentScriptExecutor
30 import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType
31 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
32 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
33 import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
34 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate
35 import org.onap.ccsdk.cds.controllerblueprints.core.logger
36 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
37 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
38 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
39 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
40 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
41 import kotlin.test.Test
42 import kotlin.test.assertEquals
43 import kotlin.test.assertNotNull
45 class ImperativeWorkflowExecutionServiceTest {
46 val log = logger(ImperativeWorkflowExecutionServiceTest::class)
50 mockkObject(BluePrintDependencyService)
51 every { BluePrintDependencyService.applicationContext.getBean(any()) } returns MockComponentFunction()
59 fun mockServiceTemplate(): ServiceTemplate {
60 return serviceTemplate(
61 "imperative-test", "1.0.0",
62 "brindasanth@onap.com", "tosca"
67 mockNodeTemplateComponentScriptExecutor(
69 "cba.wt.imperative.test.ResolveConfig"
73 mockNodeTemplateComponentScriptExecutor(
75 "cba.wt.imperative.test.ActivateConfig"
79 mockNodeTemplateComponentScriptExecutor(
80 "activate-config-rollback",
81 "cba.wt.imperative.test.ActivateConfigRollback"
85 mockNodeTemplateComponentScriptExecutor(
87 "cba.wt.imperative.test.ActivateLicence"
91 workflow("imperative-test-wf", "Test Imperative flow") {
92 step("resolve-config", "resolve-config", "") {
93 success("activate-config")
95 step("activate-config", "activate-config", "") {
96 success("activate-licence")
97 failure("activate-config-rollback")
99 step("activate-config-rollback", "activate-config-rollback", "")
100 step("activate-licence", "activate-licence", "")
103 nodeType(BluePrintTypes.nodeTypeComponentScriptExecutor())
108 fun testImperativeExecutionService() {
110 val serviceTemplate = mockServiceTemplate()
111 val bluePrintContext = BluePrintContext(serviceTemplate)
112 bluePrintContext.rootPath = normalizedPathName(".")
113 bluePrintContext.entryDefinition = "cba.imperative.test.ImperativeTestDefinitions.kt"
114 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("12345", bluePrintContext)
116 val executionServiceInput = JacksonUtils
117 .readValueFromClassPathFile(
118 "execution-input/imperative-test-input.json",
119 ExecutionServiceInput::class.java
122 val bluePrintWorkFlowService = ImperativeBluePrintWorkflowService(NodeTemplateExecutionService(mockk()))
123 val imperativeWorkflowExecutionService = ImperativeWorkflowExecutionService(bluePrintWorkFlowService)
124 val output = imperativeWorkflowExecutionService
125 .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())
126 assertNotNull(output, "failed to get imperative workflow output")
127 assertNotNull(output.status, "failed to get imperative workflow output status")
128 assertEquals(output.status.message, BluePrintConstants.STATUS_SUCCESS)
129 assertEquals(output.status.eventType, EventType.EVENT_COMPONENT_EXECUTED.name)