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.common.api.EventType
30 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
31 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
32 import org.onap.ccsdk.cds.controllerblueprints.core.data.ServiceTemplate
33 import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate
34 import org.onap.ccsdk.cds.controllerblueprints.core.logger
35 import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName
36 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintContext
37 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
38 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
39 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
40 import kotlin.test.Test
41 import kotlin.test.assertEquals
42 import kotlin.test.assertNotNull
44 class ImperativeWorkflowExecutionServiceTest {
45 val log = logger(ImperativeWorkflowExecutionServiceTest::class)
49 mockkObject(BluePrintDependencyService)
50 every { BluePrintDependencyService.applicationContext.getBean(any()) } returns MockComponentFunction()
58 fun mockServiceTemplate(): ServiceTemplate {
59 return serviceTemplate(
60 "imperative-test", "1.0.0",
61 "brindasanth@onap.com", "tosca"
66 mockNodeTemplateComponentScriptExecutor(
68 "cba.wt.imperative.test.ResolveConfig"
72 mockNodeTemplateComponentScriptExecutor(
74 "cba.wt.imperative.test.ActivateConfig"
78 mockNodeTemplateComponentScriptExecutor(
79 "activate-config-rollback",
80 "cba.wt.imperative.test.ActivateConfigRollback"
84 mockNodeTemplateComponentScriptExecutor(
86 "cba.wt.imperative.test.ActivateLicence"
90 workflow("imperative-test-wf", "Test Imperative flow") {
91 step("resolve-config", "resolve-config", "") {
92 success("activate-config")
94 step("activate-config", "activate-config", "") {
95 success("activate-licence")
96 failure("activate-config-rollback")
98 step("activate-config-rollback", "activate-config-rollback", "")
99 step("activate-licence", "activate-licence", "")
102 nodeType(BluePrintTypes.nodeTypeComponentScriptExecutor())
107 fun testImperativeExecutionService() {
109 val serviceTemplate = mockServiceTemplate()
110 val bluePrintContext = BluePrintContext(serviceTemplate)
111 bluePrintContext.rootPath = normalizedPathName(".")
112 bluePrintContext.entryDefinition = "cba.imperative.test.ImperativeTestDefinitions.kt"
113 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("12345", bluePrintContext)
115 val executionServiceInput = JacksonUtils
116 .readValueFromClassPathFile(
117 "execution-input/imperative-test-input.json",
118 ExecutionServiceInput::class.java
121 val bluePrintWorkFlowService = ImperativeBluePrintWorkflowService(NodeTemplateExecutionService())
122 val imperativeWorkflowExecutionService = ImperativeWorkflowExecutionService(bluePrintWorkFlowService)
123 val output = imperativeWorkflowExecutionService
124 .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())
125 assertNotNull(output, "failed to get imperative workflow output")
126 assertNotNull(output.status, "failed to get imperative workflow output status")
127 assertEquals(output.status.message, BluePrintConstants.STATUS_SUCCESS)
128 assertEquals(output.status.eventType, EventType.EVENT_COMPONENT_EXECUTED.name)