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.coVerify
21 import io.mockk.coEvery
24 import kotlinx.coroutines.runBlocking
25 import org.junit.Before
26 import org.junit.runner.RunWith
27 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers
28 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader
29 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
30 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
31 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractServiceFunction
32 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
33 import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
34 import org.springframework.beans.factory.annotation.Autowired
35 import org.springframework.context.ApplicationContext
36 import org.springframework.stereotype.Service
37 import org.springframework.test.context.ContextConfiguration
38 import org.springframework.test.context.TestPropertySource
39 import org.springframework.test.context.junit4.SpringRunner
40 import kotlin.test.Test
41 import kotlin.test.assertNotNull
42 import kotlin.test.assertTrue
44 @RunWith(SpringRunner::class)
45 @ContextConfiguration(classes = [MockServiceAction::class, SelfServiceApiTestConfiguration::class,
46 ErrorCatalogTestConfiguration::class])
47 @TestPropertySource(locations = ["classpath:application-test.properties"])
48 class ExecutionServiceHandlerTest {
51 lateinit var applicationContext: ApplicationContext
55 BluePrintDependencyService.inject(applicationContext)
59 fun testExecuteServiceFunction() {
60 val executionServiceInput = ExecutionServiceInput().apply {
61 commonHeader = CommonHeader().apply {
63 subRequestId = "1234-12"
64 originatorId = "cds-test"
66 actionIdentifiers = ActionIdentifiers().apply {
67 blueprintName = "default"
68 blueprintVersion = "1.0.0"
69 actionName = "mock-service-action"
73 val executionServiceHandler = ExecutionServiceHandler(mockk(), mockk(), mockk(), mockk())
74 val isServiceFunction = executionServiceHandler.checkServiceFunction(executionServiceInput)
75 assertTrue(isServiceFunction, "failed to checkServiceFunction")
76 val executionServiceOutput = executionServiceHandler.executeServiceFunction(executionServiceInput)
77 assertNotNull(executionServiceOutput, "failed to get executionServiceOutput")
82 fun testPublishAuditFunction() {
83 val executionServiceInput = ExecutionServiceInput().apply {
84 commonHeader = CommonHeader().apply {
86 subRequestId = "1234-12"
87 originatorId = "cds-test"
89 actionIdentifiers = ActionIdentifiers().apply {
90 blueprintName = "default"
91 blueprintVersion = "1.0.0"
92 actionName = "mock-service-action"
96 val publishAuditService = mockk<KafkaPublishAuditService>(relaxed = true)
97 val executionServiceHandler = ExecutionServiceHandler(
104 coEvery { publishAuditService.publishExecutionInput(ExecutionServiceInput()) } just Runs
106 var executionServiceOutput: ExecutionServiceOutput? = null
108 executionServiceOutput = executionServiceHandler.doProcess(executionServiceInput)
112 publishAuditService.publishExecutionInput(executionServiceInput)
113 publishAuditService.publishExecutionOutput(executionServiceInput.correlationUUID, executionServiceOutput!!)
118 @Service("mock-service-action")
119 class MockServiceAction : AbstractServiceFunction() {
121 override suspend fun processNB(executionRequest: ExecutionServiceInput) {
122 val responsePayload = """{"answer" : "correct"}""".jsonAsJsonType()
123 setResponsePayloadForAction(responsePayload)
126 override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {