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("imperative-test", "1.0.0",
60 "brindasanth@onap.com", "tosca") {
63 nodeTemplate(mockNodeTemplateComponentScriptExecutor("resolve-config",
64 "cba.wt.imperative.test.ResolveConfig"))
65 nodeTemplate(mockNodeTemplateComponentScriptExecutor("activate-config",
66 "cba.wt.imperative.test.ActivateConfig"))
67 nodeTemplate(mockNodeTemplateComponentScriptExecutor("activate-config-rollback",
68 "cba.wt.imperative.test.ActivateConfigRollback"))
69 nodeTemplate(mockNodeTemplateComponentScriptExecutor("activate-licence",
70 "cba.wt.imperative.test.ActivateLicence"))
72 workflow("imperative-test-wf", "Test Imperative flow") {
73 step("resolve-config", "resolve-config", "") {
74 success("activate-config")
76 step("activate-config", "activate-config", "") {
77 success("activate-licence")
78 failure("activate-config-rollback")
80 step("activate-config-rollback", "activate-config-rollback", "")
81 step("activate-licence", "activate-licence", "")
84 nodeType(BluePrintTypes.nodeTypeComponentScriptExecutor())
89 fun testImperativeExecutionService() {
91 val serviceTemplate = mockServiceTemplate()
92 val bluePrintContext = BluePrintContext(serviceTemplate)
93 bluePrintContext.rootPath = normalizedPathName(".")
94 bluePrintContext.entryDefinition = "cba.imperative.test.ImperativeTestDefinitions.kt"
95 val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("12345", bluePrintContext)
97 val executionServiceInput = JacksonUtils
98 .readValueFromClassPathFile("execution-input/imperative-test-input.json",
99 ExecutionServiceInput::class.java)!!
101 val bluePrintWorkFlowService = ImperativeBluePrintWorkflowService(NodeTemplateExecutionService())
102 val imperativeWorkflowExecutionService = ImperativeWorkflowExecutionService(bluePrintWorkFlowService)
103 val output = imperativeWorkflowExecutionService
104 .executeBluePrintWorkflow(bluePrintRuntimeService, executionServiceInput, hashMapOf())
105 assertNotNull(output, "failed to get imperative workflow output")
106 assertNotNull(output.status, "failed to get imperative workflow output status")
107 assertEquals(output.status.message, BluePrintConstants.STATUS_SUCCESS)
108 assertEquals(output.status.eventType, EventType.EVENT_COMPONENT_EXECUTED.name)