• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala FakeApplication类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: HotelFileReaderTest

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

import model.Hotel
import org.scalatest.{FunSpec, Matchers}
import play.api.Play
import play.api.Play.current
import play.api.test.{FakeApplication, Helpers}

class HotelFileReaderTest extends FunSpec with Matchers{

  describe("Hotel File Reader"){

    it("should read File and return hotels"){
      Helpers.running(FakeApplication()) {
        val filePath = Play.application.classloader.getResource("test.csv").getPath
        val reader = new HotelFileInputReader(filePath)
        val hotels = reader.read()

        hotels.size should be(4)

        hotels(0) should be(Hotel("Bangkok",1,"Deluxe",1000))
        hotels(2) should be(Hotel("Ashburn",3,"Sweet Suite",1300))
      }
    }
  }
} 
开发者ID:atiqsayyed,项目名称:request_throttling_hotel,代码行数:27,代码来源:HotelFileReaderTest.scala


示例17: UserServiceSpec

//设置package包名称以及导入依赖的类
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.UserService

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

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

  "The UserService" should {

    "add a new user" in memDB {
      UserService.addUser("[email protected]", "1", "Paula", "Huber", "Zeisigweg 4", 82346, "München", "Kunde") must be_!==(None)
    }

    "edit a user" in memDB {
      UserService.editUser(-20, "[email protected]", "1", "Paula", "Huber", "Zeisigweg 4", 82346, "München", "Kunde") must be_!==(None)
    }

    "delete a user" in memDB {
      UserService.deleteUser(-10) must beTrue
    }

    "delete an unexisting user" in memDB {
      UserService.deleteUser(1) must beFalse
    }

    "return list of users" in memDB {
      UserService.registeredUsers.length must be equalTo 2
    }

    "login user" in memDB {
      UserService.loginUser("[email protected]", "Suez82346").right.get.id must be equalTo -10
    }
  }
} 
开发者ID:maximilianoe,项目名称:grp1B-pizza,代码行数:44,代码来源:UserServiceSpec.scala


示例18: OrderDaoSpec

//设置package包名称以及导入依赖的类
import dbaccess.OrderDao
import models.OrderHistory
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

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

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

  "The OrderDao" should {

    "add an order to history" in memDB {
      OrderDao.addToHistory(OrderHistory(-1, -20, "Susanne Emil, Ulrichstr. 1, 82343 Pöcking", "1x Margarita (medium)", 6.21, "20.05.2017", "in Bearbeitung")) must be_!==(None)
    }

    "delete an order" in memDB {
      OrderDao.addToHistory(OrderHistory(-1, -20, "Susanne Emil, Ulrichstr. 1, 82343 Pöcking", "1x Margarita (medium)", 6.21, "20.05.2017", "in Bearbeitung"))
      OrderDao.rmFromHistory(1) must beTrue
    }

    "delete an unexisting order" in memDB {
      OrderDao.rmFromHistory(-1) must beFalse
    }

    "return a list of all orders" in memDB {
      OrderDao.addToHistory(OrderHistory(-1, -20, "Susanne Emil, Ulrichstr. 1, 82343 Pöcking", "1x Margarita (medium)", 6.21, "20.05.2017", "in Bearbeitung"))
      OrderDao.addToHistory(OrderHistory(-1, -20, "Susanne Emil, Ulrichstr. 1, 82343 Pöcking", "1x Regina (medium)", 7.29, "20.05.2017", "in Bearbeitung"))
      val orders = OrderDao.showOrdersEmployee
      orders.length must be equalTo 2
      orders(0).orderedProducts.contains("Margarita")
      orders(1).orderedProducts.contains("Regina")
    }

    "return a list of orders from customer" in memDB {
      OrderDao.addToHistory(OrderHistory(-1, -20, "Susanne Emil, Ulrichstr. 1, 82343 Pöcking", "1x Margarita (medium)", 6.21, "20.05.2017", "in Bearbeitung"))
      OrderDao.addToHistory(OrderHistory(-1, -10, "Herbert Padrone, Kientalstr. 10, 82346 Andechs", "1x Regina (medium)", 7.29, "20.05.2017", "in Bearbeitung"))
      val orders = OrderDao.showOrdersUser(-20)
      orders.length must be equalTo 1
      orders(0).orderedProducts.contains("Margarita")
    }

    "update status for order" in memDB {
      OrderDao.addToHistory(OrderHistory(-1, -20, "Susanne Emil, Ulrichstr. 1, 82343 Pöcking", "1x Margarita (medium)", 6.21, "20.05.2017", "in Bearbeitung"))
      OrderDao.setStatusForOrder(1, "in Auslieferung")
      val orders = OrderDao.showOrdersUser(-20)
      orders(0).status must be equalTo "in Auslieferung"
    }
  }
} 
开发者ID:maximilianoe,项目名称:grp1B-pizza,代码行数:58,代码来源:OrderDaoSpec.scala


示例19: UserDaoSpec

//设置package包名称以及导入依赖的类
import dbaccess.{OrderDao, UserDao}
import models.{OrderHistory, User}
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

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

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

  "The UserDao" should {

    "add a new user" in memDB {
      UserDao.addUser(User(-1, "[email protected]", "1", "Paula", "Huber", "Zeisigweg 4", 82346, "München", "Kunde", false)) must be_!==(None)
    }

    "add an existing user" in memDB {
      UserDao.addUser(User(-1, "[email protected]", "", "", "", "", 1, "", "", false)) must be_!==(None)
    }

    "edit a user" in memDB {
      val user = User(-20, "[email protected]", "1", "Paula", "Huber", "Zeisigweg 4", 82346, "München", "Kunde", false)
      UserDao.editUser(user) must be_==(user)
    }

    "delete a user" in memDB {
      UserDao.deleteUser(-10) must beTrue
    }

    "delete an unexisting user" in memDB {
      UserDao.deleteUser(-1) must beFalse
    }

    "delete a user with existing orders" in memDB {
      OrderDao.addToHistory(OrderHistory(-1, -10, "Herbert Padrone, Kientalstr. 10, 82346 Andechs", "1x Regina (medium)", 7.29, "20.05.2017", "in Bearbeitung"))
      UserDao.deleteUser(-10) must beTrue
    }

    "return list of users" in memDB {
      UserDao.registeredUsers.length must be equalTo 2
    }

    "login user" in memDB {
      UserDao.loginUser("[email protected]", "Suez82346").right.get.id must be equalTo -10
    }
  }
} 
开发者ID:maximilianoe,项目名称:grp1B-pizza,代码行数:55,代码来源:UserDaoSpec.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala write类代码示例发布时间:2022-05-23
下一篇:
Scala LoggingReceive类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap