当前位置: 首页>>代码示例>>Scala>>正文


Scala ServiceTest类代码示例

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


在下文中一共展示了ServiceTest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例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" 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

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

      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

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

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

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

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

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

示例12: HellolagomServiceSpec

//设置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 HellolagomServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {

  private val server = ServiceTest.startServer(
    ServiceTest.defaultSetup
      .withCassandra(true)
  ) { ctx =>
    new HellolagomApplication(ctx) with LocalServiceLocator
  }

  val client = server.serviceClient.implement[HellolagomService]

  override protected def afterAll() = server.stop()

  "hello-lagom 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:clca,项目名称:lagom-scala,代码行数:39,代码来源:HellolagomServiceSpec.scala

示例13: GithubServiceSpec

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

import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import com.onedrop.github.api.{GithubService, GreetingMessage}
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}

class GithubServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {

  private val server = ServiceTest.startServer(
    ServiceTest.defaultSetup
      .withCassandra(true)
  ) { ctx =>
    new GithubApplication(ctx) with LocalServiceLocator
  }

  val client = server.serviceClient.implement[GithubService]

  override protected def afterAll() = server.stop()

  "github 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:jewelsjacobs,项目名称:one-drop-test,代码行数:39,代码来源:GithubServiceSpec.scala

示例14: LagomhelloServiceSpec

//设置package包名称以及导入依赖的类
package de.breitbandig.lagomhello.impl

import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}
import de.breitbandig.lagomhello.api._

class LagomhelloServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {

  private val server = ServiceTest.startServer(
    ServiceTest.defaultSetup
      .withCassandra(true)
  ) { ctx =>
    new LagomhelloApplication(ctx) with LocalServiceLocator
  }

  val client = server.serviceClient.implement[LagomhelloService]

  override protected def afterAll() = server.stop()

  "lagom-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:aanno,项目名称:lagom-hello,代码行数:39,代码来源:LagomhelloServiceSpec.scala

示例15: JournalServiceSpec

//设置package包名称以及导入依赖的类
package io.namelos.journal.impl

import io.namelos.journal.api.JournalService
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}

class JournalServiceSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll {
  val server = ServiceTest.startServer(
    ServiceTest.defaultSetup.withCassandra(true)
  ) { ctx =>
    new JournalApplication(ctx) with LocalServiceLocator
  }

  val client = server.serviceClient.implement[JournalService]

  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,项目名称:namelos-journal,代码行数:37,代码来源:JournalServiceSpec.scala


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