Package org.springframework.mock.web.portlet

Examples of org.springframework.mock.web.portlet.MockPortletSession


  }

  public void testGetOrCreateSessionAttributeWithNoExistingAttributeAndClassWithNoPublicCtor() throws Exception {
    new AssertThrows(IllegalArgumentException.class) {
      public void test() throws Exception {
        PortletUtils.getOrCreateSessionAttribute(new MockPortletSession(), "bean", NoPublicCtor.class);
      }
    }.runTest();
  }
View Full Code Here


      }
    }.runTest();
  }

  public void testGetSessionMutexWithNoExistingSessionMutexDefinedJustReturnsTheSessionArgument() throws Exception {
    MockPortletSession session = new MockPortletSession();
    Object sessionMutex = PortletUtils.getSessionMutex(session);
    assertNotNull("PortletUtils.getSessionMutex(..) must never return a null mutex", sessionMutex);
    assertSame("PortletUtils.getSessionMutex(..) must return the exact same PortletSession supplied as an argument if no mutex has been bound as a Session attribute beforehand",
        session, sessionMutex);
  }
View Full Code Here

    assertSame("PortletUtils.getSessionMutex(..) must return the exact same PortletSession supplied as an argument if no mutex has been bound as a Session attribute beforehand",
        session, sessionMutex);
  }

  public void testGetSessionMutexWithExistingSessionMutexReturnsTheExistingSessionMutex() throws Exception {
    MockPortletSession session = new MockPortletSession();
    Object expectSessionMutex = new Object();
    session.setAttribute(WebUtils.SESSION_MUTEX_ATTRIBUTE, expectSessionMutex);
    Object actualSessionMutex = PortletUtils.getSessionMutex(session);
    assertNotNull("PortletUtils.getSessionMutex(..) must never return a null mutex", actualSessionMutex);
    assertSame("PortletUtils.getSessionMutex(..) must return the bound mutex attribute if a mutex has been bound as a Session attribute beforehand",
        expectSessionMutex, actualSessionMutex);
  }
View Full Code Here

  public void testGetSessionAttributeWithExistingSession() throws Exception {
    MockControl mock = MockControl.createControl(PortletRequest.class);
    PortletRequest request = (PortletRequest) mock.getMock();
    request.getPortletSession(false);
    MockPortletSession session = new MockPortletSession();
    session.setAttribute("foo", "foo");
    mock.setReturnValue(session);
    mock.replay();

    Object sessionAttribute = PortletUtils.getSessionAttribute(request, "foo");
    assertNotNull("Must not return null if session attribute exists (and Session exists)", sessionAttribute);
View Full Code Here

  public void testGetRequiredSessionAttributeWithExistingSession() throws Exception {
    MockControl mock = MockControl.createControl(PortletRequest.class);
    PortletRequest request = (PortletRequest) mock.getMock();
    request.getPortletSession(false);
    MockPortletSession session = new MockPortletSession();
    session.setAttribute("foo", "foo");
    mock.setReturnValue(session);
    mock.replay();

    Object sessionAttribute = PortletUtils.getRequiredSessionAttribute(request, "foo");
    assertNotNull("Must not return null if session attribute exists (and Session exists)", sessionAttribute);
View Full Code Here

  public void testGetRequiredSessionAttributeWithExistingSessionAndNoAttribute() throws Exception {
    MockControl mock = MockControl.createControl(PortletRequest.class);
    final PortletRequest request = (PortletRequest) mock.getMock();
    request.getPortletSession(false);
    MockPortletSession session = new MockPortletSession();
    mock.setReturnValue(session);
    mock.replay();
    new AssertThrows(IllegalStateException.class) {
      public void test() throws Exception {
        PortletUtils.getRequiredSessionAttribute(request, "foo");
View Full Code Here

    TestBean testBean = new TestBean();
    testBean.setAge(40);
    SimplePortletApplicationContext ac =
        (SimplePortletApplicationContext)simpleDispatcherPortlet.getPortletApplicationContext();
    String formAttribute = ac.getFormSessionAttributeName();
    PortletSession session = new MockPortletSession();
    session.setAttribute(formAttribute, testBean);
    renderRequest.setSession(session);
    simpleDispatcherPortlet.doDispatch(renderRequest, renderResponse);
    assertEquals("35", renderResponse.getContentAsString());
  }
View Full Code Here

  }

  public void testSimpleFormViewWithSessionNoBindOnNewForm() throws Exception {
    MockActionRequest actionRequest = new MockActionRequest();
    MockActionResponse actionResponse = new MockActionResponse();
    actionRequest.setSession(new MockPortletSession());
    actionRequest.setParameter("action", "form-session-nobind");
    actionRequest.setParameter("age", "27");
    simpleDispatcherPortlet.processAction(actionRequest, actionResponse);
    Map renderParameters = actionResponse.getRenderParameterMap();
View Full Code Here

        portletContext.setMajorVersion(getMajorVersion());
        actionContext.put(StrutsStatics.STRUTS_PORTLET_CONTEXT, portletContext);

        portletRequest = new MockPortletRequest(portletContext);
        portletResponse = new MockStateAwareResponse();
        portletSession = new MockPortletSession();
        portletRequest.setSession(portletSession);
        actionContext.setSession(createSession());
        actionContext.put(PortletConstants.REQUEST, portletRequest);
        actionContext.put(PortletConstants.RESPONSE, portletResponse);
        actionContext.put(PortletConstants.MODE_NAMESPACE_MAP, new HashMap<PortletMode, String>());
View Full Code Here

    PortletUtils.getOrCreateSessionAttribute(null, "bean", TestBean.class);
  }

  @Test
  public void testGetOrCreateSessionAttributeJustReturnsAttributeIfItAlreadyExists() throws Exception {
    MockPortletSession session = new MockPortletSession();
    final TestBean expectedAttribute = new TestBean("Donna Tartt");
    session.setAttribute("donna", expectedAttribute);
    Object actualAttribute = PortletUtils.getOrCreateSessionAttribute(session, "donna", TestBean.class);
    assertSame(expectedAttribute, actualAttribute);
  }
View Full Code Here

TOP

Related Classes of org.springframework.mock.web.portlet.MockPortletSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.