Migrate ccsdk/apps to ccsdk/cds
[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  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.cds.blueprintsprocessor.services.workflow.mock
18
19 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
20 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
21 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
22 import org.slf4j.LoggerFactory
23 import org.springframework.beans.factory.config.ConfigurableBeanFactory
24 import org.springframework.context.annotation.Bean
25 import org.springframework.context.annotation.Configuration
26 import org.springframework.context.annotation.Scope
27 import org.springframework.stereotype.Component
28
29 @Configuration
30 open class MockComponentConfiguration {
31
32     @Bean(name = ["component-resource-resolution", "component-netconf-executor", "component-jython-executor"])
33     open fun createComponentFunction(): AbstractComponentFunction {
34         return MockComponentFunction()
35     }
36 }
37
38 class MockComponentFunction : AbstractComponentFunction() {
39
40     private val log = LoggerFactory.getLogger(MockComponentFunction::class.java)
41
42     override fun process(executionRequest: ExecutionServiceInput) {
43         log.info("Processing component : $operationInputs")
44
45         bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName,
46                 "assignment-params", "params".asJsonPrimitive())
47     }
48
49     override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
50         log.info("Recovering component..")
51     }
52 }
53
54 @Component("singleton-function")
55 @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON)
56 class SingletonComponentFunction : AbstractComponentFunction() {
57
58     private val log = LoggerFactory.getLogger(MockComponentFunction::class.java)
59
60     override fun process(executionRequest: ExecutionServiceInput) {
61         log.info("Processing component : $operationInputs")
62     }
63
64     override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
65         log.info("Recovering component..")
66     }
67 }
68
69 @Component("prototype-function")
70 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
71 class PrototypeComponentFunction : AbstractComponentFunction() {
72
73     private val log = LoggerFactory.getLogger(MockComponentFunction::class.java)
74
75     override fun process(executionRequest: ExecutionServiceInput) {
76         log.info("Processing component : $operationInputs")
77     }
78
79     override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
80         log.info("Recovering component..")
81     }
82 }