add devices endpoint
- fix missing coroutine in - TypeRepository - TypesController - TypeService - TypesControllerTest - TypeServiceTest - add DevicesEndpoint - add DevicesControllerTest - add devices.http - add DevicesController - add DeviceEntity.toDevicesResponse() to Mapping.kt - add PostgresTestContainer to DeviceService - update DeviceRepository with find all - update version catalog - update container annotation in DeviceEndpoint - update container annotation in IdentityEndpoint - update container annotation in NodeEndpoint - update container annotation in TypeEndpoint - update container annotation in TypesEndpoint - update version in gradle.properties
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package ltd.hlaeja.controller
|
||||
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.coVerify
|
||||
import io.mockk.mockk
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
import java.time.ZonedDateTime
|
||||
import java.util.UUID
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.single
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import ltd.hlaeja.entity.DeviceEntity
|
||||
import ltd.hlaeja.service.DeviceService
|
||||
import ltd.hlaeja.test.isEqualToUuid
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class DevicesControllerTest {
|
||||
companion object {
|
||||
const val NIL_UUID: String = "00000000-0000-0000-0000-000000000000"
|
||||
val id: UUID = UUID.fromString(NIL_UUID)
|
||||
val type: UUID = UUID.fromString(NIL_UUID)
|
||||
val timestamp: ZonedDateTime = ZonedDateTime.of(LocalDateTime.of(2000, 1, 1, 0, 0, 0, 1), ZoneId.of("UTC"))
|
||||
}
|
||||
|
||||
val service: DeviceService = mockk()
|
||||
|
||||
lateinit var controller: DevicesController
|
||||
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
controller = DevicesController(service)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `get all devices`() = runTest {
|
||||
// given
|
||||
coEvery {
|
||||
service.getDevices(any(), any())
|
||||
} returns flowOf(DeviceEntity(id, timestamp, type))
|
||||
|
||||
// when
|
||||
val response = controller.getDevices().single()
|
||||
|
||||
// then
|
||||
coVerify(exactly = 1) { service.getDevices(0, 25) }
|
||||
|
||||
assertThat(response.id).isEqualToUuid(NIL_UUID)
|
||||
assertThat(response.type).isEqualToUuid(NIL_UUID)
|
||||
assertThat(response.timestamp).isEqualTo(timestamp)
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package ltd.hlaeja.controller
|
||||
|
||||
import io.mockk.every
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.coVerify
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
import java.time.ZonedDateTime
|
||||
@@ -37,7 +37,7 @@ class TypesControllerTest {
|
||||
@Test
|
||||
fun `get all types`() = runTest {
|
||||
// given
|
||||
every {
|
||||
coEvery {
|
||||
service.getTypes(any(), any(), any())
|
||||
} returns flowOf(TypeEntity(id, timestamp, NAME))
|
||||
|
||||
@@ -45,7 +45,7 @@ class TypesControllerTest {
|
||||
val response = controller.getTypes().single()
|
||||
|
||||
// then
|
||||
verify(exactly = 1) { service.getTypes(0, 25, null) }
|
||||
coVerify(exactly = 1) { service.getTypes(0, 25, null) }
|
||||
|
||||
assertThat(response.id).isEqualToUuid(NIL_UUID)
|
||||
assertThat(response.name).isEqualTo(NAME)
|
||||
|
||||
@@ -6,7 +6,6 @@ import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.unmockkStatic
|
||||
import io.mockk.verify
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
import java.time.ZonedDateTime
|
||||
@@ -57,29 +56,29 @@ class TypeServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `get all types`() {
|
||||
fun `get all types`() = runTest {
|
||||
// given
|
||||
every { typeRepository.findAll(any(), any()) } returns flowOf(mockk<TypeEntity>())
|
||||
coEvery { typeRepository.findAll(any(), any()) } returns flowOf(mockk<TypeEntity>())
|
||||
|
||||
// when
|
||||
service.getTypes(1, 10, null)
|
||||
|
||||
// then
|
||||
verify(exactly = 1) { typeRepository.findAll(1, 10) }
|
||||
verify(exactly = 0) { typeRepository.findAllContaining(any(), any(), any()) }
|
||||
coVerify(exactly = 1) { typeRepository.findAll(1, 10) }
|
||||
coVerify(exactly = 0) { typeRepository.findAllContaining(any(), any(), any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `get all types with filter`() {
|
||||
fun `get all types with filter`() = runTest {
|
||||
// given
|
||||
every { typeRepository.findAllContaining(any(), any(), any()) } returns flowOf(mockk<TypeEntity>())
|
||||
coEvery { typeRepository.findAllContaining(any(), any(), any()) } returns flowOf(mockk<TypeEntity>())
|
||||
|
||||
// when
|
||||
service.getTypes(1, 10, "abc")
|
||||
|
||||
// then
|
||||
verify(exactly = 1) { typeRepository.findAllContaining("%abc%", 1, 10) }
|
||||
verify(exactly = 0) { typeRepository.findAll(any(), any()) }
|
||||
coVerify(exactly = 1) { typeRepository.findAllContaining("%abc%", 1, 10) }
|
||||
coVerify(exactly = 0) { typeRepository.findAll(any(), any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user