本文整理汇总了Scala中com.lightbend.lagom.scaladsl.server.LocalServiceLocator类的典型用法代码示例。如果您正苦于以下问题:Scala LocalServiceLocator类的具体用法?Scala LocalServiceLocator怎么用?Scala LocalServiceLocator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LocalServiceLocator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: 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
示例2: 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!")
}
}
}
}
示例3: 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)
}
}
}
}
}
}
示例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" 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)
}
}
}
}
}
示例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
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)
}
}
}
}
}
示例6: 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!")
}
}
}
}
示例7: 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!")
}
}
}
}
示例8: 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!")
}
}
}
}
示例9: 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!")
}
}
}
}
示例10: 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
}
}
}
}
示例11: 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!")
}
}
}
}
示例12: 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!")
}
}
}
}
示例13: 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!")
}
}
}
}
示例14: AlphaApplication
//设置package包名称以及导入依赖的类
package com.lightbend.lagom.scaladsl.testkit
import akka.persistence.query.Offset
import akka.stream.scaladsl.Source
import akka.stream.testkit.scaladsl.TestSink
import com.lightbend.lagom.scaladsl.api.broker.Topic
import com.lightbend.lagom.scaladsl.broker.TopicProducer
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.EmptyJsonSerializerRegistry
import com.lightbend.lagom.scaladsl.server.{ LagomApplication, LagomApplicationContext, LagomServer, LocalServiceLocator }
import com.lightbend.lagom.scaladsl.testkit.services.{ AlphaEvent, AlphaService }
import org.scalatest.{ AsyncWordSpec, Matchers }
import play.api.libs.ws.ahc.AhcWSComponents
abstract class AlphaApplication(context: LagomApplicationContext)
extends LagomApplication(context)
with CassandraPersistenceComponents
with TestTopicComponents
with AhcWSComponents {
override lazy val lagomServer = serverFor[AlphaService](new AlphaServiceImpl())
override lazy val jsonSerializerRegistry = EmptyJsonSerializerRegistry
}
class AlphaServiceImpl extends AlphaService {
override def messages: Topic[AlphaEvent] =
TopicProducer.singleStreamWithOffset { offset =>
val events = (1 to 10).filter(_ % 2 == 0).map(AlphaEvent.apply)
Source(events).map(event => (event, Offset.sequence(event.message / 2)))
}
}
class TopicPublishingSpec extends AsyncWordSpec with Matchers {
"The AlphaService" should {
"publish events on alpha topic" in ServiceTest.withServer(ServiceTest.defaultSetup) { ctx =>
new AlphaApplication(ctx) with LocalServiceLocator
} { server =>
implicit val system = server.actorSystem
implicit val mat = server.materializer
val client: AlphaService = server.serviceClient.implement[AlphaService]
val source = client.messages.subscribe.atMostOnceSource
source.runWith(TestSink.probe[AlphaEvent])
.request(1)
.expectNext should ===(AlphaEvent(2))
}
}
}
示例15: ProducerStubSpec
//设置package包名称以及导入依赖的类
package com.lightbend.lagom.scaladsl.testkit
import com.lightbend.lagom.scaladsl.api.broker.Topic
import com.lightbend.lagom.scaladsl.server.{ LagomApplicationContext, LocalServiceLocator }
import com.lightbend.lagom.scaladsl.testkit.services._
import org.scalatest.concurrent.Eventually
import org.scalatest.time.{ Seconds, Span }
import org.scalatest.{ BeforeAndAfterAll, Matchers, WordSpec }
class ProducerStubSpec extends WordSpec with Matchers with BeforeAndAfterAll with Eventually {
var producerStub: ProducerStub[AlphaEvent] = _
private val stubbedApplication: LagomApplicationContext => DownstreamApplication = {
ctx =>
new DownstreamApplication(ctx) with LocalServiceLocator {
val stubFactory = new ProducerStubFactory(actorSystem, materializer)
producerStub = stubFactory.producer[AlphaEvent](AlphaService.TOPIC_ID)
override lazy val alphaService = new AlphaServiceStub(producerStub)
}
}
"The ProducerStub" should {
"send message to consuming services" in ServiceTest.withServer(ServiceTest.defaultSetup)(stubbedApplication) { server =>
implicit val exCtx = server.application.actorSystem.dispatcher
producerStub.send(AlphaEvent(22))
eventually(timeout(Span(5, Seconds))) {
server.serviceClient.implement[CharlieService].messages.invoke().map { response =>
response should ===(Seq(ReceivedMessage("A", 22)))
}.recover {
case t: Throwable => fail(t)
}
}
}
}
}
class AlphaServiceStub(stub: ProducerStub[AlphaEvent]) extends AlphaService {
override def messages: Topic[AlphaEvent] = stub.topic
}