mirror of
https://github.com/Dannecron/spring-boot-demo.git
synced 2025-12-26 00:32:34 +03:00
add kafka consumer
This commit is contained in:
9
src/test/kotlin/com/example/demo/BaseUnitTest.kt
Normal file
9
src/test/kotlin/com/example/demo/BaseUnitTest.kt
Normal 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
|
||||
}
|
||||
@@ -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"))
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user