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

Scala TestKit类代码示例

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

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



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

示例1: AbstractActorSpec

//设置package包名称以及导入依赖的类
package name.mikulskibartosz.demo.akka.actors

import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, DefaultTimeout, TestKit}
import name.mikulskibartosz.demo.akka.service.Service
import org.mockito.Mockito._
import org.scalatest.mock.MockitoSugar
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

import scala.util.Try


abstract class AbstractActorSpec extends TestKit(ActorSystem()) with DefaultTimeout with ImplicitSender
with WordSpecLike with Matchers with BeforeAndAfterAll with MockitoSugar {
  override def afterAll() = {
    super.afterAll()
    shutdown()
  }

  def createServiceReturning(value: Try[Int]) = {
    val service = mock[Service]
    when(service.generate()).thenReturn(value)
    service
  }
} 
开发者ID:mikulskibartosz,项目名称:demoAkkaAccessingUnreliableService,代码行数:26,代码来源:AbstractActorSpec.scala


示例2: NodeTest

//设置package包名称以及导入依赖的类
package communication

import java.io.File

import akka.actor.{ActorRef, ActorSystem}
import akka.testkit.{ImplicitSender, TestKit}
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}
import index.{DirectoryIndex, FileIndex}


class NodeTest() extends TestKit(ActorSystem("NodeTest")) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {

  implicit val homeDirPath = "/home/mike/Programming/scala/Cloudia"


  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }

  "Node" must {
    "send back directory index if pinged" in {
      val node: ActorRef = system.actorOf(Node.props(homeDirPath))
      node ! Ping()
      expectMsgPF() {
        case DirectoryIndex(_) => ()
      }
    }
  }

  it must {
    "send back file manifest if one was requested" in {
      val node: ActorRef = system.actorOf(Node.props(homeDirPath))
      val fileIndex = new FileIndex(new File("src/test/resources/chunkifierTest"))
      node ! Request(fileIndex)
      expectMsgPF() {
        case FileManifest(_, _) => ()
      }
    }
  }
} 
开发者ID:mprzewie,项目名称:cloudia-utils,代码行数:42,代码来源:NodeTest.scala


示例3: PersistenceSerializerDocSpec

//设置package包名称以及导入依赖的类
package docs.persistence

import com.typesafe.config._
import scala.concurrent.duration._
import org.scalatest.WordSpec
import akka.actor.ActorSystem
import akka.serialization.{ Serializer, SerializationExtension }
import akka.testkit.TestKit

class PersistenceSerializerDocSpec extends WordSpec {

  val customSerializerConfig =
    """
      //#custom-serializer-config
      akka.actor {
        serializers {
          my-payload = "docs.persistence.MyPayloadSerializer"
          my-snapshot = "docs.persistence.MySnapshotSerializer"
        }
        serialization-bindings {
          "docs.persistence.MyPayload" = my-payload
          "docs.persistence.MySnapshot" = my-snapshot
        }
      }
      //#custom-serializer-config
    """.stripMargin

  val system = ActorSystem("PersistenceSerializerDocSpec", ConfigFactory.parseString(customSerializerConfig))
  try {
    SerializationExtension(system)
  } finally {
    TestKit.shutdownActorSystem(system, 10.seconds, false)
  }
}

class MyPayload
class MySnapshot

class MyPayloadSerializer extends Serializer {
  def identifier: Int = 77124
  def includeManifest: Boolean = false
  def toBinary(o: AnyRef): Array[Byte] = ???
  def fromBinary(bytes: Array[Byte], manifest: Option[Class[_]]): AnyRef = ???
}

class MySnapshotSerializer extends Serializer {
  def identifier: Int = 77125
  def includeManifest: Boolean = false
  def toBinary(o: AnyRef): Array[Byte] = ???
  def fromBinary(bytes: Array[Byte], manifest: Option[Class[_]]): AnyRef = ???
} 
开发者ID:love1314sea,项目名称:akka-2.3.16,代码行数:52,代码来源:PersistenceSerializerDocSpec.scala


示例4: CamelConfigSpec

//设置package包名称以及导入依赖的类
package akka.camel
import org.scalatest.Matchers
import org.scalatest.WordSpec
import akka.actor.ActorSystem
import scala.concurrent.duration.Duration
import java.util.concurrent.TimeUnit._
import akka.testkit.TestKit
import akka.util.Helpers.ConfigOps

class CamelConfigSpec extends WordSpec with Matchers {

  val (settings, config) = {
    val system = ActorSystem("CamelConfigSpec")
    val result = (CamelExtension(system).settings, system.settings.config)
    TestKit.shutdownActorSystem(system)
    result
  }
  "CamelConfigSpec" must {
    "have correct activationTimeout config" in {
      settings.ActivationTimeout should be(config.getMillisDuration("akka.camel.consumer.activation-timeout"))
    }

    "have correct autoAck config" in {
      settings.AutoAck should be(config.getBoolean("akka.camel.consumer.auto-ack"))
    }

    "have correct replyTimeout config" in {
      settings.ReplyTimeout should be(config.getMillisDuration("akka.camel.consumer.reply-timeout"))
    }

    "have correct streamingCache config" in {
      settings.StreamingCache should be(config.getBoolean("akka.camel.streamingCache"))
    }

    "have correct jmxStatistics config" in {
      settings.JmxStatistics should be(config.getBoolean("akka.camel.jmx"))
    }

    "have correct body conversions config" in {
      val conversions = config.getConfig("akka.camel.conversions")

      conversions.getString("file") should be("java.io.InputStream")
      conversions.entrySet.size should be(1)
    }

    "have correct Context Provider" in {
      settings.ContextProvider.isInstanceOf[DefaultContextProvider] should be(true)
    }
  }
} 
开发者ID:love1314sea,项目名称:akka-2.3.16,代码行数:51,代码来源:CamelConfigSpec.scala


示例5: AConfigTestSuite

//设置package包名称以及导入依赖的类
package service.a.app

import org.scalatest.SpecLike

import akka.actor.ActorSystem
import akka.testkit.TestKit

class AConfigTestSuite extends TestKit(ActorSystem()) with SpecLike with AConfig {

  object `A Config` {
    object `when initialized` {
      def `should have attribute "akka.loglevel" set` {
        assert(logLevel.nonEmpty)
      }

      def `should have attribute "akka.loglevel" set to "INFO" per default` {
        assert(logLevel.equals("INFO"))
      }
      
      def `should have attribute "akka.stdout-loglevel" set` {
        assert(stdOutLogLevel.nonEmpty)
      }
      
      def `should have attribute "akka.stdout-loglevel" set to "OFF" per default` {
        assert(stdOutLogLevel.equals("OFF"))
      }
      
      def `should have attribute "akka.log-config-on-start" set` {
        assert(logConfigOnStart.nonEmpty)
      }
      
      def `should have attribute "akka.log-config-on-start" set to "OFF" per default` {
        assert(logConfigOnStart.equals("off"))
      }

      def `should have attribute "akka.interface" set` {
        assert(interface.nonEmpty)
      }
      
      def `should have attribute "http.interface" set to "0.0.0.0" per default` {
        assert(interface.equals("0.0.0.0"))
      }
      
      def `should have attribute "akka.port" set` {
        assert(port.nonEmpty)
      }
      
      def `should have attribute "http.port" set to "11011" per default` {
        assert(port.equals("11011"))
      }
    }
  }

} 
开发者ID:kevinkl,项目名称:scalakka,代码行数:55,代码来源:AConfigTestSuite.scala


示例6: 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


示例7: JmsSpec

//设置package包名称以及导入依赖的类
package akka.stream.alpakka.jms

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.testkit.TestKit
import org.apache.activemq.broker.BrokerService
import org.scalatest._
import org.scalatest.concurrent.ScalaFutures
import akka.testkit.SocketUtil

abstract class JmsSpec
    extends WordSpec
    with Matchers
    with BeforeAndAfterAll
    with BeforeAndAfterEach
    with ScalaFutures {

  implicit val system = ActorSystem(this.getClass.getSimpleName)
  implicit val materializer = ActorMaterializer()

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

  def withServer(network: Boolean = true)(test: Context => Unit): Unit = {
    val broker = new BrokerService()
    val host: String = "localhost"
    val url = if (network) {
      val port = SocketUtil.temporaryServerAddress(host).getPort
      val serverUrl = s"tcp://$host:$port"
      broker.addConnector(serverUrl)
      serverUrl
    } else {
      s"vm://$host"
    }
    broker.setPersistent(false)
    broker.setBrokerName(host)
    broker.setUseJmx(false)
    broker.start()
    try {
      test(Context(url, broker))
    } finally {
      if (broker.isStarted) {
        broker.stop()
      }
    }
  }

  case class Context(url: String, broker: BrokerService)

} 
开发者ID:akka,项目名称:alpakka,代码行数:51,代码来源:JmsSpec.scala


示例8: CsvSpec

//设置package包名称以及导入依赖的类
package akka.stream.alpakka.csv.scaladsl

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.testkit.TestKit
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, Matchers, WordSpec}

abstract class CsvSpec
    extends WordSpec
    with Matchers
    with BeforeAndAfterAll
    with BeforeAndAfterEach
    with ScalaFutures {

  implicit val system = ActorSystem(this.getClass.getSimpleName)
  implicit val materializer = ActorMaterializer()

  override protected def afterAll(): Unit =
    TestKit.shutdownActorSystem(system)
} 
开发者ID:akka,项目名称:alpakka,代码行数:22,代码来源:CsvSpec.scala


示例9: TableSpec

//设置package包名称以及导入依赖的类
package akka.stream.alpakka.dynamodb

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.stream.alpakka.dynamodb.impl.DynamoSettings
import akka.stream.alpakka.dynamodb.scaladsl.DynamoClient
import akka.testkit.TestKit
import org.scalatest.{AsyncWordSpecLike, BeforeAndAfterAll, Matchers}

import scala.collection.JavaConverters._

class TableSpec extends TestKit(ActorSystem("TableSpec")) with AsyncWordSpecLike with Matchers with BeforeAndAfterAll {

  implicit val materializer = ActorMaterializer()
  implicit val ec = system.dispatcher

  val settings = DynamoSettings(system)
  val client = DynamoClient(settings)

  override def beforeAll() = {
    System.setProperty("aws.accessKeyId", "someKeyId")
    System.setProperty("aws.secretKey", "someSecretKey")
  }

  "DynamoDB Client" should {

    import TableSpecOps._
    import akka.stream.alpakka.dynamodb.scaladsl.DynamoImplicits._

    "1) create table" in {
      client.single(createTableRequest).map(_.getTableDescription.getTableName shouldEqual tableName)
    }

    "2) list tables" in {
      client.single(listTablesRequest).map(_.getTableNames.asScala.count(_ == tableName) shouldEqual 1)
    }

    "3) describe table" in {
      client.single(describeTableRequest).map(_.getTable.getTableName shouldEqual tableName)
    }

    "4) update table" in {
      client
        .single(describeTableRequest)
        .map(_.getTable.getProvisionedThroughput.getWriteCapacityUnits shouldEqual 10L)
        .flatMap(_ => client.single(updateTableRequest))
        .map(_.getTableDescription.getProvisionedThroughput.getWriteCapacityUnits shouldEqual newMaxLimit)
    }

    "5) delete table" in {
      client
        .single(deleteTableRequest)
        .flatMap(_ => client.single(listTablesRequest))
        .map(_.getTableNames.asScala.count(_ == tableName) shouldEqual 0)
    }

  }

} 
开发者ID:akka,项目名称:alpakka,代码行数:60,代码来源:TableSpec.scala


示例10: AbstractSpec

//设置package包名称以及导入依赖的类
package core

import actors.Receptionist
import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestKit}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, MustMatchers}

class AbstractSpec extends TestKit(ActorSystem("test-system"))
  with FlatSpecLike
  with ImplicitSender
  with BeforeAndAfterAll
  with MustMatchers {

  val receptionist = system.actorOf(Receptionist.props(), "receptionist")


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

} 
开发者ID:Sengab-platform,项目名称:backend,代码行数:22,代码来源:AbstractSpec.scala


示例11: InboundFSConnectionSpec

//设置package包名称以及导入依赖的类
import akka.actor.ActorSystem
import akka.testkit.TestKit
import esl.InboundFSConnection

class InboundFSConnectionSpec extends TestKit(ActorSystem("outbound-connection"))
  with EslTestKit {

  "connect function" should {
    "enqueue Auth command" in {
      val inbound = new InboundFSConnection()
      whenReady(inbound.connect("ClueCon")) {
        commandResponse =>
          commandResponse.command.toString shouldBe "auth ClueCon\n\n"
      }
    }
  }

} 
开发者ID:CallHandling,项目名称:freeswitch-scala-esl,代码行数:19,代码来源:InboundFSConnectionSpec.scala


示例12: BankAccountSpec

//设置package包名称以及导入依赖的类
package akka

import BankAccount.BankAccount
import akka.actor.{ActorRef, ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestKit}
import org.scalatest._

class BankAccountSpec(_system: ActorSystem) extends TestKit(_system)
  with FlatSpecLike
  with ImplicitSender
  with Matchers
  with BeforeAndAfterAll {

  def this() = this(ActorSystem("BankAccountSpec"))

  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }

  it should "has 0 balance by default" in {
    val bankAccount = system.actorOf(Props[BankAccount])
    bankAccount ! BankAccount.GetBalance
    expectMsg(BankAccount.Balance(0))
  }

  it should "has deposit amount as balance" in {
    val bankAccount = system.actorOf(Props[BankAccount])
    deposit(bankAccount, 10)
    bankAccount ! BankAccount.GetBalance
    expectMsg(BankAccount.Balance(10))
  }

  it should "has reduced balance after withdraw in case of sufficient funds" in {
    val bankAccount = system.actorOf(Props[BankAccount])
    deposit(bankAccount, 10)
    bankAccount ! BankAccount.Withdraw(5)
    expectMsg(BankAccount.Done)
    bankAccount ! BankAccount.GetBalance
    expectMsg(BankAccount.Balance(5))
  }

  it should "should fail withdraw in case of insufficient funds" in {
    val bankAccount = system.actorOf(Props[BankAccount])
    bankAccount ! BankAccount.Withdraw(5)
    expectMsg(BankAccount.Failed)
  }


  def deposit(bankAccount: ActorRef, amount: Int) = {
    bankAccount ! BankAccount.Deposit(amount)
    expectMsg(BankAccount.Done)
  }


} 
开发者ID:zsomboracs,项目名称:akka-bankaccount,代码行数:56,代码来源:BankAccountSpec.scala


示例13: SettingsSpec

//设置package包名称以及导入依赖的类
package com.github.btesila.weather.monitor

import akka.actor.ActorSystem
import akka.testkit.TestKit
import org.scalatest.{Matchers, WordSpecLike}

class SettingsSpec extends TestKit(ActorSystem()) with WordSpecLike with Matchers {
  "The `Settings` extension" should {
    "provide the appropriate Accuweather settings" in {
      val settings = Settings(system).Accuweather
      settings.ApiKey shouldBe "WTUr8dnrpCGYNnwDMDyv42qU9bxsAxjv"
      settings.LocationUri shouldBe "https://dataservice.accuweather.com/locations/v1/search"
      settings.CurrentConditionUri shouldBe "https://dataservice.accuweather.com/currentconditions/v1"
      settings.DailyForecastUri shouldBe "https://dataservice.accuweather.com/forecasts/v1/daily/1day"
      settings.ExtendedForecastUri shouldBe "https://dataservice.accuweather.com/forecasts/v1/daily/5day"
    }
    "provide the appropriate Http settings" in {
      val settings = Settings(system).WeatherMonitor.Acceptor
      settings.Host shouldBe "localhost"
      settings.Port shouldBe 8140
    }
  }
} 
开发者ID:Bii03,项目名称:weather-monitor,代码行数:24,代码来源:SettingsSpec.scala


示例14: 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


示例15: PingPongActorUTest

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

import akka.actor.{Props, ActorSystem}
import akka.testkit.{ImplicitSender, TestKit}
import com.example.util.ReaperImpl
import org.scalatest.{FlatSpecLike, BeforeAndAfterAll, Matchers, WordSpecLike}
 
class PingPongActorUTest(_system: ActorSystem)
  extends TestKit(_system)
  with ImplicitSender
  with FlatSpecLike
  with Matchers
  with BeforeAndAfterAll {
 
  def this() = this(ActorSystem("MySpec"))
 
  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }

  val reaper = system.actorOf(Props[ReaperImpl], "reaper")
  val pongActor = system.actorOf(Props(classOf[PongActor], reaper), "pongActor")
  val pingActor = system.actorOf(Props(classOf[PingActor], reaper, pongActor), "pingActor")

  "A Ping actor" should "send back a ping on a pong" in {
      pingActor ! PongActor.PongMessage("pong")
      expectMsg(PingActor.PingMessage("ping"))
  }

  "A Pong actor" should "send back a pong on a ping" in {
      pongActor ! PingActor.PingMessage("ping")
      expectMsg(PongActor.PongMessage("pong"))
  }

} 
开发者ID:shafiquejamal,项目名称:akka-scala-reaper-seed,代码行数:36,代码来源:PingPongActorUTest.scala


示例16: UnhandledMessageWatcherSpec

//设置package包名称以及导入依赖的类
package com.tpalanga.newsletter.utils

import akka.actor.{Actor, ActorSystem, Props}
import akka.event.Logging.LogEvent
import akka.testkit.{ImplicitSender, TestKit, TestProbe}
import com.tpalanga.newsletter.util.UnhandledMessageWatcher
import org.scalatest.{FlatSpecLike, Matchers}

object UnhandledMessageWatcherSpec {

  abstract class Test(implicit system: ActorSystem) {
    val watcher = system.actorOf(UnhandledMessageWatcher.props())
    val logProbe = TestProbe()
    system.eventStream.subscribe(logProbe.ref, classOf[LogEvent])

    val destination = system.actorOf(Props(new Actor {
      override def receive: Receive = {
        case 'Handled =>
      }
    }))

  }
}

class UnhandledMessageWatcherSpec extends TestKit(ActorSystem("UnhandledMessageWatcherSpec")) with FlatSpecLike with Matchers with ImplicitSender {
  import UnhandledMessageWatcherSpec._

  "UnhandledMessageWatcher" should "log unhandled messages" in new Test {
    destination ! 'Unhandled

    val event = logProbe.fishForMessage() {
      case akka.event.Logging.Error(_, _, _, msg) if msg.toString startsWith "UnhandledMessage:" =>
        true
      case _ =>
        false
    }
  }

  it should "log DeadLetters" in new Test {
    system.stop(destination)
    Thread.sleep(100)
    destination ! 'Handled

    val event = logProbe.fishForMessage() {
      case akka.event.Logging.Warning(_, _, msg) if msg.toString startsWith "DeadLetter:" =>
        true
      case _ =>
        false
    }
  }
} 
开发者ID:tpalanga,项目名称:akka-http-microservice,代码行数:52,代码来源:UnhandledMessageWatcherSpec.scala


示例17: 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


示例18: AmazonFineFoodManagerSpec

//设置package包名称以及导入依赖的类
package com.taintech.aff.actor

import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestKit}
import com.taintech.aff.actor.AmazonFineFoodManager.{Review, ReviewParser}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, MustMatchers}


class AmazonFineFoodManagerSpec  extends TestKit(ActorSystem("test-system"))
  with FlatSpecLike
  with ImplicitSender
  with BeforeAndAfterAll
  with MustMatchers {

  import AmazonFineFoodManagerSpec._

  "ReviewParser" should "parse test line with values test" in {
    val rp = new ReviewParser()
    rp.parse(testLine) must equal(Review("test3", "test2", "test10"))
  }

  
}

object AmazonFineFoodManagerSpec {
  val testLine = "test1,test2,test3,test4,test5,test6,test7,test8,test9,test10"
  val mockReview: String => Review = _ => Review("test user", "test product", "test text")
} 
开发者ID:taintech,项目名称:AmazonFineFoods,代码行数:29,代码来源:AmazonFineFoodManagerSpec.scala


示例19: UserRepositorySpec

//设置package包名称以及导入依赖的类
package org.cristal.repository

import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestKit}
import akka.util.Timeout
import com.github.t3hnar.bcrypt._
import org.cristal.model.{NewUser, User}
import org.cristal.repository.UserRepository.UserCreated
import org.cristal.repository.dao.UserDAO
import org.mockito.ArgumentMatchers._
import org.mockito.Mockito.when
import org.scalatest.concurrent.Eventually
import org.scalatest.mockito.MockitoSugar
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}
import scala.concurrent.Future
import scala.concurrent.duration._

class UserRepositorySpec(_system: ActorSystem) extends TestKit(_system) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll with Eventually with MockitoSugar {
  implicit val duration: Timeout = 10 seconds
  def this() = this(ActorSystem("UserRepositorySpecSystem"))

  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }

  "An UserRepository Actor" should {
    "Create a new user" in {
      val userDAO = mock[UserDAO]
      val passowod = "my_password"
      val encryptedPassword = passowod.bcrypt
      when(userDAO.insert(any())).thenReturn(Future.successful(()))
      val userRepository = system.actorOf(UserRepository.props(userDAO))
      val newUser = NewUser("name", passowod, "[email protected]", "John", "Doe")
      userRepository ! UserRepository.CreateUser(newUser, self)
      expectMsgPF() {
        case UserCreated(User("name", encryptedPassword, "[email protected]", "John", "Doe")) => ()
      }
    }
  }

} 
开发者ID:frecano,项目名称:cristal,代码行数:43,代码来源:UserRepositorySpec.scala


示例20: GeneticAlgorithmFSMSpec

//设置package包名称以及导入依赖的类
package com.devdiscoveries.genalg

import akka.actor.{Props, ActorSystem}
import akka.testkit.{ImplicitSender, TestKit}
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}


class GeneticAlgorithmFSMSpec extends TestKit(ActorSystem("GeneticAlgorithmSpec")) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {

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

  "The Genetic Algorithm" must {
    val gaActor = system.actorOf(Props(classOf[GeneticAlgorithmFSM]))
    "should start out in status Idle" in {
      gaActor ! Status
      expectMsg(CurrentStatus(Idle, 0, 0))
    }
    "should transition to Initialized with Initialize message" in {
      gaActor ! Initialize(1,1)
      gaActor ! Status
      expectMsg(CurrentStatus(Initialized, 0, 0))
    }
  }

} 
开发者ID:hugovalk,项目名称:genetic-programming,代码行数:29,代码来源:GeneticAlgorithmFSMSpec.scala



注:本文中的akka.testkit.TestKit类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala Calendar类代码示例发布时间:2022-05-23
下一篇:
Scala ByteString类代码示例发布时间: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