本文整理汇总了Scala中org.scalatest.FlatSpecLike类的典型用法代码示例。如果您正苦于以下问题:Scala FlatSpecLike类的具体用法?Scala FlatSpecLike怎么用?Scala FlatSpecLike使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FlatSpecLike类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: S3ClientSpec
//设置package包名称以及导入依赖的类
package akka.stream.alpakka.s3.scaladsl
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import com.typesafe.config.ConfigFactory
import org.scalatest.{FlatSpecLike, Matchers}
import akka.stream.alpakka.s3.Proxy
import scala.collection.JavaConverters._
class S3ClientSpec extends FlatSpecLike with Matchers {
it should "reuse application config from actor system" in {
val config = ConfigFactory.parseMap(
Map(
"akka.stream.alpakka.s3.proxy.host" -> "localhost",
"akka.stream.alpakka.s3.proxy.port" -> 8001,
"akka.stream.alpakka.s3.proxy.secure" -> false,
"akka.stream.alpakka.s3.path-style-access" -> true
).asJava
)
implicit val system = ActorSystem.create("s3", config)
implicit val materializer = ActorMaterializer()
val client = S3Client()
client.s3Settings.proxy shouldBe Some(Proxy("localhost", 8001, "http"))
client.s3Settings.pathStyleAccess shouldBe true
}
}
示例2: MemoryBufferSpec
//设置package包名称以及导入依赖的类
package akka.stream.alpakka.s3.impl
import akka.actor.ActorSystem
import akka.stream.{ActorMaterializer, ActorMaterializerSettings}
import akka.stream.scaladsl.{Sink, Source}
import akka.testkit.TestKit
import akka.util.ByteString
import org.scalatest.time.{Millis, Seconds, Span}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
import org.scalatest.concurrent.ScalaFutures
class MemoryBufferSpec(_system: ActorSystem)
extends TestKit(_system)
with FlatSpecLike
with Matchers
with BeforeAndAfterAll
with ScalaFutures {
def this() = this(ActorSystem("MemoryBufferSpec"))
implicit val defaultPatience =
PatienceConfig(timeout = Span(5, Seconds), interval = Span(30, Millis))
implicit val materializer = ActorMaterializer(ActorMaterializerSettings(system).withDebugLogging(true))
"MemoryBuffer" should "emit a chunk on its output containg the concatenation of all input values" in {
val result = Source(Vector(ByteString(1, 2, 3, 4, 5), ByteString(6, 7, 8, 9, 10, 11, 12), ByteString(13, 14)))
.via(new MemoryBuffer(200))
.runWith(Sink.seq)
.futureValue
result should have size (1)
val chunk = result.head
chunk.size should be(14)
chunk.data.runWith(Sink.seq).futureValue should be(Seq(ByteString(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)))
}
it should "fail if more than maxSize bytes are fed into it" in {
whenReady(
Source(Vector(ByteString(1, 2, 3, 4, 5), ByteString(6, 7, 8, 9, 10, 11, 12), ByteString(13, 14)))
.via(new MemoryBuffer(10))
.runWith(Sink.seq)
.failed
) { e =>
e shouldBe a[IllegalStateException]
}
}
}
示例3: SplitAfterSizeSpec
//设置package包名称以及导入依赖的类
package akka.stream.alpakka.s3.impl
import akka.testkit.TestKit
import akka.stream.ActorMaterializerSettings
import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.ScalaFutures
import akka.stream.ActorMaterializer
import akka.actor.ActorSystem
import org.scalatest.Matchers
import org.scalatest.FlatSpecLike
import akka.stream.scaladsl.Source
import akka.stream.scaladsl.Flow
import akka.util.ByteString
import akka.stream.scaladsl.Sink
import org.scalatest.time.{Millis, Seconds, Span}
import scala.concurrent.duration._
class SplitAfterSizeSpec(_system: ActorSystem)
extends TestKit(_system)
with FlatSpecLike
with Matchers
with BeforeAndAfterAll
with ScalaFutures {
def this() = this(ActorSystem("SplitAfterSizeSpec"))
implicit val defaultPatience =
PatienceConfig(timeout = Span(5, Seconds), interval = Span(30, Millis))
implicit val materializer = ActorMaterializer(ActorMaterializerSettings(system).withDebugLogging(true))
"SplitAfterSize" should "yield a single empty substream on no input" in {
Source
.empty[ByteString]
.via(
SplitAfterSize(10)(Flow[ByteString]).concatSubstreams
)
.runWith(Sink.seq)
.futureValue should be(Seq.empty)
}
it should "start a new stream after the element that makes it reach a maximum, but not split the element itself" in {
Source(Vector(ByteString(1, 2, 3, 4, 5), ByteString(6, 7, 8, 9, 10, 11, 12), ByteString(13, 14)))
.via(
SplitAfterSize(10)(Flow[ByteString]).prefixAndTail(10).map { case (prefix, tail) => prefix }.concatSubstreams
)
.runWith(Sink.seq)
.futureValue should be(
Seq(
Seq(ByteString(1, 2, 3, 4, 5), ByteString(6, 7, 8, 9, 10, 11, 12)),
Seq(ByteString(13, 14))
)
)
}
}
示例4: 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)
}
}
示例5: ReaperUTest
//设置package包名称以及导入依赖的类
package com.example.util
import akka.actor.{ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestKit, TestProbe}
import com.example.StopSystemAfterAll
import org.scalatest.{FlatSpecLike, ShouldMatchers}
class ReaperUTest
extends TestKit(ActorSystem("testsystem"))
with FlatSpecLike
with ShouldMatchers
with StopSystemAfterAll
with ImplicitSender {
import Reaper._
override def afterAll(): Unit = {
system.shutdown()
super.afterAll()
}
trait ReaperFixture {
val reaper = system.actorOf(Props(new TestReaper(testActor)))
val actor1 = TestProbe()
val actor2 = TestProbe()
val actor3 = TestProbe()
val actor4 = TestProbe()
}
"The Reaper" should "call the allSoulsReaped method after all watched actors are dead" in new ReaperFixture {
reaper ! WatchMe(actor3.ref)
reaper ! WatchMe(actor1.ref)
system.stop(actor1.ref)
system.stop(actor3.ref)
expectMsg("Dead")
}
it should "fail to call the allSoulsReaped method if not all watched actors are dead" in new ReaperFixture {
reaper ! WatchMe(actor3.ref)
reaper ! WatchMe(actor1.ref)
system.stop(actor1.ref)
expectNoMsg()
}
}
示例6: JsonParsingSpec
//设置package包名称以及导入依赖的类
import com.fasterxml.jackson.core.JsonParseException
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
import play.api.libs.json._
class JsonParsingSpec
extends Matchers
with FlatSpecLike
with BeforeAndAfterAll {
"A json parser" should "be able to parse valid json" in {
val input = """{
"foo": "bar",
"tags": [1,2,3],
"nested": [{
"fooz": "baz",
"id": 1
}]
}"""
val baz: JsValue = Json.parse(input)
}
it should "choke on invalid json" in {
val input = """{
"foo": "bar",
"tags": [1,2,3],
"nested": [{
"fooz": unquoted text,
"id": 1
}]
}"""
intercept[JsonParseException] {
val baz: JsValue = Json.parse(input)
}
}
}
示例7: HelloAkkaSpec
//设置package包名称以及导入依赖的类
import org.scalatest.{ BeforeAndAfterAll, FlatSpecLike, Matchers }
import akka.actor.{ Actor, Props, ActorSystem }
import akka.testkit.{ ImplicitSender, TestKit, TestActorRef }
import scala.concurrent.duration._
class HelloAkkaSpec(_system: ActorSystem)
extends TestKit(_system)
with ImplicitSender
with Matchers
with FlatSpecLike
with BeforeAndAfterAll {
def this() = this(ActorSystem("HelloAkkaSpec"))
override def afterAll: Unit = {
system.shutdown()
system.awaitTermination(10.seconds)
}
"An HelloAkkaActor" should "be able to set a new greeting" in {
val greeter = TestActorRef(Props[Greeter])
greeter ! WhoToGreet("testkit")
greeter.underlyingActor.asInstanceOf[Greeter].greeting should be("hello, testkit")
}
it should "be able to get a new greeting" in {
val greeter = system.actorOf(Props[Greeter], "greeter")
greeter ! WhoToGreet("testkit")
greeter ! Greet
expectMsgType[Greeting].message.toString should be("hello, testkit")
}
}
示例8: 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
}
}
}
示例9: 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")
}
示例10: StringCounterSpec
//设置package包名称以及导入依赖的类
package com.taintech.common.actor
import akka.actor.{ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestKit, TestProbe}
import StringCounter.{GetTopStrings, StringCount}
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, MustMatchers}
class StringCounterSpec extends TestKit(ActorSystem("test-system"))
with FlatSpecLike
with ImplicitSender
with BeforeAndAfterAll
with MustMatchers {
override def afterAll {
TestKit.shutdownActorSystem(system)
}
"Counter Actor" should "handle GetTopString message with using TestProbe" in {
val sender = TestProbe()
val counter = system.actorOf(Props[StringCounter])
sender.send(counter, "a")
sender.send(counter, "c")
sender.send(counter, "c")
sender.send(counter, "b")
sender.send(counter, "b")
sender.send(counter, "c")
sender.send(counter, GetTopStrings(2))
val state = sender.expectMsgType[List[StringCount]]
state must equal(List(StringCount("c", 3), StringCount("b", 2)))
}
}
示例11: BaseAppSuite
//设置package包名称以及导入依赖的类
package im.actor.server
import java.time.Instant
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{ Seconds, Span }
import org.scalatest.{ FlatSpecLike, Inside, Matchers }
import scala.concurrent.ExecutionContext
import im.actor.server.db.DbExtension
import im.actor.server.migrations.v2.{ MigrationNameList, MigrationTsActions }
abstract class BaseAppSuite(_system: ActorSystem = {
ActorSpecification.createSystem()
})
extends ActorSuite(_system)
with FlatSpecLike
with ScalaFutures
with MessagingSpecHelpers
with Matchers
with Inside
with ServiceSpecMatchers
with ServiceSpecHelpers
with ActorSerializerPrepare {
protected implicit val materializer: ActorMaterializer = ActorMaterializer()
implicit lazy val ec: ExecutionContext = _system.dispatcher
protected implicit lazy val (db, conn) = {
DbExtension(_system).clean()
DbExtension(_system).migrate()
val ext = DbExtension(_system)
(ext.db, ext.connector)
}
system.log.debug("Writing migration timestamps")
MigrationTsActions.insertTimestamp(
MigrationNameList.MultiSequence,
Instant.now.toEpochMilli
)(conn)
MigrationTsActions.insertTimestamp(
MigrationNameList.GroupsV2,
Instant.now.toEpochMilli
)(conn)
override implicit def patienceConfig: PatienceConfig =
new PatienceConfig(timeout = Span(15, Seconds))
override protected def beforeAll(): Unit = {
super.beforeAll()
db
}
}
示例12: Parser
//设置package包名称以及导入依赖的类
package im.actor.util
import im.actor.server.api.rpc.service.messaging.CommandParser
import org.scalatest.{ Matchers, FlatSpecLike }
object Parser extends CommandParser
class CommandParserSpec extends FlatSpecLike with Matchers {
"Command parser" should "split command and text" in e1()
import Parser._
def e1() = {
parseCommand("/task kill") shouldEqual Some("task" ? Some("kill"))
parseCommand(" /task kill") shouldEqual Some("task" ? Some("kill"))
parseCommand(" /task kill all humans ") shouldEqual Some("task" ? Some("kill all humans"))
parseCommand("/task_fatal kill") shouldEqual Some("task_fatal" ? Some("kill"))
parseCommand("/task-fatal kill") shouldEqual Some("task-fatal" ? Some("kill"))
parseCommand("/sleep all day") shouldEqual Some("sleep" ? Some("all day"))
parseCommand("/task") shouldEqual Some("task" ? None)
parseCommand("/task: kill") shouldEqual None
parseCommand("this is not a /task") shouldEqual None
parseCommand("http://example.com") shouldEqual None
parseCommand("/home/rockjam/projectds") shouldEqual None
parseCommand(" / task kill") shouldEqual None
parseCommand(" task kill") shouldEqual None
parseCommand("Some text") shouldEqual None
parseCommand("#Some other text") shouldEqual None
parseCommand("\\Some text again") shouldEqual None
}
}
示例13: StringUtilsSpec
//设置package包名称以及导入依赖的类
package im.actor.util
import im.actor.util.misc.StringUtils.{ transliterate, validGlobalName }
import org.scalatest.{ Matchers, FlatSpecLike }
class StringUtilsSpec extends FlatSpecLike with Matchers {
"validNickName" should "validate nicknames" in nicknames
"transliterate" should "transform string to lower-cased string with only latin chars" in translit
def nicknames() = {
validGlobalName("rockjam") shouldEqual true
validGlobalName("abcde") shouldEqual true
validGlobalName("rock_jam") shouldEqual true
validGlobalName("r0ck_jaM___") shouldEqual true
//too long
val tooLong = 0 to 35 map (e ? ".") mkString ""
validGlobalName(tooLong) shouldEqual false
//too short
validGlobalName("roc") shouldEqual false
//wrong symbols
validGlobalName("rock-jam") shouldEqual false
validGlobalName("rock&^^jam") shouldEqual false
}
def translit() = {
transliterate("actor") shouldEqual "actor"
transliterate("?????") shouldEqual "akter"
transliterate("?????") shouldEqual "akter"
transliterate("??") shouldEqual "pai you"
transliterate("näyttelijä") shouldEqual "nayttelija"
transliterate("??") shouldEqual "yan yuan"
transliterate("??????") shouldEqual "almmthl"
transliterate("actor ????? ?? näyttelijä ?? ??????") shouldEqual "actor akter pai you nayttelija yan yuan almmthl"
}
}
示例14: ReviewerActorSpec
//设置package包名称以及导入依赖的类
package io.github.jlprat.akka.http.workshop.bookstore.actor
import akka.actor.ActorSystem
import akka.testkit.{ImplicitSender, TestKit}
import io.github.jlprat.akka.http.workshop.bookstore.model.{Author, Book, Review}
import Review._
import io.github.jlprat.akka.http.workshop.bookstore.actor.ReviewerActor._
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
class ReviewerActorSpec extends TestKit(ActorSystem("ReviewerActorSpec"))
with ImplicitSender with FlatSpecLike with Matchers with BeforeAndAfterAll {
override def afterAll {
TestKit.shutdownActorSystem(system)
}
"ReviewerActor" should "accept new reviews" in {
val reviewerActor = system.actorOf(ReviewerActor.props)
val book = Book("1234567", "The art of Doe", 321, Author("Jane Doe"))
val review = Review(author = Author("John Doe"), comment = "I liked it", stars = `*****`)
reviewerActor ! AddReview(review, book)
expectMsg(Success)
}
it should "return the reviews for a given book" in {
val reviewerActor = system.actorOf(ReviewerActor.props)
val book = Book("1234567", "The art of Doe", 321, Author("Jane Doe"))
val review = Review(author = Author("John Doe"), comment = "I liked it", stars = `*****`)
reviewerActor ! AddReview(review, book)
expectMsg(Success)
reviewerActor ! ListReviews(book)
expectMsg(Reviews(Seq(review)))
}
it should "return empty reviews if the book has none" in {
val reviewerActor = system.actorOf(ReviewerActor.props)
val book = Book("1234567", "The art of Doe", 321, Author("Jane Doe"))
reviewerActor ! ListReviews(book)
expectMsg(Reviews(Seq.empty))
}
it should "accept and return more than one review per book" in {
val reviewerActor = system.actorOf(ReviewerActor.props)
val book = Book("1234567", "The art of Doe", 321, Author("Jane Doe"))
val review1 = Review(author = Author("John Doe"), comment = "I liked it", stars = `*****`)
val review2 = Review(author = Author("Alice"), comment = "I liked it not", stars = `*`)
reviewerActor ! AddReview(review1, book)
expectMsg(Success)
reviewerActor ! AddReview(review2, book)
expectMsg(Success)
reviewerActor ! ListReviews(book)
expectMsg(Reviews(Seq(review2, review1)))
}
}
示例15: LongActorRefPublisherSpec
//设置package包名称以及导入依赖的类
package com.example
import akka.actor.ActorSystem
import akka.stream.{ActorMaterializer, ActorMaterializerSettings, Supervision}
import akka.testkit.TestKit
import org.scalatest.{BeforeAndAfterAll, FlatSpecLike, Matchers}
class LongActorRefPublisherSpec extends TestKit(ActorSystem("test-system")) with FlatSpecLike with Matchers with BeforeAndAfterAll {
override def afterAll(): Unit = {
super.afterAll()
TestKit.shutdownActorSystem(system)
}
val decider: Supervision.Decider = {
case e => {
println(s"Stopping Stream.. ${e.getMessage}")
Supervision.Stop
}
}
implicit val materializer = ActorMaterializer.create(ActorMaterializerSettings.create(system)
.withDebugLogging(true)
.withSupervisionStrategy(decider)
.withAutoFusing(true), system)
"Advert ID Actor" should "work" in {
}
}