Enabling Code Formatter
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / selfservice-api / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / selfservice / api / mock / Mock.kt
1 /*
2  * Copyright (C) 2019 Bell Canada.
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 package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api.mock
18
19 import io.mockk.mockk
20 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
21 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor
22 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
23 import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
24 import org.slf4j.LoggerFactory
25 import org.springframework.context.annotation.Bean
26 import org.springframework.context.annotation.Configuration
27
28 @Configuration
29 open class MockComponentConfiguration {
30
31     @Bean(name = ["component-resource-assignment", "component-netconf-executor", "component-jython-executor"])
32     open fun createComponentFunction(): AbstractComponentFunction {
33         return MockComponentFunction()
34     }
35 }
36
37 class MockComponentFunction : AbstractComponentFunction() {
38
39     private val log = LoggerFactory.getLogger(MockComponentFunction::class.java)
40
41     override suspend fun processNB(executionRequest: ExecutionServiceInput) {
42         log.info("Processing component : $operationInputs")
43
44         bluePrintRuntimeService.setNodeTemplateAttributeValue(
45             nodeTemplateName,
46             "assignment-params", "params".asJsonPrimitive()
47         )
48     }
49
50     override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
51         log.info("Recovering component..")
52     }
53 }
54
55 open class MockResourceSource {
56
57     @Bean(
58         name = [
59             "rr-processor-source-input",
60             "rr-processor-source-default",
61             "rr-processor-source-db",
62             "rr-processor-source-rest"
63         ]
64     )
65     open fun sourceInstance(): ResourceAssignmentProcessor {
66         return mockk<ResourceAssignmentProcessor>()
67     }
68 }