use of ninja.Result in project ninja by ninjaframework.
the class ResultHandlerTest method testRenderPlainStringAndSetDefaultContentType.
@Test
public void testRenderPlainStringAndSetDefaultContentType() {
final String toRender = "this is just a plain string";
Result result = Results.ok();
result.renderRaw(toRender);
resultHandler.handleResult(result, context);
assertEquals(Result.TEXT_PLAIN, result.getContentType());
}
use of ninja.Result in project ninja by ninjaframework.
the class ResultHandlerTest method testCacheControlDoesNotGetTouchedWhenSet.
@Test
public void testCacheControlDoesNotGetTouchedWhenSet() {
Result result = Results.json();
// just a simple cache control header:
result.addHeader(Result.CACHE_CONTROL, "must-revalidate");
// just a new object as dummy...
result.render(new Object());
// handle result
resultHandler.handleResult(result, context);
// make sure stuff is there:
assertEquals("must-revalidate", result.getHeaders().get(Result.CACHE_CONTROL));
assertNull(result.getHeaders().get(Result.DATE));
assertNull(result.getHeaders().get(Result.EXPIRES));
}
use of ninja.Result in project ninja by ninjaframework.
the class AbstractContextTest method addCookieViaResult.
@Test
public void addCookieViaResult() {
AbstractContextImpl context = spy(abstractContext);
Cookie cookie0 = Cookie.builder("cookie0", "yum0").setDomain("domain").build();
Cookie cookie1 = Cookie.builder("cookie1", "yum1").setDomain("domain").build();
// adding a cookie in the result will eventually trigger addCookie()...
Result result = Results.html();
result.addCookie(cookie0);
result.addCookie(cookie1);
doNothing().when(context).addCookie(cookie0);
doNothing().when(context).addCookie(cookie1);
// finalize the headers => the cookies must be copied over to the servletcookies
context.finalizeHeaders(result);
verify(context, times(1)).addCookie(cookie0);
verify(context, times(1)).addCookie(cookie1);
}
use of ninja.Result in project ninja by ninjaframework.
the class TemplateEngineJsonTest method setUp.
@Before
public void setUp() throws IOException {
context = mock(Context.class);
responseStreams = mock(ResponseStreams.class);
result = mock(Result.class);
objectMapper = new ObjectMapper();
outputStream = new ByteArrayOutputStream();
TestObject testObj = new TestObject();
testObj.field1 = "field_one";
testObj.field2 = "field_two";
when(result.getRenderable()).thenReturn(testObj);
when(context.finalizeHeaders(result)).thenReturn(responseStreams);
when(responseStreams.getOutputStream()).thenReturn(outputStream);
}
use of ninja.Result in project ninja by ninjaframework.
the class TemplateEngineTextTest method setUp.
@Before
public void setUp() throws IOException {
context = mock(Context.class);
responseStreams = mock(ResponseStreams.class);
result = mock(Result.class);
Map<String, String> map = new TreeMap<String, String>() {
{
put("apples", "oranges");
put("cars", "trucks");
}
};
when(result.getRenderable()).thenReturn(map);
writer = new StringWriter();
when(context.finalizeHeaders(result)).thenReturn(responseStreams);
when(responseStreams.getWriter()).thenReturn(writer);
}
Aggregations