本文整理汇总了Scala中org.scalatestplus.play.OneAppPerSuite类的典型用法代码示例。如果您正苦于以下问题:Scala OneAppPerSuite类的具体用法?Scala OneAppPerSuite怎么用?Scala OneAppPerSuite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OneAppPerSuite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: givenCleanMetricRegistry
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.agentmapping.support
import com.codahale.metrics.MetricRegistry
import com.kenshoo.play.metrics.Metrics
import org.scalatest.Matchers
import org.scalatestplus.play.OneAppPerSuite
import scala.collection.JavaConversions
trait MetricTestSupport {
self: OneAppPerSuite with Matchers =>
private var metricsRegistry: MetricRegistry = _
def givenCleanMetricRegistry(): Unit = {
val registry = app.injector.instanceOf[Metrics].defaultRegistry
for (metric <- JavaConversions.asScalaIterator[String](registry.getMetrics.keySet().iterator())) {
registry.remove(metric)
}
metricsRegistry = registry
}
def timerShouldExistsAndBeenUpdated(metric: String): Unit = {
metricsRegistry.getTimers.get(s"Timer-$metric").getCount should be >= 1L
}
}
示例2: givenCleanMetricRegistry
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.agentaccesscontrol.support
import com.codahale.metrics.MetricRegistry
import com.kenshoo.play.metrics.Metrics
import org.scalatest.Matchers
import org.scalatestplus.play.OneAppPerSuite
import scala.collection.JavaConversions
trait MetricTestSupport {
self: OneAppPerSuite with Matchers =>
private var metricsRegistry: MetricRegistry = _
def givenCleanMetricRegistry(): Unit = {
val registry = app.injector.instanceOf[Metrics].defaultRegistry
for (metric <- JavaConversions.asScalaIterator[String](registry.getMetrics.keySet().iterator())) {
registry.remove(metric)
}
metricsRegistry = registry
}
def timerShouldExistsAndBeenUpdated(metric: String): Unit = {
metricsRegistry.getTimers.get(s"Timer-$metric").getCount should be >= 1L
}
}
示例3: HomePageControllerSpec
//设置package包名称以及导入依赖的类
package controllers
import org.scalatestplus.play.{OneAppPerSuite, PlaySpec}
import play.api.test.FakeRequest
import play.api.test.Helpers._
class HomePageControllerSpec extends PlaySpec with OneAppPerSuite {
//TODO: Need to define TimeGreetingService
object TestHomeControllerTest extends HomeController {
override def greeter = ???
}
val controller = TestHomeControllerTest
"HomeController" should {
"not return 404" when {
"I go to the route /landing" in {
val result = route(app, FakeRequest(GET, "/landing"))
status(result.get) must not be NOT_FOUND
}
}
"render the correct page with the expected text" when {
"I navigate to the homepage" in {
val result = controller.landing("Good morning Helen").apply(FakeRequest(GET, "/landing"))
status(result) mustBe OK
contentAsString(result) must include ("Good morning Helen")
//arrange
//action
//assert
}
"I go to the homepage after lunch" in {
val result = controller.landing("Good afternoon Helen").apply(FakeRequest(GET, "/landing"))
contentAsString(result) must include ("Good afternoon Helen")
}
}
}
}
示例4: BreakfastAppControllerSpec
//设置package包名称以及导入依赖的类
package controllers
import org.scalatestplus.play.{OneAppPerSuite, PlaySpec}
import play.api.mvc.Result
import play.api.test.FakeRequest
import play.api.test.Helpers._
import scala.concurrent.Future
class BreakfastAppControllerSpec extends PlaySpec with OneAppPerSuite {
"BreakfastAppController" should {
"not return 404" when {
"we try to hit the route /home" in {
route(app, FakeRequest(GET, "/home")).map(status(_)) must not be Some(NOT_FOUND)
}
}
"reneder a page" when {
"we try to hit the route /home" in {
var result: Option[Future[Result]] = route(app, FakeRequest(GET, "/home"))
result.map(status(_)) mustBe Some(OK)
val text: String = result.map(contentAsString(_)).get
text must include ("Welcome to Play")
}
}
}
}
示例5: AddressDetailsControllerTest
//设置package包名称以及导入依赖的类
package controllers
import address.AddressReputationService
import akka.actor.ActorSystem
import akka.stream.{ActorMaterializer, Materializer}
import model.AddressDetails
import org.mockito.Matchers.any
import org.mockito.Mockito._
import org.scalatest.mock.MockitoSugar
import org.scalatestplus.play.{OneAppPerSuite, PlaySpec}
import play.api.libs.json.Reads
import play.api.mvc.Security
import play.api.test.FakeRequest
import play.api.test.Helpers._
import uk.gov.hmrc.http.cache.client.SessionCache
import uk.gov.hmrc.play.http.HeaderCarrier
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
class AddressDetailsControllerTest extends PlaySpec with MockitoSugar with OneAppPerSuite {
trait action {
val cache = mock[SessionCache]
val ars = mock[AddressReputationService]
val controller = new AddressDetailsController(ars, cache)
val req = FakeRequest().withSession(Security.username -> "user")
val buildingNumber = "25"
val buildingName = "Starship Enterprise"
val street = "Waterloo Road"
val town = "Darlington"
val postcode = "DL3 5BD"
val ad = AddressDetails(Some(buildingNumber), Some(buildingName), Some(street), Some(town), postcode)
implicit val system = ActorSystem("Test")
implicit def mat: Materializer = ActorMaterializer()
}
"get" should {
"return completed form" in new action {
// test that when the cache contains address details, we display filled-out form
when(cache.fetchAndGetEntry[AddressDetails](any[String])(any[HeaderCarrier], any[Reads[AddressDetails]])).thenReturn(Future(Some(ad)))
val res = call(controller.get(), req)
status(res) must be(303)
}
}
}
示例6: CatDAOSpec
//设置package包名称以及导入依赖的类
package dao
import models.Cat
import org.scalatest._
import org.scalatestplus.play.{OneAppPerSuite, PlaySpec}
import play.api.Application
import play.api.inject.guice.GuiceApplicationBuilder
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
class CatDAOSpec extends PlaySpec
with WordSpecLike
with OneAppPerSuite {
implicit override lazy val app = {
new GuiceApplicationBuilder().configure(
Map(
"slick.dbs.animaldb.driver" -> "slick.driver.H2Driver$",
"slick.dbs.animaldb.db.driver" -> "org.h2.Driver",
"slick.dbs.animaldb.db.url" -> "jdbc:h2:mem:animaldb;DATABASE_TO_UPPER=false",
"slick.dbs.animaldb.db.user" -> "sa",
"slick.dbs.animaldb.db.password" -> "",
"play.evolutions.db.animaldb.enabled" -> true,
"play.evolutions.db.animaldb.autoApply" -> true
)
).build()
}
"CatDAO" should {
"work as expected" in {
val app2dao = Application.instanceCache[CatDAO]
val dao: CatDAO = app2dao(app)
val testKitties = Set(
Cat("kit", "black"),
Cat("garfield", "orange"),
Cat("creme puff", "grey")
)
Await.result(Future.sequence(testKitties.map(dao.insert)), 1 seconds)
val storedCats = Await.result(dao.all(), 1 seconds).toVector
storedCats.sortBy(_.name) mustBe testKitties.toVector.sortBy(_.name)
}
}
}
示例7: ApplicationSpec
//设置package包名称以及导入依赖的类
package controllers
import org.scalatest.WordSpecLike
import org.scalatestplus.play.{OneAppPerSuite, PlaySpec}
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.libs.json.Json
import play.api.test.Helpers._
import play.api.test._
class ApplicationSpec extends PlaySpec with OneAppPerSuite with WordSpecLike {
implicit override lazy val app = {
new GuiceApplicationBuilder().configure(
Map(
"slick.dbs.animaldb.driver" -> "slick.driver.H2Driver$",
"slick.dbs.animaldb.db.driver" -> "org.h2.Driver",
"slick.dbs.animaldb.db.url" -> "jdbc:h2:mem:animaldb;DATABASE_TO_UPPER=false",
"slick.dbs.animaldb.db.user" -> "sa",
"slick.dbs.animaldb.db.password" -> "",
"play.evolutions.db.animaldb.enabled" -> true,
"play.evolutions.db.animaldb.autoApply" -> true
)
).build()
}
"Application" should {
"render the index page" in {
val kitty = Json.obj("name" -> "Scarlett", "color" -> "Black & White")
val postRequest = FakeRequest(
method = "POST",
uri = "/cat/insert",
headers = FakeHeaders(
Seq("Content-type" -> "application/json")
),
body = kitty
)
val Some(result) = route(postRequest)
status(result) mustBe OK
val home = route(FakeRequest(GET, "/")).get
status(home) mustBe OK
contentType(home) mustBe Some("application/json")
contentAsString(home) must include("Scarlett")
}
}
}
示例8: ProductSpec
//设置package包名称以及导入依赖的类
import com.google.common.collect.ImmutableMap
import models.ProductService
import org.scalatestplus.play.{OneAppPerSuite, PlaySpec}
import play.api.db.Databases
import play.db.Database
class ProductSpec extends PlaySpec with OneAppPerSuite {
var productService: ProductService = app.injector.instanceOf(classOf[ProductService])
Databases.withDatabase(
driver = "com.mysql.jdbc.Driver",
url = "jdbc:mysql://localhost/playtest",
config = Map(
"user" -> "play",
"password" -> "demo"
)
) { database =>
import play.api.db.evolutions._
Evolutions.applyEvolutions(database)
"Product" should {
"be retrieved by Id" in {
val product = productService.get(23)
product.get.name must equal("test")
}
}
}
}
示例9: newAppForTest
//设置package包名称以及导入依赖的类
import org.scalatest.{Suite, TestData}
import org.scalatestplus.play.{OneAppPerSuite, OneAppPerTest, OneServerPerSuite, OneServerPerTest}
import play.api.{BuiltInComponents, _}
trait OneAppPerTestWithComponents[T <: BuiltInComponents]
extends OneAppPerTest
with WithApplicationComponents[T] {
this: Suite =>
override def newAppForTest(testData: TestData): Application = newApplication
}
trait OneAppPerSuiteWithComponents[T <: BuiltInComponents]
extends OneAppPerSuite
with WithApplicationComponents[T] {
this: Suite =>
override implicit lazy val app: Application = newApplication
}
trait OneServerPerTestWithComponents[T <: BuiltInComponents]
extends OneServerPerTest
with WithApplicationComponents[T] {
this: Suite =>
override def newAppForTest(testData: TestData): Application = newApplication
}
trait OneServerPerSuiteWithComponents[T <: BuiltInComponents]
extends OneServerPerSuite
with WithApplicationComponents[T] {
this: Suite =>
override implicit lazy val app: Application = newApplication
}
示例10: IntegrationSpec
//设置package包名称以及导入依赖的类
import org.scalatestplus.play.OneAppPerSuite
import org.scalatestplus.play.PlaySpec
import play.api.libs.json.Json
import play.api.test._
import play.api.test.Helpers._
import testdata._
class IntegrationSpec extends PlaySpec with OneAppPerSuite with IntegrationSuiteMixin {
"Application" should {
"get closest locations from twitter" in {
val locationsUrl = s"/locations/$latitude/$longitude"
val Some(result) = route(FakeRequest(GET, locationsUrl))
status(result) must be(OK)
contentType(result) must be(Some("application/json"))
contentAsJson(result) must be(Json.toJson(closetLocationsHavingTrends))
verifyBearerTokenCall()
}
}
"get trends for a place" in {
val trendsUrl = s"/trends/$woeid"
val Some(result) = route(FakeRequest(GET, trendsUrl))
status(result) must be(OK)
contentType(result) must be(Some("application/json"))
contentAsJson(result) must be(Json.toJson(trendsList))
verifyBearerTokenCall()
}
override implicit lazy val app: FakeApplication = FakeApplication(
additionalConfiguration = Map(
"twitter.api.url" -> s"http://$host:$wireMockPort",
"twitter.consumer.key" -> twitterConsumerKey,
"twitter.consumer.secret" -> twitterConsumerSecret))
}
示例11: BreakfastAppControllerSpec
//设置package包名称以及导入依赖的类
package controllers
import org.scalatestplus.play.{OneAppPerSuite, PlaySpec}
import play.api.mvc.Result
import play.api.test.FakeRequest
import play.api.test.Helpers._
import scala.concurrent.Future
class BreakfastAppControllerSpec extends PlaySpec with OneAppPerSuite {
"BreakfastAppController" should {
"not return 404" when {
"we try to hit the route /home" in {
route(app, FakeRequest(GET, "/home")).map(status(_)) must not be Some(NOT_FOUND)
}
}
"render a page" when {
"we try to hit the route /home" in {
val result: Option[Future[Result]] = route(app, FakeRequest(GET, "/home"))
result.map(status(_)) mustBe Some(OK)
val text: String = result.map(contentAsString(_)).get
text must include ("Welcome to Play")
}
}
}
}
示例12: EncryptionServiceSpec
//设置package包名称以及导入依赖的类
package services.auth
import config.ApplicationConfig
import helpers.TestSpec
import org.scalatestplus.play.OneAppPerSuite
class EncryptionServiceSpec extends TestSpec with OneAppPerSuite {
lazy val config: ApplicationConfig = app.injector.instanceOf[ApplicationConfig]
lazy val service = new EncryptionService(config)
"Calling .encrypt" should {
lazy val result = service.encrypt("testData")
"return a map" which {
"contains a nonce of size 64" in {
result("nonce").length shouldBe 64
}
"contains a value of size 32" in {
result("value").length shouldBe 32
}
}
}
"Calling .decrypt" should {
val map = Map(
"nonce" -> "a954bf74662060335285a4b482055ef8b9b38eeee1808f97ea7602fcde77b2ed",
"value" -> "33b8c73001f82ca28f3e26e1af1db245"
)
lazy val result = service.decrypt(map)
"return a string of 'testData'" in {
result shouldBe "testData"
}
}
}
示例13: AdminServiceSpec
//设置package包名称以及导入依赖的类
package services
import connectors.MongoConnector
import helpers.TestSpec
import models.coordinates.SectorCoordinateModel
import models.universe.{SectorModel, UniverseModel}
import org.mockito.ArgumentMatchers
import org.scalatestplus.play.OneAppPerSuite
import org.mockito.Mockito._
import scala.concurrent.Future
class AdminServiceSpec extends TestSpec with OneAppPerSuite {
def setupService(inputResponse: Future[Unit]): AdminService = {
val mockConnector = mock[MongoConnector]
when(mockConnector.putEntry(ArgumentMatchers.any(), ArgumentMatchers.any())(ArgumentMatchers.any()))
.thenReturn(inputResponse)
new AdminService(mockConnector)
}
"Calling .storeUniverse" when {
val universeModel = UniverseModel(Seq(SectorModel(SectorCoordinateModel(0, 0), Seq()), SectorModel(SectorCoordinateModel(0, 1), Seq())))
"an error is returned from the connector" should {
lazy val service = setupService(Future.failed(new Exception("error message")))
lazy val result = service.storeUniverse("test", universeModel)
"return the correct error message" in {
lazy val exception = intercept[Exception](await(result))
exception.getMessage shouldBe "error message"
}
}
"a success is returned from the connector" should {
lazy val service = setupService(Future.successful({}))
lazy val result = service.storeUniverse("test", universeModel)
"return a Unit" in {
await(result).isInstanceOf[Unit] shouldBe true
}
}
}
}
示例14: CandidatesRepoSpec
//设置package包名称以及导入依赖的类
package repos
import db.MongoConnectivity
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{BeforeAndAfter, Matchers, WordSpec}
import org.scalatestplus.play.OneAppPerSuite
import support.Mongo
class CandidatesRepoSpec extends WordSpec with Matchers with BeforeAndAfter with ScalaFutures with OneAppPerSuite {
val mongoConnectivity = new MongoConnectivity(app.configuration)
val repo = new CandidatesRepo(mongoConnectivity)
val scala = Candidate("scala", "Scala", "The Scala Language", "2.12.0", "http://www.scala-lang.org/", "UNIVERSAL")
val groovy = Candidate("groovy", "Groovy", "The Groovy Language", "2.4.7", "http://www.groovy-lang.org/", "UNIVERSAL")
val java = Candidate("java", "Java", "The Java Language", "8u111", "https://www.oracle.com", "MULTI_PLATFORM")
"candidates repository" should {
"find all candidates regardless of distribution" in {
whenReady(repo.findAllCandidates()) { candidates =>
candidates.size shouldBe 3
candidates should contain(scala)
candidates should contain(groovy)
candidates should contain(java)
}
}
"find candidates in alphabetically sorted order" in {
whenReady(repo.findAllCandidates()) { candidates =>
candidates.size shouldBe 3
candidates(0) shouldBe groovy
candidates(1) shouldBe java
candidates(2) shouldBe scala
}
}
"find some single candidate when searching by know candidate identifier" in {
val candidate = "java"
whenReady(repo.findByIdentifier(candidate)) { maybeCandidate =>
maybeCandidate shouldBe defined
maybeCandidate.foreach(_.candidate shouldBe candidate)
}
}
"find none when searching by unknown candidate identifier" in {
val candidate = "scoobeedoo"
whenReady(repo.findByIdentifier(candidate)) { maybeCandidate =>
maybeCandidate shouldNot be(defined)
}
}
}
before {
Mongo.dropAllCollections()
Mongo.insertCandidates(Seq(scala, groovy, java))
}
}
示例15: 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
}
}