add json tests
This commit is contained in:
parent
a1c02b739d
commit
f64c30de1c
@ -16,14 +16,7 @@ class SampleModuleExampleApplication {
|
||||
|
||||
@EventListener(ApplicationReadyEvent::class)
|
||||
fun onApplicationReady() {
|
||||
val json = """
|
||||
{
|
||||
"name": "Sambo",
|
||||
"age": 24
|
||||
}
|
||||
""".trimIndent()
|
||||
val node = json.toModel<Person>()
|
||||
print(node)
|
||||
println("Application running....")
|
||||
}
|
||||
}
|
||||
|
||||
|
39
src/test/kotlin/com/cubetiqs/modules/example/JsonTests.kt
Normal file
39
src/test/kotlin/com/cubetiqs/modules/example/JsonTests.kt
Normal file
@ -0,0 +1,39 @@
|
||||
package com.cubetiqs.modules.example
|
||||
|
||||
import com.cubetiqs.enterprise.comutils.json.toJsonNode
|
||||
import com.cubetiqs.enterprise.comutils.json.toModel
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
|
||||
@SpringBootTest
|
||||
class JsonTests {
|
||||
|
||||
@Test
|
||||
fun jsonToModel() {
|
||||
val json = """
|
||||
{
|
||||
"name": "Sambo",
|
||||
"age": 24
|
||||
}
|
||||
""".trimIndent()
|
||||
val node = json.toModel<SampleModuleExampleApplication.Person>()
|
||||
|
||||
Assertions.assertEquals(SampleModuleExampleApplication.Person("Sambo", 24), node)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun jsonToJsonNode() {
|
||||
val json = """
|
||||
{
|
||||
"name": "Sambo",
|
||||
"age": 24
|
||||
}
|
||||
""".trimIndent()
|
||||
val node = json.toJsonNode()
|
||||
|
||||
Assertions.assertEquals("Sambo", node?.get("name")?.asText())
|
||||
Assertions.assertEquals(24, node?.get("age")?.asInt())
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user