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
19 import io.mockk.verify
20 import io.mockk.coVerify
22 import io.mockk.coEvery
25 import kotlinx.coroutines.runBlocking
26 import org.junit.Before
27 import org.junit.runner.RunWith
28 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers
29 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader
30 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
31 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
32 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractServiceFunction
33 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
34 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
35 import org.springframework.beans.factory.annotation.Autowired
36 import org.springframework.context.ApplicationContext
37 import org.springframework.stereotype.Service
38 import org.springframework.test.context.ContextConfiguration
39 import org.springframework.test.context.TestPropertySource
40 import org.springframework.test.context.junit4.SpringRunner
41 import kotlin.test.Test
42 import kotlin.test.assertNotNull
43 import kotlin.test.assertTrue
45 @RunWith(SpringRunner::class)
46 @ContextConfiguration(classes = [MockServiceAction::class, SelfServiceApiTestConfiguration::class,
47 ErrorCatalogTestConfiguration::class])
48 @TestPropertySource(locations = ["classpath:application-test.properties"])
49 class ExecutionServiceHandlerTest {
52 lateinit var applicationContext: ApplicationContext
56 BluePrintDependencyService.inject(applicationContext)
60 fun testExecuteServiceFunction() {
61 val executionServiceInput = ExecutionServiceInput().apply {
62 commonHeader = CommonHeader().apply {
64 subRequestId = "1234-12"
65 originatorId = "cds-test"
67 actionIdentifiers = ActionIdentifiers().apply {
68 blueprintName = "default"
69 blueprintVersion = "1.0.0"
70 actionName = "mock-service-action"
74 val executionServiceHandler = ExecutionServiceHandler(mockk(), mockk(), mockk(), mockk())
75 val isServiceFunction = executionServiceHandler.checkServiceFunction(executionServiceInput)
76 assertTrue(isServiceFunction, "failed to checkServiceFunction")
77 val executionServiceOutput = executionServiceHandler.executeServiceFunction(executionServiceInput)
78 assertNotNull(executionServiceOutput, "failed to get executionServiceOutput")
83 fun testPublishAuditFunction() {
84 val executionServiceInput = ExecutionServiceInput().apply {
85 commonHeader = CommonHeader().apply {
87 subRequestId = "1234-12"
88 originatorId = "cds-test"
90 actionIdentifiers = ActionIdentifiers().apply {
91 blueprintName = "default"
92 blueprintVersion = "1.0.0"
93 actionName = "mock-service-action"
97 val publishAuditService = mockk<KafkaPublishAuditService>(relaxed = true)
98 val executionServiceHandler = ExecutionServiceHandler(
105 coEvery { publishAuditService.publish(ExecutionServiceInput()) } just Runs
107 var executionServiceOutput: ExecutionServiceOutput? = null
109 executionServiceOutput = executionServiceHandler.doProcess(executionServiceInput)
113 publishAuditService.publish(executionServiceInput)
117 publishAuditService.publish(executionServiceInput.correlationUUID, executionServiceOutput!!)
122 @Service("mock-service-action")
123 class MockServiceAction : AbstractServiceFunction() {
125 override suspend fun processNB(executionRequest: ExecutionServiceInput) {
126 val responsePayload = """{"answer" : "correct"}""".jsonAsJsonType()
127 setResponsePayloadForAction(responsePayload)
130 override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {