Search in sources :

Example 36 with Result

use of ninja.Result in project ninja by ninjaframework.

the class NinjaServletContextTest method testContentTypeWithNullEncodingGetsConvertedProperlyUponFinalize.

@Test
public void testContentTypeWithNullEncodingGetsConvertedProperlyUponFinalize() {
    // init the context
    context.init(servletContext, httpServletRequest, httpServletResponse);
    // this must be Content-Type: application/json; encoding=utf-8
    Result result = Results.json();
    // force a characterset that is not there. Stupid but tests that its working.
    result.charset(null);
    context.finalizeHeaders(result);
    // make sure utf-8 is used under all circumstances:
    verify(httpServletResponse).setCharacterEncoding(NinjaConstant.UTF_8);
}
Also used : Result(ninja.Result) Test(org.junit.Test)

Example 37 with Result

use of ninja.Result in project ninja by ninjaframework.

the class NinjaServletContextTest method testContentTypeGetsConvertedProperlyUponFinalize.

@Test
public void testContentTypeGetsConvertedProperlyUponFinalize() {
    // init the context
    context.init(servletContext, httpServletRequest, httpServletResponse);
    // this must be Content-Type: application/json; encoding=utf-8
    Result result = Results.json();
    context.finalizeHeaders(result);
    verify(httpServletResponse).setCharacterEncoding(result.getCharset());
    verify(httpServletResponse).setContentType(result.getContentType());
}
Also used : Result(ninja.Result) Test(org.junit.Test)

Aggregations

Result (ninja.Result)37 Test (org.junit.Test)26 TemplateModel (freemarker.template.TemplateModel)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 Cookie (ninja.Cookie)6 SimpleScalar (freemarker.template.SimpleScalar)4 Context (ninja.Context)3 Timed (ninja.metrics.Timed)3 ResponseStreams (ninja.utils.ResponseStreams)3 BeansWrapper (freemarker.ext.beans.BeansWrapper)2 StringModel (freemarker.ext.beans.StringModel)2 Date (java.util.Date)2 ConstraintViolation (ninja.validation.ConstraintViolation)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Before (org.junit.Before)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1