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


Scala AnyContentAsJson类代码示例

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


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

示例1: TestSocialProvider

//设置package包名称以及导入依赖的类
package com.clemble.loveit.common.util

import java.util.concurrent.ConcurrentHashMap

import com.mohiva.play.silhouette.api.util.{ExtractableRequest, HTTPLayer}
import com.mohiva.play.silhouette.impl.providers._
import play.api.libs.json.{JsValue, Json}
import play.api.mvc.{AnyContentAsJson, Result}
import com.clemble.loveit.user.model.User.socialProfileJsonFormat

import scala.concurrent.Future

case class TestSocialProvider(
                               protected val httpLayer: HTTPLayer,
                               protected val stateProvider: OAuth2StateProvider,
                               val settings: OAuth2Settings)
  extends OAuth2Provider
    with CommonSocialProfileBuilder {

  override type Content = JsValue
  override protected def urls: Map[String, String] = Map.empty
  override val id = "test"
  override type Self = TestSocialProvider

  val cache = new ConcurrentHashMap[String, CommonSocialProfile]()

  override def authenticate[B]()(implicit request: ExtractableRequest[B]): Future[Either[Result, OAuth2Info]] = {
    val user = request.body match {
      case AnyContentAsJson(json) => json.as[CommonSocialProfile]
    }
    cache.put(user.loginInfo.providerKey, user)
    Future.successful(Right(OAuth2Info(accessToken = user.loginInfo.providerKey)))
  }

  override def withSettings(f: (Settings) => Settings) = {
    new TestSocialProvider(httpLayer, stateProvider, f(settings))
  }

  override protected def buildProfile(authInfo: OAuth2Info): Future[Profile] = {
    Future.successful(cache.remove(authInfo.accessToken))
  }

  override protected def profileParser: SocialProfileParser[JsValue, Profile, OAuth2Info] = ???

} 
开发者ID:thankyo,项目名称:thank,代码行数:46,代码来源:TestSocialProvider.scala

示例2: EffectiveDateResourceTimemachineOffSpec

//设置package包名称以及导入依赖的类
package cjp.catalogue.resource

import java.util.concurrent.TimeUnit

import akka.util.Timeout
import org.joda.time.DateTime
import org.mockito.Mockito._
import cjp.catalogue.repository.EffectiveDateRepository
import org.scalatest.mock.MockitoSugar
import org.scalatest.{Matchers, BeforeAndAfter, WordSpec}
import play.api.GlobalSettings
import play.api.http.{Status, HeaderNames}
import play.api.libs.json.Json
import play.api.mvc.{AnyContentAsJson, AnyContentAsText}
import play.api.test._

class EffectiveDateResourceTimemachineOffSpec extends WordSpec with BeforeAndAfter with PlayRunners with ResultExtractors with HeaderNames with Status with Matchers with MockitoSugar {
  implicit val timeout = Timeout(10L, TimeUnit.SECONDS)

  private val effectiveDateRepository = mock[EffectiveDateRepository]
  private val controller = new EffectiveDateResource(effectiveDateRepository, enableTimemachine = false)

  object TestGlobal extends GlobalSettings {
    override def getControllerInstance[A](controllerClass: Class[A]): A =
      controller.asInstanceOf[A]
  }

  before {
    reset(effectiveDateRepository)
  }

  "calling PUT /manage/effectiveDate" should {
    "return 403 if timemachine feature switch is disabled" in {
      running(TestServer(18888, FakeApplication(withGlobal = Some(TestGlobal)))) {
        val json = Json.parse("""{"effectiveDate":"2015-04-10T14:12:57.159Z"}""")
        val request: FakeRequest[AnyContentAsJson] = FakeRequest().withJsonBody(json).withHeaders("ContentType" -> "application/json")

        val result = controller.setEffectiveDate.apply(request)

        status(result) should be(403)
        verifyZeroInteractions(effectiveDateRepository)
      }
    }
  }

  "calling DELETE /manage/effectiveDate" should {
    "return 403 if timemachine feature switch is disabled" in {
      running(TestServer(18888, FakeApplication(withGlobal = Some(TestGlobal)))) {
        val result = controller.resetEffectiveDate.apply(FakeRequest())

        status(result) should be(403)
        verifyZeroInteractions(effectiveDateRepository)
      }
    }
  }
} 
开发者ID:UKHomeOffice,项目名称:product-catalogue,代码行数:57,代码来源:EffectiveDateResourceTimemachineOffSpec.scala


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