2 * Copyright © 2019 IBM.
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.message.service
22 import kotlinx.coroutines.runBlocking
23 import org.apache.kafka.clients.producer.KafkaProducer
24 import org.apache.kafka.clients.producer.RecordMetadata
25 import org.junit.runner.RunWith
26 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertiesService
27 import org.onap.ccsdk.cds.blueprintsprocessor.core.BluePrintPropertyConfiguration
28 import org.onap.ccsdk.cds.blueprintsprocessor.message.BluePrintMessageLibConfiguration
29 import org.springframework.beans.factory.annotation.Autowired
30 import org.springframework.test.annotation.DirtiesContext
31 import org.springframework.test.context.ContextConfiguration
32 import org.springframework.test.context.TestPropertySource
33 import org.springframework.test.context.junit4.SpringRunner
34 import java.util.concurrent.Future
35 import kotlin.test.Test
36 import kotlin.test.assertTrue
38 @RunWith(SpringRunner::class)
40 @ContextConfiguration(
41 classes = [BluePrintMessageLibConfiguration::class,
42 BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class]
46 ["blueprintsprocessor.messageproducer.sample.type=kafka-basic-auth",
47 "blueprintsprocessor.messageproducer.sample.bootstrapServers=127.0.0.1:9092",
48 "blueprintsprocessor.messageproducer.sample.topic=default-topic",
49 "blueprintsprocessor.messageproducer.sample.clientId=default-client-id"
52 open class BlueprintMessageProducerServiceTest {
55 lateinit var bluePrintMessageLibPropertyService: BluePrintMessageLibPropertyService
58 fun testKafkaBasicAuthProducertService() {
60 val blueprintMessageProducerService = bluePrintMessageLibPropertyService
61 .blueprintMessageProducerService("sample") as KafkaBasicAuthMessageProducerService
63 val mockKafkaTemplate = mockk<KafkaProducer<String, ByteArray>>()
65 val responseMock = mockk<Future<RecordMetadata>>()
66 every { responseMock.get() } returns mockk()
68 every { mockKafkaTemplate.send(any(), any()) } returns responseMock
70 val spyBluePrintMessageProducerService = spyk(blueprintMessageProducerService, recordPrivateCalls = true)
72 every { spyBluePrintMessageProducerService.messageTemplate(any()) } returns mockKafkaTemplate
74 val response = spyBluePrintMessageProducerService.sendMessage("Testing message")
75 assertTrue(response, "failed to get command response")