Created
July 16, 2012 09:47
-
-
Save raphaelbauer/3121858 to your computer and use it in GitHub Desktop.
simple mocked ninja controller test
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
@Test | |
public void restRedirectToIndex() { | |
Result result = applicationController.redirectToIndex(context); | |
//assert that status is temporary redirect: | |
assertEquals(Result.SC_307_TEMPORARY_REDIRECT, result.getStatusCode()); | |
//assert that Location header was set correctly | |
Map<String, String> headers = result.getHeaders(); | |
String locationHeader = headers.get(Result.LOCATION); | |
assertEquals("/index", locationHeader); | |
} | |
@Test | |
public void testGwtPathAndSimulateGoogleBotAjaxCrawling() throws Exception { | |
//first of all config the snapshotter: | |
when(SnapshotMachine.getSnapshotForUri("/index")).thenReturn(listenableFuture); | |
when(listenableFuture.get()).thenReturn("dummy_result"); | |
//Now do the call: | |
//let's say we got a escaped fragment at path /index | |
when(context.getParameter("_escaped_fragment_")).thenReturn(""); | |
when(context.getRequestUri()).thenReturn("/index"); | |
//exec the controller method | |
Result result = applicationController.gwtpath(context); | |
Map<String, String> map = (Map<String, String>) result.getRenderable(); | |
//assert some stuff of the result: | |
assertEquals("dummy_result", map.get("content")); | |
assertEquals("views/ApplicationController/emtpy_page.ftl.html", result.getTemplate()); | |
assertEquals(Result.TEXT_HTML, result.getContentType()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment