Search in sources :

Example 1 with IPortletCookieDao

use of org.apereo.portal.portlet.dao.IPortletCookieDao in project uPortal by Jasig.

the class PortletCookieServiceImplTest method testGetOrCreatePortalCookieGetExistingFromRequestCookies.

/**
     * Test {@link
     * PortletCookieServiceImpl#getOrCreatePortalCookie(javax.servlet.http.HttpServletRequest)}.
     * that results in returning an existing portalcookie from the request cookies
     */
@Test
public void testGetOrCreatePortalCookieGetExistingFromRequestCookies() {
    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();
    Cookie[] cookies = new Cookie[1];
    Cookie cookie = new Cookie(IPortletCookieService.DEFAULT_PORTAL_COOKIE_NAME, "ABCDEF");
    cookies[0] = cookie;
    request.setCookies(cookies);
    IPortalCookie result = cookieService.getOrCreatePortalCookie(request);
    Assert.assertEquals(portalCookie, result);
    EasyMock.verify(portletCookieDao);
}
Also used : IPortletCookie(org.apereo.portal.portlet.om.IPortletCookie) IPortalCookie(org.apereo.portal.portlet.om.IPortalCookie) Cookie(javax.servlet.http.Cookie) 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 2 with IPortletCookieDao

use of org.apereo.portal.portlet.dao.IPortletCookieDao in project uPortal by Jasig.

the class PortletCookieServiceImplTest method testUpdatePortletCookieControl.

/**
     * Control test invocation of {@link
     * PortletCookieServiceImpl#updatePortalCookie(javax.servlet.http.HttpServletRequest,
     * javax.servlet.http.HttpServletResponse)}.
     */
@Test
public void testUpdatePortletCookieControl() {
    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.updatePortalCookieExpiration(portalCookie, PortletCookieServiceImpl.DEFAULT_MAX_AGE)).andReturn(portalCookie);
    EasyMock.replay(portletCookieDao);
    PortletCookieServiceImpl cookieService = new PortletCookieServiceImpl();
    cookieService.setPortletCookieDao(portletCookieDao);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    cookieService.updatePortalCookie(request, response);
    Cookie[] cookies = response.getCookies();
    Assert.assertNotNull(cookies);
    Assert.assertEquals(1, cookies.length);
    EasyMock.verify(portletCookieDao);
}
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) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 3 with IPortletCookieDao

use of org.apereo.portal.portlet.dao.IPortletCookieDao in project uPortal by Jasig.

the class PortletCookieServiceImplTest method testAddCookieControl.

/**
     * Control test for adding a portlet cookie: no existing portalCookie, portlet cookie requires
     * persistence.
     */
@Test
public void testAddCookieControl() {
    Cookie portletCookie = new Cookie("somePortletCookieName", "somePortletCookieValue");
    // max age will trigger persistence
    portletCookie.setMaxAge(360);
    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)

Example 4 with IPortletCookieDao

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);
}
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)

Example 5 with IPortletCookieDao

use of org.apereo.portal.portlet.dao.IPortletCookieDao in project uPortal by Jasig.

the class PortletCookieServiceImplTest method testGetOrCreatePortalCookieCreate.

/**
     * Test {@link
     * PortletCookieServiceImpl#getOrCreatePortalCookie(javax.servlet.http.HttpServletRequest)}.
     * that results in creating a new PortalCookie.
     */
@Test
public void testGetOrCreatePortalCookieCreate() {
    IPortletCookieDao portletCookieDao = EasyMock.createMock(IPortletCookieDao.class);
    MockPortalCookie portalCookie = new MockPortalCookie();
    portalCookie.setValue("ABCDEF");
    EasyMock.expect(portletCookieDao.createPortalCookie(PortletCookieServiceImpl.DEFAULT_MAX_AGE)).andReturn(portalCookie);
    EasyMock.replay(portletCookieDao);
    PortletCookieServiceImpl cookieService = new PortletCookieServiceImpl();
    cookieService.setPortletCookieDao(portletCookieDao);
    MockHttpServletRequest request = new MockHttpServletRequest();
    cookieService.getOrCreatePortalCookie(request);
    EasyMock.verify(portletCookieDao);
}
Also used : IPortletCookieDao(org.apereo.portal.portlet.dao.IPortletCookieDao) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test)

Aggregations

IPortletCookieDao (org.apereo.portal.portlet.dao.IPortletCookieDao)7 Test (org.junit.Test)7 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)7 IPortalCookie (org.apereo.portal.portlet.om.IPortalCookie)6 Cookie (javax.servlet.http.Cookie)5 IPortletCookie (org.apereo.portal.portlet.om.IPortletCookie)5 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1