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.micrometer.core.instrument.MeterRegistry
20 import io.mockk.coVerify
22 import io.mockk.coEvery
23 import io.mockk.coVerify
26 import kotlinx.coroutines.runBlocking
27 import org.junit.Before
28 import org.junit.runner.RunWith
29 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ActionIdentifiers
30 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.CommonHeader
31 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
32 import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutput
33 import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractServiceFunction
34 import org.onap.ccsdk.cds.controllerblueprints.core.jsonAsJsonType
35 import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintDependencyService
36 import org.springframework.beans.factory.annotation.Autowired
37 import org.springframework.boot.test.mock.mockito.MockBean
38 import org.springframework.context.ApplicationContext
39 import org.springframework.stereotype.Service
40 import org.springframework.test.context.ContextConfiguration
41 import org.springframework.test.context.TestPropertySource
42 import org.springframework.test.context.junit4.SpringRunner
43 import kotlin.test.Test
44 import kotlin.test.assertNotNull
45 import kotlin.test.assertTrue
47 @RunWith(SpringRunner::class)
48 @ContextConfiguration(
50 MockServiceAction::class, SelfServiceApiTestConfiguration::class,
51 ErrorCatalogTestConfiguration::class
54 @TestPropertySource(locations = ["classpath:application-test.properties"])
55 class ExecutionServiceHandlerTest {
58 lateinit var meterRegistry: MeterRegistry
61 lateinit var applicationContext: ApplicationContext
65 BlueprintDependencyService.inject(applicationContext)
69 fun testExecuteServiceFunction() {
70 val executionServiceInput = ExecutionServiceInput().apply {
71 commonHeader = CommonHeader().apply {
73 subRequestId = "1234-12"
74 originatorId = "cds-test"
76 actionIdentifiers = ActionIdentifiers().apply {
77 blueprintName = "default"
78 blueprintVersion = "1.0.0"
79 actionName = "mock-service-action"
83 val executionServiceHandler = ExecutionServiceHandler(mockk(), mockk(), mockk(), mockk(), mockk(relaxed = true))
84 val isServiceFunction = executionServiceHandler.checkServiceFunction(executionServiceInput)
85 assertTrue(isServiceFunction, "failed to checkServiceFunction")
86 val executionServiceOutput = executionServiceHandler.executeServiceFunction(executionServiceInput)
87 assertNotNull(executionServiceOutput, "failed to get executionServiceOutput")
92 fun testPublishAuditFunction() {
93 val executionServiceInput = ExecutionServiceInput().apply {
94 commonHeader = CommonHeader().apply {
96 subRequestId = "1234-12"
97 originatorId = "cds-test"
99 actionIdentifiers = ActionIdentifiers().apply {
100 blueprintName = "default"
101 blueprintVersion = "1.0.0"
102 actionName = "mock-service-action"
106 val publishAuditService = mockk<KafkaPublishAuditService>(relaxed = true)
107 val executionServiceHandler = ExecutionServiceHandler(
112 mockk(relaxed = true)
115 coEvery { publishAuditService.publishExecutionInput(ExecutionServiceInput()) } just Runs
117 var executionServiceOutput: ExecutionServiceOutput? = null
119 executionServiceOutput = executionServiceHandler.doProcess(executionServiceInput)
123 publishAuditService.publishExecutionInput(executionServiceInput)
124 publishAuditService.publishExecutionOutput(executionServiceInput.correlationUUID, executionServiceOutput!!)
129 @Service("mock-service-action")
130 class MockServiceAction : AbstractServiceFunction() {
132 override suspend fun processNB(executionRequest: ExecutionServiceInput) {
133 val responsePayload = """{"answer" : "correct"}""".jsonAsJsonType()
134 setResponsePayloadForAction(responsePayload)
137 override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {