Skip to content

Instantly share code, notes, and snippets.

@twoism
Created July 13, 2012 21:33
Show Gist options
  • Select an option

  • Save twoism/3107659 to your computer and use it in GitHub Desktop.

Select an option

Save twoism/3107659 to your computer and use it in GitHub Desktop.
package com.twitter.finatrahelloworld
import com.twitter.finatra.{Controller, FinatraServer, View}
case class Tweet(status:String)
class TimelineView(val tweets:List[Tweet]) extends View {
val template = "timeline.mustache"
}
object App {
class HelloWorld extends Controller {
def tweets = List(new Tweet("hey!"), new Tweet("lol"))
get("/tweets.json") { request =>
render.json(tweets)
}
get("/tweets") { request =>
val tweetsView = new TimelineView(tweets)
render.view(tweetsView)
}
get("/status/:status") { request =>
val statusCode = request.params("status").toInt
render.nothing.status(statusCode)
}
get("/not_found") { request =>
render.nothing.notFound
}
get("/headers") { request =>
render.nothing.header("X-GitSHA", "1ecd6b1")
}
}
def main(args: Array[String]) {
val helloWorld = new HelloWorld
FinatraServer.register(helloWorld)
FinatraServer.start()
}
}
package com.twitter.finatrahelloword.test
import com.twitter.finatra.test.SpecHelper
import com.twitter.finatrahelloworld.App
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class AppSpec extends SpecHelper {
def app = { new App.HelloWorld }
"GET /tweets.json" should "respond 200" in {
get("/tweets.json")
response.code should equal (200)
}
"GET /tweets" should "respond 200" in {
get("/tweets")
response.code should equal (200)
response.body should include ("lol")
}
"GET /status/401" should "respond 401" in {
get("/status/401")
response.code should equal (401)
}
"GET /not_found" should "respond 404" in {
get("/not_found")
response.code should equal (404)
}
"GET /headers" should "respond with headers" in {
get("/headers")
response.getHeader("X-GitSHA") should equal ("1ecd6b1")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment