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

Scala GuiceApplicationBuilder类代码示例

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

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



在下文中一共展示了GuiceApplicationBuilder类的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: IntegrationSpec

//设置package包名称以及导入依赖的类
import org.scalatestplus.play._
import org.scalatestplus.play.guice.GuiceOneServerPerSuite
import play.api.{Configuration, Mode}
import play.api.cache.{CacheApi, EhCacheModule}
import play.api.inject._
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test._
import play.api.test.Helpers._
import util.FakeCache


class IntegrationSpec extends PlaySpec with GuiceOneServerPerSuite with OneBrowserPerTest with HtmlUnitFactory {

  implicit override lazy val app = new GuiceApplicationBuilder()
    .overrides(bind[CacheApi].to[FakeCache])
    .loadConfig(env => Configuration.load(env))
    .in(Mode.Test)
    .build

  "Application" should {

    "work from within a browser" in {

      go to ("http://localhost:" + port)

      pageSource must include ("Aktuelles der Fakultät Informatik")
    }
  }
} 
开发者ID:P1tt187,项目名称:spirit-play,代码行数:30,代码来源:IntegrationSpec.scala


示例3: ApplicationSpec

//设置package包名称以及导入依赖的类
import org.scalatestplus.play._
import org.scalatestplus.play.guice.GuiceOneAppPerSuite
import play.api._
import play.api.cache.CacheApi
import play.api.inject._
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test.Helpers._
import play.api.test._
import util.FakeCache


class ApplicationSpec extends PlaySpec with GuiceOneAppPerSuite {

  implicit override lazy val app = new GuiceApplicationBuilder()
    .overrides(bind[CacheApi].to[FakeCache])
    .loadConfig(env => Configuration.load(env))
    .in(Mode.Test)
    .build

  "Routes" should {

    "send 404 on a bad request" in {
      route(app, FakeRequest(GET, "/boum")).map(status(_)) mustBe Some(NOT_FOUND)
    }

  }

  "NewsPageController" should {

    "render the index page" in {
      val home = route(app, FakeRequest(GET, "/")).get

      status(home) mustBe OK
      contentType(home) mustBe Some("text/html")
      contentAsString(home) must include("Aktuelles der Fakultät Informatik")
    }

  }

} 
开发者ID:P1tt187,项目名称:spirit-play,代码行数:41,代码来源:ApplicationSpec.scala


示例4: 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

} 
开发者ID:hmrc,项目名称:updated-print-suppressions,代码行数:47,代码来源:TestServer.scala


示例5: 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


示例6: 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


示例7: 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


示例8: 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


示例9: 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


示例10: 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


示例11: 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


示例12: overrideModules

//设置package包名称以及导入依赖的类
package com.eigenroute.scalikejdbctesthelpers

import org.scalatest._
import play.api.Application
import play.api.inject.guice.{GuiceApplicationBuilder, GuiceableModule}
import play.api.test._

trait OneAppPerTestWithOverrides extends SuiteMixin { this: Suite ?

  def overrideModules: Seq[GuiceableModule] = Nil

  def newAppForTest(testData: TestData): Application =
    new GuiceApplicationBuilder()
    .overrides(overrideModules: _*)
    .build

  var appPerTest: Application = _

  implicit final def app: Application = synchronized { appPerTest }

  abstract override def withFixture(test: NoArgTest) = {
    synchronized { appPerTest = newAppForTest(test) }
    Helpers.running(app) { super.withFixture(test) }
  }
} 
开发者ID:shafiquejamal,项目名称:eigenroute-scalikejdbc-test-helpers,代码行数:26,代码来源:OneAppPerTestWithOverrides.scala


示例13: PersonDAOImplSpec

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

import org.scalatestplus.play._
import play.api.test._
import play.api.test.Helpers._
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.inject.bind
import org.scalatest.TestData
import play.api.Application
import com.typesafe.config.ConfigFactory
import org.scalatest.concurrent.ScalaFutures
import play.api.Configuration
import play.api.db.slick.DatabaseConfigProvider
import slick.profile.BasicProfile
import modules.ExampleModule

class PersonDAOImplSpec extends PlaySpec with OneAppPerSuite with ScalaFutures {

  implicit override lazy val app = new GuiceApplicationBuilder().
    configure(
      "slick.dbs.mydb.driver" -> "slick.driver.H2Driver$",
      "slick.dbs.mydb.db.driver" -> "org.h2.Driver",
      "slick.dbs.mydb.db.url" -> "jdbc:h2:mem:blah;",
      "slick.dbs.mydb.db.user" -> "test",
      "slick.dbs.mydb.db.password" -> "").build

  def personDAO(implicit app: Application): PersonDAO = Application.instanceCache[PersonDAO].apply(app)
  
  "PersonDAO" should {
    "do whatever" in {
      whenReady(personDAO.findAll) { res =>
        println(res)
      }
    }
  }

} 
开发者ID:sake92,项目名称:PlayGuiceExample,代码行数:38,代码来源:PersonDAOImplSpec.scala


示例14: PersonControllerSpec3

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

import org.scalatestplus.play._
import play.api.test._
import play.api.test.Helpers._
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.inject.bind
import dao._
import org.scalatest.TestData
import play.api.Application
import dao.PersonDAO
import dao.PersonDAOMock
import play.api.inject.guice.GuiceableModule.fromPlayBinding
import com.typesafe.config.ConfigFactory
import org.scalatest.concurrent.ScalaFutures


class PersonControllerSpec3 extends PlaySpec with ScalaFutures{

  val app = new GuiceApplicationBuilder()
    .overrides(bind(classOf[PersonDAO]).to(classOf[PersonDAOMock]))
    .build

  "Find all route" should {
    "return all persons" in running(app) {
      route(app, FakeRequest(GET, "/persons")).map(status(_)) mustBe Some(OK)
      
      // this should return PersonDAOMock, because we've overriden it
      val app2PersonDao = play.api.Application.instanceCache[PersonDAO]
      val personDAO: PersonDAO = app2PersonDao(app)
      val personsFuture = personDAO.findAll
      
      whenReady(personsFuture){ persons =>
        persons.map(_.name) must contain("Mocked Person")
      }
    }
  }
} 
开发者ID:sake92,项目名称:PlayGuiceExample,代码行数:39,代码来源:PersonControllerSpec.scala


示例15: ApplicationSpec

//设置package包名称以及导入依赖的类
import java.io.{File, PrintWriter}

import models.{UpdateRequest, V1thResult}
import org.scalatest.{BeforeAndAfter, TestData}
import org.scalatestplus.play._
import play.api.Application
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.libs.json.Json
import play.api.test._
import play.api.test.Helpers._


class ApplicationSpec extends PlaySpec with OneAppPerTest with BeforeAndAfter {

  implicit override def newAppForTest(td: TestData): Application = {

    val f1File = new File("f1.csv")
    val content = "1, 2, 3, 4, 5"
    createTestFile(f1File, content)

    val f2File = new File("f2.csv")

    new GuiceApplicationBuilder().configure(
      Map(
        "f1.location" -> f1File.getAbsolutePath,
        "f2.location" -> f2File.getAbsolutePath
      )).build()
  }

  "NumberCalculationController" should {

    "return correct v1-th result" in {

      val v2=19
      val v3=2
      val v4=3
      val v1=v4

      await(route(app, FakeRequest(POST, "/postv2v3v4").withJsonBody(Json.toJson(UpdateRequest(v2,v3,v4)))).get)

      val result = route(app, FakeRequest(GET, s"/getf1v1?v1=${v1}")).get

      status(result) mustBe OK
      contentAsJson(result) must equal(Json.toJson(V1thResult(12)))
    }

  }

  def createTestFile(f2File: File, content: String): Unit = {
    val pw = new PrintWriter(f2File)
    pw.write(content)
    pw.close()
  }

} 
开发者ID:ydalekorey,项目名称:rest-calculator,代码行数:56,代码来源:ApplicationSpec.scala


示例16: 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


示例17: AcceptanceTest

//设置package包名称以及导入依赖的类
package com.primedesem.home

import org.scalatest._
import org.scalatestplus.play._

import play.api.test._
//import play.api.test.Helpers.{GET => GET_REQUEST, _}
//import play.api.test.Helpers.{POST => POST_REQUEST, _}
import play.api.inject.guice.GuiceApplicationBuilder

import controllers._
import play.api.routing.Router

import play.api.routing.sird._
import play.api.routing._
import play.api.mvc._
import play.api.mvc.Results._

import scala.concurrent.ExecutionContext.Implicits

class AcceptanceTest extends PlaySpec with OneServerPerSuite with OneBrowserPerSuite with HtmlUnitFactory{
  
  
  implicit val ec = Implicits.global
  
  val homeController = new HomeController()
  
  implicit override lazy val app = 
    new GuiceApplicationBuilder()
      .router(Router.from{
        case GET(p"/") => homeController.index
//        case GET(p"/about") => homeController.about
        case GET(p"/login") => homeController.getLogin
//        case POST(p"/login") => homeController.postLogin
        case GET(p"/register") => homeController.getRegister
        //case POST(p"/register") => homeController.postRegister
        case GET(p"/assets/*") => Action(Ok("assets"))
      })
      .build()
      
  
  "Person visits site" must {
    
    val url = s"http://localhost:$port"
    
    "visit home and see Home in the title" in {
      go to url
      pageTitle mustBe "Home"
      click on find(name("register")).value
      eventually { pageTitle mustBe "Register"}
    }
    
    "visit home and be able to go to login page" in {
      go to url
      click on find(name("login")).value
      eventually {pageTitle mustBe "Login"}
    }
  }
      
      
} 
开发者ID:eric416283,项目名称:primdesem-demo-home-front-end,代码行数:62,代码来源:AcceptanceTest.scala


示例18: overrideModules

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

import play.api.Application
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.inject.guice.GuiceableModule
import play.api.test._
import org.scalatest._

trait OneAppPerTestWithOverrides extends SuiteMixin { this: Suite =>
  def overrideModules: Seq[GuiceableModule] = Nil

  def newAppForTest(testData: TestData): Application =
    new GuiceApplicationBuilder()
      .overrides(overrideModules: _*)
      .build

  private var appPerTest: Application = _
  implicit final def app: Application = synchronized { appPerTest }

  abstract override def withFixture(test: NoArgTest) = {
    synchronized { appPerTest = newAppForTest(test) }
    Helpers.running(app) {
      super.withFixture(test)
    }
  }
} 
开发者ID:fagossa,项目名称:play-reactive-couchbase,代码行数:27,代码来源:OneAppPerTestWithOverrides.scala


示例19: fakeApplication

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

import com.google.inject.Inject
import org.flywaydb.core.Flyway
import org.flywaydb.core.internal.util.jdbc.DriverDataSource
import org.scalatestplus.play.FakeApplicationFactory
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.inject.{Binding, Module}
import play.api.{Application, Configuration, Environment}


trait MyApplicationFactory extends FakeApplicationFactory {
  def fakeApplication(): Application = {
    new GuiceApplicationBuilder()
      .configure(Map("myapp.database.url" -> "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1"))
      .bindings(new FlywayModule)
      .build()
  }
}

class FlywayModule extends Module {
  override def bindings(environment: Environment, configuration: Configuration): Seq[Binding[_]] = {
    Seq(bind[FlywayMigrator].toSelf.eagerly() )
  }
}

class FlywayMigrator @Inject()(env: Environment, configuration: Configuration) {
  def onStart(): Unit = {
    val driver = configuration.underlying.getString("myapp.database.driver")
    val url = configuration.underlying.getString("myapp.database.url")
    val user = configuration.underlying.getString("myapp.database.user")
    val password = configuration.underlying.getString("myapp.database.password")
    val flyway = new Flyway
    flyway.setDataSource(new DriverDataSource(env.classLoader, driver, url, user, password))
    flyway.setLocations("filesystem:modules/flyway/src/main/resources/db/migration")
    flyway.migrate()
  }

  onStart()
} 
开发者ID:wouzar,项目名称:tracker,代码行数:41,代码来源:MyApplicationFactory.scala


示例20: inject

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

import play.api.inject.guice.GuiceApplicationBuilder
import scala.reflect.ClassTag

import models.TSData
import org.specs2.mutable._
import play.api.libs.json.Json
import play.api.test.Helpers._
import play.api.test._

trait Inject {
  lazy val injector = (new GuiceApplicationBuilder).injector()

  def inject[T : ClassTag]: T = injector.instanceOf[T]
}

class ApplicationSpec extends Specification with Inject {
  lazy val appController = inject[Application]

  "Application" should {

    "add a data point" in  {
      val addData = appController.addData()(FakeRequest(POST, "/tsdata").withBody(
        Json.parse("""{"station": "MACHINE1", "status": false, "temp": 28.1, "humid": 67.0}"""))
        )
      status(addData) must equalTo(OK)
      Json.parse(contentAsString(addData)).as[TSData].station must beEqualTo ("MACHINE1")
      Json.parse(contentAsString(addData)).as[TSData].status must beEqualTo (false)
      Json.parse(contentAsString(addData)).as[TSData].temp must beEqualTo (28.1)
      Json.parse(contentAsString(addData)).as[TSData].humid must beEqualTo (67.0)
    }

    "get all data" in {
      val dataset = appController.dataSet()(FakeRequest(GET, "/tsdata"))
      status(dataset) must equalTo(OK)
      Json.parse(contentAsString(dataset)).as[Seq[TSData]].length must beGreaterThan (0)
    }

  }
} 
开发者ID:istanleyy,项目名称:play-w-mqtt,代码行数:42,代码来源:ApplicationSpec.scala



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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