本文整理汇总了Scala中play.api.inject.bind类的典型用法代码示例。如果您正苦于以下问题:Scala bind类的具体用法?Scala bind怎么用?Scala bind使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了bind类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: OneAppSpecs
//设置package包名称以及导入依赖的类
package controllers
import data.CassandraAsyncContextImpl
import org.scalatest._
import org.scalatestplus.play._
import play.api.inject.bind
import play.api.inject.guice._
class OneAppSpecs extends Suites(
new ApplicationTest,
new TaskSolverTest,
new AddTaskTest,
new UserControllerTest,
new GitHubUserTest
) with OneAppPerSuite with MockitoSugar {
implicit override lazy val app = new GuiceApplicationBuilder()
.configure(Map("ehcacheplugin" -> "disabled"))
.overrides(bind[CassandraAsyncContextImpl] to mockito[CassandraAsyncContextImpl])
.build()
}
开发者ID:DmytroOrlov,项目名称:devgym,代码行数:22,代码来源:OneAppSpecs.scala
示例2: ArticleServiceSpec
//设置package包名称以及导入依赖的类
package services.article
import domains.article.{ArticleEntity, ArticleRepository}
import org.mockito.Mockito._
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.mockito.MockitoSugar
import org.scalatestplus.play.PlaySpec
import play.api.Application
import play.api.inject.bind
import play.api.inject.guice.GuiceApplicationBuilder
class ArticleServiceSpec extends PlaySpec with MockitoSugar with ScalaFutures {
"listAll" should {
val sut: ArticleService = Application.instanceCache[ArticleService].apply(MockBuilder.build())
// ?????
"success" in {
val actual = sut.listAll()
actual.size mustBe 1
}
}
private object MockBuilder {
def build(): Application = {
new GuiceApplicationBuilder().
overrides(bind[ArticleRepository].toInstance(articleRepository())).
build
}
@SuppressWarnings(Array("org.wartremover.warts.NonUnitStatements"))
private def articleRepository(): ArticleRepository = {
// Mock???????
val articleEntities: Seq[ArticleEntity] = Seq(ArticleEntity(None, "sample_title", "sample_url"))
// Mock????????
val articleRepository = mock[ArticleRepository]
when(articleRepository.listAll()).thenReturn(articleEntities)
articleRepository
}
}
}
开发者ID:tmknom,项目名称:scala-ddd,代码行数:43,代码来源:ArticleServiceSpec.scala
示例3: TwitterServiceSpec
//设置package包名称以及导入依赖的类
package services.crawler
import domains.tweet.{TweetEntity, TweetRepository, TwitterApi}
import org.mockito.ArgumentMatchers._
import org.mockito.Mockito._
import org.scalatest.mockito.MockitoSugar
import org.scalatestplus.play.PlaySpec
import play.api.Application
import play.api.inject.bind
import play.api.inject.guice.GuiceApplicationBuilder
import resources.builder.TweetEntityBuilder
class TwitterServiceSpec extends PlaySpec with MockitoSugar {
"crawl" should {
val sut: TwitterService = Application.instanceCache[TwitterService].apply(MockBuilder.build())
// ?????
"success" in {
val actual = sut.crawl()
actual.size mustBe 1
}
}
private object MockBuilder {
def build(): Application = {
new GuiceApplicationBuilder().
overrides(bind[TwitterApi].toInstance(mockTwitterApi())).
overrides(bind[TweetRepository].toInstance(mockTweetRepository())).
build
}
@SuppressWarnings(Array("org.wartremover.warts.NonUnitStatements"))
def mockTwitterApi(): TwitterApi = {
// Mock???????
val tweetEntity = TweetEntityBuilder.one
// Mock????????
val mockInstance = mock[TwitterApi]
when(mockInstance.request()).thenReturn(Seq[TweetEntity](tweetEntity))
mockInstance
}
@SuppressWarnings(Array("org.wartremover.warts.NonUnitStatements"))
def mockTweetRepository(): TweetRepository = {
// Mock????????
val mockInstance = mock[TweetRepository]
when(mockInstance.insert(any[TweetEntity])).thenReturn(2)
mockInstance
}
}
}
开发者ID:tmknom,项目名称:scala-ddd,代码行数:54,代码来源:TwitterServiceSpec.scala
示例4: ProductControllerSpec
//设置package包名称以及导入依赖的类
package product.test.unit
import scala.io.Source
import org.junit.runner.RunWith
import org.scalatest.mockito.MockitoSugar
import org.scalatestplus.play._
import org.scalatestplus.play.PlaySpec
import play.api.inject.bind
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.libs.json._
import play.api.libs.json.Json
import product.model.OfferDetail
import product.model.OfferList
import product.services.market.walmart.WalmartRepository
import org.mockito.Mockito._
import org.mockito.Matchers._
import play.api.test.Helpers._
import play.api.test.CSRFTokenHelper._
import play.api.test.WithApplication
import play.api.test.FakeRequest
import scala.concurrent.Future
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class ProductControllerSpec extends PlaySpec with MockitoSugar {
val productList = Json.parse(Source.fromFile("conf/app/sample_offer.json").getLines.mkString).as[OfferList]
val offerDetail = Json.parse(Source.fromFile("conf/app/offer_detail.json").getLines.mkString).as[OfferDetail]
val walmartMock = mock[WalmartRepository]
when(walmartMock.search(any[Map[String,String]])) thenReturn Future.successful(Some(productList))
val appMock = new GuiceApplicationBuilder()
.overrides(bind[WalmartRepository].toInstance(walmartMock))
.build
"index" in new WithApplication(appMock) {
val request = FakeRequest(GET, "/products").withHeaders(HOST -> "localhost:9000").withCSRFToken
val response = route(app, request).get
val json = contentAsJson(response)
val elem0 = (json \ "list")(0)
val summary = (json \ "summary")
status(response) mustBe OK
(elem0 \ "id").as[String] mustBe "1"
(elem0 \ "upc").as[String] mustBe "upc1"
(elem0 \ "name").as[String] mustBe "prod 1"
(elem0 \ "partyName").as[String] mustBe "pty 1"
(summary \ "page").as[Int] mustBe 0
(summary \ "pageCount").as[Int] mustBe 1
(summary \ "totalCount").as[Int] mustBe 3
}
}
开发者ID:guilhebl,项目名称:offer-backend,代码行数:55,代码来源:ProductControllerSpec.scala
示例5: MailerControllerIntegration
//设置package包名称以及导入依赖的类
package integration
import mocks.{MailServiceMock, AuthServiceMock, Samples}
import models.Formatters._
import org.scalatestplus.play.OneAppPerSuite
import play.api.Application
import play.api.inject.bind
import play.api.libs.json.Json
import play.api.test.FakeRequest
import play.api.test.Helpers._
import services.{AuthService, MailService}
import traits.TestBuilder
class MailerControllerIntegration extends TestBuilder with OneAppPerSuite {
implicit override lazy val app: Application = builder
.overrides(bind[AuthService].to[AuthServiceMock])
.overrides(bind[MailService].to[MailServiceMock])
.build()
it should "not send email without authorization" in {
val request = FakeRequest(POST, "/send")
.withJsonBody(Json.toJson(Samples.sendmailAction.copy(auth = AuthServiceMock.invalidBulkEmailAuth)))
val response = route(app, request).get
status(response) shouldBe FORBIDDEN
}
it should "send email with authorization" in {
val request = FakeRequest(POST, "/send")
.withJsonBody(Json.toJson(Samples.sendmailAction.copy(auth = AuthServiceMock.validBulkEmailAuth)))
val response = route(app, request).get
status(response) shouldBe OK
}
}
开发者ID:waveinch,项目名称:ses-transactional,代码行数:40,代码来源:MailerControllerIntegration.scala
示例6: AuthorsControllerSpec
//设置package包名称以及导入依赖的类
package controllers
import java.util.UUID
import dao.AuthorDAO
import de.leanovate.swaggercheck.playhelper._
import de.leanovate.swaggercheck.schema.model.ValidationResult
import models.{Author, Page}
import org.scalacheck.Arbitrary
import org.specs2.ScalaCheck
import org.specs2.mock.Mockito
import play.api.Application
import play.api.inject.bind
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test.{PlaySpecification, WithApplication}
import support.{Arbitraries, BookDbApi}
import scala.concurrent.Future
class AuthorsControllerSpec extends PlaySpecification with ScalaCheck with BookDbApi with Mockito with Arbitraries {
"AuthorsController" should {
"handle all /authors routes" in {
implicit val arbitraryRequest = Arbitrary[PlayOperationVerifier](swaggerCheck.operationVerifier(_.startsWith("/v1/authors")))
prop {
requestVerifier: PlayOperationVerifier =>
val Some(result) = route(requestVerifier.request)
requestVerifier.responseVerifier.verify(result) must be equalTo ValidationResult.success
}.setContext(new WithApplication(testApp) {})
}
}
def testApp: Application = {
val mockAuthorDAO = mock[AuthorDAO]
mockAuthorDAO.all(any[Int], any[Int]) answers { _ => Future.successful(Arbitrary.arbitrary[Page[Author]].sample.getOrElse(Page.empty)) }
mockAuthorDAO.findById(any[UUID]) answers { _ => Future.successful(Arbitrary.arbitrary[Option[Author]].sample.getOrElse(None)) }
mockAuthorDAO.insert(any[Author]) returns Future.successful(Unit)
mockAuthorDAO.delete(any[UUID]) returns Future.successful(Unit)
new GuiceApplicationBuilder()
.overrides(bind[AuthorDAO].toInstance(mockAuthorDAO))
.build()
}
}
开发者ID:leanovate,项目名称:book-db-sample,代码行数:47,代码来源:AuthorsControllerSpec.scala
注:本文中的play.api.inject.bind类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论