01199c1315e2c2bf9dc6cf8d4816b7fb5699e525
[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(classes = [BluePrintMessageLibConfiguration::class,
38     BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class])
39 @TestPropertySource(locations = ["classpath:application-test.properties"])
40 class BluePrintProcessingKafkaConsumerTest {
41
42     @Autowired
43     lateinit var bluePrintMessageLibPropertyService: BluePrintMessageLibPropertyService
44
45     @Test
46     fun testExecutionInputMessageConsumer() {
47         runBlocking {
48             assertNotNull(bluePrintMessageLibPropertyService,
49                     "failed to initialise bluePrintMessageLibPropertyService")
50
51             val executionServiceHandle = mockk<ExecutionServiceHandler>()
52
53             coEvery { executionServiceHandle.doProcess(any()) } returns mockk()
54
55             val bluePrintProcessingKafkaConsumer = BluePrintProcessingKafkaConsumer(bluePrintMessageLibPropertyService,
56                     executionServiceHandle)
57
58             launch {
59                 bluePrintProcessingKafkaConsumer.setupMessageListener()
60             }
61             delay(100)
62             bluePrintProcessingKafkaConsumer.shutdownMessageListener()
63         }
64     }
65
66 }