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

Scala PlaySpec类代码示例

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

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



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

示例1: CountriesDestroySpec

//设置package包名称以及导入依赖的类
import org.scalatest.BeforeAndAfterAll
import org.scalatestplus.play.PlaySpec

import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test.FakeRequest
import play.api.test.Helpers._

import play.api.libs.json._

import test.helpers.{DatabaseCleaner, DatabaseInserter}

import play.api.Play

import utils.TimeUtil.now

class CountriesDestroySpec extends PlaySpec with BeforeAndAfterAll {
  val app = new GuiceApplicationBuilder().build

  override def beforeAll() {
    Play.maybeApplication match {
      case Some(app) => ()
      case _ => Play.start(app)
    }

    DatabaseCleaner.clean(List("Countries"))
    DatabaseInserter.insert("Users", 12, List("[email protected]", "John", "Doe", "password", "token", now.toString, "User", "1", "999999", "2016-01-01"))
    DatabaseInserter.insert("Users", 13, List("[email protected]", "Johnny", "Doe", "password", "admin_token", now.toString, "Admin", "1", "999999", "2016-01-01"))
    DatabaseInserter.insert("Countries", 11, List("Denmark", "DEN", "1", "2016-10-10"))
  }

  override def afterAll() {
    DatabaseCleaner.clean(List("Countries"))
  }

  "deleting countries" should {
    "returns 404 if no such record" in {
      val request = FakeRequest(DELETE, "/countries/200").withHeaders("Authorization" -> "admin_token")
      val destroy = route(app, request).get

      status(destroy) mustBe NOT_FOUND
    }

    "returns 204 if successfully deleted and user is Admin" in {
      val request = FakeRequest(DELETE, "/countries/11").withHeaders("Authorization" -> "admin_token")
      val destroy = route(app, request).get

      status(destroy) mustBe NO_CONTENT
    }

    "returns 403 if user is not Admin" in {
      val request = FakeRequest(DELETE, "/countries/11").withHeaders("Authorization" -> "token")
      val destroy = route(app, request).get

      status(destroy) mustBe FORBIDDEN
    }
  }
} 
开发者ID:dsounded,项目名称:money_exchanger,代码行数:58,代码来源:CountriesDestroySpec.scala


示例2: myPublicAddress

//设置package包名称以及导入依赖的类
package org.zalando.hutmann.spec

import org.scalatest.concurrent.PatienceConfiguration.Interval
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{ Seconds, Span }
import org.scalatestplus.play.{ PlaySpec, PortNumber, WsScalaTestClient }
import play.api.Application
import play.api.http.{ HeaderNames, MimeTypes }
import play.api.libs.ws.{ WSClient, WSResponse }

trait PlayUnitSpec extends PlaySpec with ScalaFutures with WsScalaTestClient {
  def myPublicAddress(): String
  implicit val portNumber: PortNumber

  def callWs(testPaymentGatewayURL: String)(implicit app: Application): WSResponse = {
    implicit val wSClient = app.injector.instanceOf[WSClient]
    val callbackURL = s"http://${myPublicAddress()}/callback"
    whenReady(
      wsUrl(testPaymentGatewayURL)
        .withQueryStringParameters("callbackURL" -> callbackURL)
        .withHttpHeaders(HeaderNames.ACCEPT -> MimeTypes.TEXT)
        .get(),
      Interval(Span(10, Seconds))
    ) { result =>
        result
      }
  }
} 
开发者ID:zalando-incubator,项目名称:hutmann,代码行数:29,代码来源:PlayUnitSpec.scala


示例3: PlayWithFoodWithTestComponents

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

import config.ExampleComponents
import org.scalatest.BeforeAndAfterEach
import org.scalatestplus.play.PlaySpec
import org.scalatestplus.play.components.OneServerPerTestWithComponents
import play.api.db.evolutions.Evolutions
import play.api.http.Status
import play.api.libs.ws.WSClient
import play.api.test.{DefaultAwaitTimeout, FutureAwaits, Helpers, TestServer}
import play.api.{Application, Configuration}
import slick.dbio.DBIO

trait PlayWithFoodWithServerBaseTest extends PlaySpec
  with OneServerPerTestWithComponents
  with DefaultFutureDuration
  with DefaultExecutionContext
  with Status
  with DefaultAwaitTimeout
  with FutureAwaits
  with BeforeAndAfterEach {

  class PlayWithFoodWithTestComponents extends ExampleComponents(context) {

    override def configuration: Configuration = {
      val testConfig = Configuration.from(TestUtils.config)
      val config = super.configuration
      val testConfigMerged = config ++ testConfig
      config.toString
      testConfigMerged
    }

    implicit lazy val testWsClient: WSClient = wsClient
  }

  override def components: PlayWithFoodWithTestComponents = new PlayWithFoodWithTestComponents

  private def runServerAndCleanUpInMemDb(c: PlayWithFoodWithTestComponents) = {
    runServerAndExecute(c.application) {
      val dbapi = c.dbApi
      Evolutions.cleanupEvolutions(dbapi.database("default"))
    }
  }

  override protected def afterEach(): Unit = {
    runServerAndCleanUpInMemDb(components)
  }

  protected def runServerAndExecute[T](app: Application)(blockWithComponents: => T): T = {
    Helpers.running(TestServer(port, app))(blockWithComponents)
  }

  def runAndAwaitResult[T](action: DBIO[T])(implicit components: ExampleComponents): T = {
    TestUtils.runAndAwaitResult(action)(components.actionRunner, duration)
  }

} 
开发者ID:Dasiu,项目名称:play-framework-scala-example-project,代码行数:58,代码来源:PlayWithFoodWithServerBaseTest.scala


示例4: MongoSpec

//设置package包名称以及导入依赖的类
import com.fasterxml.jackson.annotation.JsonValue
import org.scalatestplus.play.PlaySpec
import play.api.test._
import play.modules.reactivemongo._
import services._
import connectors._
import play.api.libs.json.{JsValue, Json}
import reactivemongo.api.collections.bson.BSONCollection
import reactivemongo.bson
import reactivemongo.bson.{BSONDocument, BSONObjectID}
import play.api.test.Helpers._

class MongoSpec extends PlaySpec {

  val mongo = new MongoExecutor(new MyMongoConnection)

  "mongo" should {
    val document = BSONDocument(
      "_id" -> BSONObjectID.parse("5951aa22c8e144a1c7e2b9dc").get,
      "name" -> "mongoTest",
      "requests" -> 0,
      "userErrors" -> 0
    )

    "return a BSON document" in {
      val result = await(mongo.getController("mongoTest"))
      result mustBe Some(document)
      result match {
        case Some(document) => document.getAs[Int]("requests").map(x => x mustBe 0)
        case None => throw fail("No document found")
      }
    }
  }
} 
开发者ID:ZDevelop94,项目名称:ZolvedIT,代码行数:35,代码来源:MongoSpec.scala


示例5: 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")
      }
    }
  }
} 
开发者ID:Hejocaso,项目名称:LunchApp,代码行数:44,代码来源:HomePageControllerSpec.scala


示例6: 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")
      }
    }
  }
} 
开发者ID:Hejocaso,项目名称:LunchApp,代码行数:29,代码来源:BreakfastAppControllerSpec.scala


示例7: SessionCreateSpec

//设置package包名称以及导入依赖的类
import org.scalatest.BeforeAndAfterAll
import org.scalatestplus.play.PlaySpec

import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test.FakeRequest
import play.api.test.Helpers._

import play.api.libs.json._

import test.helpers.{DatabaseCleaner, DatabaseInserter}

import play.api.Play

import com.github.t3hnar.bcrypt._

class SessionCreateSpec extends PlaySpec with BeforeAndAfterAll {
  val app = new GuiceApplicationBuilder().build

  override def beforeAll() {
    Play.maybeApplication match {
      case Some(app) => ()
      case _ => Play.start(app)
    }

    DatabaseCleaner.clean(List("Users"))

    val password = "password".bcrypt

    DatabaseInserter.insert("Users", 12, List("[email protected]", "John", "Doe", password, "token", "2016-01-01", "User", "1", "999999", "2016-01-01"))
  }

  override def afterAll() {
    DatabaseCleaner.clean(List("Users"))
  }

  "creates session if data is ok" in {
    val request = FakeRequest(POST, "/session").withJsonBody(Json.parse("""{ "email":"[email protected]", "password":"password" }"""))
    val create = route(app, request).get

    status(create) mustBe CREATED
    contentType(create) mustBe Some("application/json")
    contentAsString(create) must include("user")
    contentAsString(create) must include("authToken")
  }

  "responses with error if data is not ok" in {
    val request = FakeRequest(POST, "/session").withJsonBody(Json.parse("""{ "email":"[email protected]", "password":"bad_password" }"""))
    val create = route(app, request).get

    status(create) mustBe BAD_REQUEST
    contentType(create) mustBe Some("application/json")
    contentAsString(create) must include("error")
  }
} 
开发者ID:dsounded,项目名称:money_exchanger,代码行数:55,代码来源:SessionCreateSpec.scala


示例8: CountriesShowSpec

//设置package包名称以及导入依赖的类
import org.scalatest.BeforeAndAfterAll
import org.scalatestplus.play.PlaySpec

import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test.FakeRequest
import play.api.test.Helpers._

import play.api.libs.json._

import test.helpers.{DatabaseCleaner, DatabaseInserter}

import play.api.Play

import utils.TimeUtil.now

class CountriesShowSpec extends PlaySpec with BeforeAndAfterAll {
  val app = new GuiceApplicationBuilder().build

  override def beforeAll() {
    Play.maybeApplication match {
      case Some(app) => ()
      case _ => Play.start(app)
    }

    DatabaseCleaner.clean(List("Countries"))
    DatabaseInserter.insert("Users", 12, List("[email protected]", "John", "Doe", "password", "token", now.toString, "User", "1", "999999", "2016-01-01"))
    DatabaseInserter.insert("Countries", 88, List("Austria", "AU", "0", "2015-01-01"))
  }

  override def afterAll() {
    DatabaseCleaner.clean(List("Countries"))
  }

  "renders error" in {
    val request = FakeRequest(GET, "/countries/20").withHeaders("Authorization" -> "token")
    val show = route(app, request).get

    status(show) mustBe NOT_FOUND
    contentType(show) mustBe Some("application/json")
    contentAsString(show) must include("error")
    contentAsString(show) must include("not found")
  }

  "renders country" in {
    val request = FakeRequest(GET, "/countries/88").withHeaders("Authorization" -> "token")
    val show = route(app, request).get

    status(show) mustBe OK
    contentType(show) mustBe Some("application/json")
    contentAsString(show) must include("country")
  }
} 
开发者ID:dsounded,项目名称:money_exchanger,代码行数:53,代码来源:CountriesShowSpec.scala


示例9: CountriesIndexSpec

//设置package包名称以及导入依赖的类
import org.scalatest.BeforeAndAfterAll
import org.scalatestplus.play.PlaySpec

import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test.FakeRequest
import play.api.test.Helpers._

import play.api.libs.json._

import test.helpers.{DatabaseCleaner, DatabaseInserter}

import play.api.Play

import utils.TimeUtil.now

class CountriesIndexSpec extends PlaySpec with BeforeAndAfterAll {
  val app = new GuiceApplicationBuilder().build

  override def beforeAll() {
    Play.maybeApplication match {
      case Some(app) => ()
      case _ => Play.start(app)
    }

    DatabaseCleaner.clean(List("Countries"))
    DatabaseInserter.insert("Users", 12, List("[email protected]", "John", "Doe", "password", "token", now.toString, "User", "1", "999999", "2016-01-01"))
  }

  override def afterAll() {
    DatabaseCleaner.clean(List("Countries"))
  }

  "renders the forbidden for unauthorized response" in {
    val request = FakeRequest(GET, "/countries")
    val index = route(app, request).get

    status(index) mustBe FORBIDDEN
    contentType(index) mustBe Some("application/json")
    contentAsString(index) must include("errors")
  }

  "renders countries list for authorized user response" in {
    val request = FakeRequest(GET, "/countries").withHeaders("Authorization" -> "token")
    val index = route(app, request).get

    status(index) mustBe OK
    contentType(index) mustBe Some("application/json")
    contentAsString(index) must include("countries")
  }
} 
开发者ID:dsounded,项目名称:money_exchanger,代码行数:51,代码来源:CountriesIndexSpec.scala


示例10: CountriesCreateSpec

//设置package包名称以及导入依赖的类
import org.scalatest.BeforeAndAfterAll
import org.scalatestplus.play.PlaySpec

import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test.FakeRequest
import play.api.test.Helpers._

import play.api.libs.json._

import test.helpers.{DatabaseCleaner, DatabaseInserter}

import play.api.Play

import utils.TimeUtil.now

class CountriesCreateSpec extends PlaySpec with BeforeAndAfterAll {
  val app = new GuiceApplicationBuilder().build

  override def beforeAll() {
    Play.maybeApplication match {
      case Some(app) => ()
      case _ => Play.start(app)
    }

    DatabaseInserter.insert("Users", 12, List("[email protected]", "John", "Doe", "password", "token", now.toString, "Moderator", "1", "999999", "2016-01-01"))
    DatabaseCleaner.clean(List("Countries"))
  }

  override def afterAll() {
    DatabaseCleaner.clean(List("Countries"))
  }

  "saves the record on create" in {
    val request = FakeRequest(POST, "/countries").withJsonBody(Json.parse("""{ "country": {"title":"Germany", "abbreviation":"GER"} }""")).withHeaders("Authorization" -> "token")
    val create = route(app, request).get

    status(create) mustBe CREATED
    contentType(create) mustBe Some("application/json")
    contentAsString(create) must include("country")
  }
} 
开发者ID:dsounded,项目名称:money_exchanger,代码行数:42,代码来源:CountriesCreateSpec.scala


示例11: UsersIndexSpec

//设置package包名称以及导入依赖的类
import org.scalatest.BeforeAndAfterAll
import org.scalatestplus.play.PlaySpec

import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test.FakeRequest
import play.api.test.Helpers._

import play.api.libs.json._

import test.helpers.{DatabaseCleaner, DatabaseInserter}

import play.api.Play

import utils.TimeUtil.now

class UsersIndexSpec extends PlaySpec with BeforeAndAfterAll {
  val app = new GuiceApplicationBuilder().build

  override def beforeAll() {
    Play.maybeApplication match {
      case Some(app) => ()
      case _ => Play.start(app)
    }

    DatabaseCleaner.clean(List("Users"))
    DatabaseInserter.insert("Users", 12, List("[email protected]", "John", "Doe", "password", "token", now.toString, "User", "1", "999999", "2016-01-01"))
  }

  override def afterAll() {
    DatabaseCleaner.clean(List("Users"))
  }

  "renders the index response" in {
    val index = route(app, FakeRequest(GET, "/users").withHeaders("Authorization" -> "token")).get

    status(index) mustBe OK
    contentType(index) mustBe Some("application/json")
    contentAsString(index) must include("users")
    contentAsString(index) mustNot include("authToken")
  }
} 
开发者ID:dsounded,项目名称:money_exchanger,代码行数:42,代码来源:UsersIndexSpec.scala


示例12: UsersShowSpec

//设置package包名称以及导入依赖的类
import org.scalatest.BeforeAndAfterAll
import org.scalatestplus.play.PlaySpec

import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test.FakeRequest
import play.api.test.Helpers._

import play.api.libs.json._

import test.helpers.{DatabaseCleaner, DatabaseInserter}

import play.api.Play

import utils.TimeUtil.now

class UsersShowSpec extends PlaySpec with BeforeAndAfterAll {
  val app = new GuiceApplicationBuilder().build

  override def beforeAll() {
    Play.maybeApplication match {
      case Some(app) => ()
      case _ => Play.start(app)
    }

    DatabaseCleaner.clean(List("Users"))
    DatabaseInserter.insert("Users", 10, List("[email protected]", "John", "Doe", "password", "token", now.toString, "User", "1", "999999", "2016-01-01"))
  }

  override def afterAll() {
    DatabaseCleaner.clean(List("Users"))
  }

  "show response" should {
    "responses 404 if there is no such user" in {
      val show = route(app, FakeRequest(GET, "/users/1").withHeaders("Authorization" -> "token")).get

      status(show) mustBe NOT_FOUND
      contentType(show) mustBe Some("application/json")
      contentAsString(show) mustNot include("user")
    }

    "responses 200 if record exists" in {
      val show = route(app, FakeRequest(GET, "/users/10").withHeaders("Authorization" -> "token")).get

      status(show) mustBe OK
      contentAsString(show) must include("user")
      contentAsString(show) mustNot include("authToken")
    }
  }
} 
开发者ID:dsounded,项目名称:money_exchanger,代码行数:51,代码来源:UsersShowSpec.scala


示例13: UsersCreateSpec

//设置package包名称以及导入依赖的类
import org.scalatest.BeforeAndAfterAll
import org.scalatestplus.play.PlaySpec

import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test.FakeRequest
import play.api.test.Helpers._

import play.api.libs.json._

import test.helpers.DatabaseCleaner

import play.api.Play

class UsersCreateSpec extends PlaySpec with BeforeAndAfterAll {
  val app = new GuiceApplicationBuilder().build

  override def beforeAll() {
    Play.maybeApplication match {
      case Some(app) => ()
      case _ => Play.start(app)
    }

    DatabaseCleaner.clean(List("Users"))
  }

  override def afterAll() {
    DatabaseCleaner.clean(List("Users"))
  }

  "creating" should {
    "returns 400 if bad request" in {
      val request = FakeRequest(POST, "/users").withJsonBody(Json.parse("""{ "user": {"password":"pass"} }"""))
      val create = route(app, request).get

      status(create) mustBe BAD_REQUEST
      contentType(create) mustBe Some("application/json")
      contentAsString(create) must include("errors")
      contentAsString(create) must include("\"email\":[\"must not be empty\"]")
    }

    "returns 201 if request is acceptable" in {
      DatabaseCleaner.clean(List("Users"))

      val request = FakeRequest(POST, "/users").withHeaders("Authorization" -> "token").withJsonBody(Json.parse("""{ "user": {"email":"[email protected]", "password":"pass"} }"""))
      val create = route(app, request).get

      status(create) mustBe CREATED
      contentType(create) mustBe Some("application/json")
      contentAsString(create) must include("user")
      contentAsString(create) must include("authToken")
    }
  }
} 
开发者ID:dsounded,项目名称:money_exchanger,代码行数:54,代码来源:UsersCreateSpec.scala


示例14: DatabaseSpec

//设置package包名称以及导入依赖的类
import java.sql.{Driver, DriverManager}

import org.scalatest.BeforeAndAfter
import org.scalatestplus.play.PlaySpec
import play.api.Logger
import scalikejdbc._
import scalikejdbc.config.DBs

import scala.collection.mutable.Stack

class DatabaseSpec extends PlaySpec with BeforeAndAfter {
  implicit var session = AutoSession

  before {
    DBs.setupAll()
  }

  after {
    DBs.closeAll()
  }

  "Database" must {
    "List of database drivers" in {
      val drivers = DriverManager.getDrivers

      while (drivers.hasMoreElements) {
        val driver:Driver = drivers.nextElement()
        Logger.info(driver.toString)
      }
    }
    "Fetch users" in {
      val sql: SQL[Nothing, NoExtractor] = sql"select * from users"
      val map: SQL[Map[String, Any], HasExtractor] = sql.toMap
      val list: SQLToList[Map[String, Any], HasExtractor] = map.list
      val users: List[Map[String, Any]] = list.apply()
    }
  }

  "Slick" must {
    "How to use Scala test" in {
      // TODO
    }

    "throw NoSuchElementException if an empty stack is popped" in {
      val emptyStack = new Stack[Int]
      a [NoSuchElementException] must be thrownBy {
        emptyStack.pop()
      }
    }
  }
} 
开发者ID:esperia,项目名称:play-scala-sample,代码行数:52,代码来源:DatabaseSpec.scala


示例15: PlaySpecApplication

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

import org.scalatestplus.play.PlaySpec
import play.api.http.{ HeaderNames, HttpProtocol, HttpVerbs, Status }
import play.api.test._

class PlaySpecApplication extends PlaySpec
    with PlayRunners
    with HeaderNames
    with Status
    with HttpProtocol
    with DefaultAwaitTimeout
    with ResultExtractors
    with Writeables
    with RouteInvokers
    with FutureAwaits
    with HttpVerbs 
开发者ID:cm-wada-yusuke,项目名称:ecn-news,代码行数:18,代码来源:PlaySpecApplication.scala


示例16: UtilsTest

//设置package包名称以及导入依赖的类
import org.scalatestplus.play.PlaySpec
import utils.StringUtils

class UtilsTest extends PlaySpec {

  "StringUtils" should {

    "validate an email" in {
      val email_1 = "[email protected]"
      val email_2 = "[email protected]"

      StringUtils.isEmail(email_1) mustBe true
      StringUtils.isEmail(email_2) mustBe false
      StringUtils.isEmail(null) mustBe false
      StringUtils.isEmail("") mustBe false
    }

    "validate an uuid" in {
      val uuid_1 = "a6075fc2-07b7-4a71-9f99-e648daeda35e"
      val uuid_2 = "[email protected]"
      val uuid_3 = StringUtils.generateUuid()

      StringUtils.isUuid(uuid_1) mustBe true
      StringUtils.isUuid(uuid_2) mustBe false
      StringUtils.isUuid(uuid_3) mustBe true
      StringUtils.isUuid(null) mustBe false
      StringUtils.isUuid("") mustBe false
    }

    "validate an ip" in {
      val ip_1 = "192.128.1.1"
      val ip_2 = "567.98.3.12"
      val ip_3 = "ldfkjlgkjlgdjfgl"

      StringUtils.isIp(ip_1) mustBe true
      StringUtils.isIp(ip_2) mustBe false
      StringUtils.isIp(ip_3) mustBe false
      StringUtils.isIp(null) mustBe false
      StringUtils.isIp("") mustBe false
    }
  }
} 
开发者ID:Driox,项目名称:play-app-seed,代码行数:43,代码来源:UtilsTest.scala


示例17: AddonDescriptorControllerSpec

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

import io.toolsplus.atlassian.connect.play.models.AddonProperties
import org.scalatestplus.play.PlaySpec
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import play.api.Configuration
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.libs.json.Json
import play.api.test.FakeRequest
import play.api.test.Helpers._

class AddonDescriptorControllerSpec extends PlaySpec with GuiceOneAppPerSuite {

  val config = Configuration.reference ++ TestData.configuration
  val addonProperties = new AddonProperties(config)
  val $ = new AddonDescriptorController(addonProperties)

  override def fakeApplication() = {
    GuiceApplicationBuilder(configuration = config).build()
  }

  "AddonDescriptorController" when {

    "GET atlassian-connect.json" should {

      "render descriptor" in {
        val descriptor = $.descriptor.apply(FakeRequest())

        status(descriptor) mustBe OK
        contentType(descriptor) mustBe Some(JSON)

        val json = Json.parse(contentAsString(descriptor))
        (json \ "key").as[String] mustBe addonProperties.key
        (json \ "baseUrl").as[String] mustBe addonProperties.baseUrl
        (json \ "name")
          .as[String] mustBe config.getString("atlassian.connect.name").get
      }

    }

    "GET to base URL" should {

      "redirect to descriptor" in {
        val redirect = $.redirectToDescriptor.apply(FakeRequest())

        redirectLocation(redirect) mustBe Some(
          routes.AddonDescriptorController
            .descriptor()
            .url)
      }

    }

  }

} 
开发者ID:toolsplus,项目名称:atlassian-connect-play-seed,代码行数:57,代码来源:AddonDescriptorControllerSpec.scala


示例18: ServiceSpec

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

import models._
import org.mockito.Mockito._
import org.scalatest.mock.MockitoSugar
import org.scalatestplus.play.PlaySpec
import play.api.cache.CacheApi
import services._

class ServiceSpec extends PlaySpec with MockitoSugar {

  "UserService" should {
    "set list" in {
      val cacheService = mock[CacheTrait]
      val cache = mock[CacheApi]
      cacheService.setCache("kunal", SignUp("", "", "", "", "", "", "", false, false))
      when(cache.get[SignUp]("kunal")) thenReturn (Option(SignUp("", "", "", "", "", "", "", false, false)))
    }

    "get list" in {
      val cacheService = mock[CacheTrait]
      val cache = mock[CacheApi]
      cache.set("kunal", SignUp("", "", "", "", "", "", "", false, false))
      when(cacheService.getCache("kunal")) thenReturn (Option(SignUp("", "", "", "", "", "", "", false, false)))
    }

    "remove list" in {
      val cacheService = mock[CacheTrait]
      val cache = mock[CacheApi]
      cache.set("kunal", SignUp("kunal", "", "", "", "", "", "", false, false))
      cacheService.removeFromCache("kunal")
      when(cache.get("kunal")) thenReturn (None)

    }
  }
} 
开发者ID:kunals201,项目名称:play2-assignment-kunal-testcases,代码行数:37,代码来源:ServiceSpec.scala


示例19: writes

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

import models.Person
import org.joda.time.DateTime
import org.scalatestplus.play.{ OneAppPerTest, PlaySpec }
import play.api.libs.functional.syntax._
import play.api.libs.json.{ JsPath, Json, Reads, Writes }
import play.api.mvc.Result
import play.api.test.Helpers._
import play.api.test.{ FakeHeaders, FakeRequest }

import scala.concurrent.Future

trait PersonTestHelper extends PlaySpec with OneAppPerTest {

  private val PostHeaders = FakeHeaders(Seq("Content-type" -> "application/json"))

  private implicit val PersonWrites = new Writes[Person] {
    def writes(person: Person) = Json.obj(
      "id" -> person.id,
      "name" -> person.name,
      "age" -> person.age,
      "lastUpdate" -> person.lastUpdate
    )
  }

  private implicit val PersonReads: Reads[Person] = (
    (JsPath \ "id").read[Long] and
    (JsPath \ "name").read[String] and
    (JsPath \ "age").read[Int] and
    (JsPath \ "lastUpdate").read[DateTime]
  )(Person.apply _)

  def getPeople: Future[Result] = {
    val postRequest = FakeRequest(GET, controllers.routes.PersonController.returnPeople().url)
    route(app, postRequest).get
  }

  def postPerson(person: Person): Future[Result] = {
    val json = Json.toJson(person)
    val request = FakeRequest(POST, controllers.routes.PersonController.createPerson().url, PostHeaders, json)
    route(app, request).get
  }

  def persons(response: Future[Result]): Seq[Person] = {
    Json.fromJson[Seq[Person]](Json.parse(contentAsString(response))).get
  }
} 
开发者ID:marciogualtieri,项目名称:PersonService,代码行数:49,代码来源:PersonTestHelper.scala


示例20: EventSourceControllerSpec

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

import org.scalatest.concurrent.ScalaFutures
import org.scalatestplus.play.PlaySpec
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import play.api.test.FakeRequest
import play.api.test.Helpers._


class EventSourceControllerSpec extends PlaySpec
    with GuiceOneAppPerSuite
    with ScalaFutures
{
  "event source controller" should {
    "return OK through route" in {
      val request = FakeRequest(method = GET, path = "/scala/eventSource/liveClock")
      route(app, request) match {
        case Some(future) =>
          whenReady(future) { result =>
            result.header.status mustEqual(OK)
          }
        case None =>
          fail
      }
    }
  }
} 
开发者ID:juancamilogaviriaacosta,项目名称:proyecto-transmimetro-JuanGaviria-MauricioMontano,代码行数:28,代码来源:EventSourceControllerSpec.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Scala LocalDate类代码示例发布时间:2022-05-23
下一篇:
Scala Millis类代码示例发布时间: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