Created
May 24, 2012 23:26
-
-
Save twoism/2784866 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.twitter.demo | |
| import com.twitter.macaw.{FinatraController, Status} | |
| class EchoController extends FinatraController { | |
| get("/echo.json") { request => | |
| request.params.get("s") match { | |
| case Some(s) => | |
| actionJsonObjectResponse(Map("echo" -> s)) | |
| case None => | |
| actionApiError("missing parameter: s", Status.BadRequest) | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.twitter.demo | |
| import com.twitter.macaw.test.MacawSpec | |
| import com.twitter.macaw.Status | |
| import org.junit.runner.RunWith | |
| import org.scalatest.junit.JUnitRunner | |
| @RunWith(classOf[JUnitRunner]) | |
| class EchoControllerSpec extends MacawSpec { | |
| def app = { new EchoController() } | |
| "GET /echo.json?s=foo" should "respond with an echo" in { | |
| get("/echo.json", Map("s"->"foo")) | |
| response should matchActionResponse(Map("echo" -> "foo")) | |
| } | |
| "GET /echo.json" should "respond with an error" in { | |
| get("/echo.json") | |
| response should matchActionApiError("missing parameter: s", Status.BadRequest) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment