本文整理汇总了Scala中com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver类的典型用法代码示例。如果您正苦于以下问题:Scala PersistentEntityTestDriver类的具体用法?Scala PersistentEntityTestDriver怎么用?Scala PersistentEntityTestDriver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PersistentEntityTestDriver类的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: 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!"
}
}
}
开发者ID:Hultner,项目名称:hello_scala_microservices,代码行数:40,代码来源:HelloEntitySpec.scala
示例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")))
}
}
}
开发者ID:chriswk,项目名称:gameranker,代码行数:43,代码来源:PlayerSpec.scala
示例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!"
}
}
}
开发者ID:code-star,项目名称:lagom-playground,代码行数:40,代码来源:LagomshoppingEntitySpec.scala
示例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))))
}
}
}
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:61,代码来源:BasketSpec.scala
示例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))
}
}
}
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:40,代码来源:BasketSpec.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)))
}
}
}
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:36,代码来源:BasketSpec.scala
示例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)))
}
}
}
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:53,代码来源:BasketSpec.scala
示例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!"
}
}
}
开发者ID:ytaras,项目名称:iot_lagom_poc,代码行数:40,代码来源:SsEntitySpec.scala
示例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!"
}
}
}
开发者ID:sarathraj-coder,项目名称:lagommicroapp,代码行数:40,代码来源:UserEntitySpec.scala
示例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!"
}
}
}
开发者ID:shinhwazx160,项目名称:test,代码行数:40,代码来源:MonitorEntitySpec.scala
示例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!"
}
}
}
开发者ID:Saneyan,项目名称:lagom-practice,代码行数:40,代码来源:LagompracticeEntitySpec.scala
示例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!"
}
}
}
开发者ID:drobert,项目名称:lagom-prototype,代码行数:40,代码来源:LagomdemoEntitySpec.scala
示例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))
}
}
}
开发者ID:yannickdeturck,项目名称:lagom-shop-scala,代码行数:50,代码来源:OrderEntitySpec.scala
示例16: ItemEntitySpec
//设置package包名称以及导入依赖的类
package be.yannickdeturck.lagomshopscala.item.impl
import java.util.UUID
import akka.actor.ActorSystem
import akka.testkit.TestKit
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver
import org.scalatest.{BeforeAndAfterAll, Matchers, OptionValues, WordSpec}
class ItemEntitySpec extends WordSpec with Matchers with BeforeAndAfterAll with OptionValues {
private val system = ActorSystem("ItemEntitySpec",
JsonSerializerRegistry.actorSystemSetupFor(ItemSerializerRegistry))
override protected def afterAll(): Unit = {
TestKit.shutdownActorSystem(system)
}
private val id = UUID.randomUUID
private val item = Item(id, "title", "desc", BigDecimal.valueOf(25.95))
private def withTestDriver[T](block: PersistentEntityTestDriver[ItemCommand, ItemEvent, Option[Item]] => T): T = {
val driver = new PersistentEntityTestDriver(system, new ItemEntity, id.toString)
try {
block(driver)
} finally {
driver.getAllIssues shouldBe empty
}
}
"item entity" should {
"allow creating an item" in withTestDriver { driver =>
val outcome = driver.run(CreateItem(item))
outcome.events should contain only ItemCreated(item)
outcome.state should ===(Some(item))
}
"allow looking up an item" in withTestDriver { driver =>
driver.run(CreateItem(item))
val outcome = driver.run(GetItem)
outcome.events shouldBe empty
outcome.replies should contain only Some(item)
outcome.state should ===(Some(item))
}
}
}
开发者ID:yannickdeturck,项目名称:lagom-shop-scala,代码行数:48,代码来源:ItemEntitySpec.scala
示例17: HelloEntitySpec
//设置package包名称以及导入依赖的类
package com.example.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:team3,项目名称:slotbook-api-lagom,代码行数:40,代码来源:HelloEntitySpec.scala
示例18: HelloEntitySpec
//设置package包名称以及导入依赖的类
package com.example.order.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 OrderEntity, "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:xebia,项目名称:lagom-saga,代码行数:40,代码来源:HelloEntitySpec.scala
示例19: SagaEntitySpec
//设置package包名称以及导入依赖的类
package com.example.saga.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 SagaEntitySpec extends WordSpec with Matchers with BeforeAndAfterAll {
private val system = ActorSystem("SagalagomEntitySpec",
JsonSerializerRegistry.actorSystemSetupFor(SagaSerializerRegistry))
override protected def afterAll(): Unit = {
TestKit.shutdownActorSystem(system)
}
private def withTestDriver(block: PersistentEntityTestDriver[SagaCommand[_], SagaEvent, SagaState] => Unit): Unit = {
val driver = new PersistentEntityTestDriver(system, new SagaEntity, "saga-lagom-1")
block(driver)
driver.getAllIssues should have size 0
}
"saga-lagom entity" should {
"get result" in withTestDriver { driver =>
val outcome = driver.run(GetResult("1"))
outcome.replies should contain only "x"
}
"begin saga, get saga id" in withTestDriver { driver =>
val outcome1 = driver.run(Begin("2"))
outcome1.events should contain only SagaBegun("2")
}
}
}
开发者ID:dsugden,项目名称:saga-lagom,代码行数:38,代码来源:SagaEntitySpec.scala
示例20: HelloEntitySpec
//设置package包名称以及导入依赖的类
package com.example.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"))
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"))
outcome2.replies should contain only "Hi, Alice!"
}
}
}
开发者ID:namelos,项目名称:lagom-spike,代码行数:40,代码来源:HelloEntitySpec.scala
注:本文中的com.lightbend.lagom.scaladsl.testkit.PersistentEntityTestDriver类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论