@Test
public void testPortalCookieLifeCycle() {
final String value = this.execute(new Callable<String>() {
@Override
public String call() throws Exception {
final IPortalCookie portalCookie = portletCookieDao.createPortalCookie(1);
assertNotNull(portalCookie);
final String cookieValue = portalCookie.getValue();
assertNotNull(cookieValue);
assertEquals(40, cookieValue.length());
assertEquals(0, portalCookie.getPortletCookies().size());
assertNotNull(portalCookie.getCreated());
assertNotNull(portalCookie.getExpires());
return cookieValue;
}
});
this.execute(new Callable<String>() {
@Override
public String call() throws Exception {
final IPortalCookie portalCookie = portletCookieDao.getPortalCookie(value);
assertNotNull(portalCookie);
Cookie cookie2 = new Cookie("cookieName2", "cookieValue2");
portletCookieDao.addOrUpdatePortletCookie(portalCookie, cookie2);
return null;
}
});
this.execute(new Callable<String>() {
@Override
public String call() throws Exception {
final IPortalCookie portalCookie = portletCookieDao.getPortalCookie(value);
assertNotNull(portalCookie);
long expirationDelay = portalCookie.getExpires().getMillis() - System.currentTimeMillis();
if (expirationDelay > 0) {
Thread.sleep(Math.max(500, expirationDelay));
}
portletCookieDao.purgeExpiredCookies(1);
return null;
}
});
this.execute(new Callable<String>() {
@Override
public String call() throws Exception {
final IPortalCookie portalCookie = portletCookieDao.getPortalCookie(value);
assertNull(portalCookie);
return null;
}
});