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 {
47 val log = logger(ImperativeWorkflowExecutionServiceTest::class)
51 mockkObject(BlueprintDependencyService)
52 every { BlueprintDependencyService.applicationContext.getBean(any()) } returns MockComponentFunction()
60 fun mockServiceTemplate(): ServiceTemplate {
61 return serviceTemplate(
62 "imperative-test", "1.0.0",
63 "brindasanth@onap.com", "tosca"
68 mockNodeTemplateComponentScriptExecutor(
70 "cba.wt.imperative.test.ResolveConfig"
74 mockNodeTemplateComponentScriptExecutor(
76 "cba.wt.imperative.test.ActivateConfig"
80 mockNodeTemplateComponentScriptExecutor(
81 "activate-config-rollback",
82 "cba.wt.imperative.test.ActivateConfigRollback"
86 mockNodeTemplateComponentScriptExecutor(
88 "cba.wt.imperative.test.ActivateLicence"
92 workflow("imperative-test-wf", "Test Imperative flow") {
93 step("resolve-config", "resolve-config", "") {
94 success("activate-config")
96 step("activate-config", "activate-config", "") {
97 success("activate-licence")
98 failure("activate-config-rollback")
100 step("activate-config-rollback", "activate-config-rollback", "")
101 step("activate-licence", "activate-licence", "")
104 nodeType(BlueprintTypes.nodeTypeComponentScriptExecutor())
109 fun testImperativeExecutionService() {
111 val serviceTemplate = mockServiceTemplate()
112 val bluePrintContext = BlueprintContext(serviceTemplate)
113 bluePrintContext.rootPath = normalizedPathName(".")
114 bluePrintContext.entryDefinition = "cba.imperative.test.ImperativeTestDefinitions.kt"
115 val bluePrintRuntimeService = BlueprintMetadataUtils.getBlueprintRuntime("12345", bluePrintContext)
117 val executionServiceInput = JacksonUtils
118 .readValueFromClassPathFile(
119 "execution-input/imperative-test-input.json",
120 ExecutionServiceInput::class.java
123 val imperativeWorkflowExecutionService = ImperativeWorkflowExecutionService(NodeTemplateExecutionService(mockk()))
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)