Refactoring BP Code with ErrorCatalog
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / selfservice-api / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / selfservice / api / BluePrintProcessingKafkaConsumerTest.kt
1 /*
2  *  Copyright © 2019 IBM.
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api
18
19 import io.mockk.coEvery
20 import io.mockk.mockk
21 import kotlinx.coroutines.delay
22 import kotlinx.coroutines.launch
23 import kotlinx.coroutines.runBlocking
24 import org.junit.runner.RunWith
25 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService
26 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration
27 import org.onap.ccsdk.cds.blueprintsprocessor.message.BluePrintMessageLibConfiguration
28 import org.onap.ccsdk.cds.blueprintsprocessor.message.service.BluePrintMessageLibPropertyService
29 import org.springframework.beans.factory.annotation.Autowired
30 import org.springframework.test.context.ContextConfiguration
31 import org.springframework.test.context.TestPropertySource
32 import org.springframework.test.context.junit4.SpringRunner
33 import kotlin.test.Test
34 import kotlin.test.assertNotNull
35
36 @RunWith(SpringRunner::class)
37 @ContextConfiguration(
38     classes = [BluePrintMessageLibConfiguration::class, SelfServiceApiTestConfiguration::class,
39         BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, ErrorCatalogTestConfiguration::class]
40 )
41 @TestPropertySource(locations = ["classpath:application-test.properties"])
42 class BluePrintProcessingKafkaConsumerTest {
43
44     @Autowired
45     lateinit var bluePrintMessageLibPropertyService: BluePrintMessageLibPropertyService
46
47     @Test
48     fun testExecutionInputMessageConsumer() {
49         runBlocking {
50             assertNotNull(
51                 bluePrintMessageLibPropertyService,
52                 "failed to initialise bluePrintMessageLibPropertyService"
53             )
54
55             val executionServiceHandle = mockk<ExecutionServiceHandler>()
56
57             coEvery { executionServiceHandle.doProcess(any()) } returns mockk()
58
59             val bluePrintProcessingKafkaConsumer = BluePrintProcessingKafkaConsumer(
60                 bluePrintMessageLibPropertyService,
61                 executionServiceHandle
62             )
63
64             launch {
65                 bluePrintProcessingKafkaConsumer.setupMessageListener()
66             }
67             delay(100)
68             bluePrintProcessingKafkaConsumer.shutdownMessageListener()
69         }
70     }
71 }