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


Scala FakeApplication类代码示例

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


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

示例1: ApiTest

//设置package包名称以及导入依赖的类
package global

import user.Fixtures

import scala.concurrent.Future
import play.api.libs.json.Json
import play.api.mvc.Result
import play.api.test.FakeApplication
import play.api.test.FakeRequest
import play.api.test.Helpers._
import org.scalatest.TestData

class ApiTest extends ApiSpecServer with TestUtils {

  implicit override def newAppForTest(td: TestData): FakeApplication = getFakeApp(new TestGlobal()(Fixtures))

  "The application " should {

    "return OK on ping" in {
      val result: Future[Result] = (new controllers.Application()).ping().apply(FakeRequest())
      val bodyText: String = contentAsString(result)
      bodyText mustBe "Ok"
    }
  }
} 
开发者ID:Driox,项目名称:play-app-seed,代码行数:26,代码来源:ApiTest.scala

示例2: FakeApplicationHelper

//设置package包名称以及导入依赖的类
package integration.helper

import play.api.mvc.{AnyContentAsEmpty, Result}
import play.api.test.Helpers._
import play.api.test.{FakeApplication, FakeRequest}
import play.api.{Application, Play}

import scala.concurrent.Await
import scala.concurrent.duration._
import scala.language.postfixOps

object FakeApplicationHelper {


  def withApplication(app: Application)(call: () => Unit): Unit = {
    Play.start(app)
    try {
      call()
    }
    finally {
      Play.stop(app)
    }
  }

  def call(fakeRequest: FakeRequest[AnyContentAsEmpty.type], application: Application): Option[Result] =
    route(application, fakeRequest).map(t => Await.result(t, 100000 seconds))


  def callWithBody(fakeRequest: FakeRequest[String], application: Application): Option[Result] =
    route(application, fakeRequest).map(t => Await.result(t, 100000 seconds))


  def application(host: String = "localhost", port: Option[Integer] = None): FakeApplication = {
    val portPart= port.map( port => s":$port").getOrElse("")
    FakeApplication(additionalConfiguration = Map(("server.uri", s"http://$host$portPart")))
  }

} 
开发者ID:innoq,项目名称:docster,代码行数:39,代码来源:FakeApplicationHelper.scala

示例3: WireMockHelper

//设置package包名称以及导入依赖的类
package integration.helper

import java.net.ServerSocket
import java.util.UUID

import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.matching.RequestPattern._
import com.github.tomakehurst.wiremock.verification.LoggedRequest
import integration.helper.FakeApplicationHelper.withApplication
import play.api.test.FakeApplication

object WireMockHelper {

  def findCapturedRequest(server: WireMockServer): LoggedRequest = {
    server.findRequestsMatching(everything()).getRequests.get(0)
  }

  def withAppAndMock(app: FakeApplication, server: WireMockServer, call: () => Unit): Unit = {
    withApplication(app) {
      () => withWireMock(server) {
        () => {
          call()
        }
      }
    }
  }

  def randomUri: String = {
    "/" + UUID.randomUUID()
  }


  def withWireMock(server: WireMockServer)(call: () => Unit): Unit = {
    server.start()
    try {
      call()
    } finally {
      server.shutdownServer()
    }
  }


  def freePort(): Int = {
    val socket = new ServerSocket(0)
    val port = socket.getLocalPort
    socket.close()
    port
  }

} 
开发者ID:innoq,项目名称:docster,代码行数:51,代码来源:WireMockHelper.scala

示例4: PizzaServiceSpec

//设置package包名称以及导入依赖的类
package servicesSpec

import org.junit.runner.RunWith
import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner
import play.api.test.Helpers.running
import play.api.test.FakeApplication
import services.PizzaService


@RunWith(classOf[JUnitRunner])
class PizzaServiceSpec extends Specification {

  def memDB[T](code: => T) =
    running(FakeApplication(additionalConfiguration = Map(
      "db.default.driver" -> "org.h2.Driver",
      "db.default.url" -> "jdbc:h2:mem:test;MODE=PostgreSQL"
    )))(code)

  "The PizzaService" should {

    "return a list of five Pizza" in memDB {
      PizzaService.availablePizza.length must be equalTo 4
    }

    "return a list of six Pizza after adding a Pizza called Popey" in memDB {
      PizzaService.addPizza("Popey",0.2,"Spinat","Stark","Alle")
      PizzaService.availablePizza.length must be equalTo 5
      PizzaService.availablePizza(4).name must be equalTo "Popey"
      PizzaService.availablePizza(4).comment must be equalTo "Stark"
    }

    "return updated values for name and comment of Pizza called Popey" in memDB {
      PizzaService.addPizza("Popey",0.2,"Spinat","Stark","Alle")
      PizzaService.updatePizza(4, "Popey", 0.3,"Spinat","Heiß","Nix")
      PizzaService.selectPizza(4).name must be equalTo "Popey"
      PizzaService.selectPizza(4).comment must be equalTo "Heiß"
    }

    "remove Pizza and return available Pizza" in memDB {
      PizzaService.addPizza("Popey",0.2,"Spinat","Stark","Alle")
      PizzaService.addPizza("Popey",0.2,"Spinat","Stark","Alle")
      PizzaService.availablePizza.length must be equalTo 6
      PizzaService.rmPizza(4)
      PizzaService.availablePizza(4).name must be equalTo "Popey"
      PizzaService.availablePizza(4).comment must be equalTo "Stark"
      PizzaService.availablePizza.length must be equalTo 5
    }
  }
} 
开发者ID:Chapere,项目名称:grp2A-pizza,代码行数:51,代码来源:PizzaServiceSpec.scala

示例5: OrderServiceSpec

//设置package包名称以及导入依赖的类
package servicesSpec

import org.junit.runner.RunWith
import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner
import play.api.test.FakeApplication
import play.api.test.Helpers.running
import services.OrderService


@RunWith(classOf[JUnitRunner])
class OrderServiceSpec extends Specification {

  def memDB[T](code: => T) =
    running(FakeApplication(additionalConfiguration = Map(
      "db.default.driver" -> "org.h2.Driver",
      "db.default.url" -> "jdbc:h2:mem:test;MODE=PostgreSQL"
    )))(code)

  "The OrderService" should {

    "return an empty list of orders" in memDB {
      OrderService.availableOrder.length must be equalTo 0
    }

    "create an order and return it" in memDB {
      OrderService.createOrder(1,1,0,"N/A","N/A",1,14,0,0,0,0,"N/A",0,0,"N/A",0,0,"N/A",0,"N/A","N/A","N/A")
      OrderService.availableOrder.length must be equalTo 1
      OrderService.getOrderbyID(1).pizzaPrice must be equalTo 0.60
      OrderService.availableOrderByID(1).head.pizzaName must be equalTo "Margherita"
      OrderService.availableOrderByID(1).head.status must be equalTo "Bestellung empfangen"
      OrderService.availableOrderWithAdress.head.adress must be equalTo "Lerchenauer Str. 12"
      OrderService.availableOrderWithAdress.head.city must be equalTo "München"
    }

    "change order status" in memDB {
      OrderService.createOrder(1,1,0,"N/A","N/A",1,14,0,0,0,0,"N/A",0,0,"N/A",0,0,"N/A",0,"N/A","N/A","N/A")
      OrderService.orderSetStaus(1,"ausgeliefert")
      OrderService.getOrderbyID(1).status must be equalTo "ausgeliefert"
    }

    "delete an order" in memDB {
      OrderService.createOrder(1,1,0,"N/A","N/A",1,14,0,0,0,0,"N/A",0,0,"N/A",0,0,"N/A",0,"N/A","N/A","N/A")
      OrderService.availableOrder.length must be equalTo 1
      OrderService.rmOrder(1)
      OrderService.availableOrder.length must be equalTo 0
    }

    "deactivate an order" in memDB {
      OrderService.createOrder(1,1,0,"N/A","N/A",1,14,0,0,0,0,"N/A",0,0,"N/A",0,0,"N/A",0,"N/A","N/A","N/A")
      OrderService.availableOrder.length must be equalTo 1
      OrderService.deactivateOrder(1)
      OrderService.availableOrder.length must be equalTo 1
      OrderService.getOrderbyID(1).status must be equalTo "Storniert"
    }
  }
} 
开发者ID:Chapere,项目名称:grp2A-pizza,代码行数:58,代码来源:OrderServiceSpec.scala

示例6: setupData

//设置package包名称以及导入依赖的类
package base

import models.store.{OrdersAction, ProductAction, UserStepAction}
import org.specs2.mock.Mockito
import org.specs2.specification.{BeforeAfterAll, BeforeAfterEach}
import play.api.test.{FakeApplication, PlaySpecification}
import play.api.{Application, Logger}
import slick.driver.MySQLDriver.api._
import utils.Slick

import scala.concurrent.Await

trait SpecBase extends PlaySpecification with Mockito with BeforeAfterEach with BeforeAfterAll with Slick{
    val logger = Logger.logger

    val app = {
        val application = FakeApplication(
            additionalConfiguration = Map("isTestApp" -> true))
        play.api.Play.start(application)
        application
    }

    private def setupData(application: Application) {
        if (application.configuration.getBoolean("isTestApp").getOrElse(false)) {
            Await.result( db.run(
                DBIO.seq(
                    OrdersAction.delete,
                    ProductAction.delete,
                    UserStepAction.delete
                )
            ),duration)
        }

    }

    def beforeAll(): Unit = {
    }

    override protected def before: Any = {
        setupData(app)
    }

    override protected def after: Any = {

    }

    def afterAll(): Unit = {
    }
} 
开发者ID:suya55,项目名称:kakaoYellowIdBot,代码行数:50,代码来源:SpecBase.scala

示例7: Statics

//设置package包名称以及导入依赖的类
package utilities

import java.io.File

import org.specs2.mutable.Specification
import org.specs2.specification.BeforeAfterEach
import play.api.Play
import play.api.db.evolutions.{OfflineEvolutions, Evolutions}
import play.api.test.{FakeApplication, FakeHeaders}
import play.api.test.Helpers._
import play.api.db._
import play.mvc.Http.MimeTypes

object Statics {


  def WithFreshDatabase[T](block: => T) = {
    val dbApi = Play.current.injector.instanceOf[DBApi]
    for(db <- dbApi.databases()) {
      Evolutions.cleanupEvolutions(db)
      Evolutions.applyEvolutions(db)
    }
    block
  }

  val jsonHeaders = FakeHeaders(Seq((CONTENT_TYPE, MimeTypes.JSON)))

  val conf = Map(
    "slick.dbs.default.driver" -> "slick.driver.H2Driver$",
    "slick.dbs.default.db.driver" -> "org.h2.Driver",
    "slick.dbs.default.db.url" -> "jdbc:h2:mem:test;MODE=PostgreSQL;DATABASE_TO_UPPER=FALSE"
  )

  val fakeApp: FakeApplication = new FakeApplication(additionalConfiguration = conf)

  Play.start(fakeApp)

} 
开发者ID:RichyHBM,项目名称:Dux,代码行数:39,代码来源:Statics.scala

示例8: SelfEmploymentAnnualSummaryFeatureSwitchSpec

//设置package包名称以及导入依赖的类
package uk.gov.hmrc.selfassessmentapi.featureswitch

import play.api.libs.json.Json
import play.api.test.FakeApplication
import uk.gov.hmrc.selfassessmentapi.resources.Jsons
import uk.gov.hmrc.selfassessmentapi.models.selfemployment.SelfEmploymentAnnualSummary
import uk.gov.hmrc.support.BaseFunctionalSpec

class SelfEmploymentAnnualSummaryFeatureSwitchSpec extends BaseFunctionalSpec {

  private val conf: Map[String, _] =
    Map("Test.feature-switch.self-employments" ->
      Map("enabled" -> true, "annual" -> Map("enabled" -> false), "periods" -> Map("enabled" -> true))
    )

  override lazy val app: FakeApplication = new FakeApplication(additionalConfiguration = conf)

  "self-employments" should {
    "not be visible if feature Switched Off" in {

      given()
        .userIsSubscribedToMtdFor(nino)
        .userIsFullyAuthorisedForTheResource
        .des().selfEmployment.willBeReturnedFor(nino)
        .when()
        .put(Json.toJson(SelfEmploymentAnnualSummary(None, None))).at(s"/ni/$nino/self-employments/abc/$taxYear")
        .thenAssertThat()
        .statusIs(404)
    }
  }

} 
开发者ID:hmrc,项目名称:self-assessment-api,代码行数:33,代码来源:SelfEmploymentAnnualSummaryFeatureSwitchSpec.scala

示例9: SelfEmploymentPeriodicSummaryFeatureSwitchSpec

//设置package包名称以及导入依赖的类
package uk.gov.hmrc.selfassessmentapi.featureswitch

import play.api.test.FakeApplication
import uk.gov.hmrc.selfassessmentapi.resources.Jsons
import uk.gov.hmrc.support.BaseFunctionalSpec

class SelfEmploymentPeriodicSummaryFeatureSwitchSpec extends BaseFunctionalSpec {

  private val conf: Map[String, _] =
    Map("Test" ->
      Map("feature-switch" ->
        Map("self-employments" ->
          Map("enabled" -> true, "annual" -> Map("enabled" -> true), "periods" -> Map("enabled" -> false))
        )
      )
    )

  override lazy val app: FakeApplication = new FakeApplication(additionalConfiguration = conf)

  "self-employments" should {
    "not be visible if feature Switched Off" in {
      given()
        .userIsSubscribedToMtdFor(nino)
        .userIsFullyAuthorisedForTheResource
        .des().selfEmployment.willBeCreatedFor(nino)
        .when()
        .post(Jsons.SelfEmployment()).to(s"/ni/$nino/self-employments")
        .thenAssertThat()
        .statusIs(201)
        .when()
        .get(s"%sourceLocation%/periods")
        .thenAssertThat()
        .statusIs(404)
    }
  }

} 
开发者ID:hmrc,项目名称:self-assessment-api,代码行数:38,代码来源:SelfEmploymentPeriodicSummaryFeatureSwitchSpec.scala

示例10: AgentSimulationFeatureSwitchDisabledSpec

//设置package包名称以及导入依赖的类
package uk.gov.hmrc.selfassessmentapi.featureswitch

import play.api.test.FakeApplication
import uk.gov.hmrc.selfassessmentapi.resources.GovTestScenarioHeader
import uk.gov.hmrc.support.BaseFunctionalSpec

class AgentSimulationFeatureSwitchDisabledSpec extends BaseFunctionalSpec {

  private val conf = Map("Test.feature-switch.test-scenario-simulation.enabled" -> false)

  override lazy val app: FakeApplication = new FakeApplication(additionalConfiguration = conf)

  "Agent simulation filters" should {
    "not be applied if feature is switched off" in {
      given()
        .userIsSubscribedToMtdFor(nino)
        .userIsFullyAuthorisedForTheResource
        .des().selfEmployment.willBeReturnedFor(nino)
        .when()
        .get(s"/ni/$nino/self-employments")
        .withHeaders(GovTestScenarioHeader, "AGENT_NOT_SUBSCRIBED")
        .thenAssertThat()
        .statusIs(200)
    }
  }

} 
开发者ID:hmrc,项目名称:self-assessment-api,代码行数:28,代码来源:AgentSimulationFeatureSwitchDisabledSpec.scala

示例11: SelfEmploymentFeatureSwitchSpec

//设置package包名称以及导入依赖的类
package uk.gov.hmrc.selfassessmentapi.featureswitch

import play.api.test.FakeApplication
import uk.gov.hmrc.selfassessmentapi.models.{SourceId, SourceType}
import uk.gov.hmrc.support.BaseFunctionalSpec

class SelfEmploymentFeatureSwitchSpec extends BaseFunctionalSpec {

  private val conf: Map[String, Map[SourceId, Map[SourceId, Map[SourceId, Any]]]] =
    Map("Test" ->
      Map("feature-switch" ->
        Map("self-employments" ->
          Map("enabled" -> false)
        )
      )
    )

  override lazy val app: FakeApplication = new FakeApplication(additionalConfiguration = conf)

  "self-employments" should {
    "not be visible if feature Switched Off" in {
      given()
        .userIsSubscribedToMtdFor(nino)
        .userIsFullyAuthorisedForTheResource
        .when()
        .get(s"/ni/$nino/${SourceType.SelfEmployments.toString}")
        .thenAssertThat()
        .statusIs(404)
    }
  }

} 
开发者ID:hmrc,项目名称:self-assessment-api,代码行数:33,代码来源:SelfEmploymentFeatureSwitchSpec.scala

示例12: AuthorisationDisabledSpec

//设置package包名称以及导入依赖的类
package uk.gov.hmrc.selfassessmentapi

import play.api.test.FakeApplication
import uk.gov.hmrc.selfassessmentapi.resources.Jsons
import uk.gov.hmrc.support.BaseFunctionalSpec

class AuthorisationDisabledSpec extends BaseFunctionalSpec {
  private val conf = Map("Test.microservice.services.auth.enabled" -> false)

  override lazy val app: FakeApplication = new FakeApplication(additionalConfiguration = conf)

  "when auth is disabled, any request" should {
    "be allowed" in {
      given()
        .des().selfEmployment.willBeCreatedFor(nino)
        .when()
        .post(Jsons.SelfEmployment()).to(s"/ni/$nino/self-employments")
        .thenAssertThat()
        .statusIs(201)
    }
  }
} 
开发者ID:hmrc,项目名称:self-assessment-api,代码行数:23,代码来源:AuthorisationDisabledSpec.scala

示例13: HomeViewSpec

//设置package包名称以及导入依赖的类
package views

import org.specs2.mutable.Specification
import play.api.test.FakeApplication
import play.api.test.Helpers._
import org.jsoup.Jsoup


class HomeViewSpec extends Specification{

  def getHtml() = {
    running(FakeApplication()) {
      val viewText = views.html.home().body
      Jsoup.parse(viewText)
    }
  }

  "Home page" should {

    val html=getHtml()

    "Heading must be" in {
      html.select("#head h1").text mustEqual "Pizza Hut"
    }

    "url for custom Pizza" in {
      html.select("#custPizza a").attr("href") mustEqual "/customPizza"
      html.select("#custPizza a").text mustEqual "Get custom Pizza"
    }

    "search button have correct lable" in {
      html.select("#searchBtn").attr("value") mustEqual "Search"
    }

    "having correct image" in {
      html.select("#custPizza img").attr("src") mustEqual "/assets/images/pizza1.jpg"
    }
  }

} 
开发者ID:Tausif10,项目名称:NewPizzaSystem,代码行数:41,代码来源:HomeViewSpec.scala

示例14: SearchViewSpec

//设置package包名称以及导入依赖的类
package views

import model.Types
import org.specs2.mutable.Specification
import play.api.test.FakeApplication
import play.api.test.Helpers._
import org.jsoup.Jsoup


class SearchViewSpec extends Specification{

  def getHtml() = {
    running(FakeApplication()) {
      val viewText = views.html.search("pizza",List(Types("normal","small","onion",100)),List("small"),List()).body
      Jsoup.parse(viewText)
    }
  }

  def getHtmlForEmptySizeList() = {
    running(FakeApplication()) {
      val viewText = views.html.search("pizza",List(Types("normal","small","onion",100)),Nil,List()).body
      Jsoup.parse(viewText)
    }
  }

  "Search " should {

    val html=getHtml()
    val htmlFoeEmptyFacet=getHtmlForEmptySizeList()

    "display size facet" in {
      html.select("#content").isEmpty mustEqual false
    }

    "if size is empty then does not show size facet" in {
      htmlFoeEmptyFacet.select("#content").isEmpty mustEqual true
    }

  }

} 
开发者ID:Tausif10,项目名称:NewPizzaSystem,代码行数:42,代码来源:SearchViewSpec.scala

示例15: inMemoryDatabase

//设置package包名称以及导入依赖的类
package org.intracer.finance.slick

import play.api.test.FakeApplication
import play.api.test.Helpers._

trait InMemDb {

  private def inMemoryDatabase(name: String = "default", options: Map[String, Any] = Map.empty[String, Any]): Map[String, Any] = {
    val optionsForDbUrl = options.map { case (k, v) => k + "=" + v }.mkString(";", ";", "")

    Map(
      "play.evolutions.enabled" -> true,
      ("slick.dbs." + name + ".driver") -> "slick.driver.H2Driver$",
      ("slick.dbs." + name + ".db.driver") -> "org.h2.Driver",
      ("slick.dbs." + name + ".db.url") -> ("jdbc:h2:mem:play-test-" + scala.util.Random.nextInt + optionsForDbUrl)
    )
  }

  def inMemDbApp[T](block: => T): T = {
    running(FakeApplication(additionalConfiguration = inMemoryDatabase()))(block)
  }

} 
开发者ID:intracer,项目名称:wmua-finance,代码行数:24,代码来源:InMemDb.scala


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