Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
58 lines (48 sloc) 1.82 KB
package com.example.demo
import com.example.demo.persistence.VehicleCustomRepository
import com.example.demo.persistence.VehicleEntity
import com.example.demo.persistence.VehicleNotFoundException
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.testcontainers.junit.jupiter.Container
import org.testcontainers.junit.jupiter.Testcontainers
import util.IntegrationTest
import java.util.*
* This test class demonstrates Integration test with usage of test containers
class VehicleCustomRepositoryContainersTest {
private lateinit var vehicleCustomRepository: VehicleCustomRepository
private val redisContainer = KFixedHostPortGenericContainer("redis:latest")
.withFixedExposedPort(6379, 6379)
fun `saving vehicle without an error`() {
//prepare data to be saved in Redis
val vehicleId = UUID.randomUUID().toString()
val vehicleEntity = VehicleEntity(
id = vehicleId,
model = "BMW",
colour = "black"
//Verify that vehicle is being saved
val result = vehicleCustomRepository.findById(vehicleId)
fun `looking for non existing vehicle`() {
val nonExistingId = UUID.randomUUID().toString()
//assert that VehicleNotFoundException will be thrown when no vehicle exists for the given id
assertThrows<VehicleNotFoundException> {
You can’t perform that action at this time.