use of ninja.Cookie 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.Cookie in project ninja by ninjaframework.
the class AbstractContextTest method unsetCookieAddsCookieWithMaxAgeZero.
@Test
public void unsetCookieAddsCookieWithMaxAgeZero() {
AbstractContextImpl context = spy(abstractContext);
Cookie cookie = Cookie.builder("cookie", "yummy").setDomain("domain").build();
ArgumentCaptor<Cookie> argument = ArgumentCaptor.forClass(Cookie.class);
doNothing().when(context).addCookie(argument.capture());
context.unsetCookie(cookie);
assertThat(argument.getValue().getMaxAge(), is(0));
}
use of ninja.Cookie in project ninja by ninjaframework.
the class FlashScopeTest method testThatFlashCookieClearWorks.
@Test
public void testThatFlashCookieClearWorks() {
// 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.clearCurrentFlashCookieData();
assertEquals(0, ((FlashScopeImpl) flashCookie).getCurrentFlashCookieData().size());
assertEquals(1, ((FlashScopeImpl) flashCookie).getOutgoingFlashCookieData().size());
}
use of ninja.Cookie in project ninja by ninjaframework.
the class FlashScopeTest method testThatFlashCookieWorksAndIsActiveOnlyOneTime.
@Test
public void testThatFlashCookieWorksAndIsActiveOnlyOneTime() {
// 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("another message", "is there...");
flashCookie.put("yet another message", "is there...");
flashCookie.save(context);
// a cookie will be set => hello:flashScope
verify(context).addCookie(cookieCaptor.capture());
// verify some stuff on the set cookie
assertEquals("NINJA_FLASH", cookieCaptor.getValue().getName());
// the new flash messages must be there..
// but the old has disappeared (flashScope):
assertEquals("another+message=is+there...&yet+another+message=is+there...", cookieCaptor.getValue().getValue());
assertEquals(3, ((FlashScopeImpl) flashCookie).getCurrentFlashCookieData().size());
assertEquals(2, ((FlashScopeImpl) flashCookie).getOutgoingFlashCookieData().size());
}
use of ninja.Cookie in project ninja by ninjaframework.
the class FlashScopeTest method testThatFlashCookieKeepWorks.
@Test
public void testThatFlashCookieKeepWorks() {
// 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"));
// make sure outgoing is 0
assertEquals(1, ((FlashScopeImpl) flashCookie).getCurrentFlashCookieData().size());
assertEquals(0, ((FlashScopeImpl) flashCookie).getOutgoingFlashCookieData().size());
// now call keep.
flashCookie.keep();
// => now both queues must be 1
assertEquals(1, ((FlashScopeImpl) flashCookie).getCurrentFlashCookieData().size());
assertEquals(1, ((FlashScopeImpl) flashCookie).getOutgoingFlashCookieData().size());
}
Aggregations