Skip to content

Commit

Permalink
test: add tests for video rest client implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukinhasssss committed May 28, 2024
1 parent 9501bc9 commit b1afcbf
Show file tree
Hide file tree
Showing 9 changed files with 373 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.lukinhasssss.catalogo.infrastructure.configuration.annotations

import org.springframework.beans.factory.annotation.Qualifier

@Qualifier("Videos")
@Qualifier("Video")
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.VALUE_PARAMETER)
@Retention(AnnotationRetention.RUNTIME)
annotation class Videos
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.lukinhasssss.catalogo.infrastructure.video

import com.lukinhasssss.catalogo.infrastructure.authentication.GetClientCredentials
import com.lukinhasssss.catalogo.infrastructure.configuration.annotations.Keycloak
import com.lukinhasssss.catalogo.infrastructure.configuration.annotations.Videos
import com.lukinhasssss.catalogo.infrastructure.utils.HttpClient
import com.lukinhasssss.catalogo.infrastructure.video.models.VideoDTO
Expand All @@ -14,17 +13,20 @@ import org.springframework.http.HttpHeaders
import org.springframework.stereotype.Component
import org.springframework.web.client.RestClient

private const val NAMESPACE = "videos"
private const val VIDEO_CACHE_NAME = "admin-videos"
private const val VIDEO_CACHE_KEY = "#videoId"

@Component
@CacheConfig(cacheNames = [VIDEO_CACHE_NAME])
class VideoRestClient(
@Videos private val restClient: RestClient,
@Keycloak private val getClientCredentials: GetClientCredentials
private val getClientCredentials: GetClientCredentials
) : VideoClient, HttpClient {

companion object {
const val NAMESPACE = "videos"
}

override fun namespace(): String = NAMESPACE

// Resilience4j default order: Bulkhead -> TimeLimiter -> RateLimiter -> CircuitBreaker -> Retry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.github.tomakehurst.wiremock.client.WireMock
import com.lukinhasssss.catalogo.infrastructure.category.CategoryRestClient
import com.lukinhasssss.catalogo.infrastructure.configuration.WebServerConfig
import com.lukinhasssss.catalogo.infrastructure.genre.GenreRestClient
import com.lukinhasssss.catalogo.infrastructure.video.VideoRestClient
import io.github.resilience4j.bulkhead.BulkheadRegistry
import io.github.resilience4j.circuitbreaker.CircuitBreaker
import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry
Expand All @@ -30,6 +31,7 @@ abstract class AbstractRestClientTest {
companion object {
const val CATEGORY = CategoryRestClient.NAMESPACE
const val GENRE = GenreRestClient.NAMESPACE
const val VIDEO = VideoRestClient.NAMESPACE
}

@Autowired
Expand All @@ -51,6 +53,7 @@ abstract class AbstractRestClientTest {
resetAllCaches()
listOf(CATEGORY).forEach { resetFaultTolerance(it) }
listOf(GENRE).forEach { resetFaultTolerance(it) }
listOf(VIDEO).forEach { resetFaultTolerance(it) }
}

fun cache(name: String) = cacheManager.getCache(name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.lukinhasssss.catalogo
import com.lukinhasssss.catalogo.infrastructure.castmember.persistence.CastMemberRepository
import com.lukinhasssss.catalogo.infrastructure.category.persistence.CategoryRepository
import com.lukinhasssss.catalogo.infrastructure.genre.persistence.GenreRepository
import com.lukinhasssss.catalogo.infrastructure.video.persistence.VideoRepository
import io.mockk.mockk
import org.springframework.context.annotation.Bean

Expand All @@ -16,4 +17,7 @@ class IntegrationTestConfiguration {

@Bean
fun genreRepository() = mockk<GenreRepository>()

@Bean
fun videoRepository() = mockk<VideoRepository>()
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.springframework.http.MediaType
import kotlin.test.assertEquals
import kotlin.test.assertNull

class CategoryRestGatewayTest : AbstractRestClientTest() {
class CategoryRestClientTest : AbstractRestClientTest() {

@Autowired
lateinit var target: CategoryRestClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.springframework.http.MediaType
import kotlin.test.assertEquals
import kotlin.test.assertNull

class GenreRestGatewayTest : AbstractRestClientTest() {
class GenreRestClientTest : AbstractRestClientTest() {

@Autowired
lateinit var target: GenreRestClient
Expand Down
Loading

0 comments on commit b1afcbf

Please sign in to comment.