add toIdentityResponse to mapping
This commit is contained in:
@@ -3,6 +3,7 @@ package ltd.hlaeja.util
|
|||||||
import java.time.ZonedDateTime
|
import java.time.ZonedDateTime
|
||||||
import ltd.hlaeja.entity.NodeEntity
|
import ltd.hlaeja.entity.NodeEntity
|
||||||
import ltd.hlaeja.entity.TypeEntity
|
import ltd.hlaeja.entity.TypeEntity
|
||||||
|
import ltd.hlaeja.library.deviceRegistry.Identity
|
||||||
import ltd.hlaeja.library.deviceRegistry.Node
|
import ltd.hlaeja.library.deviceRegistry.Node
|
||||||
import ltd.hlaeja.library.deviceRegistry.Type
|
import ltd.hlaeja.library.deviceRegistry.Type
|
||||||
import org.springframework.http.HttpStatus.EXPECTATION_FAILED
|
import org.springframework.http.HttpStatus.EXPECTATION_FAILED
|
||||||
@@ -29,3 +30,9 @@ fun NodeEntity.toNodeResponse(): Node.Response = Node.Response(
|
|||||||
device,
|
device,
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun NodeEntity.toIdentityResponse(): Identity.Response = Identity.Response(
|
||||||
|
client,
|
||||||
|
id ?: throw ResponseStatusException(EXPECTATION_FAILED),
|
||||||
|
device,
|
||||||
|
)
|
||||||
|
|||||||
@@ -145,4 +145,48 @@ class MappingKtTest {
|
|||||||
assertThat(exception.message).isEqualTo("417 EXPECTATION_FAILED")
|
assertThat(exception.message).isEqualTo("417 EXPECTATION_FAILED")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
inner class IdentityMapping {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `entity to identity response successful`() {
|
||||||
|
// given
|
||||||
|
val entity = NodeEntity(
|
||||||
|
UUID.fromString("00000000-0000-0000-0000-000000000001"),
|
||||||
|
timestamp,
|
||||||
|
UUID.fromString("00000000-0000-0000-0000-000000000002"),
|
||||||
|
UUID.fromString("00000000-0000-0000-0000-000000000003"),
|
||||||
|
"test",
|
||||||
|
)
|
||||||
|
|
||||||
|
// when
|
||||||
|
val result = entity.toIdentityResponse()
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(result.node).isUUID("00000000-0000-0000-0000-000000000001")
|
||||||
|
assertThat(result.client).isUUID("00000000-0000-0000-0000-000000000002")
|
||||||
|
assertThat(result.device).isUUID("00000000-0000-0000-0000-000000000003")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `entity to identity response exception`() {
|
||||||
|
// given
|
||||||
|
val entity = NodeEntity(
|
||||||
|
null,
|
||||||
|
timestamp,
|
||||||
|
UUID.fromString("00000000-0000-0000-0000-000000000002"),
|
||||||
|
UUID.fromString("00000000-0000-0000-0000-000000000003"),
|
||||||
|
"test",
|
||||||
|
)
|
||||||
|
|
||||||
|
// then exception
|
||||||
|
val exception = assertThrows(ResponseStatusException::class.java) {
|
||||||
|
entity.toIdentityResponse()
|
||||||
|
}
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(exception.message).isEqualTo("417 EXPECTATION_FAILED")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user