Created
February 12, 2010 03:52
-
-
Save rossabaker/302275 to your computer and use it in GitHub Desktop.
This file contains 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
import org.scalatest.matchers.ShouldMatchers | |
import org.scalatest.FunSuite | |
import javax.servlet.http.{HttpServletResponse, HttpServletRequest, HttpServlet} | |
import java.net.URLEncoder | |
import org.mortbay.jetty.testing.{HttpTester, ServletTester} | |
class CharsetServlet extends HttpServlet { | |
override def doGet(req: HttpServletRequest, res: HttpServletResponse) = { | |
val foo = req.getParameter("foo") | |
res.setContentType("text/plain; charset=utf-8") | |
res.getWriter.write(foo) | |
} | |
} | |
class CharsetTest extends FunSuite with ShouldMatchers { | |
val tester = new ServletTester | |
tester.addServlet(classOf[CharsetServlet], "/*") | |
tester.start | |
val russianAlphabet = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя" | |
test("GET handles UTF-8") { | |
val req = new HttpTester | |
req.setVersion("HTTP/1.0") | |
req.setURI("/?foo="+URLEncoder.encode(russianAlphabet, "UTF-8")) | |
req.setMethod("GET") | |
val res = new HttpTester | |
res.parse(tester.getResponses(req.generate)) | |
res.getContent should equal (russianAlphabet) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment