本文整理汇总了Scala中org.scalatestplus.play.OneAppPerTest类的典型用法代码示例。如果您正苦于以下问题:Scala OneAppPerTest类的具体用法?Scala OneAppPerTest怎么用?Scala OneAppPerTest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OneAppPerTest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: UsersSpec
//设置package包名称以及导入依赖的类
package models
import _root_.test._
import org.scalatest.Matchers._
import org.scalatest.{ TestData, WordSpec }
import org.scalatestplus.play.OneAppPerTest
import play.api._
class UsersSpec extends WordSpec with OneAppPerTest {
override def newAppForTest(testData: TestData): Application = fakeApp
"Users" should {
"create and find" in {
val users = app.injector.instanceOf(classOf[Users])
val user = users.create(User(0L, "test1", true))
user.id !== 0L
val userFound = users.find(user.id)
userFound shouldBe defined
userFound.foreach(_.name shouldBe "test1")
}
}
}
示例2: 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
}
}
示例3: SchemaSpec
//设置package包名称以及导入依赖的类
package models
import org.scalatestplus.play.{OneAppPerTest, PlaySpec}
import slick.driver.SQLiteDriver.api._
class SchemaSpec extends PlaySpec with OneAppPerTest {
"Accounts" should {
"print the table schema" in {
Accounts.schema.createStatements.foreach(println)
}
}
"Users" should {
"print the table schema" in {
Users.schema.createStatements.foreach(println)
}
}
"Posts" should {
"print the table schema" in {
Posts.schema.createStatements.foreach(println)
}
}
}
示例4: RootControllerSuite
//设置package包名称以及导入依赖的类
package controllers
import org.scalatestplus.play.{OneAppPerTest, PlaySpec}
import play.api.test.FakeRequest
import play.api.test.Helpers._
import utils.TimeTestSpec
class RootControllerSuite extends PlaySpec with OneAppPerTest with TimeTestSpec {
"index action" should {
"render index page" in withFixture {
finishMaintenance()
val index = route(app, FakeRequest(GET, "/")).get
status(index) mustBe OK
contentType(index) mustBe Some("text/html")
contentAsString(index) must include ("Your new application is ready.")
}
"render maintenance page when maintenance" in withFixture {
startMaintenance()
val index = route(app, FakeRequest(GET, "/")).get
status(index) mustBe OK
contentType(index) mustBe Some("text/html")
contentAsString(index) must include ("Under maintenance.")
}
}
"api action" should {
"return OK" in withFixture {
finishMaintenance()
route(app, FakeRequest(GET, "/api")).map(status) mustBe Some(OK)
}
"return ServiceUnavailable when maintenance" in withFixture {
startMaintenance()
route(app, FakeRequest(GET, "/api")).map(status) mustBe Some(SERVICE_UNAVAILABLE)
}
}
}
示例5: StorageUrlControllerTest
//设置package包名称以及导入依赖的类
package controllers.storage
import com.google.gson.Gson
import domain.storage.StorageUrl
import org.scalatestplus.play.{OneAppPerTest, PlaySpec}
import play.api.libs.json.Json
import play.api.test.FakeRequest
import play.api.test.Helpers._
class StorageUrlControllerTest extends PlaySpec with OneAppPerTest {
val gson = new Gson()
val storageUrl = StorageUrl(
"SIT52",
"458K",
"Triu",
"https://zi.com")
"Routes" should {
"StorageUrlController" should {
"Create StorageUrl Object in Through Controller" in {
val request = route(app, FakeRequest(POST, "/storageUrl/create")
.withJsonBody(Json.toJson(storageUrl)))
.get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Content is ", contentAsString(request))
}
"Get StorageUrl From Controller" in {
val request = route(app, FakeRequest(GET, "/storageUrl/")
).get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Output", contentAsJson(request))
}
}
}
}
示例6: FileMetaControllerTest
//设置package包名称以及导入依赖的类
package controllers.storage
import com.google.gson.Gson
import domain.storage.FileMeta
import org.scalatestplus.play.{OneAppPerTest, PlaySpec}
import play.api.libs.json.Json
import play.api.test.FakeRequest
import play.api.test.Helpers._
class FileMetaControllerTest extends PlaySpec with OneAppPerTest {
val gson = new Gson()
val fileMeta = FileMeta(
"SIT52",
"Mozulla",
"Triupa")
"Routes" should {
"FileMetaController" should {
"Create FileMeta Object in Through Controller" in {
val request = route(app, FakeRequest(POST, "/fileMeta/create")
.withJsonBody(Json.toJson(fileMeta)))
.get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Content is ", contentAsString(request))
}
"Get FileMeta From Controller" in {
val request = route(app, FakeRequest(GET, "/fileMeta/")
).get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Output", contentAsJson(request))
}
}
}
}
示例7: FileResultsControllerTest
//设置package包名称以及导入依赖的类
package controllers.storage
import com.google.gson.Gson
import domain.storage.FileResults
import org.scalatestplus.play.{OneAppPerTest, PlaySpec}
import play.api.libs.json.Json
import play.api.test.FakeRequest
import play.api.test.Helpers._
class FileResultsControllerTest extends PlaySpec with OneAppPerTest {
val gson = new Gson()
val fileResults = FileResults(
"SIT52",
"MO47",
"https://tri.com",
Option("Triupa"))
"Routes" should {
"FileResultsController" should {
"Create FileResults Object in Through Controller" in {
val request = route(app, FakeRequest(POST, "/fileResults/create")
.withJsonBody(Json.toJson(fileResults)))
.get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Content is ", contentAsString(request))
}
"Get FileResults From Controller" in {
val request = route(app, FakeRequest(GET, "/fileResults/")
).get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Output", contentAsJson(request))
}
}
}
}
示例8: UserImagesControllerTest
//设置package包名称以及导入依赖的类
package controllers.users
import com.google.gson.Gson
import domain.users.UserImages
import org.joda.time.DateTime
import org.scalatestplus.play.{OneAppPerTest, PlaySpec}
import play.api.libs.json.Json
import play.api.test.FakeRequest
import play.api.test.Helpers._
class UserImagesControllerTest extends PlaySpec with OneAppPerTest {
val gson = new Gson()
val userImages = UserImages(
"SIT52",
"458K",
"DO67",
"https://zi.com",
"Triu",
"GHJ",
Option("gugu"),
new DateTime("2004-12-13T21:39:45.618-08:00"))
"Routes" should {
"UserImagesController" should {
"Create UserImages Object in Through Controller" in {
val request = route(app, FakeRequest(POST, "/userImages/create")
.withJsonBody(Json.toJson(userImages)))
.get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Content is ", contentAsString(request))
}
"Get UserImages From Controller" in {
val request = route(app, FakeRequest(GET, "/userImages/")
).get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Output", contentAsJson(request))
}
}
}
}
示例9: UserPositionControllerTest
//设置package包名称以及导入依赖的类
package controllers.users
import com.google.gson.Gson
import domain.users.UserPosition
import org.joda.time.DateTime
import org.scalatestplus.play.{OneAppPerTest, PlaySpec}
import play.api.libs.json.Json
import play.api.test.FakeRequest
import play.api.test.Helpers._
class UserPositionControllerTest extends PlaySpec with OneAppPerTest {
val gson = new Gson()
val userImages = UserPosition(
"SIT52",
"458K",
"DO67",
new DateTime("2004-12-13T21:39:45.618-08:00"),
"PO354",
"Triu",
"GHJ")
"Routes" should {
"UserPositionController" should {
"Create UserPosition Object in Through Controller" in {
val request = route(app, FakeRequest(POST, "/userPosition/create")
.withJsonBody(Json.toJson(userImages)))
.get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Content is ", contentAsString(request))
}
"Get UserPosition From Controller" in {
val request = route(app, FakeRequest(GET, "/userPosition/")
).get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Output", contentAsJson(request))
}
}
}
}
示例10: UserRoleControllerTest
//设置package包名称以及导入依赖的类
package controllers.users
import com.google.gson.Gson
import domain.users.UserRole
import org.joda.time.DateTime
import org.scalatestplus.play.{OneAppPerTest, PlaySpec}
import play.api.libs.json.Json
import play.api.test.FakeRequest
import play.api.test.Helpers._
class UserRoleControllerTest extends PlaySpec with OneAppPerTest {
val gson = new Gson()
val userImages = UserRole(
"SIT52",
"458K",
"DO67",
"Triu",
new DateTime("2004-12-13T21:39:45.618-08:00")
)
"Routes" should {
"UserRoleController" should {
"Create UserRole Object in Through Controller" in {
val request = route(app, FakeRequest(POST, "/userRole/create")
.withJsonBody(Json.toJson(userImages)))
.get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Content is ", contentAsString(request))
}
"Get UserRole From Controller" in {
val request = route(app, FakeRequest(GET, "/userRole/")
).get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Output", contentAsJson(request))
}
}
}
}
示例11: JobEventControllerTest
//设置package包名称以及导入依赖的类
package controllers.job
import com.google.gson.Gson
import domain.job.JobEvent
import org.joda.time.DateTime
import org.scalatestplus.play.{OneAppPerTest, PlaySpec}
import play.api.libs.json.Json
import play.api.test.FakeRequest
import play.api.test.Helpers._
class JobEventControllerTest extends PlaySpec with OneAppPerTest {
val gson = new Gson()
val job = JobEvent(
"1",
"1",
new DateTime("2016-12-13T21:39:45.618-08:00"),
"Sandton"
)
"Routes" should {
"JobEventController" should {
"Create JobEvent Object in Through Controller" in {
val request = route(app, FakeRequest(POST, "/jobEvent/create")
.withJsonBody(Json.toJson(job)))
.get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Content is ", contentAsString(request))
}
"Get JobEvent From Controller" in {
val request = route(app, FakeRequest(GET, "/jobEvent/")
).get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Output", contentAsJson(request))
}
}
}
}
示例12: JobControllerTest
//设置package包名称以及导入依赖的类
package controllers.job
import com.google.gson.Gson
import domain.job.Job
import org.joda.time.DateTime
import org.scalatestplus.play.{OneAppPerTest, PlaySpec}
import play.api.libs.json.Json
import play.api.test.FakeRequest
import play.api.test.Helpers._
class JobControllerTest extends PlaySpec with OneAppPerTest {
val gson = new Gson()
val job = Job(
"1",
"1",
"1",
"SIT52",
"7754",
"Triu",
new DateTime("2016-12-13T21:39:45.618-08:00"),
"RSA"
)
"Routes" should {
"JobController" should {
"Create Job Object in Through Controller" in {
val request = route(app, FakeRequest(POST, "/job/create")
.withJsonBody(Json.toJson(job)))
.get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Content is ", contentAsString(request))
}
"Get Job From Controller" in {
val request = route(app, FakeRequest(GET, "/job/")
).get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Output", contentAsJson(request))
}
}
}
}
示例13: 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
}
示例14: DaoTest
//设置package包名称以及导入依赖的类
package dao
import org.scalatestplus.play.{OneAppPerTest, PlaySpec}
import scala.concurrent.Await
import scala.concurrent.duration.Duration
class DaoTest extends PlaySpec with OneAppPerTest {
"CSV DAO" should {
"number of runways should be equal to 39536" in {
val csvDAO = new CsvDAO
val res = Await.result(csvDAO.allRunaways(), Duration.create(10, scala.concurrent.duration.SECONDS))
res.length mustBe 39536
}
"number of airports should be equal to 46505" in {
val csvDAO = new CsvDAO
val res = Await.result(csvDAO.allAirports(), Duration.create(10, scala.concurrent.duration.SECONDS))
res.length mustBe 46505
}
"number of countries should be equal to 247" in {
val csvDAO = new CsvDAO
val res = Await.result(csvDAO.allCountries(), Duration.create(10, scala.concurrent.duration.SECONDS))
res.length mustBe 247
}
"number of airports for russia should be equal to 920" in {
val csvDAO = new CsvDAO
val res = Await.result(csvDAO.findAirportsByName("russia"), Duration.create(10, scala.concurrent.duration.SECONDS))
res.length mustBe 920
}
"number of airports for country should be equal to both lowercase and uppercase" in {
val csvDAO = new CsvDAO
val res1 = Await.result(csvDAO.findAirportsByName("netherlands"), Duration.create(10, scala.concurrent.duration.SECONDS))
val res2 = Await.result(csvDAO.findAirportsByName("NETHERLANDS"), Duration.create(10, scala.concurrent.duration.SECONDS))
res1.length mustBe res2.length
}
"number of airports for top-3 countries" in {
val csvDAO = new CsvDAO
val res = Await.result(csvDAO.allCountriesSortedByNumberOfAirports(), Duration.create(10, scala.concurrent.duration.SECONDS))
res.length mustBe 247
res.apply(0)._1.code mustBe "US"
res.apply(0)._2 mustBe 21501
res.apply(1)._1.code mustBe "BR"
res.apply(1)._2 mustBe 3839
res.apply(2)._1.code mustBe "CA"
res.apply(2)._2 mustBe 2454
}
}
}
示例15: ClassificationControllerTest
//设置package包名称以及导入依赖的类
package controllers.classification
import domain.Classification.Classification
import org.scalatestplus.play.{OneAppPerTest, PlaySpec}
import play.api.libs.json.Json
import play.api.test.FakeRequest
import play.api.test.Helpers._
class ClassificationControllerTest extends PlaySpec with OneAppPerTest {
val classification = Classification(
"test",
"1",
"test",
"test")
"Routes" should {
"ClassificationController" should {
"Create Classification Object in Through Controller" in {
val request = route(app, FakeRequest(POST, "/classification/create")
.withJsonBody(Json.toJson(classification)))
.get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Content is ", contentAsString(request))
}
"Get Classification From Controller" in {
val request = route(app, FakeRequest(GET, "/classification/1")
).get
status(request) mustBe OK
contentType(request) mustBe Some("application/json")
println(" The Output", contentAsJson(request))
}
}
}
}