b21f968c9ec12a96d50721502dd0b5f00f62f252
[ccsdk/cds.git] /
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.TestPropertySource
34 import org.springframework.test.context.junit4.SpringRunner
35 import kotlin.test.Test
36 import kotlin.test.assertNotNull
37 import kotlin.test.assertTrue
38
39 @RunWith(SpringRunner::class)
40 @ContextConfiguration(classes = [MockServiceAction::class, SelfServiceApiTestConfiguration::class,
41     ErrorCatalogTestConfiguration::class])
42 @TestPropertySource(locations = ["classpath:application-test.properties"])
43 class ExecutionServiceHandlerTest {
44
45     @Autowired
46     lateinit var applicationContext: ApplicationContext
47
48     @Before
49     fun init() {
50         BluePrintDependencyService.inject(applicationContext)
51     }
52
53     @Test
54     fun testExecuteServiceFunction() {
55         val executionServiceInput = ExecutionServiceInput().apply {
56             commonHeader = CommonHeader().apply {
57                 requestId = "1234"
58                 subRequestId = "1234-12"
59                 originatorId = "cds-test"
60             }
61             actionIdentifiers = ActionIdentifiers().apply {
62                 blueprintName = "default"
63                 blueprintVersion = "1.0.0"
64                 actionName = "mock-service-action"
65             }
66         }
67         runBlocking {
68             val executionServiceHandler = ExecutionServiceHandler(mockk(), mockk(), mockk())
69             val isServiceFunction = executionServiceHandler.checkServiceFunction(executionServiceInput)
70             assertTrue(isServiceFunction, "failed to checkServiceFunction")
71             val executionServiceOutput = executionServiceHandler.executeServiceFunction(executionServiceInput)
72             assertNotNull(executionServiceOutput, "failed to get executionServiceOutput")
73         }
74     }
75 }
76
77 @Service("mock-service-action")
78 class MockServiceAction : AbstractServiceFunction() {
79
80     override suspend fun processNB(executionRequest: ExecutionServiceInput) {
81         val responsePayload = """{"answer" : "correct"}""".jsonAsJsonType()
82         setResponsePayloadForAction(responsePayload)
83     }
84
85     override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
86     }
87 }