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 io.mockk.coEvery
21 import io.mockk.coVerify
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(
47 MockServiceAction::class, SelfServiceApiTestConfiguration::class,
48 ErrorCatalogTestConfiguration::class
51 @TestPropertySource(locations = ["classpath:application-test.properties"])
52 class ExecutionServiceHandlerTest {
55 lateinit var applicationContext: ApplicationContext
59 BluePrintDependencyService.inject(applicationContext)
63 fun testExecuteServiceFunction() {
64 val executionServiceInput = ExecutionServiceInput().apply {
65 commonHeader = CommonHeader().apply {
67 subRequestId = "1234-12"
68 originatorId = "cds-test"
70 actionIdentifiers = ActionIdentifiers().apply {
71 blueprintName = "default"
72 blueprintVersion = "1.0.0"
73 actionName = "mock-service-action"
77 val executionServiceHandler = ExecutionServiceHandler(mockk(), mockk(), mockk(), mockk())
78 val isServiceFunction = executionServiceHandler.checkServiceFunction(executionServiceInput)
79 assertTrue(isServiceFunction, "failed to checkServiceFunction")
80 val executionServiceOutput = executionServiceHandler.executeServiceFunction(executionServiceInput)
81 assertNotNull(executionServiceOutput, "failed to get executionServiceOutput")
86 fun testPublishAuditFunction() {
87 val executionServiceInput = ExecutionServiceInput().apply {
88 commonHeader = CommonHeader().apply {
90 subRequestId = "1234-12"
91 originatorId = "cds-test"
93 actionIdentifiers = ActionIdentifiers().apply {
94 blueprintName = "default"
95 blueprintVersion = "1.0.0"
96 actionName = "mock-service-action"
100 val publishAuditService = mockk<KafkaPublishAuditService>(relaxed = true)
101 val executionServiceHandler = ExecutionServiceHandler(
108 coEvery { publishAuditService.publishExecutionInput(ExecutionServiceInput()) } just Runs
110 var executionServiceOutput: ExecutionServiceOutput? = null
112 executionServiceOutput = executionServiceHandler.doProcess(executionServiceInput)
116 publishAuditService.publishExecutionInput(executionServiceInput)
117 publishAuditService.publishExecutionOutput(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) {