use of org.apereo.portal.portlet.dao.IPortletCookieDao in project uPortal by Jasig.
the class PortletCookieServiceImplTest method testAddCookieSessionOnly.
/**
* Control test for adding a portlet cookie with maxAge == -1, which results in a session-only
* cookie.
*/
@Test
public void testAddCookieSessionOnly() {
Cookie portletCookie = new Cookie("somePortletCookieName", "somePortletCookieValue");
// max age will trigger persistence
portletCookie.setMaxAge(-1);
IPortletCookieDao portletCookieDao = EasyMock.createMock(IPortletCookieDao.class);
MockPortalCookie portalCookie = new MockPortalCookie();
portalCookie.setValue("ABCDEF");
EasyMock.expect(portletCookieDao.createPortalCookie(PortletCookieServiceImpl.DEFAULT_MAX_AGE)).andReturn(portalCookie);
PortletCookieServiceImpl cookieService = new PortletCookieServiceImpl();
cookieService.setPortletCookieDao(portletCookieDao);
IPortletWindowId mockWindowId = EasyMock.createMock(IPortletWindowId.class);
EasyMock.replay(portletCookieDao, mockWindowId);
MockHttpServletRequest request = new MockHttpServletRequest();
cookieService.addCookie(request, mockWindowId, portletCookie);
Map<String, SessionOnlyPortletCookieImpl> sessionOnlyMap = cookieService.getSessionOnlyPortletCookieMap(request);
SessionOnlyPortletCookieImpl sessionOnlyCookie = sessionOnlyMap.get("somePortletCookieName");
Assert.assertNotNull(sessionOnlyCookie);
Assert.assertEquals(-1, sessionOnlyCookie.getMaxAge());
Assert.assertEquals("somePortletCookieValue", sessionOnlyCookie.getValue());
EasyMock.verify(portletCookieDao, mockWindowId);
}
use of org.apereo.portal.portlet.dao.IPortletCookieDao in project uPortal by Jasig.
the class PortletCookieServiceImplTest method testAddCookieRemove.
/**
* Control test for removing a portlet cookie. Logic is nearly identical to create, as both
* {@link IPortletCookieDao#addOrUpdatePortletCookie(IPortalCookie, Cookie)} is used in both
* scenarios.
*/
@Test
public void testAddCookieRemove() {
Cookie portletCookie = new Cookie("somePortletCookieName", "somePortletCookieValue");
// max age will trigger persistence removal
portletCookie.setMaxAge(0);
IPortletCookieDao portletCookieDao = EasyMock.createMock(IPortletCookieDao.class);
MockPortalCookie portalCookie = new MockPortalCookie();
portalCookie.setValue("ABCDEF");
EasyMock.expect(portletCookieDao.createPortalCookie(PortletCookieServiceImpl.DEFAULT_MAX_AGE)).andReturn(portalCookie);
EasyMock.expect(portletCookieDao.addOrUpdatePortletCookie(portalCookie, portletCookie)).andReturn(portalCookie);
PortletCookieServiceImpl cookieService = new PortletCookieServiceImpl();
cookieService.setPortletCookieDao(portletCookieDao);
IPortletWindowId mockWindowId = EasyMock.createMock(IPortletWindowId.class);
EasyMock.replay(portletCookieDao, mockWindowId);
MockHttpServletRequest request = new MockHttpServletRequest();
cookieService.addCookie(request, mockWindowId, portletCookie);
EasyMock.verify(portletCookieDao, mockWindowId);
}
Aggregations