Skip to content

Commit

Permalink
fix: JsonCodec encode, decode private fields too (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb authored Apr 7, 2024
1 parent 25a600c commit a03b664
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.rooftop.netx.redis

import com.fasterxml.jackson.annotation.JsonAutoDetect
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.PropertyAccessor
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.KotlinModule
Expand Down Expand Up @@ -116,7 +118,9 @@ class RedisSagaConfigurer(
@Bean
@ConditionalOnProperty(prefix = "netx", name = ["mode"], havingValue = "redis")
internal fun netxObjectMapper(): ObjectMapper =
ObjectMapper().registerModule(ParameterNamesModule(JsonCreator.Mode.PROPERTIES))
ObjectMapper()
.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY)
.registerModule(ParameterNamesModule(JsonCreator.Mode.PROPERTIES))
.registerModule(KotlinModule.Builder().build())
.registerModule(JavaTimeModule())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import reactor.core.publisher.Mono
import java.time.Instant

@Configuration
internal class OrchestratorConfigurer {
internal class OrchestratorConfigurer(
private val orchestratorFactory: OrchestratorFactory,
) {

@Bean(name = ["numberOrchestrator"])
fun numberOrchestrator(): Orchestrator<Int, Int> {
Expand Down Expand Up @@ -226,6 +228,15 @@ internal class OrchestratorConfigurer {
})
}

@Bean(name = ["privateFieldOrchestrator"])
fun privateFieldOrchestrator(): Orchestrator<OrchestratorTest.Private, OrchestratorTest.Private> {
return OrchestratorFactory.instance()
.create<OrchestratorTest.Private>("privateFieldOrchestrator")
.start({ it })
.join({ it })
.commit({ it })
}

object PairOrchestrate :
Orchestrate<Pair<OrchestratorTest.Foo, OrchestratorTest.Foo>, Pair<OrchestratorTest.Foo, OrchestratorTest.Foo>> {
override fun orchestrate(request: Pair<OrchestratorTest.Foo, OrchestratorTest.Foo>): Pair<OrchestratorTest.Foo, OrchestratorTest.Foo> {
Expand Down
19 changes: 18 additions & 1 deletion src/test/kotlin/org/rooftop/netx/engine/OrchestratorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.kotest.core.annotation.DisplayName
import io.kotest.core.spec.style.DescribeSpec
import io.kotest.matchers.equality.shouldBeEqualToComparingFields
import io.kotest.matchers.equals.shouldBeEqual
import io.kotest.matchers.shouldBe
import org.rooftop.netx.api.Orchestrator
import org.rooftop.netx.api.TypeReference
import org.rooftop.netx.meta.EnableSaga
Expand Down Expand Up @@ -36,7 +37,8 @@ internal class OrchestratorTest(
@Qualifier("contextOrchestrator") private val contextOrchestrator: Orchestrator<String, String>,
@Qualifier("pairOrchestrator") private val pairOrchestrator: Orchestrator<String, Pair<Foo, Foo>>,
@Qualifier("startWithContextOrchestrator") private val startWithContextOrchestrator: Orchestrator<String, String>,
@Qualifier("fooContextOrchestrator") private val fooContextOrchestrator: Orchestrator<String, List<Foo>>
@Qualifier("fooContextOrchestrator") private val fooContextOrchestrator: Orchestrator<String, List<Foo>>,
private val privateOrchestrator: Orchestrator<Private, Private>,
) : DescribeSpec({

describe("numberOrchestrator 구현채는") {
Expand Down Expand Up @@ -210,6 +212,19 @@ internal class OrchestratorTest(
}
}
}

describe("privateFieldOrchestrator 구현채는") {
context("saga 메소드가 호출되면,") {
val private = Private("I'm private")

it("Private 필드가 포함된 객체를 반환한다.") {
val result = privateOrchestrator.sagaSync(private)

result.isSuccess shouldBeEqual true
result.decodeResultOrThrow(Private::class) shouldBeEqual private
}
}
}
}) {
data class Home(
val address: String,
Expand All @@ -228,6 +243,8 @@ internal class OrchestratorTest(

data class Foo(val name: String)

data class Private(private val name: String)

companion object {
val rollbackOrchestratorResult = mutableListOf<String>()
val upChainResult = mutableListOf<String>()
Expand Down

0 comments on commit a03b664

Please sign in to comment.