mirror of
https://github.com/InsanusMokrassar/SDI.git
synced 2024-11-23 18:48:52 +00:00
hotfix and test adding
This commit is contained in:
parent
4103aebaad
commit
41eb2341f7
@ -72,7 +72,7 @@ internal fun createModuleBasedOnConfigRoot(jsonObject: JsonObject): Json {
|
|||||||
DependencyResolver(this, kclass) {
|
DependencyResolver(this, kclass) {
|
||||||
caches.getValue(it).invoke()
|
caches.getValue(it).invoke()
|
||||||
}
|
}
|
||||||
} catch (e: SerializationException) {
|
} catch (e: SerializerAlreadyRegisteredException) {
|
||||||
// here we are thinking that already registered
|
// here we are thinking that already registered
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
54
src/commonTest/kotlin/com/insanusmokrassar/sdi/ListTest.kt
Normal file
54
src/commonTest/kotlin/com/insanusmokrassar/sdi/ListTest.kt
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
package com.insanusmokrassar.sdi
|
||||||
|
|
||||||
|
import kotlinx.serialization.*
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import kotlin.test.*
|
||||||
|
|
||||||
|
interface List_ParentalAPI {
|
||||||
|
val services: List<List_ChildAPI>
|
||||||
|
}
|
||||||
|
interface List_ChildAPI {
|
||||||
|
val names: List<String>
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
class List_Parent(override val services: List<@ContextualSerialization List_ChildAPI>) : List_ParentalAPI
|
||||||
|
@Serializable
|
||||||
|
class List_Child(override val names: List<String>) : List_ChildAPI
|
||||||
|
|
||||||
|
@ImplicitReflectionSerializer
|
||||||
|
class ListTest {
|
||||||
|
val servicesNum = 10
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun test_that_simple_config_correctly_work() {
|
||||||
|
val names = (0 until servicesNum).map {
|
||||||
|
"service$it" to arrayOf("nameOne$it", "nameTwo$it")
|
||||||
|
}
|
||||||
|
val controllerName = "parent"
|
||||||
|
val input = """
|
||||||
|
{
|
||||||
|
${names.joinToString { (title, currentNames) -> """
|
||||||
|
"$title": [
|
||||||
|
"${List_Child::class.qualifiedName}",
|
||||||
|
{
|
||||||
|
"names": ${currentNames.joinToString(prefix = "[", postfix = "]") { "\"$it\"" }}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
""" }},
|
||||||
|
"$controllerName": [
|
||||||
|
"${List_Parent::class.qualifiedName}",
|
||||||
|
{
|
||||||
|
"services": ${names.joinToString(prefix = "[", postfix = "]") { "\"${it.first}\"" }}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
val module = Json.plain.parse(Module.serializer(), input)
|
||||||
|
(module[controllerName] as List_ParentalAPI)
|
||||||
|
val controller = (module[controllerName] as List_Parent)
|
||||||
|
controller.services.forEachIndexed { i, service ->
|
||||||
|
assertEquals(names[i].second.toList(), service.names)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,24 +4,24 @@ import kotlinx.serialization.*
|
|||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
interface ControllerAPI {
|
interface Simple_ControllerAPI {
|
||||||
fun showUp()
|
fun showUp()
|
||||||
}
|
}
|
||||||
interface ServiceAPI {
|
interface Simple_ServiceAPI {
|
||||||
val names: List<String>
|
val names: List<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class Controller(@ContextualSerialization val service: ServiceAPI) : ControllerAPI {
|
class Simple_Controller(@ContextualSerialization val service: Simple_ServiceAPI) : Simple_ControllerAPI {
|
||||||
override fun showUp() {
|
override fun showUp() {
|
||||||
println("Inited with name \"${service.names}\"")
|
println("Inited with name \"${service.names}\"")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Serializable
|
@Serializable
|
||||||
class BusinessService(override val names: List<String>) : ServiceAPI
|
class Simple_BusinessService(override val names: List<String>) : Simple_ServiceAPI
|
||||||
|
|
||||||
@ImplicitReflectionSerializer
|
@ImplicitReflectionSerializer
|
||||||
class DeserializationTest {
|
class SimpleTest {
|
||||||
@Test
|
@Test
|
||||||
fun test_that_simple_config_correctly_work() {
|
fun test_that_simple_config_correctly_work() {
|
||||||
val names = arrayOf("nameOne", "nameTwo")
|
val names = arrayOf("nameOne", "nameTwo")
|
||||||
@ -29,13 +29,13 @@ class DeserializationTest {
|
|||||||
val input = """
|
val input = """
|
||||||
{
|
{
|
||||||
"service": [
|
"service": [
|
||||||
"${BusinessService::class.qualifiedName}",
|
"${Simple_BusinessService::class.qualifiedName}",
|
||||||
{
|
{
|
||||||
"names": ${names.joinToString(prefix = "[", postfix = "]") { "\"$it\"" }}
|
"names": ${names.joinToString(prefix = "[", postfix = "]") { "\"$it\"" }}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"$controllerName": [
|
"$controllerName": [
|
||||||
"${Controller::class.qualifiedName}",
|
"${Simple_Controller::class.qualifiedName}",
|
||||||
{
|
{
|
||||||
"service": "service"
|
"service": "service"
|
||||||
}
|
}
|
||||||
@ -43,8 +43,8 @@ class DeserializationTest {
|
|||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
val module = Json.plain.parse(Module.serializer(), input)
|
val module = Json.plain.parse(Module.serializer(), input)
|
||||||
(module[controllerName] as ControllerAPI)
|
(module[controllerName] as Simple_ControllerAPI)
|
||||||
val controller = (module["controller"] as Controller)
|
val controller = (module["controller"] as Simple_Controller)
|
||||||
assertEquals(names.toList(), controller.service.names)
|
assertEquals(names.toList(), controller.service.names)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user