本文整理汇总了Scala中com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver类的典型用法代码示例。如果您正苦于以下问题:Scala PersistentEntityTestDriver类的具体用法?Scala PersistentEntityTestDriver怎么用?Scala PersistentEntityTestDriver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PersistentEntityTestDriver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
}
}
示例2: 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
示例3: 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!"
}
}
}
示例4: PlayerSpec
//设置package包名称以及导入依赖的类
package com.chriswk.gameranker.player
import akka.actor.ActorSystem
import com.chriswk.gameranker.player.impl.{CreatePlayer, Player, PlayerCreated, PlayerEntity}
import com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver
import com.typesafe.config.ConfigFactory
import org.scalactic.ConversionCheckedTripleEquals
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}
import scala.concurrent.Await
import scala.concurrent.duration._
class PlayerSpec extends WordSpecLike with Matchers with BeforeAndAfterAll with ConversionCheckedTripleEquals {
val config = ConfigFactory.load()
val system = ActorSystem("PlayerSpec", config)
override def afterAll(): Unit = {
Await.ready(system.terminate, 10.seconds)
}
"Player entity" must {
"handle CreatePlayer" in {
val driver = new PersistentEntityTestDriver(system, new PlayerEntity, "player-1")
val name = "Testing hero"
val outcome = driver.run(CreatePlayer(name))
outcome.events should ===(List(PlayerCreated(name)))
outcome.state should ===(Some(Player("Testing hero")))
}
"be idempotent" in {
val driver = new PersistentEntityTestDriver(system, new PlayerEntity, "player-1")
val name = "Testing hero"
val outcome = driver.run(CreatePlayer(name), CreatePlayer(name), CreatePlayer(name))
outcome.events should ===(List(PlayerCreated(name)))
outcome.state should ===(Some(Player("Testing hero")))
val secondRun = driver.run(CreatePlayer("Frank"))
secondRun.events should ===(List())
secondRun.state should ===(Some(Player("Testing hero")))
}
}
}
示例5: 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!"
}
}
}
示例6: 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))))
}
}
}
示例7: 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))
}
}
}
示例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)))
}
}
}
示例9: 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)))
}
}
}
示例10: SsEntitySpec
//设置package包名称以及导入依赖的类
package com.ss.ss.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 SsEntitySpec extends WordSpec with Matchers with BeforeAndAfterAll {
private val system = ActorSystem("SsEntitySpec",
JsonSerializerRegistry.actorSystemSetupFor(SsSerializerRegistry))
override protected def afterAll(): Unit = {
TestKit.shutdownActorSystem(system)
}
private def withTestDriver(block: PersistentEntityTestDriver[SsCommand[_], SsEvent, SsState] => Unit): Unit = {
val driver = new PersistentEntityTestDriver(system, new SsEntity, "ss-1")
block(driver)
driver.getAllIssues should have size 0
}
"ss 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!"
}
}
}
示例11: UserEntitySpec
//设置package包名称以及导入依赖的类
package com.grossbit.user.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 UserEntitySpec extends WordSpec with Matchers with BeforeAndAfterAll {
private val system = ActorSystem("UserEntitySpec",
JsonSerializerRegistry.actorSystemSetupFor(UserSerializerRegistry))
override protected def afterAll(): Unit = {
TestKit.shutdownActorSystem(system)
}
private def withTestDriver(block: PersistentEntityTestDriver[UserCommand[_], UserEvent, UserState] => Unit): Unit = {
val driver = new PersistentEntityTestDriver(system, new UserEntity, "user-1")
block(driver)
driver.getAllIssues should have size 0
}
"User 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!"
}
}
}
示例12: MonitorEntitySpec
//设置package包名称以及导入依赖的类
package org.wex.cmsfs.monitor.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 MonitorEntitySpec extends WordSpec with Matchers with BeforeAndAfterAll {
private val system = ActorSystem("MonitorEntitySpec",
JsonSerializerRegistry.actorSystemSetupFor(MonitorSerializerRegistry))
override protected def afterAll(): Unit = {
TestKit.shutdownActorSystem(system)
}
private def withTestDriver(block: PersistentEntityTestDriver[MonitorCommand[_], MonitorEvent, MonitorState] => Unit): Unit = {
val driver = new PersistentEntityTestDriver(system, new MonitorEntity, "monitor-1")
block(driver)
driver.getAllIssues should have size 0
}
"Monitor 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!"
}
}
}
示例13: LagompracticeEntitySpec
//设置package包名称以及导入依赖的类
package com.example.lagompractice.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 LagompracticeEntitySpec extends WordSpec with Matchers with BeforeAndAfterAll {
private val system = ActorSystem("LagompracticeEntitySpec",
JsonSerializerRegistry.actorSystemSetupFor(LagompracticeSerializerRegistry))
override protected def afterAll(): Unit = {
TestKit.shutdownActorSystem(system)
}
private def withTestDriver(block: PersistentEntityTestDriver[LagompracticeCommand[_], LagompracticeEvent, LagompracticeState] => Unit): Unit = {
val driver = new PersistentEntityTestDriver(system, new LagompracticeEntity, "lagom-practice-1")
block(driver)
driver.getAllIssues should have size 0
}
"lagom-practice 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!"
}
}
}
示例14: LagomdemoEntitySpec
//设置package包名称以及导入依赖的类
package com.dannyrobert.lagomdemo.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 LagomdemoEntitySpec extends WordSpec with Matchers with BeforeAndAfterAll {
private val system = ActorSystem("LagomdemoEntitySpec",
JsonSerializerRegistry.actorSystemSetupFor(LagomdemoSerializerRegistry))
override protected def afterAll(): Unit = {
TestKit.shutdownActorSystem(system)
}
private def withTestDriver(block: PersistentEntityTestDriver[LagomdemoCommand[_], LagomdemoEvent, LagomdemoState] => Unit): Unit = {
val driver = new PersistentEntityTestDriver(system, new LagomdemoEntity, "lagom-demo-1")
block(driver)
driver.getAllIssues should have size 0
}
"lagom-demo 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!"
}
}
}
示例15: OrderEntitySpec
//设置package包名称以及导入依赖的类
package be.yannickdeturck.lagomshopscala.order.impl
import java.util.UUID
import akka.actor.ActorSystem
import akka.testkit.TestKit
import be.yannickdeturck.lagomshopscala.order.impl._
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver
import org.scalatest.{BeforeAndAfterAll, Matchers, OptionValues, WordSpec}
class OrderEntitySpec extends WordSpec with Matchers with BeforeAndAfterAll with OptionValues {
private val system = ActorSystem("OrderEntitySpec",
JsonSerializerRegistry.actorSystemSetupFor(OrderSerializerRegistry))
override protected def afterAll(): Unit = {
TestKit.shutdownActorSystem(system)
}
private val id = UUID.randomUUID
private val itemId = UUID.randomUUID
private val order = Order(id, itemId, 3, "Yannick")
private def withTestDriver[T](block: PersistentEntityTestDriver[OrderCommand, OrderEvent, Option[Order]] => T): T = {
val driver = new PersistentEntityTestDriver(system, new OrderEntity, id.toString)
try {
block(driver)
} finally {
driver.getAllIssues shouldBe empty
}
}
"order entity" should {
"allow creating an order" in withTestDriver { driver =>
val outcome = driver.run(CreateOrder(order))
outcome.events should contain only OrderCreated(order)
outcome.state should ===(Some(order))
}
"allow looking up an order" in withTestDriver { driver =>
driver.run(CreateOrder(order))
val outcome = driver.run(GetOrder)
outcome.events shouldBe empty
outcome.replies should contain only Some(order)
outcome.state should ===(Some(order))
}
}
}