add kafka consumer

This commit is contained in:
Denis Savosin
2024-10-02 18:16:51 +07:00
parent 568989917f
commit f6211ea5d3
9 changed files with 61 additions and 39 deletions

View File

@@ -0,0 +1,9 @@
package com.example.demo
import com.example.demo.services.kafka.Consumer
import org.springframework.boot.test.mock.mockito.MockBean
open class BaseUnitTest {
@MockBean
lateinit var consumer: Consumer
}

View File

@@ -1,6 +1,6 @@
package com.example.demo.http.controllers
import com.example.demo.http.controllers.GreetingController
import com.example.demo.BaseUnitTest
import org.hamcrest.core.StringContains
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
@@ -11,7 +11,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import kotlin.test.Test
@WebMvcTest(GreetingController::class)
class GreetingControllerTest(@Autowired val mockMvc: MockMvc) {
class GreetingControllerTest(@Autowired val mockMvc: MockMvc): BaseUnitTest() {
@Test
fun greetings_shouldSeeGreetingMessage() {
mockMvc.perform(get("/greeting"))

View File

@@ -1,5 +1,6 @@
package com.example.demo.http.controllers
import com.example.demo.BaseUnitTest
import com.example.demo.http.responses.ResponseStatus
import com.example.demo.models.Product
import com.example.demo.services.database.product.ProductService
@@ -24,7 +25,7 @@ import java.time.format.DateTimeFormatter
import java.util.*
@WebMvcTest(ProductController::class)
class ProductControllerTest(@Autowired val mockMvc: MockMvc) {
class ProductControllerTest(@Autowired val mockMvc: MockMvc): BaseUnitTest() {
@MockBean
private lateinit var productService: ProductService
private val mapper = jacksonObjectMapper()

View File

@@ -1,5 +1,6 @@
package com.example.demo.http.controllers
import com.example.demo.BaseUnitTest
import com.example.demo.models.*
import com.example.demo.providers.ShopProvider
import org.mockito.kotlin.doReturn
@@ -16,7 +17,7 @@ import java.util.*
import kotlin.test.Test
@WebMvcTest(ShopController::class)
class ShopControllerTest(@Autowired val mockMvc: MockMvc) {
class ShopControllerTest(@Autowired val mockMvc: MockMvc): BaseUnitTest() {
@MockBean
private lateinit var shopProvider: ShopProvider

View File

@@ -1,5 +1,6 @@
package com.example.demo.services.database.product
import com.example.demo.BaseUnitTest
import com.example.demo.models.Product
import com.example.demo.providers.ProductRepository
import com.example.demo.services.database.product.exceptions.ProductNotFoundException
@@ -19,7 +20,7 @@ import kotlin.test.Test
@RunWith(SpringRunner::class)
@SpringBootTest
class ProductServiceImplTest {
class ProductServiceImplTest: BaseUnitTest() {
private val defaultTopic = "some-default-topic"
private lateinit var productService: ProductServiceImpl

View File

@@ -1,5 +1,6 @@
package com.example.demo.services.kafka
import com.example.demo.BaseUnitTest
import com.example.demo.models.Product
import com.example.demo.services.kafka.dto.ProductDto
import com.fasterxml.jackson.databind.ObjectMapper
@@ -23,7 +24,7 @@ import kotlin.test.assertEquals
@RunWith(SpringRunner::class)
@SpringBootTest
class ProducerImplTest {
class ProducerImplTest: BaseUnitTest() {
@Autowired
private lateinit var producerImpl: ProducerImpl