Skip to content

Instantly share code, notes, and snippets.

@raphaelbauer
Created July 16, 2012 09:47
Show Gist options
  • Save raphaelbauer/3121858 to your computer and use it in GitHub Desktop.
Save raphaelbauer/3121858 to your computer and use it in GitHub Desktop.
simple mocked ninja controller test
@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