本文整理汇总了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)
}
)
}
}
}
}
}
示例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)
}
)
}
}
}
}
}
示例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)
}
)
}
}
}
}
}
示例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))
}
}
}
}
示例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")
}
}
}
}
}