mirror of
https://github.com/InsanusMokrassar/SDI.git
synced 2025-11-15 10:50:03 +00:00
custom objects instead of dependencies
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package com.insanusmokrassar.sdi
|
||||
|
||||
import kotlinx.serialization.*
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlin.test.*
|
||||
|
||||
interface SimpleCustomObject_ControllerAPI {
|
||||
fun showUp()
|
||||
}
|
||||
interface SimpleCustomObject_ServiceAPI {
|
||||
val names: List<String>
|
||||
}
|
||||
|
||||
@Serializable
|
||||
class SimpleCustomObject_Controller(@ContextualSerialization val service: SimpleCustomObject_ServiceAPI) : SimpleCustomObject_ControllerAPI {
|
||||
override fun showUp() {
|
||||
println("Inited with name \"${service.names}\"")
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
class SimpleCustomObject_CustomController1(@ContextualSerialization val service: SimpleCustomObject_ServiceAPI) : SimpleCustomObject_ControllerAPI {
|
||||
override fun showUp() {
|
||||
println("Inited with name \"${service.names}\"")
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
class SimpleCustomObject_CustomController2(@ContextualSerialization val service: SimpleCustomObject_BusinessService) : SimpleCustomObject_ControllerAPI {
|
||||
override fun showUp() {
|
||||
println("Inited with name \"${service.names}\"")
|
||||
}
|
||||
}
|
||||
@Serializable
|
||||
class SimpleCustomObject_BusinessService(override val names: List<String>) : SimpleCustomObject_ServiceAPI
|
||||
|
||||
@ImplicitReflectionSerializer
|
||||
class SimpleCustomObjectTest {
|
||||
@Test
|
||||
fun test_that_simple_config_correctly_work() {
|
||||
val names = arrayOf("nameOne", "nameTwo")
|
||||
val customNames = arrayOf("customNameOne", "customNameTwo")
|
||||
val controllerName = "controller"
|
||||
val customController1Name = "controller1"
|
||||
val customController2Name = "controller2"
|
||||
val input = """
|
||||
{
|
||||
"service": [
|
||||
"${SimpleCustomObject_BusinessService::class.qualifiedName}",
|
||||
{
|
||||
"names": ${names.joinToString(prefix = "[", postfix = "]") { "\"$it\"" }}
|
||||
}
|
||||
],
|
||||
"$controllerName": [
|
||||
"${SimpleCustomObject_Controller::class.qualifiedName}",
|
||||
{
|
||||
"service": "service"
|
||||
}
|
||||
],
|
||||
"$customController1Name": [
|
||||
"${SimpleCustomObject_CustomController1::class.qualifiedName}",
|
||||
{
|
||||
"service": [
|
||||
"${SimpleCustomObject_BusinessService::class.qualifiedName}",
|
||||
{
|
||||
"names": ${customNames.joinToString(prefix = "[", postfix = "]") { "\"$it\"" }}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
"$customController2Name": [
|
||||
"${SimpleCustomObject_CustomController2::class.qualifiedName}",
|
||||
{
|
||||
"service": {
|
||||
"names": "${customNames.joinToString(prefix = "[", postfix = "]") { "\"$it\"" }}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
""".trimIndent()
|
||||
val module = Json.plain.parse(Module.serializer(), input)
|
||||
|
||||
(module[controllerName] as SimpleCustomObject_ControllerAPI)
|
||||
val controller = (module["controller"] as SimpleCustomObject_Controller)
|
||||
assertEquals(names.toList(), controller.service.names)
|
||||
|
||||
|
||||
(module[customController1Name] as SimpleCustomObject_ControllerAPI)
|
||||
val customController1 = (module[customController1Name] as SimpleCustomObject_CustomController1)
|
||||
assertEquals(customNames.toList(), customController1.service.names)
|
||||
|
||||
|
||||
(module[customController2Name] as SimpleCustomObject_ControllerAPI)
|
||||
val customController2 = (module[customController2Name] as SimpleCustomObject_CustomController2)
|
||||
assertEquals(customNames.toList(), customController2.service.names)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user