2 * Copyright © 2018-2019 AT&T Intellectual Property.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api
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
38 @RunWith(SpringRunner::class)
39 @ContextConfiguration(classes = [MockServiceAction::class])
40 class ExecutionServiceHandlerTest {
43 lateinit var applicationContext: ApplicationContext
47 BluePrintDependencyService.inject(applicationContext)
51 fun testExecuteServiceFunction() {
52 val executionServiceInput = ExecutionServiceInput().apply {
53 commonHeader = CommonHeader().apply {
55 subRequestId = "1234-12"
56 originatorId = "cds-test"
58 actionIdentifiers = ActionIdentifiers().apply {
59 blueprintName = "default"
60 blueprintVersion = "1.0.0"
61 actionName = "mock-service-action"
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")
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)
81 override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {