本文整理汇总了Scala中org.scalatestplus.play.OneServerPerSuite类的典型用法代码示例。如果您正苦于以下问题:Scala OneServerPerSuite类的具体用法?Scala OneServerPerSuite怎么用?Scala OneServerPerSuite使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OneServerPerSuite类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: get
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.ups.controllers
import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.ScalaFutures
import org.scalatestplus.play.{OneServerPerSuite, WsScalaTestClient}
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.libs.ws.WSRequest
import uk.gov.hmrc.play.test.UnitSpec
trait DatabaseName {
val testName: String = "updated-print-suppressions"
}
trait TestServer
extends ScalaFutures
with DatabaseName
with UnitSpec
with BeforeAndAfterAll
with OneServerPerSuite
with WsScalaTestClient {
override implicit lazy val app = new GuiceApplicationBuilder()
.configure(Map("auditing.enabled" -> false,
"mongodb.uri" -> "mongodb://localhost:27017/updated-print-suppressions",
"application.router" -> "testOnlyDoNotUseInAppConf.Routes"
))
.build()
def `/preferences/sa/individual/print-suppression`(updatedOn: Option[String], offset: Option[String], limit: Option[String], isAdmin: Boolean = false) = {
val queryString = List(
updatedOn.map(value => "updated-on" -> value),
offset.map(value => "offset" -> value),
limit.map(value => "limit" -> value)
).flatten
if (isAdmin)
wsUrl("/test-only/preferences/sa/individual/print-suppression").withQueryString(queryString: _*)
else
wsUrl("/preferences/sa/individual/print-suppression").withQueryString(queryString: _*)
}
def get(url: WSRequest) = url.get().futureValue
}
示例2: WiremockHelper
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.emailverification
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig
import org.scalatest._
import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import org.scalatestplus.play.OneServerPerSuite
object WiremockHelper {
val wiremockPort = 11111
val wiremockHost = "localhost"
val url = s"http://$wiremockHost:$wiremockPort"
}
trait WiremockHelper {
import uk.gov.hmrc.emailverification.WiremockHelper._
val wmConfig = wireMockConfig().port(wiremockPort)
val wireMockServer = new WireMockServer(wmConfig)
def startWiremock() = {
wireMockServer.start()
WireMock.configureFor(wiremockHost, wiremockPort)
}
def stopWiremock() = wireMockServer.stop()
def resetWiremock() = WireMock.reset()
}
trait IntegrationSpecBase extends FeatureSpec with GivenWhenThen with OneServerPerSuite with ScalaFutures with IntegrationPatience with Matchers with WiremockHelper with BeforeAndAfterEach with BeforeAndAfterAll {
override def beforeEach() = {
resetWiremock()
}
override def beforeAll() = {
super.beforeAll()
startWiremock()
}
override def afterAll() = {
stopWiremock()
super.afterAll()
}
}
示例3: ReviewSummaryServiceSpec
//设置package包名称以及导入依赖的类
package services
import connectors.ZolAPIConnector
import org.scalatestplus.play.{OneServerPerSuite, PlaySpec}
import play.api.test.Helpers._
//Play frequently requires a running Application as context.
//Sometimes you want to test with the real HTTP stack.
// If all tests in your test class can reuse the same server instance, you can mix in OneServerPerSuite (which will also provide a new Application for the suite):
class ReviewSummaryServiceSpec extends PlaySpec with OneServerPerSuite {
object TestReviewSummaryService extends ReviewSummaryService {
override val zolAPIConnector = ZolAPIConnector
}
"ReviewSummaryService" must {
"get all the review summaries " in {
val x = TestReviewSummaryService.getArsDetails("K4411C00Y")
await(x).status must be(OK)
}
}
}
示例4: 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
}
示例5: ProtractorSpec
//设置package包名称以及导入依赖的类
import org.scalatestplus.play.{OneServerPerSuite, PlaySpec}
import play.api.libs.ws.WSClient
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.io.Source._
import scala.sys.process.{Process, ProcessIO}
class ProtractorSpec extends PlaySpec with OneServerPerSuite {
"my application" should {
"pass the protractor tests" in {
val baseUrl = s"http://localhost:$port/"
val wsClient = app.injector.instanceOf[WSClient]
val resp = Await.result(wsClient.url(baseUrl).get(), 2.seconds)
resp.status must be(200)
println(s"Executing protractor using command: 'npm run e2e -- --baseUrl $baseUrl")
runProtractorTests(baseUrl) must be(0)
}
}
private def runProtractorTests(baseUrl: String): Int = {
Process(s"npm run e2e -- --baseUrl $baseUrl", app.getFile("ui"))
.run(pipingInputAndOutput)
.exitValue()
}
private def pipingInputAndOutput = new ProcessIO(_ => (),
stdout => fromInputStream(stdout).getLines().foreach(println),
stderr => fromInputStream(stderr).getLines().foreach(println)
)
}
示例6: mongoConfiguration
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.agentrelationships.support
import org.scalatest.{BeforeAndAfterEach, Suite}
import org.scalatestplus.play.OneServerPerSuite
import uk.gov.hmrc.mongo.{MongoSpecSupport, Awaiting => MongoAwaiting}
import scala.concurrent.ExecutionContext
import scala.concurrent.ExecutionContext.global
trait MongoApp extends MongoSpecSupport with ResetMongoBeforeTest with OneServerPerSuite {
me: Suite =>
protected def mongoConfiguration = Map("mongodb.uri" -> mongoUri)
}
trait ResetMongoBeforeTest extends BeforeAndAfterEach {
me: Suite with MongoSpecSupport =>
override protected def beforeEach(): Unit = {
super.beforeEach()
dropMongoDb()
}
def dropMongoDb()(implicit ec: ExecutionContext = global): Unit = {
Awaiting.await(mongo().drop())
}
}
object Awaiting extends MongoAwaiting
示例7: RendererISpec
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.emailrenderertemplate
import org.scalatest.words.EmptyWord
import org.scalatestplus.play.{OneServerPerSuite, PlaySpec, WsScalaTestClient}
import play.api.http.Status
import play.api.libs.json.Json
import play.api.test.Helpers._
class RendererISpec extends PlaySpec with OneServerPerSuite with WsScalaTestClient {
"email renderer" should {
"render the html and text content for sample1 template" in {
val result = await(wsUrl("/templates/sample1").
post(Json.obj("parameters" -> Json.obj("name" -> "Dr. Bruce Banner"))))
result.status mustBe Status.OK
(result.json \ "fromAddress").as[String] mustBe "<sample1> @gov.uk"
(result.json \ "subject").as[String] mustBe "New message for sample1 template"
(result.json \ "service").as[String] mustBe "REPLACE WITH YOUR TAX DOMAIN"
(result.json \ "plain").as[String] mustNot be(new EmptyWord())
(result.json \ "html").as[String] mustNot be(new EmptyWord())
(result.json \ "priority").as[String] mustBe "standard"
}
"return NOT_FOUND if template does not exist" in {
val result = await(wsUrl("/templates/notExistTemplate").
post(Json.obj("parameters" -> Json.obj("name" -> "Dr. Bruce Banner"))))
result.status mustBe NOT_FOUND
(result.json \ "reason").as[String] mustBe "Missing template with id: notExistTemplate"
}
"return BAD_REQUEST if required parameter is not in the request body" in {
val result = await(wsUrl("/templates/sample1").
post(Json.obj("parameters" -> Json.obj("noName" -> "Dr. Bruce Banner"))))
result.status mustBe BAD_REQUEST
(result.json \ "reason").as[String] mustBe "Failed to render template due to: key not found: name"
}
}
}
示例8: RendererControllerISpec
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.hmrcemailrenderer
import org.scalatest.concurrent.ScalaFutures
import org.scalatestplus.play.{OneServerPerSuite, ServerProvider, WsScalaTestClient}
import play.api.libs.json._
import uk.gov.hmrc.play.config.ServicesConfig
import uk.gov.hmrc.play.http.test.ResponseMatchers
import uk.gov.hmrc.play.test.UnitSpec
class RendererControllerISpec extends UnitSpec
with ServicesConfig
with WsScalaTestClient
with OneServerPerSuite
with ScalaFutures
with ResponseMatchers
with ServerProvider {
"POST /templates/:templateId" should {
"return 200 and yield the rendered template data when supplied a valid templateId" in {
val params = Map(
"verificationLink" -> "/abc"
)
val response = wsUrl(s"/templates/verifyEmailAddress").post(Json.obj("parameters" -> params))
response should have(
status(200),
jsonProperty(__ \ "fromAddress", "HMRC digital <[email protected]>"),
jsonProperty(__ \ "subject", "HMRC electronic communications: verify your email address"),
jsonProperty(__ \ "service", "sa"),
jsonProperty(__ \ "plain"),
jsonProperty(__ \ "html")
)
}
"return 404 when a non-existent templateId is specified on the path" in {
wsUrl(s"/templates/nonExistentTemplateId").
post(Json.obj("parameters" -> Map.empty[String, String])) should have(status(404))
}
"return 400 and indicate the first point of failure when the parameters for the template are not supplied" in {
wsUrl(s"/templates/verifyEmailAddress")
.post(Json.obj("parameters" -> Map.empty[String, String])) should have(
status(400),
jsonProperty(__ \ "reason", "key not found: verificationLink")
)
}
}
}
示例9: ProtractorSpec
//设置package包名称以及导入依赖的类
import org.scalatestplus.play.{OneServerPerSuite, PlaySpec}
import play.api.libs.ws.WSClient
import scala.concurrent.Await
import scala.concurrent.duration._
import scala.io.Source._
import scala.sys.process.{Process, ProcessIO}
class ProtractorSpec extends PlaySpec with OneServerPerSuite {
"my application" should {
"pass the protractor tests" in {
val baseUrl = s"http://localhost:$port/"
val wsClient = app.injector.instanceOf[WSClient]
val resp = Await.result(wsClient.url(baseUrl).get(), 2.seconds)
resp.status must be(200)
println(s"Executing protractor using command: 'npm run play-e2e -- --baseUrl $baseUrl")
runProtractorTests(baseUrl) must be(0)
}
}
private def runProtractorTests(baseUrl: String): Int = {
var runProtractor: String = "npm run play-e2e -- --baseUrl " + baseUrl
if (System.getProperty("os.name").toLowerCase().contains("win")){
runProtractor = "cmd /c " + runProtractor
}
Process(runProtractor, app.getFile("ui"))
.run(pipingInputAndOutput)
.exitValue()
}
private def pipingInputAndOutput = new ProcessIO(_ => (),
stdout => fromInputStream(stdout).getLines().foreach(println),
stderr => fromInputStream(stderr).getLines().foreach(println)
)
}
示例10: IntegrationSpec
//设置package包名称以及导入依赖的类
import org.junit.runner._
import org.scalatest.junit.JUnitRunner
import org.scalatestplus.play.{BrowserInfo, AllBrowsersPerSuite, ChromeInfo, FirefoxInfo, OneServerPerSuite, PlaySpec}
@RunWith(classOf[JUnitRunner])
class IntegrationSpec extends PlaySpec with OneServerPerSuite with AllBrowsersPerSuite {
override lazy val browsers = Vector(
FirefoxInfo(firefoxProfile),
ChromeInfo
)
def sharedTests(browser: BrowserInfo) = {
"Application" must {
"????????? " + browser.name in {
go to ("http://localhost:" + port)
pageTitle mustEqual "Hello, world!"
eventually {
find(className("greeting")).get.text mustEqual "?????????"
}
}
}
}
}
示例11: ApplicationSpec
//设置package包名称以及导入依赖的类
import org.scalatestplus.play.{OneServerPerSuite, PlaySpec}
import play.api.libs.ws._
import play.mvc.Http.Status._
class ApplicationSpec extends PlaySpec with OneServerPerSuite {
implicit val ws: WSClient = app.injector.instanceOf[WSClient]
val baseURL: String = s"http://localhost:$port/"
"Application" should {
"be reachable" in {
Util.getResponse(baseURL) { res =>
res.status mustBe OK
}
}
"return 404 on bad request" in {
Util.getResponse(baseURL + "badResponse") { res =>
res.status mustBe NOT_FOUND
}
}
}
}
示例12: APISpec
//设置package包名称以及导入依赖的类
import org.scalatestplus.play.{OneServerPerSuite, PlaySpec}
import play.api.libs.json.Json
import play.api.libs.ws._
import play.mvc.Http.Status._
class APISpec extends PlaySpec with OneServerPerSuite {
implicit val ws: WSClient = app.injector.instanceOf[WSClient]
val baseURL: String = s"http://localhost:$port/api/"
val channelID: String = "UCboMX_UNgaPBsUOIgasn3-Q"
"API" must {
//TODO better define tests
"return a random video on /api/getRandomVideo/:channelID" in {
Util.getResponse(baseURL + "getRandomVideo/" + channelID) { res =>
res.status mustBe OK
assert(!res.body.isEmpty)
}
}
"return a random video on /api/getRandomPlaylist/:channelID" in {
Util.getResponse(baseURL + "getRandomPlaylist/" + channelID) { res =>
res.status mustBe OK
assert(!res.body.isEmpty)
}
}
"return a random queue on /api/getQueue/:channelID with no filters" in {
Util.postResponse(baseURL + "getQueue/" + channelID,
Json.obj(
"series" -> Seq[String](),
"filters" -> Seq[String](),
"options" -> Json.obj(
"matchMethod" -> "matchAll",
"videoCount" -> 50
)
)) { res =>
res.status mustBe OK
assert(!res.body.isEmpty)
}
}
}
}
示例13: ProtractorSpec
//设置package包名称以及导入依赖的类
import org.scalatestplus.play.{OneServerPerSuite, PlaySpec}
import play.api.libs.ws.WSClient
import scala.concurrent.Await
import scala.sys.process.{Process, ProcessIO}
import scala.io.Source._
import scala.concurrent.duration._
class ProtractorSpec extends PlaySpec with OneServerPerSuite {
"my application" should {
"pass the protractor tests" in {
val baseUrl = s"http://localhost:$port"
val wsClient = app.injector.instanceOf[WSClient]
val resp = Await.result(wsClient.url(baseUrl).get(), 2.seconds)
resp.status === 200
println(s"Executing protractor using command: 'node_modules/protractor/bin/protractor --baseUrl=$baseUrl")
runProtractorTests(baseUrl) === 0
}
}
private def compileE2Etests: Int = {
Process("tsc" :: "-p" :: "e2e" :: Nil, app.getFile("ui"))
.run(usingProcessIO)
.exitValue()
}
private def runProtractorTests(baseUrl: String): Int = {
val e2eTestsCompilationResult = compileE2Etests
if (e2eTestsCompilationResult === 0) {
Process("node_modules/protractor/bin/protractor" :: s"--baseUrl=$baseUrl" :: Nil, app.getFile("ui"))
.run(usingProcessIO)
.exitValue()
} else e2eTestsCompilationResult
}
private def usingProcessIO = new ProcessIO(_ => (),
stdout => fromInputStream(stdout).getLines().foreach(println),
stderr => fromInputStream(stderr).getLines().foreach(println)
)
}
示例14: BaseISpec
//设置package包名称以及导入依赖的类
package uk.gov.hmrc.agentsubscription.support
import org.scalatestplus.play.OneServerPerSuite
import play.api.Application
import play.api.inject.guice.GuiceApplicationBuilder
import uk.gov.hmrc.play.test.UnitSpec
abstract class BaseISpec extends UnitSpec with OneServerPerSuite with WireMockSupport {
override implicit lazy val app: Application = appBuilder
.build()
protected def appBuilder: GuiceApplicationBuilder =
new GuiceApplicationBuilder()
.configure(
"microservice.services.auth.port" -> wireMockPort,
"microservice.services.des.port" -> wireMockPort,
"microservice.services.gg.port" -> wireMockPort,
"microservice.services.gg-admin.port" -> wireMockPort
)
}