use of ninja.Result in project ninja by ninjaframework.
the class ResultHandlerTest method testRenderPlainStringLeavesExplicitlySetContentTypeUntouched.
@Test
public void testRenderPlainStringLeavesExplicitlySetContentTypeUntouched() {
final String toRender = "this is just a plain string";
final String contentType = "any/contenttype";
Result result = Results.ok();
result.contentType(contentType);
result.renderRaw(toRender);
resultHandler.handleResult(result, context);
assertEquals(contentType, result.getContentType());
}
use of ninja.Result in project ninja by ninjaframework.
the class ResultHandlerTest method testThatNoHttpBodyWorks.
@Test
public void testThatNoHttpBodyWorks() {
// make sure that NoHttpBody causes the resulthandler to finalize
// the context and does not call a tempate render engine.
Result result = new Result(200);
result.render(new NoHttpBody());
resultHandler.handleResult(result, context);
verify(context).finalizeHeaders(result);
}
use of ninja.Result in project ninja by ninjaframework.
the class ResultHandlerTest method testContentNegotiation.
@Test
public void testContentNegotiation() {
when(context.getAcceptContentType()).thenReturn("text/html");
Result result = Results.ok();
resultHandler.handleResult(result, context);
assertEquals("text/html", result.getContentType());
verify(templateEngineHtml).invoke(context, result);
}
use of ninja.Result in project ninja by ninjaframework.
the class ResultHandlerTest method testThatFallbackContentTypeWorks.
@Test
public void testThatFallbackContentTypeWorks() {
Result result = new Result(200).fallbackContentType(Result.TEXT_HTML).contentType(null);
resultHandler.handleResult(result, context);
assertThat(result.getContentType(), equalTo(Result.TEXT_HTML));
}
use of ninja.Result in project ninja by ninjaframework.
the class ResultHandlerTest method testAddingOfDefaultHeadersWorks.
/**
* If Cache-Control is not set the no-cache strategy has to be applied.
*
* We expect Cache-Control: ... Date: ... Expires: ...
*/
@Test
public void testAddingOfDefaultHeadersWorks() {
Result result = Results.json();
// just a new object as dummy...
result.render(new Object());
// make sure the stuff is not set by default json method (just in
// case...)
assertNull(result.getHeaders().get(Result.CACHE_CONTROL));
assertNull(result.getHeaders().get(Result.DATE));
assertNull(result.getHeaders().get(Result.EXPIRES));
// handle result
resultHandler.handleResult(result, context);
// make sure stuff is there:
assertEquals(Result.CACHE_CONTROL_DEFAULT_NOCACHE_VALUE, result.getHeaders().get(Result.CACHE_CONTROL));
assertNotNull(result.getHeaders().get(Result.DATE));
assertEquals(DateUtil.formatForHttpHeader(0L), result.getHeaders().get(Result.EXPIRES));
}
Aggregations