diff --git a/build.sbt b/build.sbt index 4144d20..6b6ce7c 100644 --- a/build.sbt +++ b/build.sbt @@ -9,7 +9,6 @@ lazy val `telegram-bot-delivery` = (project in file(".")) .settings( name := "telegram-bot-delivery", libraryDependencies ++= Seq( - scalaTest % Test, akkaTyped, akkaSerializationJackson, akkaClusterShardingTyped, @@ -19,6 +18,8 @@ lazy val `telegram-bot-delivery` = (project in file(".")) akkaPersistence, akkaPersistenceCassandra, akkaPersistenceQuery, + akkaTestkitTyped % Test, + scalaTest % Test, slibTelegram, logback ), @@ -29,7 +30,7 @@ lazy val `telegram-bot-delivery` = (project in file(".")) Docker / daemonUserUid := Some("1001"), Docker / daemonUser := "telegram-bot", Docker / defaultLinuxInstallLocation := "/opt/telegram-bot-delivery", - version := "1.1.2" + version := "1.1.3" ) .enablePlugins(JavaServerAppPackaging) .enablePlugins(DockerPlugin) diff --git a/project/Dependencies.scala b/project/Dependencies.scala index ba3b64a..8932854 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -22,6 +22,7 @@ object Dependencies { val akkaClusterShardingTyped = "com.typesafe.akka" %% "akka-cluster-sharding-typed" % akkaVersion val akkaPersistenceCassandra = "com.typesafe.akka" %% "akka-persistence-cassandra" % akkaPersistenceCassandraVersion val akkaPersistenceQuery = "com.typesafe.akka" %% "akka-persistence-query" % akkaVersion + val akkaTestkitTyped = "com.typesafe.akka" %% "akka-actor-testkit-typed" % akkaVersion val slibTelegram = "eu.xeppaka" %% "slib-telegram" % slibTelegramVersion val scalaTest = "org.scalatest" %% "scalatest" % scalaTestVersion val logback = "ch.qos.logback" % "logback-classic" % logbackVersion diff --git a/src/main/scala/eu/xeppaka/bot/CzechPostDeliveryCheck.scala b/src/main/scala/eu/xeppaka/bot/CzechPostDeliveryCheck.scala index 28dcd79..935068d 100644 --- a/src/main/scala/eu/xeppaka/bot/CzechPostDeliveryCheck.scala +++ b/src/main/scala/eu/xeppaka/bot/CzechPostDeliveryCheck.scala @@ -189,7 +189,7 @@ object CzechPostDeliveryCheck { case Success(response) => if (response.status.isSuccess()) Success(response) else Failure(new Exception(s"Check parcel returned HTTP status: ${response.status.value}.")) case response: Failure[HttpResponse] => response } - .flatMap(response => Unmarshal(response).to[Array[Entities.ParcelHistory]]) + .flatMap(response => Unmarshal(response).to[Seq[Entities.ParcelHistory]]) .andThen { case Success(parcelHistories) => parcelHistories.foreach(parcelHistory => ctx.self ! ParcelHistoryRetrieved(parcelHistory)) diff --git a/src/main/scala/eu/xeppaka/bot/Main.scala b/src/main/scala/eu/xeppaka/bot/Main.scala index 778d9f2..2f8c288 100644 --- a/src/main/scala/eu/xeppaka/bot/Main.scala +++ b/src/main/scala/eu/xeppaka/bot/Main.scala @@ -10,6 +10,7 @@ import akka.http.scaladsl.Http import akka.util.Timeout import akka.{ actor, Done } import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.databind.DeserializationFeature import de.heikoseeberger.akkahttpjackson.JacksonSupport import scala.concurrent.duration._ @@ -18,6 +19,7 @@ import scala.io.StdIn object Main { JacksonSupport.defaultObjectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY) + JacksonSupport.defaultObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) def main(args: Array[String]): Unit = { val botId = System.getProperty("botId", "570855144:AAEv7b817cuq2JJI9f2kG5B9G3zW1x-btz4") diff --git a/src/test/scala/eu/xeppaka/bot/UnmarshalSpec.scala b/src/test/scala/eu/xeppaka/bot/UnmarshalSpec.scala new file mode 100644 index 0000000..03a0930 --- /dev/null +++ b/src/test/scala/eu/xeppaka/bot/UnmarshalSpec.scala @@ -0,0 +1,38 @@ +package eu.xeppaka.bot + +import akka.actor.testkit.typed.scaladsl.ActorTestKit +import akka.actor.typed.ActorSystem +import akka.http.scaladsl.model.{ ContentTypes, HttpEntity } +import akka.http.scaladsl.unmarshalling.Unmarshal +import akka.util.ByteString +import com.fasterxml.jackson.databind.DeserializationFeature +import de.heikoseeberger.akkahttpjackson.JacksonSupport +import org.scalatest.BeforeAndAfterAll +import org.scalatest.flatspec.AnyFlatSpec + +import scala.concurrent.Await +import scala.concurrent.duration.DurationInt + +class UnmarshalSpec extends AnyFlatSpec with BeforeAndAfterAll { + import de.heikoseeberger.akkahttpjackson.JacksonSupport._ + + private var testkit: ActorTestKit = _ + + override protected def beforeAll(): Unit = { + JacksonSupport.defaultObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + testkit = ActorTestKit() + } + + override protected def afterAll(): Unit = { + testkit.shutdownTestKit() + } + + "test unmarshal" should "ok" in { + implicit val system: ActorSystem[Nothing] = testkit.system + val json = + "[{\"attributes\":{\"parcelType\":\"1 \",\"weight\":0,\"currency\":\"\",\"telefonTyp\":null,\"telefonNazev\":null,\"telefonCislo\":null,\"dobirka\":0,\"kusu\":null,\"ulozeniDo\":null,\"ulozniDoba\":null,\"zemePuvodu\":null,\"zemeUrceni\":null,\"dorucovaniDate\":null,\"dorucovaniOd\":null,\"dorucovaniDo\":null},\"states\":{\"state\":[{\"id\":\"-4\",\"date\":\"2020-12-27\",\"text\":\"Pro tento druh zásilek Česká pošta informace nezobrazuje.\",\"postcode\":null,\"postoffice\":null,\"idIcon\":null,\"publicAccess\":0,\"latitude\":null,\"longitude\":null,\"timeDeliveryAttempt\":null}]},\"id\":\"123456\"}]" + val entity = HttpEntity(contentType = ContentTypes.`application/json`, data = ByteString(json)) + val result = Await.result(Unmarshal(json).to[Seq[Entities.ParcelHistory]], 2.seconds) + println(result) + } +}