diff --git a/build.sbt b/build.sbt index 307b7fd..e637186 100644 --- a/build.sbt +++ b/build.sbt @@ -7,7 +7,7 @@ lazy val rxmongoVersion = "0.20.3" lazy val commonSettings = Seq( name := "akka-reactivemongo-plugin", organization := "null-vector", - version := "1.3.7", + version := "1.3.8", scalaVersion := scala213, crossScalaVersions := supportedScalaVersions, scalacOptions := Seq( diff --git a/core/src/test/scala/org/nullvector/EventAdapterFactorySpec.scala b/core/src/test/scala/org/nullvector/EventAdapterFactorySpec.scala index 4c13703..378c3a6 100644 --- a/core/src/test/scala/org/nullvector/EventAdapterFactorySpec.scala +++ b/core/src/test/scala/org/nullvector/EventAdapterFactorySpec.scala @@ -12,7 +12,7 @@ import scala.util.{Success, Try} class EventAdapterFactorySpec extends FlatSpec { it should "create a complex mapping" in { - val eventAdapter = EventAdatpterFactory.adapt[A]("Aed") + val eventAdapter = EventAdapterFactory.adapt[A]("Aed") val anInstance = A( B(Set(F(Some(C("Hola", Map("2" -> Seq(J("j"))))))), @@ -42,7 +42,7 @@ class EventAdapterFactorySpec extends FlatSpec { case BSONDocument(_) => BSONDocument("s" -> "Reader Overrided") }: PartialFunction[BSONDocument, BSONDocument]) - val eventAdapter = EventAdatpterFactory.adapt[I]("Ied") + val eventAdapter = EventAdapterFactory.adapt[I]("Ied") val anInstance = I(K("k")) val document = eventAdapter.payloadToBson(anInstance) eventAdapter.bsonToPayload(document).k.s shouldBe "Reader Overrided" @@ -59,7 +59,7 @@ class EventAdapterFactorySpec extends FlatSpec { case _ => Set("TagN") } - val eventAdapter = EventAdatpterFactory.adapt[I]("Ied", justForTestTags) + val eventAdapter = EventAdapterFactory.adapt[I]("Ied", justForTestTags) eventAdapter.tags("A") should contain("TagA") eventAdapter.tags("x") should contain("TagN") @@ -81,7 +81,7 @@ class EventAdapterFactorySpec extends FlatSpec { } val tags = Set("aTag") - val eventAdapter = EventAdatpterFactory.adapt[L]("Led", tags) + val eventAdapter = EventAdapterFactory.adapt[L]("Led", tags) val document = eventAdapter.payloadToBson(L(Map(Monday -> "A"), Sunday)) val payload = eventAdapter.bsonToPayload(document) @@ -94,13 +94,25 @@ class EventAdapterFactorySpec extends FlatSpec { val distanceFromEarthAndMars = PlanetDistanceBetweenEarth(and = Mars, kilometers = 209050000.0) implicit val conf: Aux[MacroOptions] = MacroConfiguration(discriminator = "_type", typeNaming = TypeNaming.SimpleName) - val eventAdapter = EventAdatpterFactory.adapt[PlanetDistanceBetweenEarth]("x") + val eventAdapter = EventAdapterFactory.adapt[PlanetDistanceBetweenEarth]("x") val document = eventAdapter.payloadToBson(distanceFromEarthAndMars) document.getAsOpt[BSONDocument]("and").get.getAsOpt[String]("_type").get should be ("Mars") eventAdapter.bsonToPayload(document).and should be (Mars) } + it should "mapping sealed trit familly as root event" in { + val jupiter: SolarPlanet = Jupiter + + implicit val conf: Aux[MacroOptions] = MacroConfiguration(discriminator = "_type", typeNaming = TypeNaming.SimpleName) + val eventAdapter = EventAdapterFactory.adapt[SolarPlanet]("x") + + val document = eventAdapter.payloadToBson(jupiter) + + document.getAsOpt[String]("_type").get should be ("Jupiter") + eventAdapter.bsonToPayload(document) should be (Jupiter) + } + } diff --git a/macros/src/main/scala/org/nullvector/EventAdatpterFactory.scala b/macros/src/main/scala/org/nullvector/EventAdapterFactory.scala similarity index 92% rename from macros/src/main/scala/org/nullvector/EventAdatpterFactory.scala rename to macros/src/main/scala/org/nullvector/EventAdapterFactory.scala index ae8e838..8c1c0da 100644 --- a/macros/src/main/scala/org/nullvector/EventAdatpterFactory.scala +++ b/macros/src/main/scala/org/nullvector/EventAdapterFactory.scala @@ -1,6 +1,6 @@ package org.nullvector -object EventAdatpterFactory { +object EventAdapterFactory { def adapt[E](withManifest: String): EventAdapter[E] = macro EventAdapterMacroFactory.adapt[E]