Fix unmarshal for czech post delivery
This commit is contained in:
@@ -9,7 +9,6 @@ lazy val `telegram-bot-delivery` = (project in file("."))
|
|||||||
.settings(
|
.settings(
|
||||||
name := "telegram-bot-delivery",
|
name := "telegram-bot-delivery",
|
||||||
libraryDependencies ++= Seq(
|
libraryDependencies ++= Seq(
|
||||||
scalaTest % Test,
|
|
||||||
akkaTyped,
|
akkaTyped,
|
||||||
akkaSerializationJackson,
|
akkaSerializationJackson,
|
||||||
akkaClusterShardingTyped,
|
akkaClusterShardingTyped,
|
||||||
@@ -19,6 +18,8 @@ lazy val `telegram-bot-delivery` = (project in file("."))
|
|||||||
akkaPersistence,
|
akkaPersistence,
|
||||||
akkaPersistenceCassandra,
|
akkaPersistenceCassandra,
|
||||||
akkaPersistenceQuery,
|
akkaPersistenceQuery,
|
||||||
|
akkaTestkitTyped % Test,
|
||||||
|
scalaTest % Test,
|
||||||
slibTelegram,
|
slibTelegram,
|
||||||
logback
|
logback
|
||||||
),
|
),
|
||||||
@@ -29,7 +30,7 @@ lazy val `telegram-bot-delivery` = (project in file("."))
|
|||||||
Docker / daemonUserUid := Some("1001"),
|
Docker / daemonUserUid := Some("1001"),
|
||||||
Docker / daemonUser := "telegram-bot",
|
Docker / daemonUser := "telegram-bot",
|
||||||
Docker / defaultLinuxInstallLocation := "/opt/telegram-bot-delivery",
|
Docker / defaultLinuxInstallLocation := "/opt/telegram-bot-delivery",
|
||||||
version := "1.1.2"
|
version := "1.1.3"
|
||||||
)
|
)
|
||||||
.enablePlugins(JavaServerAppPackaging)
|
.enablePlugins(JavaServerAppPackaging)
|
||||||
.enablePlugins(DockerPlugin)
|
.enablePlugins(DockerPlugin)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ object Dependencies {
|
|||||||
val akkaClusterShardingTyped = "com.typesafe.akka" %% "akka-cluster-sharding-typed" % akkaVersion
|
val akkaClusterShardingTyped = "com.typesafe.akka" %% "akka-cluster-sharding-typed" % akkaVersion
|
||||||
val akkaPersistenceCassandra = "com.typesafe.akka" %% "akka-persistence-cassandra" % akkaPersistenceCassandraVersion
|
val akkaPersistenceCassandra = "com.typesafe.akka" %% "akka-persistence-cassandra" % akkaPersistenceCassandraVersion
|
||||||
val akkaPersistenceQuery = "com.typesafe.akka" %% "akka-persistence-query" % akkaVersion
|
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 slibTelegram = "eu.xeppaka" %% "slib-telegram" % slibTelegramVersion
|
||||||
val scalaTest = "org.scalatest" %% "scalatest" % scalaTestVersion
|
val scalaTest = "org.scalatest" %% "scalatest" % scalaTestVersion
|
||||||
val logback = "ch.qos.logback" % "logback-classic" % logbackVersion
|
val logback = "ch.qos.logback" % "logback-classic" % logbackVersion
|
||||||
|
|||||||
@@ -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 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
|
case response: Failure[HttpResponse] => response
|
||||||
}
|
}
|
||||||
.flatMap(response => Unmarshal(response).to[Array[Entities.ParcelHistory]])
|
.flatMap(response => Unmarshal(response).to[Seq[Entities.ParcelHistory]])
|
||||||
.andThen {
|
.andThen {
|
||||||
case Success(parcelHistories) =>
|
case Success(parcelHistories) =>
|
||||||
parcelHistories.foreach(parcelHistory => ctx.self ! ParcelHistoryRetrieved(parcelHistory))
|
parcelHistories.foreach(parcelHistory => ctx.self ! ParcelHistoryRetrieved(parcelHistory))
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import akka.http.scaladsl.Http
|
|||||||
import akka.util.Timeout
|
import akka.util.Timeout
|
||||||
import akka.{ actor, Done }
|
import akka.{ actor, Done }
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude
|
import com.fasterxml.jackson.annotation.JsonInclude
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature
|
||||||
import de.heikoseeberger.akkahttpjackson.JacksonSupport
|
import de.heikoseeberger.akkahttpjackson.JacksonSupport
|
||||||
|
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
@@ -18,6 +19,7 @@ import scala.io.StdIn
|
|||||||
|
|
||||||
object Main {
|
object Main {
|
||||||
JacksonSupport.defaultObjectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
|
JacksonSupport.defaultObjectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
|
||||||
|
JacksonSupport.defaultObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||||
|
|
||||||
def main(args: Array[String]): Unit = {
|
def main(args: Array[String]): Unit = {
|
||||||
val botId = System.getProperty("botId", "570855144:AAEv7b817cuq2JJI9f2kG5B9G3zW1x-btz4")
|
val botId = System.getProperty("botId", "570855144:AAEv7b817cuq2JJI9f2kG5B9G3zW1x-btz4")
|
||||||
|
|||||||
38
src/test/scala/eu/xeppaka/bot/UnmarshalSpec.scala
Normal file
38
src/test/scala/eu/xeppaka/bot/UnmarshalSpec.scala
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user