use of ninja.Cookie in project ninja by ninjaframework.
the class AbstractContextTest method finalizeInAbstractContextSavesFlashSessionCookies.
@Test
public void finalizeInAbstractContextSavesFlashSessionCookies() {
AbstractContextImpl context = spy(abstractContext);
Result result = Results.json();
Cookie cookie = Cookie.builder("TEST", "value").build();
result.addCookie(cookie);
doNothing().when(context).addCookie(cookie);
ResponseStreams streams = context.finalizeHeaders(result);
// abstract finalizeHeaders does not return anything
assertThat(streams, is(nullValue()));
verify(flashCookie, times(1)).save(context);
verify(sessionCookie, times(1)).save(context);
verify(context, times(1)).addCookie(cookie);
}
use of ninja.Cookie in project ninja by ninjaframework.
the class LangImplTest method testClearLanguage.
@Test
public void testClearLanguage() {
Cookie cookie = Cookie.builder("NINJA_TEST" + NinjaConstant.LANG_COOKIE_SUFFIX, "de").build();
when(ninjaProperties.getOrDie(NinjaConstant.applicationCookiePrefix)).thenReturn("NINJA_TEST");
Lang lang = new LangImpl(ninjaProperties);
Result result = Results.ok();
lang.clearLanguage(result);
Cookie returnCookie = result.getCookie(cookie.getName());
assertEquals("", returnCookie.getValue());
assertEquals(0, returnCookie.getMaxAge());
}
use of ninja.Cookie in project ninja by ninjaframework.
the class FlashScopeTest method testThatFlashCookieClearOfOutgoingWorks.
@Test
public void testThatFlashCookieClearOfOutgoingWorks() {
// setup this testmethod
Cookie cookie = Cookie.builder("NINJA_FLASH", "hello=flashScope").build();
when(context.getCookie("NINJA_FLASH")).thenReturn(cookie);
FlashScope flashCookie = new FlashScopeImpl(ninjaProperties);
flashCookie.init(context);
// make sure the old cookue gets parsed:
assertEquals("flashScope", flashCookie.get("hello"));
flashCookie.put("funny new flash message", "is there...");
// now test clearCurrentFlashCookieData
flashCookie.discard();
assertEquals(2, ((FlashScopeImpl) flashCookie).getCurrentFlashCookieData().size());
assertEquals(0, ((FlashScopeImpl) flashCookie).getOutgoingFlashCookieData().size());
}
use of ninja.Cookie in project ninja by ninjaframework.
the class SessionImplTest method testThatCookieUsesContextPath.
@Test
public void testThatCookieUsesContextPath() {
Mockito.when(context.getContextPath()).thenReturn("/my_context");
Session sessionCookie = createNewSession();
sessionCookie.init(context);
sessionCookie.put("anykey", "anyvalue");
sessionCookie.save(context);
verify(context).addCookie(cookieCaptor.capture());
Cookie cookie = cookieCaptor.getValue();
assertThat(cookie.getPath(), CoreMatchers.equalTo("/my_context/"));
}
use of ninja.Cookie in project ninja by ninjaframework.
the class SessionImplTest method testThatCookieUseApplicationDomain.
@Test
public void testThatCookieUseApplicationDomain() {
when(ninjaProperties.get(NinjaConstant.applicationCookieDomain)).thenReturn("domain.com");
Session sessionCookie = createNewSession();
sessionCookie.init(context);
sessionCookie.put("anykey", "anyvalue");
sessionCookie.save(context);
verify(context).addCookie(cookieCaptor.capture());
Cookie cookie = cookieCaptor.getValue();
assertThat(cookie.getDomain(), CoreMatchers.equalTo("domain.com"));
}
Aggregations