Skip to content

Commit

Permalink
Also test entity ID codec directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Marius Soutier committed Nov 27, 2024
1 parent f2b0e01 commit 0dfe53e
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions akka-components/src/test/scala/ClusterComponentSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,20 @@ class ClusterComponentSpec extends ScalaTestWithActorTestKit(ConfigFactory.parse

val component = new ComponentObject.Component
ComponentObject.init(component).delayedInit()
val entityRef = component.entityRefFor(ComponentObject.EntityId("a", "b"))
entityRef.entityId shouldBe """{"id1":"a","id2":"b"}"""

val entityRefWithPlaceholder = component.entityRefFor(ComponentObject.EntityId("a|b", "c|d"))
entityRefWithPlaceholder.entityId shouldBe """{"id1":"a❘❘bar❘❘b","id2":"c❘❘bar❘❘d"}"""
val expectedJson = """{"id1":"a","id2":"b"}"""
val abEntityId = ComponentObject.EntityId("a", "b")
val entityRef = component.entityRefFor(abEntityId)
entityRef.entityId shouldBe expectedJson
ComponentObject.entityIdCodec.encode(abEntityId) shouldBe expectedJson
ComponentObject.entityIdCodec.decode(expectedJson) shouldBe Success(abEntityId)

val expectedJsonWithPlaceholders = """{"id1":"a❘❘bar❘❘b","id2":"c❘❘bar❘❘d"}"""
val placeholdersEntityId = ComponentObject.EntityId("a|b", "c|d")
val entityRefWithPlaceholders = component.entityRefFor(placeholdersEntityId)
entityRefWithPlaceholders.entityId shouldBe expectedJsonWithPlaceholders
ComponentObject.entityIdCodec.encode(placeholdersEntityId) shouldBe expectedJsonWithPlaceholders
ComponentObject.entityIdCodec.decode(expectedJsonWithPlaceholders) shouldBe Success(placeholdersEntityId)
}
"custom json EntityId with custom placeholder" in {
object ComponentObject extends ClusterComponent.Sharded with ClusterComponent.SameSerializableCommand with ClusterComponent.Sharded.JsonEntityId {
Expand Down Expand Up @@ -289,8 +298,12 @@ class ClusterComponentSpec extends ScalaTestWithActorTestKit(ConfigFactory.parse

val component = new ComponentObject.Component
ComponentObject.init(component).delayedInit()
val entityRefWithPlaceholder = component.entityRefFor(ComponentObject.EntityId("a|b", "c|d"))
entityRefWithPlaceholder.entityId shouldBe """{"id1":"a/b","id2":"c/d"}"""
val expectedJsonWithPlaceholders = """{"id1":"a/b","id2":"c/d"}"""
val placeholdersEntityId = ComponentObject.EntityId("a|b", "c|d")
val entityRefWithPlaceholder = component.entityRefFor(placeholdersEntityId)
entityRefWithPlaceholder.entityId shouldBe expectedJsonWithPlaceholders
ComponentObject.entityIdCodec.encode(placeholdersEntityId) shouldBe expectedJsonWithPlaceholders
ComponentObject.entityIdCodec.decode(expectedJsonWithPlaceholders) shouldBe Success(placeholdersEntityId)
}
"long EntityId" in {
object ComponentObject extends ClusterComponent.Sharded with ClusterComponent.SameSerializableCommand with ClusterComponent.Sharded.LongEntityId {
Expand Down

0 comments on commit 0dfe53e

Please sign in to comment.