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


Scala Server类代码示例

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


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

示例1: AuthServiceSpec

//设置package包名称以及导入依赖的类
import services.AuthService
import org.scalatestplus.play._
import play.core.server.Server
import play.api.routing.sird._
import play.api.test._

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Await
import scala.concurrent.duration._
import models.GithubUser
import org.scalatestplus.play.guice.GuiceOneAppPerSuite

class AuthServiceSpec extends PlaySpec with GuiceOneAppPerSuite {
  "AuthServiceSpec" should {
    "return return an access_token via postCode method call" in {
      Server.withRouter() {
        case POST(p"/login/oauth/access_token") => ActionMocks.getGithubTokenResponse()
      } { implicit port =>
        WsTestClient.withClient { client =>
          val authService = new AuthService(client, app.environment, app.configuration ,"", "")
          val result = Await.result(authService.postCode("1234"), 10.seconds)
          result must be ("12345551233123a")
        }
      }
    }

    "return a github user object via getUserInfo method" in {
      Server.withRouter() {
        case GET(p"/user") => ActionMocks.getGithubUserResponse()
      } { implicit port =>
        WsTestClient.withClient { client =>

          val authService = new AuthService(client, app.environment, app.configuration ,"", "")
          val resp = Await.result(authService.getUserInfo("1234"), 10.seconds)
          val jsresp = resp.validate[GithubUser]
          jsresp.fold(
            error => assertTypeError("GithubUser validation fails"),
            result => {
              result.login must be ("poweruser")
              result.id must be (12313)
            }
          )
        }
      }
    }

  }
} 
开发者ID:malaman,项目名称:scala-weather-app,代码行数:49,代码来源:AuthServiceSpec.scala

示例2: WeatherServiceSpec

//设置package包名称以及导入依赖的类
import services.WeatherService
import org.scalatestplus.play._
import play.core.server.Server
import play.api.routing.sird._
import play.api.test._

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Await
import scala.concurrent.duration._
import models.WeatherResponse

class WeatherServiceSpec extends PlaySpec {
  "WeatherService" should {
    "return an Array of Weather Response objects via getWeatherForCity method call" in {
      Server.withRouter() {
        case GET(p"/data/2.5/find") => ActionMocks.getWeatherList()
      } { implicit port =>
        WsTestClient.withClient { client =>
          val weatherService = new WeatherService(client, "")
          val result = Await.result(weatherService.getWeatherForCity("some"), 10.seconds)
          val jsresp = result.validate[List[WeatherResponse]]
          jsresp fold (
            err => fail,
            resp => {
              resp.head.id must be (2950159)
              resp.head.name must be ("Berlin")
              assert(math.abs(resp.head.main.temp - 14) < Fixtures.Eps)
            }
          )
        }
      }
    }
  }
} 
开发者ID:malaman,项目名称:scala-weather-app,代码行数:35,代码来源:WeatherServiceSpec.scala

示例3: WeatherForecastServiceSpec

//设置package包名称以及导入依赖的类
import services.WeatherForecastService
import org.scalatestplus.play._

import play.core.server.Server
import play.api.routing.sird._
import play.api.test._

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Await
import scala.concurrent.duration._
import models.WeatherForecast

class WeatherForecastServiceSpec extends PlaySpec {
  "WeatherForecastService" should {
    "return an WeatherForecast object via getForecastForCity method call" in {
      Server.withRouter() {
        case GET(p"/data/2.5/forecast") => ActionMocks.getWeatherForecast()
      } { implicit port =>
        WsTestClient.withClient { client =>
          val forecastService = new WeatherForecastService(client, "")
          val result = Await.result(forecastService.getForecastForCityByID("1234"), 10.seconds)
          val jsresp = result.validate[WeatherForecast]
          jsresp fold (
            err => fail,
            resp => {
              resp.daily.length must be (5)
              resp.daily.head.day must be (2)
              assert(math.abs(resp.daily.head.temp_max - 21.51) < Fixtures.Eps)
            }
          )
        }
      }
    }
  }
} 
开发者ID:malaman,项目名称:scala-weather-app,代码行数:36,代码来源:WeatherForecastServiceSpec.scala

示例4: TestUtils

//设置package包名称以及导入依赖的类
import helpers.JobcoinConfig
import play.api.mvc.{Action, Results}
import play.api.test.WsTestClient
import play.core.server.Server
import services.JobcoinService
import play.api.routing.sird._
import scala.concurrent.duration._
import scala.language.postfixOps

object TestUtils {

  private val emptyConfig = new JobcoinConfig(
    url = "",
    transactionEndpoint = "/transactions",
    addressEndpoint = "",
    retries = 2,
    timeout = 1 minute
  )

  def withJobcoinService[T](block: JobcoinService => T): T = {
    Server.withRouter() {

      case GET(p"/transactions") =>
        Action(Results.Ok(JobcoinMockPayloads.Transactions))

      case POST(p"/transactions") =>
        Action(Results.Ok(JobcoinMockPayloads.NewTransactionSuccessResponse))

    } { implicit port =>
      WsTestClient.withClient { client =>
        block(new JobcoinService(emptyConfig, client))
      }
    }
  }

} 
开发者ID:agaro1121,项目名称:jobcoin-mixer,代码行数:37,代码来源:TestUtils.scala

示例5: UserServiceSpec

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

import org.specs2.mutable.Specification
import play.api.mvc._
import play.api.routing.sird._
import play.api.test._
import play.core.server.Server

import scala.concurrent.Await
import scala.concurrent.duration._


object UserServiceSpec extends Specification {

  "UserService" should {
    "Return user information" in {
      Server.withRouter() {
        case GET(p"/users") => Action {
          Results.Ok.sendResource("services/users.json")
        }
      } { implicit port =>
        WsTestClient.withClient { client =>
          val result = Await.result(
            new UserService(client, "").authentication("", ""), 10.seconds)
          result must_== Seq("octocat/Hello-World")
        }
      }
    }
  }
} 
开发者ID:elvay1,项目名称:TrackingTimeCompanion,代码行数:31,代码来源:UserServiceSpec.scala


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