• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala JsonSerializerRegistry类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry的典型用法代码示例。如果您正苦于以下问题:Scala JsonSerializerRegistry类的具体用法?Scala JsonSerializerRegistry怎么用?Scala JsonSerializerRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了JsonSerializerRegistry类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: HelloEntitySpec

//设置package包名称以及导入依赖的类
package sample.helloworld.impl

import akka.Done
import akka.actor.ActorSystem
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver
import org.scalactic.ConversionCheckedTripleEquals
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

import scala.concurrent.Await
import scala.concurrent.duration._


class HelloEntitySpec extends WordSpecLike with Matchers with BeforeAndAfterAll
  with ConversionCheckedTripleEquals {
  val system = ActorSystem("HelloEntitySpec", JsonSerializerRegistry.actorSystemSetupFor(HelloSerializerRegistry))

  override def afterAll(): Unit = {
    Await.ready(system.terminate, 10 seconds)
  }

  "Hello Entity " must {

    "handle UseGreeting Message and fire an event" in {
      val driver = new PersistentEntityTestDriver(system, new HelloEntity, "Hello Entity-1")
      val newMessage = "Welcome Back!!"
      val outcome = driver.run(UseGreetingMessage(newMessage))
      assert(outcome.events.toList === List(GreetingMessageChanged(newMessage)))
      assert(outcome.replies.toList === List(Done))
      assert(outcome.issues === Nil)
    }

    "handle hello Message and return a reply" in {
      val driver = new PersistentEntityTestDriver(system, new HelloEntity, "Hello Entity-2")
      val id = "Alice"
      val outcome = driver.run(Hello(id,None))


      assert(outcome.events.toList === List())
      assert(outcome.replies.toList === List("Hello, Alice!"))
      assert(outcome.issues === Nil)
    }
  }
} 
开发者ID:knoldus,项目名称:lagom-scala-wordcount.g8,代码行数:45,代码来源:HelloEntitySpec.scala


示例2: SaveNewMessage

//设置package包名称以及导入依赖的类
package sample.helloworldconsumer.impl

import com.lightbend.lagom.scaladsl.persistence.PersistentEntity.ReplyType
import play.api.libs.json.Json
import akka.Done
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}

import scala.collection.immutable.Seq


sealed trait MessageCommand [T] extends ReplyType[T]

case class SaveNewMessage(message: String) extends MessageCommand[Done]

object SaveNewMessage {
  implicit val formatter = Json.format[SaveNewMessage]
}

object HelloConsumerSerializerRegistry extends JsonSerializerRegistry {
  override def serializers: Seq[JsonSerializer[_]] = Seq(
    JsonSerializer[SaveNewMessage],
    JsonSerializer[MessageSaved],
    JsonSerializer[MessageState]
  )
} 
开发者ID:knoldus,项目名称:lagom-scala-wordcount.g8,代码行数:26,代码来源:MessageCommand.scala


示例3: LagomhandsondevelopmentEntitySpec

//设置package包名称以及导入依赖的类
package com.example.lagomhandsondevelopment.impl

import akka.actor.ActorSystem
import akka.testkit.TestKit
import com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpec}

class LagomhandsondevelopmentEntitySpec extends WordSpec with Matchers with BeforeAndAfterAll {

  private val system = ActorSystem("LagomhandsondevelopmentEntitySpec",
    JsonSerializerRegistry.actorSystemSetupFor(LagomhandsondevelopmentSerializerRegistry))

  override protected def afterAll(): Unit = {
    TestKit.shutdownActorSystem(system)
  }

  private def withTestDriver(block: PersistentEntityTestDriver[LagomhandsondevelopmentCommand[_], LagomhandsondevelopmentEvent, LagomhandsondevelopmentState] => Unit): Unit = {
    val driver = new PersistentEntityTestDriver(system, new LagomhandsondevelopmentEntity, "lagom-hands-on-development-1")
    block(driver)
    driver.getAllIssues should have size 0
  }

  "lagom-hands-on-development entity" should {

    "say hello by default" in withTestDriver { driver =>
      val outcome = driver.run(Hello("Alice", None))
      outcome.replies should contain only "Hello, Alice!"
    }

    "allow updating the greeting message" in withTestDriver { driver =>
      val outcome1 = driver.run(UseGreetingMessage("Hi"))
      outcome1.events should contain only GreetingMessageChanged("Hi")
      val outcome2 = driver.run(Hello("Alice", None))
      outcome2.replies should contain only "Hi, Alice!"
    }

  }
} 
开发者ID:negokaz,项目名称:lagom-hands-on-development.scala,代码行数:40,代码来源:LagomhandsondevelopmentEntitySpec.scala


示例4: AccountSerializerRegistry

//设置package包名称以及导入依赖的类
package org.ioreskovic.greatmaterialcontinuum.impl.ent.acc

import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import org.ioreskovic.greatmaterialcontinuum.impl.cmd.acc._
import org.ioreskovic.greatmaterialcontinuum.impl.evt.acc._
import org.ioreskovic.greatmaterialcontinuum.impl.stt.acc.AccountState

import scala.collection.immutable

object AccountSerializerRegistry extends JsonSerializerRegistry {
  override def serializers: immutable.Seq[JsonSerializer[_]] = immutable.Seq(
    JsonSerializer[AccountState],

    JsonSerializer[CreateAccount],
    JsonSerializer[DeleteAccount],
    JsonSerializer[ActivateAccount],
    JsonSerializer[DeactivateAccount],
    JsonSerializer[RetrieveAccount],

    JsonSerializer[AccountCreated],
    JsonSerializer[AccountDeleted],
    JsonSerializer[AccountActivated],
    JsonSerializer[AccountDeactivated],
    JsonSerializer[AccountRetrieved]
  )
} 
开发者ID:ioreskovic,项目名称:great-material-continuum,代码行数:27,代码来源:AccountSerializerRegistry.scala


示例5: HelloEntitySpec

//设置package包名称以及导入依赖的类
package se.hultner.hello.impl

import akka.actor.ActorSystem
import akka.testkit.TestKit
import com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpec}

class HelloEntitySpec extends WordSpec with Matchers with BeforeAndAfterAll {

  private val system = ActorSystem("HelloEntitySpec",
    JsonSerializerRegistry.actorSystemSetupFor(HelloSerializerRegistry))

  override protected def afterAll(): Unit = {
    TestKit.shutdownActorSystem(system)
  }

  private def withTestDriver(block: PersistentEntityTestDriver[HelloCommand[_], HelloEvent, HelloState] => Unit): Unit = {
    val driver = new PersistentEntityTestDriver(system, new HelloEntity, "hello-1")
    block(driver)
    driver.getAllIssues should have size 0
  }

  "Hello entity" should {

    "say hello by default" in withTestDriver { driver =>
      val outcome = driver.run(Hello("Alice", None))
      outcome.replies should contain only "Hello, Alice!"
    }

    "allow updating the greeting message" in withTestDriver { driver =>
      val outcome1 = driver.run(UseGreetingMessage("Hi"))
      outcome1.events should contain only GreetingMessageChanged("Hi")
      val outcome2 = driver.run(Hello("Alice", None))
      outcome2.replies should contain only "Hi, Alice!"
    }

  }
} 
开发者ID:Hultner,项目名称:hello_scala_microservices,代码行数:40,代码来源:HelloEntitySpec.scala


示例6: LagomshoppingEntitySpec

//设置package包名称以及导入依赖的类
package com.example.lagomshopping.impl

import akka.actor.ActorSystem
import akka.testkit.TestKit
import com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpec}

class LagomshoppingEntitySpec extends WordSpec with Matchers with BeforeAndAfterAll {

  private val system = ActorSystem("LagomshoppingEntitySpec",
    JsonSerializerRegistry.actorSystemSetupFor(LagomshoppingSerializerRegistry))

  override protected def afterAll(): Unit = {
    TestKit.shutdownActorSystem(system)
  }

  private def withTestDriver(block: PersistentEntityTestDriver[LagomshoppingCommand[_], LagomshoppingEvent, LagomshoppingState] => Unit): Unit = {
    val driver = new PersistentEntityTestDriver(system, new LagomshoppingEntity, "lagomshopping-1")
    block(driver)
    driver.getAllIssues should have size 0
  }

  "LagomShopping entity" should {

    "say hello by default" in withTestDriver { driver =>
      val outcome = driver.run(Hello("Alice", None))
      outcome.replies should contain only "Hello, Alice!"
    }

    "allow updating the greeting message" in withTestDriver { driver =>
      val outcome1 = driver.run(UseGreetingMessage("Hi"))
      outcome1.events should contain only GreetingMessageChanged("Hi")
      val outcome2 = driver.run(Hello("Alice", None))
      outcome2.replies should contain only "Hi, Alice!"
    }

  }
} 
开发者ID:code-star,项目名称:lagom-playground,代码行数:40,代码来源:LagomshoppingEntitySpec.scala


示例7: BasketApplication

//设置package包名称以及导入依赖的类
package demo.impl.basket

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import demo.api.basket.{Basket, BasketService}
import play.api.libs.ws.ahc.AhcWSComponents

import scala.collection.immutable.Seq

abstract class BasketApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
  with AhcWSComponents
  with LagomKafkaComponents
  with CassandraPersistenceComponents {
  override def lagomServer: LagomServer = LagomServer.forServices {
    bindService[BasketService].to(wire[BasketServiceImpl])
  }

  persistentEntityRegistry.register(wire[BasketEntity])
}

class BasketApplicationLoader extends LagomApplicationLoader {
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BasketApplication(context) with LagomDevModeComponents {
      override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
    }

  override def load(context: LagomApplicationContext): LagomApplication = new BasketApplication(context) {
    override def serviceLocator: ServiceLocator = NoServiceLocator
    override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
  }
}

object BasketSerializerRegistry extends JsonSerializerRegistry {
  import BasketEntityFormats._
  override def serializers: Seq[JsonSerializer[_]] = Seq (
    JsonSerializer[AddItem],
    JsonSerializer[GetBasket.type],
    JsonSerializer[GetTotal.type],
    JsonSerializer[ClearAll.type],
    JsonSerializer[BasketCleared.type],
    JsonSerializer[ItemAdded],
    JsonSerializer[BasketEntityState],
    JsonSerializer[Basket],
    JsonSerializer[OrderPlaced],
    JsonSerializer[PlaceOrder.type],
    JsonSerializer[Basket]
  )
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:55,代码来源:BasketApplication.scala


示例8: BasketSpec

//设置package包名称以及导入依赖的类
import akka.Done
import akka.actor.ActorSystem
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver
import demo.api.basket.{Basket, Item}
import demo.impl.basket._
import org.scalactic.TypeCheckedTripleEquals
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

import scala.concurrent.duration._
import scala.concurrent.Await

class BasketSpec extends WordSpecLike with Matchers with BeforeAndAfterAll with TypeCheckedTripleEquals {
  val system = ActorSystem("PostSpec", JsonSerializerRegistry.actorSystemSetupFor(BasketSerializerRegistry))

  override protected def afterAll() {
    Await.ready(system.terminate(), 20.seconds)
  }

  "Basket" must {
    "Add an item" in {
      val driver = new PersistentEntityTestDriver(system, new BasketEntity, "Basket1")
      val addItemOutcome = driver.run(AddItem(Item("Apple", 50)))
      addItemOutcome.events should ===(List(ItemAdded(Item("Apple", 50))))
      addItemOutcome.state.currentBasket.total should ===(50)
      addItemOutcome.state.currentBasket.items should ===(IndexedSeq(Item("Apple", 50)))
      addItemOutcome.replies should ===(List(Done))
      addItemOutcome.issues should ===(Nil)

      val getItemsOutcome = driver.run(GetBasket)
      getItemsOutcome.issues should ===(Nil)
      getItemsOutcome.replies should ===(List(Basket(Seq(Item("Apple", 50)), 50)))

      val getPriceOutcome = driver.run(GetTotal)
      getPriceOutcome.issues should ===(Nil)
      getPriceOutcome.replies should ===(List(50))
    }

    "Clear the basket" in {
      val driver = new PersistentEntityTestDriver(system, new BasketEntity, "Basket1")
      val addItemOutcome = driver.run(AddItem(Item("Apple", 50)))

      val clearOutcome = driver.run(ClearAll)
      clearOutcome.issues should ===(Nil)
      clearOutcome.replies should ===(List(Done))

      val getBasketOutcome = driver.run(GetBasket)
      getBasketOutcome.issues should ===(Nil)
      getBasketOutcome.replies should ===(List(Basket(Seq(), 0)))
    }

    "Place an order" in {
      val driver = new PersistentEntityTestDriver(system, new BasketEntity, "Basket2")
      driver.run(AddItem(Item("Apple", 50)))
      val outcome = driver.run(PlaceOrder)
      outcome.issues should ===(List())
      outcome.events should ===(List(OrderPlaced("Basket2", Basket(Seq(Item("Apple", 50)), 50))))
    }
  }
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:61,代码来源:BasketSpec.scala


示例9: OrderApplication

//设置package包名称以及导入依赖的类
package demo.impl.order

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire.wire
import demo.api.basket.BasketService
import demo.api.order.OrderService
import play.api.libs.ws.ahc.AhcWSComponents

import scala.collection.immutable.Seq

abstract class OrderApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
  with AhcWSComponents
  with CassandraPersistenceComponents
  with LagomKafkaComponents {
  override def lagomServer: LagomServer = LagomServer.forServices {
    bindService[OrderService].to(wire[OrderServiceImpl])
  }

  lazy val basketService: BasketService = serviceClient.implement[BasketService]

  persistentEntityRegistry.register(wire[Order])

  wire[BasketServiceSubscriber]
}

class OrderApplicationLoader extends LagomApplicationLoader {
  override def loadDevMode(context: LagomApplicationContext): LagomApplication = {
    new OrderApplication(context) with LagomDevModeComponents {
      override def jsonSerializerRegistry: JsonSerializerRegistry = OrderSerializerRegistry
    }
  }

  override def load(context: LagomApplicationContext): LagomApplication = {
    new OrderApplication(context) {
      override def serviceLocator: ServiceLocator = NoServiceLocator
      override def jsonSerializerRegistry: JsonSerializerRegistry = OrderSerializerRegistry
    }
  }
}

object OrderSerializerRegistry extends JsonSerializerRegistry {
  import OrderEntityFormats._
  override def serializers: Seq[JsonSerializer[_]] = {
    Seq(JsonSerializer[OrderInitialized],
      JsonSerializer[OrderState],
      JsonSerializer[CreateOrder],
      JsonSerializer[GetOrder.type],
      JsonSerializer[OrderItems])
  }
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:57,代码来源:OrderApplication.scala


示例10: OrderSpec

//设置package包名称以及导入依赖的类
import akka.Done
import akka.actor.ActorSystem
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver
import com.typesafe.config.ConfigFactory
import demo.impl.order._
import org.scalactic.TypeCheckedTripleEquals
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

import scala.concurrent.duration._
import scala.concurrent.Await

class OrderSpec extends WordSpecLike with Matchers with BeforeAndAfterAll with TypeCheckedTripleEquals {
  val system = ActorSystem("PostSpec", JsonSerializerRegistry.actorSystemSetupFor(OrderSerializerRegistry))

  override protected def afterAll() {
    Await.ready(system.terminate(), 20.seconds)
  }

  "Order" must {
    "be created" in {
      val driver = new PersistentEntityTestDriver(system, new Order, "order1")
      val items = IndexedSeq("Apple", "Banana")
      val outcome = driver.run(CreateOrder(items))
      outcome.issues should ===(List())
      outcome.state should ===(OrderState(items))
      outcome.events should ===(List(OrderInitialized(items)))
      outcome.replies should ===(List(Done))

      val getOutcome = driver.run(GetOrder)

      getOutcome.issues should ===(List())
      getOutcome.state should ===(OrderState(items))
      getOutcome.replies should ===(List(OrderItems(items)))
    }
  }
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:38,代码来源:OrderSpec.scala


示例11: BasketApplication

//设置package包名称以及导入依赖的类
package demo.impl.basket

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import demo.api.basket.{Basket, BasketService}
import play.api.libs.ws.ahc.AhcWSComponents

import scala.collection.immutable.Seq

abstract class BasketApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
  with AhcWSComponents
  with LagomKafkaComponents
  with CassandraPersistenceComponents {
  override def lagomServer: LagomServer = LagomServer.forServices {
    bindService[BasketService].to(wire[BasketServiceImpl])
  }


  persistentEntityRegistry.register(wire[BasketEntity])
}

class BasketApplicationLoader extends LagomApplicationLoader {
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BasketApplication(context) with LagomDevModeComponents {
      override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
    }

  override def load(context: LagomApplicationContext): LagomApplication = new BasketApplication(context) {
    override def serviceLocator: ServiceLocator = NoServiceLocator
    override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
  }
}

object BasketSerializerRegistry extends JsonSerializerRegistry {
  import BasketEntityFormats._
  override def serializers: Seq[JsonSerializer[_]] = Seq (
    JsonSerializer[AddItem],
    JsonSerializer[GetBasket.type],
    JsonSerializer[GetTotal.type],
    JsonSerializer[ClearAll.type],
    JsonSerializer[BasketCleared.type],
    JsonSerializer[ItemAdded],
    JsonSerializer[BasketEntityState],
    JsonSerializer[Basket],
    JsonSerializer[OrderPlaced],
    JsonSerializer[PlaceOrder.type],
    JsonSerializer[Basket]
  )
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:56,代码来源:BasketApplication.scala


示例12: BasketApplication

//设置package包名称以及导入依赖的类
package demo.impl.basket

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import demo.api.basket.{Basket, BasketService, Item}
import play.api.libs.ws.ahc.AhcWSComponents
import com.softwaremill.macwire._

import scala.collection.immutable.Seq

abstract class BasketApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
  with AhcWSComponents
  with LagomKafkaComponents
  with CassandraPersistenceComponents {
  override def lagomServer: LagomServer = LagomServer.forServices {
    bindService[BasketService].to(wire[BasketServiceImpl])
  }

  persistentEntityRegistry.register(wire[BasketEntity])
}

class BasketApplicationLoader extends LagomApplicationLoader {
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BasketApplication(context) with LagomDevModeComponents {
      override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
    }

  override def load(context: LagomApplicationContext): LagomApplication = new BasketApplication(context) {
    override def serviceLocator: ServiceLocator = NoServiceLocator
    override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
  }
}

object BasketSerializerRegistry extends JsonSerializerRegistry {
  import BasketEntityFormats._
  override def serializers: Seq[JsonSerializer[_]] = Seq (
    JsonSerializer[AddItem],
    JsonSerializer[GetBasket.type],
    JsonSerializer[GetTotal.type],
    JsonSerializer[ItemAdded],
    JsonSerializer[BasketEntityState],
    JsonSerializer[Basket]
  )
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:50,代码来源:BasketApplication.scala


示例13: BasketServiceSpec

//设置package包名称以及导入依赖的类
import akka.{Done, NotUsed}
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import demo.api.basket.{Basket, BasketService, Item}
import demo.impl.basket.{BasketApplication, BasketSerializerRegistry}
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}

import scala.concurrent.Future

class BasketServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {
  lazy val service = ServiceTest.startServer(ServiceTest.defaultSetup.withCassandra(true)) { ctx =>
    new BasketApplication(ctx) with LocalServiceLocator {
      override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
    }
  }

  override protected def beforeAll() = service
  override protected def afterAll() = service.stop()
  val client = service.serviceClient.implement[BasketService]

  "Basket Service" should {
    "add a single item and get the basket" in {
      client.addItem("basket1").invoke(Item("Apple", 50)).flatMap { response =>
        response should ===(NotUsed)

        client.getBasket("basket1").invoke().map { getItemsResponse =>
          getItemsResponse should ===(Basket(Seq(Item("Apple", 50)), 50))
        }
      }
    }

    "get an empty basket" in {
      client.getBasket("basket2").invoke().map { getItemsResponse =>
        getItemsResponse should ===(Basket(Seq(), 0))
      }
    }

    "add multiple items" in {
      val items = "Apple" -> 50 :: "Apple" -> 50 :: "Orange" -> 30 :: Nil

      Future.sequence(items.map(i => client.addItem("basket3").invoke(Item(i._1, i._2)))).flatMap{ f =>
        client.getBasket("basket3").invoke().flatMap { getItemsResponse =>
          getItemsResponse.items should contain(Item("Apple", 50))
          getItemsResponse.items should contain(Item("Orange", 30))
          getItemsResponse.total should===(130)

          client.getTotal("basket3").invoke().map { getItemsResponse =>
            getItemsResponse should===(130)
          }
        }
      }
    }
  }
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:56,代码来源:BasketServiceSpec.scala


示例14: BasketSpec

//设置package包名称以及导入依赖的类
import akka.Done
import akka.actor.ActorSystem
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver
import demo.api.basket.{Basket, Item}
import demo.impl.basket._
import org.scalactic.TypeCheckedTripleEquals
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

import scala.concurrent.duration._
import scala.concurrent.Await

class BasketSpec extends WordSpecLike with Matchers with BeforeAndAfterAll with TypeCheckedTripleEquals {
  val system = ActorSystem("PostSpec", JsonSerializerRegistry.actorSystemSetupFor(BasketSerializerRegistry))

  override protected def afterAll() {
    Await.ready(system.terminate(), 20.seconds)
  }

  "Basket" must {
    "Add an item" in {
      val driver = new PersistentEntityTestDriver(system, new BasketEntity, "Basket1")
      val addItemOutcome = driver.run(AddItem(Item("Apple", 50)))
      addItemOutcome.events should ===(List(ItemAdded(Item("Apple", 50))))
      addItemOutcome.state.currentBasket.total should ===(50)
      addItemOutcome.state.currentBasket.items should ===(IndexedSeq(Item("Apple", 50)))
      addItemOutcome.replies should ===(List(Done))
      addItemOutcome.issues should ===(Nil)

      val getItemsOutcome = driver.run(GetBasket)
      getItemsOutcome.issues should ===(Nil)
      getItemsOutcome.replies should ===(List(Basket(Seq(Item("Apple", 50)), 50)))

      val getPriceOutcome = driver.run(GetTotal)
      getPriceOutcome.issues should ===(Nil)
      getPriceOutcome.replies should ===(List(50))
    }
  }
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:40,代码来源:BasketSpec.scala


示例15: BasketApplication

//设置package包名称以及导入依赖的类
package demo.impl.basket

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import demo.api.basket.{BasketService, Item}
import play.api.libs.ws.ahc.AhcWSComponents
import com.softwaremill.macwire._

import scala.collection.immutable.Seq

abstract class BasketApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
  with AhcWSComponents
  with LagomKafkaComponents
  with CassandraPersistenceComponents {
  override def lagomServer: LagomServer = LagomServer.forServices {
    bindService[BasketService].to(wire[BasketServiceImpl])
  }
}

class BasketApplicationLoader extends LagomApplicationLoader {
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BasketApplication(context) with LagomDevModeComponents {
      override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
    }

  override def load(context: LagomApplicationContext): LagomApplication = new BasketApplication(context) {
    override def serviceLocator: ServiceLocator = NoServiceLocator
    override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
  }
}

object BasketSerializerRegistry extends JsonSerializerRegistry {
  override def serializers: Seq[JsonSerializer[_]] = Seq (
  )
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:41,代码来源:BasketApplication.scala


示例16: BasketServiceSpec

//设置package包名称以及导入依赖的类
import akka.{Done, NotUsed}
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import demo.api.basket.{Basket, BasketService, Item}
import demo.impl.basket.{BasketApplication, BasketSerializerRegistry}
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}

import scala.concurrent.Future

class BasketServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {
  lazy val service = ServiceTest.startServer(ServiceTest.defaultSetup.withCassandra(true)) { ctx =>
    new BasketApplication(ctx) with LocalServiceLocator {
      override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
    }
  }

  override protected def beforeAll() = service
  override protected def afterAll() = service.stop()
  val client = service.serviceClient.implement[BasketService]

  "Basket Service" should {
    "add a single item" in {
      client.addItem("basket1").invoke(Item("Apple", 50)).flatMap { response =>
        response should ===(NotUsed)

        client.getBasket("basket1").invoke().map { getItemsResponse =>
          getItemsResponse should ===(Basket(Seq(Item("Apple", 50)), 50))
        }
      }
    }

    "get an empty basket" in {
      client.getBasket("basket2").invoke().map { getItemsResponse =>
        getItemsResponse should ===(Basket(Seq(), 0))
      }
    }

    "add multiple items" in {
      val items = ("Apple" -> 50 :: "Apple" -> 50 :: "Orange" -> 30 :: Nil).map { t =>
        Item(t._1, t._2)
      }

      items.foldLeft(Future.successful(List[NotUsed]())) { (f, i) =>
        f.flatMap(l => client.addItem("basket3").invoke(i).map(n => n :: l))
      }.flatMap { f =>
        client.getBasket("basket3").invoke().map { getItemsResponse =>
          getItemsResponse.items should be(items)
          getItemsResponse.total should===(130)
        }
      }
    }
  }
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:55,代码来源:BasketServiceSpec.scala


示例17: BasketApplication

//设置package包名称以及导入依赖的类
package demo.impl.basket

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import demo.api.basket.{Basket, BasketService, Item}
import play.api.libs.ws.ahc.AhcWSComponents
import com.softwaremill.macwire._

import scala.collection.immutable.Seq

abstract class BasketApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
  with AhcWSComponents
  with LagomKafkaComponents
  with CassandraPersistenceComponents {
  override def lagomServer: LagomServer = LagomServer.forServices {
    bindService[BasketService].to(wire[BasketServiceImpl])
  }

  persistentEntityRegistry.register(wire[BasketEntity])
}

class BasketApplicationLoader extends LagomApplicationLoader {
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BasketApplication(context) with LagomDevModeComponents {
      override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
    }

  override def load(context: LagomApplicationContext): LagomApplication = new BasketApplication(context) {
    override def serviceLocator: ServiceLocator = NoServiceLocator
    override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
  }
}

object BasketSerializerRegistry extends JsonSerializerRegistry {
  import BasketEntityFormats._
  override def serializers: Seq[JsonSerializer[_]] = Seq (
    JsonSerializer[AddItem],
    JsonSerializer[GetBasket.type],
    JsonSerializer[ItemAdded],
    JsonSerializer[BasketEntityState],
    JsonSerializer[Basket]
  )
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:49,代码来源:BasketApplication.scala


示例18: BasketServiceSpec

//设置package包名称以及导入依赖的类
import akka.{Done, NotUsed}
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import demo.api.basket.{Basket, BasketService, Item}
import demo.impl.basket.{BasketApplication, BasketSerializerRegistry}
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}

import scala.concurrent.Future

class BasketServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {
  lazy val service = ServiceTest.startServer(ServiceTest.defaultSetup.withCassandra(true)) { ctx =>
    new BasketApplication(ctx) with LocalServiceLocator {
      override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
    }
  }

  override protected def beforeAll() = service
  override protected def afterAll() = service.stop()
  val client = service.serviceClient.implement[BasketService]

  "Basket Service" should {
    "add a single item" in {
      client.addItem("basket1").invoke(Item("Apple", 50)).flatMap { response =>
        response should ===(NotUsed)

        client.getBasket("basket1").invoke().map { getItemsResponse =>
          getItemsResponse should ===(Basket(Seq(Item("Apple", 50)), 50))
        }
      }
    }

    "get an empty basket" in {
      client.getBasket("basket2").invoke().map { getItemsResponse =>
        getItemsResponse should ===(Basket(Seq(), 0))
      }
    }

    "add multiple items" in {
      val items = "Apple" -> 50 :: "Apple" -> 50 :: "Orange" -> 30 :: Nil

      Future.sequence(items.map(i => client.addItem("basket3").invoke(Item(i._1, i._2)))).flatMap{ f =>
        client.getBasket("basket3").invoke().map { getItemsResponse =>
          getItemsResponse.items should contain(Item("Apple", 50))
          getItemsResponse.items should contain(Item("Orange", 30))
          getItemsResponse.total should===(130)
        }
      }
    }
  }
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:52,代码来源:BasketServiceSpec.scala


示例19: BasketSpec

//设置package包名称以及导入依赖的类
import akka.Done
import akka.actor.ActorSystem
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver
import demo.api.basket.{Basket, Item}
import demo.impl.basket._
import org.scalactic.TypeCheckedTripleEquals
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

import scala.concurrent.duration._
import scala.concurrent.Await

class BasketSpec extends WordSpecLike with Matchers with BeforeAndAfterAll with TypeCheckedTripleEquals {
  val system = ActorSystem("PostSpec", JsonSerializerRegistry.actorSystemSetupFor(BasketSerializerRegistry))

  override protected def afterAll() {
    Await.ready(system.terminate(), 20.seconds)
  }

  "Basket" must {
    "Add an item" in {
      val driver = new PersistentEntityTestDriver(system, new BasketEntity, "Basket1")
      val addItemOutcome = driver.run(AddItem(Item("Apple", 50)))
      addItemOutcome.events should ===(List(ItemAdded(Item("Apple", 50))))
      addItemOutcome.state.currentBasket.total should ===(50)
      addItemOutcome.state.currentBasket.items should ===(IndexedSeq(Item("Apple", 50)))
      addItemOutcome.replies should ===(List(Done))
      addItemOutcome.issues should ===(Nil)

      val getItemsOutcome = driver.run(GetBasket)
      getItemsOutcome.issues should ===(Nil)
      getItemsOutcome.replies should ===(List(Basket(Seq(Item("Apple", 50)), 50)))
    }
  }
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:36,代码来源:BasketSpec.scala


示例20: BasketApplication

//设置package包名称以及导入依赖的类
package demo.impl.basket

import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import demo.api.basket.{BasketService}
import play.api.libs.ws.ahc.AhcWSComponents
import com.softwaremill.macwire._

import scala.collection.immutable.Seq

abstract class BasketApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
  with AhcWSComponents
  with LagomKafkaComponents
  with CassandraPersistenceComponents {
  override def lagomServer: LagomServer = LagomServer.forServices {
    ???
    //bindService[BasketService].to(wire[BasketServiceImpl])
  }
}

class BasketApplicationLoader extends LagomApplicationLoader {
  override def loadDevMode(context: LagomApplicationContext): LagomApplication =
    new BasketApplication(context) with LagomDevModeComponents {
      override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
    }

  override def load(context: LagomApplicationContext): LagomApplication = new BasketAp 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Gson类代码示例发布时间:2022-05-23
下一篇:
Scala ToolBox类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap