Renaming Files having BluePrint to have Blueprint
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / services / workflow-service / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / services / workflow / mock / MockComponentFunction.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2019 IBM.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.mock
19
20 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
21 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
22 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.nodeTemplateComponentScriptExecutor
23 import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintTypes
24 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
25 import org.slf4j.LoggerFactory
26 import org.springframework.beans.factory.config.ConfigurableBeanFactory
27 import org.springframework.context.annotation.Bean
28 import org.springframework.context.annotation.Configuration
29 import org.springframework.context.annotation.Scope
30 import org.springframework.stereotype.Component
31
32 fun mockNodeTemplateComponentScriptExecutor(id: String, script: String) = BlueprintTypes.nodeTemplateComponentScriptExecutor(
33     id,
34     "mock($id) component function"
35 ) {
36     definedOperation("") {
37         inputs {
38             type("kotlin")
39             scriptClassReference(script)
40         }
41     }
42 }
43
44 @Configuration
45 open class MockComponentConfiguration {
46
47     @Bean(name = ["component-resource-resolution", "component-netconf-executor", "component-jython-executor"])
48     open fun createComponentFunction(): AbstractComponentFunction {
49         return MockComponentFunction()
50     }
51 }
52
53 class MockComponentFunction : AbstractComponentFunction() {
54
55     private val log = LoggerFactory.getLogger(MockComponentFunction::class.java)
56
57     override suspend fun processNB(executionRequest: ExecutionServiceInput) {
58         log.info("Processing component : $operationInputs")
59
60         bluePrintRuntimeService.setNodeTemplateAttributeValue(
61             nodeTemplateName,
62             "assignment-params", "params".asJsonPrimitive()
63         )
64     }
65
66     override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
67         log.info("Recovering component..")
68     }
69 }
70
71 @Component("singleton-function")
72 @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
73 class SingletonComponentFunction : AbstractComponentFunction() {
74
75     private val log = LoggerFactory.getLogger(MockComponentFunction::class.java)
76
77     override suspend fun processNB(executionRequest: ExecutionServiceInput) {
78         log.info("Processing component : $operationInputs")
79     }
80
81     override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
82         log.info("Recovering component..")
83     }
84 }
85
86 @Component("prototype-function")
87 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
88 class PrototypeComponentFunction : AbstractComponentFunction() {
89
90     private val log = LoggerFactory.getLogger(MockComponentFunction::class.java)
91
92     override suspend fun processNB(executionRequest: ExecutionServiceInput) {
93         log.info("Processing component : $operationInputs")
94     }
95
96     override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
97         log.info("Recovering component..")
98     }
99 }