-
Notifications
You must be signed in to change notification settings - Fork 0
/
DemoTest.kt
59 lines (48 loc) · 2.1 KB
/
DemoTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.example
import com.fasterxml.jackson.databind.ObjectMapper
import io.micronaut.runtime.EmbeddedApplication
import io.micronaut.test.extensions.kotest5.annotation.MicronautTest
import io.kotest.core.spec.style.StringSpec
import io.micronaut.core.annotation.Introspected
import java.util.*
@MicronautTest
class DemoTest(
private val application: EmbeddedApplication<*>,
private val objectMapper: ObjectMapper
): StringSpec({
"test the server is running" {
assert(application.isRunning)
}
"test deserialization without introspect" {
val output1 = objectMapper.readValue("{\"field1\": \"value1\", \"field2\": \"value2\"}", TestNoIntrospection::class.java)
val output2 = objectMapper.readValue("{\"field1\": null, \"field2\": \"value2\"}", TestNoIntrospection::class.java)
val output3 = objectMapper.readValue("{}", TestNoIntrospection::class.java)
assert(output1.field1?.get() == "value1")
assert(output1.field2?.get() == "value2")
assert(output2.field1!!.isEmpty)
assert(output2.field2?.get() == "value2")
assert(output3.field1 == null)
assert(output3.field2 == null)
}
"test deserialization with introspect" {
val output1 = objectMapper.readValue("{\"field1\": \"value1\", \"field2\": \"value2\"}", TestWithIntrospection::class.java)
val output2 = objectMapper.readValue("{\"field1\": null, \"field2\": \"value2\"}", TestWithIntrospection::class.java)
val output3 = objectMapper.readValue("{}", TestWithIntrospection::class.java)
assert(output1.field1?.get() == "value1")
assert(output1.field2?.get() == "value2")
assert(output2.field1!!.isEmpty)
assert(output2.field2?.get() == "value2")
assert(output3.field1 == null)
assert(output3.field2 == null)
}
}) {
data class TestNoIntrospection(
val field1: Optional<String>? = null,
val field2: Optional<String>? = null
)
@Introspected
data class TestWithIntrospection(
val field1: Optional<String>? = null,
val field2: Optional<String>? = null
)
}