Search in sources :

Example 11 with IPortalCookie

use of org.apereo.portal.portlet.om.IPortalCookie in project uPortal by Jasig.

the class PortletCookieServiceImplTest method testGetOrCreatePortalCookieGetExistingFromSession.

/**
 * Test {@link
 * PortletCookieServiceImpl#getOrCreatePortalCookie(javax.servlet.http.HttpServletRequest)}.
 * that results in returning an existing portalcookie from the id stored in the session.
 */
@Test
public void testGetOrCreatePortalCookieGetExistingFromSession() {
    IPortletCookieDao portletCookieDao = EasyMock.createMock(IPortletCookieDao.class);
    MockPortalCookie portalCookie = new MockPortalCookie();
    portalCookie.setValue("ABCDEF");
    EasyMock.expect(portletCookieDao.getPortalCookie("ABCDEF")).andReturn(portalCookie);
    EasyMock.replay(portletCookieDao);
    PortletCookieServiceImpl cookieService = new PortletCookieServiceImpl();
    cookieService.setPortletCookieDao(portletCookieDao);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.getSession().setAttribute(PortletCookieServiceImpl.SESSION_ATTRIBUTE__PORTAL_COOKIE_ID, "ABCDEF");
    IPortalCookie result = cookieService.getOrCreatePortalCookie(request);
    Assert.assertEquals(portalCookie, result);
    EasyMock.verify(portletCookieDao);
}
Also used : IPortalCookie(org.apereo.portal.portlet.om.IPortalCookie) IPortletCookieDao(org.apereo.portal.portlet.dao.IPortletCookieDao) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Example 12 with IPortalCookie

use of org.apereo.portal.portlet.om.IPortalCookie 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);
}
Also used : IPortletCookie(org.apereo.portal.portlet.om.IPortletCookie) IPortalCookie(org.apereo.portal.portlet.om.IPortalCookie) Cookie(javax.servlet.http.Cookie) IPortletCookieDao(org.apereo.portal.portlet.dao.IPortletCookieDao) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId) Test(org.junit.Test)

Aggregations

IPortalCookie (org.apereo.portal.portlet.om.IPortalCookie)12 Cookie (javax.servlet.http.Cookie)8 IPortletCookie (org.apereo.portal.portlet.om.IPortletCookie)7 Test (org.junit.Test)4 IPortletCookieDao (org.apereo.portal.portlet.dao.IPortletCookieDao)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 DateTime (org.joda.time.DateTime)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 HttpSession (javax.servlet.http.HttpSession)1 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)1 BasePortalJpaDaoTest (org.apereo.portal.test.BasePortalJpaDaoTest)1 HibernateOptimisticLockingFailureException (org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException)1