Add remote service function execution.
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / selfservice-api / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / selfservice / api / ExecutionServiceHandlerTest.kt
1 /*
2  * Copyright © 2018-2019 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.selfservice.api
18
19 import io.mockk.mockk
20 import kotlinx.coroutines.runBlocking
21 import org.junit.Before
22 import org.junit.runner.RunWith
23 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers
24 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader
25 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
26 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractServiceFunction
27 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
28 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
29 import org.springframework.beans.factory.annotation.Autowired
30 import org.springframework.context.ApplicationContext
31 import org.springframework.stereotype.Service
32 import org.springframework.test.context.ContextConfiguration
33 import org.springframework.test.context.junit4.SpringRunner
34 import kotlin.test.Test
35 import kotlin.test.assertNotNull
36 import kotlin.test.assertTrue
37
38 @RunWith(SpringRunner::class)
39 @ContextConfiguration(classes = [MockServiceAction::class])
40 class ExecutionServiceHandlerTest {
41
42     @Autowired
43     lateinit var applicationContext: ApplicationContext
44
45     @Before
46     fun init() {
47         BluePrintDependencyService.inject(applicationContext)
48     }
49
50     @Test
51     fun testExecuteServiceFunction() {
52         val executionServiceInput = ExecutionServiceInput().apply {
53             commonHeader = CommonHeader().apply {
54                 requestId = "1234"
55                 subRequestId = "1234-12"
56                 originatorId = "cds-test"
57             }
58             actionIdentifiers = ActionIdentifiers().apply {
59                 blueprintName = "default"
60                 blueprintVersion = "1.0.0"
61                 actionName = "mock-service-action"
62             }
63         }
64         runBlocking {
65             val executionServiceHandler = ExecutionServiceHandler(mockk(), mockk(), mockk())
66             val isServiceFunction = executionServiceHandler.checkServiceFunction(executionServiceInput)
67             assertTrue(isServiceFunction, "failed to checkServiceFunction")
68             val executionServiceOutput = executionServiceHandler.executeServiceFunction(executionServiceInput)
69             assertNotNull(executionServiceOutput, "failed to get executionServiceOutput")
70         }
71     }
72 }
73
74 @Service("mock-service-action")
75 class MockServiceAction : AbstractServiceFunction() {
76     override suspend fun processNB(executionRequest: ExecutionServiceInput) {
77         val responsePayload = """{"answer" : "correct"}""".jsonAsJsonType()
78         setResponsePayloadForAction(responsePayload)
79     }
80
81     override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
82
83     }
84 }