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