本文整理汇总了Scala中org.scalatest.AsyncWordSpec类的典型用法代码示例。如果您正苦于以下问题:Scala AsyncWordSpec类的具体用法?Scala AsyncWordSpec怎么用?Scala AsyncWordSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AsyncWordSpec类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: TenantEventProcessorSpec
//设置package包名称以及导入依赖的类
package optrak.lagomtest.tenant.impl
import java.util.concurrent.atomic.AtomicInteger
import akka.persistence.query.Sequence
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server.LagomApplication
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import TenantEvents.{TenantCreated, TenantEvent}
import optrak.lagomtest.data.Data.TenantId
import optrak.lagomtest.utils.ReadSideTestDriver
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}
import play.api.libs.ws.ahc.AhcWSComponents
class TenantEventProcessorSpec extends AsyncWordSpec with BeforeAndAfterAll with Matchers {
private val server = ServiceTest.startServer(ServiceTest.defaultSetup.withCassandra(true)) { ctx =>
new LagomApplication(ctx) with TenantComponents with AhcWSComponents {
override def serviceLocator = NoServiceLocator
override lazy val readSide: ReadSideTestDriver = new ReadSideTestDriver
}
}
override def afterAll() = server.stop()
private val testDriver = server.application.readSide
private val tenantRepository = server.application.tenantRepository
private val offset = new AtomicInteger()
"The tenant event processor" should {
"create a tenant" in {
val tenantCreated = TenantCreated("tim", "hello")
for {
_ <- feed(tenantCreated.id, tenantCreated)
tenants <- getTenants
} yield {
tenants should contain only tenantCreated.id
}
}
}
private def getTenants = {
tenantRepository.selectAllTenants
}
private def feed(tenantId: TenantId, event: TenantEvent) = {
testDriver.feed(tenantId.toString, event, Sequence(offset.getAndIncrement))
}
}
开发者ID:TimPigden,项目名称:lagom-multitenant,代码行数:52,代码来源:TenantEventProcessorSpec.scala
示例2: LagomhandsondevelopmentServiceSpec
//设置package包名称以及导入依赖的类
package com.example.lagomhandsondevelopment.impl
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}
import com.example.lagomhandsondevelopment.api._
class LagomhandsondevelopmentServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {
private val server = ServiceTest.startServer(
ServiceTest.defaultSetup
.withCassandra(true)
) { ctx =>
new LagomhandsondevelopmentApplication(ctx) with LocalServiceLocator
}
val client = server.serviceClient.implement[LagomhandsondevelopmentService]
override protected def afterAll() = server.stop()
"lagom-hands-on-development service" should {
"say hello" in {
client.hello("Alice").invoke().map { answer =>
answer should ===("Hello, Alice!")
}
}
"allow responding with a custom message" in {
for {
_ <- client.useGreeting("Bob").invoke(GreetingMessage("Hi"))
answer <- client.hello("Bob").invoke()
} yield {
answer should ===("Hi, Bob!")
}
}
}
}
开发者ID:negokaz,项目名称:lagom-hands-on-development.scala,代码行数:39,代码来源:LagomhandsondevelopmentServiceSpec.scala
示例3: HelloServiceSpec
//设置package包名称以及导入依赖的类
package se.hultner.hello.impl
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}
import se.hultner.hello.api._
class HelloServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {
private val server = ServiceTest.startServer(
ServiceTest.defaultSetup
.withCassandra(true)
) { ctx =>
new HelloApplication(ctx) with LocalServiceLocator
}
val client = server.serviceClient.implement[HelloService]
override protected def afterAll() = server.stop()
"Hello service" should {
"say hello" in {
client.hello("Alice").invoke().map { answer =>
answer should ===("Hello, Alice!")
}
}
"allow responding with a custom message" in {
for {
_ <- client.useGreeting("Bob").invoke(GreetingMessage("Hi"))
answer <- client.hello("Bob").invoke()
} yield {
answer should ===("Hi, Bob!")
}
}
}
}
开发者ID:Hultner,项目名称:hello_scala_microservices,代码行数:39,代码来源:HelloServiceSpec.scala
示例4: GraphSpec
//设置package包名称以及导入依赖的类
package spec
import com.outr.arango.rest.EdgeDefinition
import com.outr.arango.{ArangoDB, ArangoSession}
import org.scalatest.{AsyncWordSpec, Matchers}
import scala.concurrent.Future
class GraphSpec extends AsyncWordSpec with Matchers {
private var session: ArangoSession = _
private var db: ArangoDB = _
"Graphs" should {
"create the session" in {
ArangoSession.default.map { s =>
session = s
db = session.db()
s.token shouldNot be("")
}
}
"list all the graphs" in {
db.graph.list().map { result =>
result.error should be(false)
result.code should be(200)
result.graphs should be(Nil)
}
}
"create a graph" in {
db.graph("test").create(edgeDefinitions = List(
EdgeDefinition("edges", from = List("startVertices"), to = List("endVertices"))
)).map { response =>
response.error should be(false)
}
}
"delete a graph" in {
db.graph("test").delete(dropCollections = true).map { response =>
response.error should be(false)
}
}
"dispose the session" in {
Future {
session.instance.dispose()
session.instance.isDisposed should be(true)
}
}
}
}
开发者ID:outr,项目名称:scarango,代码行数:48,代码来源:GraphSpec.scala
示例5: BasketServiceSpec
//设置package包名称以及导入依赖的类
import akka.{Done, NotUsed}
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import demo.api.basket.{Basket, BasketService, Item}
import demo.impl.basket.{BasketApplication, BasketSerializerRegistry}
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}
import scala.concurrent.Future
class BasketServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {
lazy val service = ServiceTest.startServer(ServiceTest.defaultSetup.withCassandra(true)) { ctx =>
new BasketApplication(ctx) with LocalServiceLocator {
override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
}
}
override protected def beforeAll() = service
override protected def afterAll() = service.stop()
val client = service.serviceClient.implement[BasketService]
"Basket Service" should {
"add a single item and get the basket" in {
client.addItem("basket1").invoke(Item("Apple", 50)).flatMap { response =>
response should ===(NotUsed)
client.getBasket("basket1").invoke().map { getItemsResponse =>
getItemsResponse should ===(Basket(Seq(Item("Apple", 50)), 50))
}
}
}
"get an empty basket" in {
client.getBasket("basket2").invoke().map { getItemsResponse =>
getItemsResponse should ===(Basket(Seq(), 0))
}
}
"add multiple items" in {
val items = "Apple" -> 50 :: "Apple" -> 50 :: "Orange" -> 30 :: Nil
Future.sequence(items.map(i => client.addItem("basket3").invoke(Item(i._1, i._2)))).flatMap{ f =>
client.getBasket("basket3").invoke().flatMap { getItemsResponse =>
getItemsResponse.items should contain(Item("Apple", 50))
getItemsResponse.items should contain(Item("Orange", 30))
getItemsResponse.total should===(130)
client.getTotal("basket3").invoke().map { getItemsResponse =>
getItemsResponse should===(130)
}
}
}
}
}
}
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:56,代码来源:BasketServiceSpec.scala
示例6: BasketServiceSpec
//设置package包名称以及导入依赖的类
import akka.{Done, NotUsed}
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import demo.api.basket.{Basket, BasketService, Item}
import demo.impl.basket.{BasketApplication, BasketSerializerRegistry}
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}
import scala.concurrent.Future
class BasketServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {
lazy val service = ServiceTest.startServer(ServiceTest.defaultSetup.withCassandra(true)) { ctx =>
new BasketApplication(ctx) with LocalServiceLocator {
override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
}
}
override protected def beforeAll() = service
override protected def afterAll() = service.stop()
val client = service.serviceClient.implement[BasketService]
"Basket Service" should {
"add a single item" in {
client.addItem("basket1").invoke(Item("Apple", 50)).flatMap { response =>
response should ===(NotUsed)
client.getBasket("basket1").invoke().map { getItemsResponse =>
getItemsResponse should ===(Basket(Seq(Item("Apple", 50)), 50))
}
}
}
"get an empty basket" in {
client.getBasket("basket2").invoke().map { getItemsResponse =>
getItemsResponse should ===(Basket(Seq(), 0))
}
}
"add multiple items" in {
val items = ("Apple" -> 50 :: "Apple" -> 50 :: "Orange" -> 30 :: Nil).map { t =>
Item(t._1, t._2)
}
items.foldLeft(Future.successful(List[NotUsed]())) { (f, i) =>
f.flatMap(l => client.addItem("basket3").invoke(i).map(n => n :: l))
}.flatMap { f =>
client.getBasket("basket3").invoke().map { getItemsResponse =>
getItemsResponse.items should be(items)
getItemsResponse.total should===(130)
}
}
}
}
}
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:55,代码来源:BasketServiceSpec.scala
示例7: BasketServiceSpec
//设置package包名称以及导入依赖的类
import akka.{Done, NotUsed}
import com.lightbend.lagom.scaladsl.playjson.JsonSerializerRegistry
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import demo.api.basket.{Basket, BasketService, Item}
import demo.impl.basket.{BasketApplication, BasketSerializerRegistry}
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}
import scala.concurrent.Future
class BasketServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {
lazy val service = ServiceTest.startServer(ServiceTest.defaultSetup.withCassandra(true)) { ctx =>
new BasketApplication(ctx) with LocalServiceLocator {
override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
}
}
override protected def beforeAll() = service
override protected def afterAll() = service.stop()
val client = service.serviceClient.implement[BasketService]
"Basket Service" should {
"add a single item" in {
client.addItem("basket1").invoke(Item("Apple", 50)).flatMap { response =>
response should ===(NotUsed)
client.getBasket("basket1").invoke().map { getItemsResponse =>
getItemsResponse should ===(Basket(Seq(Item("Apple", 50)), 50))
}
}
}
"get an empty basket" in {
client.getBasket("basket2").invoke().map { getItemsResponse =>
getItemsResponse should ===(Basket(Seq(), 0))
}
}
"add multiple items" in {
val items = "Apple" -> 50 :: "Apple" -> 50 :: "Orange" -> 30 :: Nil
Future.sequence(items.map(i => client.addItem("basket3").invoke(Item(i._1, i._2)))).flatMap{ f =>
client.getBasket("basket3").invoke().map { getItemsResponse =>
getItemsResponse.items should contain(Item("Apple", 50))
getItemsResponse.items should contain(Item("Orange", 30))
getItemsResponse.total should===(130)
}
}
}
}
}
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:52,代码来源:BasketServiceSpec.scala
示例8: BalanceSpec
//设置package包名称以及导入依赖的类
package spec
import com.outr.stripe.{Money, QueryConfig}
import org.scalatest.{AsyncWordSpec, Matchers}
class BalanceSpec extends AsyncWordSpec with Matchers {
"Balance" should {
"list a test balance" in {
TestStripe.balance().map {
case Left(failure) => fail(s"Receive error response: ${failure.text} (${failure.code})")
case Right(balance) => {
balance.`object` should be("balance")
balance.available.length should be(6)
balance.available.head.currency should be("usd")
balance.available.head.amount should be(Money(206109502.75))
balance.available.head.sourceTypes.card should be(Money(205014418.19))
balance.livemode should be(false)
balance.pending.length should be(6)
balance.pending.last.currency should be("gbp")
}
}
}
"list most recent balance transaction history" in {
TestStripe.balance.list(config = QueryConfig(limit = 1)).map {
case Left(failure) => fail(s"Receive error response: ${failure.text} (${failure.code})")
case Right(list) => {
list.`object` should be("list")
list.url should be("/v1/balance/history")
list.hasMore should be(true)
list.data.length should be(1)
}
}
}
}
}
开发者ID:outr,项目名称:scala-stripe,代码行数:36,代码来源:BalanceSpec.scala
示例9: UserServiceSpec
//设置package包名称以及导入依赖的类
package com.grossbit.user.impl
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}
import com.grossbit.user.api._
class UserServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {
private val server = ServiceTest.startServer(
ServiceTest.defaultSetup
.withCassandra(true)
) { ctx =>
new UserApplication(ctx) with LocalServiceLocator
}
val client = server.serviceClient.implement[UserService]
override protected def afterAll() = server.stop()
"User service" should {
"say hello" in {
client.hello("Alice").invoke().map { answer =>
answer should ===("Hello, Alice!")
}
}
"allow responding with a custom message" in {
for {
_ <- client.useGreeting("Bob").invoke(GreetingMessage("Hi"))
answer <- client.hello("Bob").invoke()
} yield {
answer should ===("Hi, Bob!")
}
}
}
}
开发者ID:sarathraj-coder,项目名称:lagommicroapp,代码行数:39,代码来源:UserServiceSpec.scala
示例10: InstitutionComponentSpec
//设置package包名称以及导入依赖的类
package hmda.query.repository.institutions
import hmda.model.institution.InstitutionGenerators
import hmda.query.DbConfiguration._
import scala.concurrent.duration._
import org.scalatest.{ AsyncWordSpec, BeforeAndAfterAll, MustMatchers }
import scala.concurrent.Await
class InstitutionComponentSpec extends AsyncWordSpec with MustMatchers with InstitutionComponent with BeforeAndAfterAll {
import InstitutionConverter._
val timeout = 5.seconds
val repository = new InstitutionRepository(config)
override def beforeAll(): Unit = {
super.beforeAll()
Await.result(repository.createSchema(), timeout)
}
override def afterAll(): Unit = {
super.afterAll()
Await.result(repository.dropSchema(), timeout)
}
"Institution Repository" must {
"insert new records" in {
val i = InstitutionGenerators.sampleInstitution
repository.insertOrUpdate(i).map(x => x mustBe 1)
}
"modify records and read them back" in {
val i = InstitutionGenerators.sampleInstitution.copy(cra = false)
repository.insertOrUpdate(i).map(x => x mustBe 1)
val modified = i.copy(cra = true)
repository.insertOrUpdate(modified).map(x => x mustBe 1)
repository.findById(i.id).map {
case Some(x) => x.cra mustBe modified.cra
case None => fail
}
}
"delete record" in {
val i = InstitutionGenerators.sampleInstitution
repository.insertOrUpdate(i).map(x => x mustBe 1)
repository.findById(i.id).map {
case Some(x) => succeed
case None => fail
}
repository.deleteById(i.id).map(x => x mustBe 1)
repository.findById(i.id).map {
case Some(x) => fail
case None => succeed
}
}
}
}
开发者ID:cfpb,项目名称:hmda-platform,代码行数:59,代码来源:InstitutionComponentSpec.scala
示例11: SourceUtilsSpec
//设置package包名称以及导入依赖的类
package hmda.util
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.Source
import org.scalatest.{ AsyncWordSpec, BeforeAndAfterAll, MustMatchers }
class SourceUtilsSpec extends AsyncWordSpec with MustMatchers with BeforeAndAfterAll with SourceUtils {
implicit val system = ActorSystem()
implicit val materializer = ActorMaterializer()
implicit val ec = system.dispatcher
val l5 = List(1, 2, 3, 4, 5)
val l4 = List(1, 2, 3, 4)
val l3 = List(1, 2, 3)
"SourceUtils" must {
"count the elements in a Source" in {
val s5 = Source.fromIterator(() => l5.toIterator)
val s4 = Source.fromIterator(() => l4.toIterator)
val s3 = Source.fromIterator(() => l3.toIterator)
count(s5).map(total => total mustBe 5)
count(s4).map(total => total mustBe 4)
count(s3).map(total => total mustBe 3)
}
"sum the elements in a Source" in {
def itself(int: Int) = int
val s5 = Source.fromIterator(() => l5.toIterator)
val s4 = Source.fromIterator(() => l4.toIterator)
val s3 = Source.fromIterator(() => l3.toIterator)
sum(s5, itself).map(total => total mustBe 15)
sum(s4, itself).map(total => total mustBe 10)
sum(s3, itself).map(total => total mustBe 6)
}
}
override def afterAll(): Unit = {
system.terminate()
}
}
开发者ID:cfpb,项目名称:hmda-platform,代码行数:45,代码来源:SourceUtilsSpec.scala
示例12: TsQualityEngineSpec
//设置package包名称以及导入依赖的类
package hmda.validation.engine.ts.quality
import java.io.File
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import hmda.model.fi.ts.TransmittalSheet
import hmda.parser.fi.ts.TsCsvParser
import hmda.validation.context.ValidationContext
import org.scalatest.{ AsyncWordSpec, MustMatchers }
import org.scalatest.prop.PropertyChecks
import scala.concurrent.ExecutionContext
import scala.io.Source
class TsQualityEngineSpec
extends AsyncWordSpec
with PropertyChecks
with MustMatchers
with TsQualityEngine {
implicit val system = ActorSystem("ts-quality-test")
implicit val materializer = ActorMaterializer()
override implicit val ec: ExecutionContext = scala.concurrent.ExecutionContext.Implicits.global
private val ctx = ValidationContext(None, None)
"A Transmittal Sheet" must {
"pass quality checks" in {
val line = Source.fromFile(new File("parser/jvm/src/test/resources/txt/clean_10-lars.txt")).getLines().take(1)
val ts = line.map(l => TsCsvParser(l).right.getOrElse(TransmittalSheet())).toList.head
checkQuality(ts, ctx).isSuccess mustBe true
}
}
}
开发者ID:cfpb,项目名称:hmda-platform,代码行数:36,代码来源:TsQualityEngineSpec.scala
示例13: LarMacroEngineSpec
//设置package包名称以及导入依赖的类
package hmda.validation.engine.lar.`macro`
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.Source
import hmda.validation.context.ValidationContext
import hmda.validation.rules.lar.`macro`.MacroTestData
import org.scalatest.{ AsyncWordSpec, MustMatchers }
import scalaz.{ Failure, Success }
class LarMacroEngineSpec extends AsyncWordSpec with MustMatchers with LarMacroEngine {
implicit val system = ActorSystem("macro-edits-test")
implicit val materializer = ActorMaterializer()
implicit val ec = system.dispatcher
val lars = MacroTestData.lars
val larSource = Source.fromIterator(() => lars.toIterator)
val ctx = ValidationContext(None, None)
"Lar Macro Engine" must {
"pass macro edits" in {
checkMacro(larSource, ctx).map(validation => validation mustBe a[Success[_]])
}
"fail Q007" in {
val larsQ007 = lars.map(lar => lar.copy(actionTakenType = 2))
val q007Source = Source.fromIterator(() => larsQ007.toIterator)
checkMacro(q007Source, ctx).map(validation => validation mustBe a[Failure[_]])
}
"fail Q008" in {
val larsQ008 = lars.map(lar => lar.copy(actionTakenType = 4))
val q008Source = Source.fromIterator(() => larsQ008.toIterator)
checkMacro(q008Source, ctx).map(validation => validation mustBe a[Failure[_]])
}
"fail S040" in {
val larsWithDuplicate = lars :+ lars.head
val s040Source = Source.fromIterator(() => larsWithDuplicate.toIterator)
checkMacro(s040Source, ctx).map(result => result mustBe a[Failure[_]])
}
}
}
开发者ID:cfpb,项目名称:hmda-platform,代码行数:45,代码来源:LarMacroEngineSpec.scala
示例14: executionContext
//设置package包名称以及导入依赖的类
package hmda.validation.rules.lar.`macro`
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.Source
import akka.util.Timeout
import com.typesafe.config.ConfigFactory
import hmda.model.fi.lar.{ LarGenerators, LoanApplicationRegister }
import hmda.model.institution.InstitutionGenerators.sampleInstitution
import hmda.validation.ValidationStats._
import hmda.validation.context.ValidationContext
import hmda.validation.rules.lar.`macro`.MacroEditTypes.LoanApplicationRegisterSource
import org.scalacheck.Gen
import org.scalatest.{ AsyncWordSpec, BeforeAndAfterAll, MustMatchers }
import scala.concurrent.duration._
trait MacroSpecWithValidationStats extends AsyncWordSpec with MustMatchers with LarGenerators with BeforeAndAfterAll {
implicit val system: ActorSystem = ActorSystem()
implicit val materializer = ActorMaterializer()
implicit override def executionContext = system.dispatcher
val duration = 5.seconds
implicit val timeout = Timeout(duration)
val validationStats = createValidationStats(system)
val configuration = ConfigFactory.load()
override def afterAll(): Unit = {
super.afterAll()
system.terminate()
}
def any: Int = Gen.choose(0, 100).sample.get
def ctx(institutionId: String, currentYear: Int = 2017): ValidationContext = {
ValidationContext(Some(sampleInstitution.copy(id = institutionId)), Some(currentYear))
}
def toSource(lars: List[LoanApplicationRegister]): LoanApplicationRegisterSource = {
Source.fromIterator(() => lars.toIterator)
}
def listOfN(n: Int, transform: LoanApplicationRegister => LoanApplicationRegister): List[LoanApplicationRegister] = {
larNGen(n).sample.getOrElse(List()).map(transform)
}
}
开发者ID:cfpb,项目名称:hmda-platform,代码行数:47,代码来源:MacroSpecWithValidationStats.scala
示例15: DbRunHelperSpec
//设置package包名称以及导入依赖的类
package com.snapswap.db.helpers.runner
import com.opentable.db.postgres.embedded.EmbeddedPostgres
import com.snapswap.db.errors.{EntityNotFound, InternalDataError}
import org.scalatest.{AsyncWordSpec, Matchers, OneInstancePerTest}
//import slick.jdbc.PostgresProfile.api._
import com.snapswap.db.driver.ExtendedPostgresProfile.api._
import slick.lifted.TableQuery
class DbRunHelperSpec
extends AsyncWordSpec
with Matchers
with OneInstancePerTest {
import runSafe._
val epg: EmbeddedPostgres = EmbeddedPostgres.start
val db: Database = Database.forDataSource(epg.getPostgresDatabase, None)
val tbl: TableQuery[TestTable] = TableQuery[TestTable]
"SlickRunWrapper" should {
"replace known errors by appropriate DataError" in {
val action = for {
_ <- db.runSafe(tbl.schema.create)
result <- db.runSafe(sql"""select "IntColumn" from "TestTable" """.as[Int].head)
} yield result
action.failed.map { r =>
r shouldBe a[EntityNotFound]
}
}
"replace unknown errors by InternalDataError with original error description" in {
val action = for {
_ <- db.runSafe(tbl.schema.create)
result <- db.runSafe(DBIO.seq(sql"""select IntColumn from NotExistingTable""".as[Int]).map(_ => ()))
} yield result
action.failed map { result =>
result shouldBe a[InternalDataError]
result.getMessage should startWith("ERROR: relation \"notexistingtable\" does not exist\n Position: 23")
}
}
"when success - return Future result" in {
val action = for {
_ <- db.runSafe(tbl.schema.create)
result <- db.runSafe((tbl += 1).andThen(tbl.map(_.IntColumn).result))
} yield result
action.map { result =>
result should equal(Seq(1))
}
}
}
class TestTable(tag: Tag) extends Table[Int](tag, "TestTable") {
def IntColumn = column[Int]("IntColumn")
def * = IntColumn
}
}
开发者ID:snap-swap,项目名称:slick-postgres-helpers,代码行数:62,代码来源:DbRunHelperSpec.scala
示例16: LagomdemoServiceSpec
//设置package包名称以及导入依赖的类
package com.dannyrobert.lagomdemo.impl
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}
import com.dannyrobert.lagomdemo.api._
class LagomdemoServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {
private val server = ServiceTest.startServer(
ServiceTest.defaultSetup
.withCassandra(true)
) { ctx =>
new LagomdemoApplication(ctx) with LocalServiceLocator
}
val client = server.serviceClient.implement[LagomdemoService]
override protected def afterAll() = server.stop()
"lagom-demo service" should {
"say hello" in {
client.hello("Alice").invoke().map { answer =>
answer should ===("Hello, Alice!")
}
}
"allow responding with a custom message" in {
for {
_ <- client.useGreeting("Bob").invoke(GreetingMessage("Hi"))
answer <- client.hello("Bob").invoke()
} yield {
answer should ===("Hi, Bob!")
}
}
}
}
开发者ID:drobert,项目名称:lagom-prototype,代码行数:39,代码来源:LagomdemoServiceSpec.scala
示例17: HelloServiceSpec
//设置package包名称以及导入依赖的类
package com.example.hello.impl
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}
import com.example.hello.api._
class HelloServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {
private val server = ServiceTest.startServer(
ServiceTest.defaultSetup
.withCassandra(true)
) { ctx =>
new HelloApplication(ctx) with LocalServiceLocator
}
val client = server.serviceClient.implement[HelloService]
override protected def afterAll() = server.stop()
"Hello service" should {
"say hello" in {
client.hello("Alice").invoke().map { answer =>
answer should ===("Hello, Alice!")
}
}
"allow responding with a custom message" in {
for {
_ <- client.useGreeting("Bob").invoke(GreetingMessage("Hi"))
answer <- client.hello("Bob").invoke()
} yield {
answer should ===("Hi, Bob!")
}
}
}
}
开发者ID:team3,项目名称:slotbook-api-lagom,代码行数:39,代码来源:HelloServiceSpec.scala
示例18: HelloServiceSpec
//设置package包名称以及导入依赖的类
package com.example.order.impl
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}
import com.example.order.api._
class HelloServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {
private val server = ServiceTest.startServer(
ServiceTest.defaultSetup
.withCassandra(true)
) { ctx =>
new HelloApplication(ctx) with LocalServiceLocator
}
val client = server.serviceClient.implement[OrderService]
override protected def afterAll() = server.stop()
"Hello service" should {
"say hello" in {
client.hello("Alice").invoke().map { answer =>
answer should ===("Hello, Alice!")
}
}
"allow responding with a custom message" in {
for {
_ <- client.useGreeting("Bob").invoke(GreetingMessage("Hi"))
answer <- client.hello("Bob").invoke()
} yield {
answer should ===("Hi, Bob!")
}
}
}
}
开发者ID:xebia,项目名称:lagom-saga,代码行数:39,代码来源:HelloServiceSpec.scala
示例19: CounterServiceSpec
//设置package包名称以及导入依赖的类
package com.example.counter.impl
import com.example.counter.api.CounterService
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}
class CounterServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {
val server = ServiceTest.startServer(
ServiceTest.defaultSetup.withCassandra(true)
) { ctx =>
new CounterApplication(ctx) with LocalServiceLocator
}
val client = server.serviceClient.implement[CounterService]
def AfterAll() = server.stop()
"Counter service" should {
"return value" in {
client.counter("1").invoke().map { value =>
value shouldBe 0
}
}
"add value" in {
for {
_ <- client.add("1").invoke(1)
_ <- client.add("1").invoke(2)
value <- client.counter("1").invoke()
} yield {
value shouldBe 3
}
}
}
}
开发者ID:namelos,项目名称:lagom-spike,代码行数:37,代码来源:CounterServiceSpec.scala
示例20: FlywayPreparerSpec
//设置package包名称以及导入依赖的类
package com.snapswap.db
import org.scalatest.{AsyncWordSpec, Matchers, OneInstancePerTest}
import slick.jdbc.PostgresProfile.api._
class FlywayPreparerSpec
extends AsyncWordSpec
with Matchers
with OneInstancePerTest {
val db: Database = Postgres.nextDB
"FlywayPreparer" should {
"correct apply migration" in {
val result = db.run(sql"""select count(*) from test_data""".as[Int].head)
result map { count =>
count shouldBe 1
}
}
}
}
开发者ID:snap-swap,项目名称:slick-postgres-testkit,代码行数:23,代码来源:FlywayPreparerSpec.scala
注:本文中的org.scalatest.AsyncWordSpec类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论