add json tests

This commit is contained in:
Sambo Chea 2020-11-21 11:09:31 +07:00
parent a1c02b739d
commit f64c30de1c
3 changed files with 43 additions and 11 deletions

View File

@ -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....")
}
}

View 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())
}
}

View File

@ -6,8 +6,8 @@ import org.springframework.boot.test.context.SpringBootTest
@SpringBootTest
class SampleModuleExampleApplicationTests {
@Test
fun contextLoads() {
}
@Test
fun contextLoads() {
}
}