View Javadoc
1   /**
2    *
3    */
4   package org.melati.login.test;
5   
6   
7   
8   import org.melati.login.HttpSessionAccessHandler;
9   import org.melati.poem.AccessPoemException;
10  import org.melati.servlet.test.MockHttpServletRequest;
11  import org.melati.servlet.test.MockHttpServletResponse;
12  import org.melati.servlet.test.MockHttpSession;
13  import org.melati.util.HttpServletRequestParameters;
14  
15  
16  /**
17   * @author timp
18   *
19   */
20  public class HttpSessionAccessHandlerTest extends AccessHandlerTestAbstract {
21  
22    /**
23     * @param name
24     */
25    public HttpSessionAccessHandlerTest(String name) {
26      super(name);
27    }
28  
29    public void setUp() throws Exception {
30      super.setUp();
31      MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest(); 
32      
33      MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse(); 
34      MockHttpSession mockSession = new MockHttpSession();
35      mockSession.setAttribute("org.melati.login.Login.triggeringRequestParameters", 
36          new HttpServletRequestParameters(mockHttpServletRequest));
37      mockSession.setAttribute("org.melati.login.Login.triggeringException", new AccessPoemException());
38      //mockSession.setAttribute("org.melati.login.Login.HttpSessionAccessHandler.overlayParameters", null);
39      mockSession.setAttribute("org.melati.login.HttpSessionAccessHandler.user", m.getDatabase().guestAccessToken());
40      mockHttpServletRequest.setSession(mockSession);
41      m.setRequest(mockHttpServletRequest);
42      m.setResponse(mockHttpServletResponse);
43    }
44  
45    /**
46     * Create the AccessHandler and set its input stream.
47     *
48     * @see org.melati.login.test.AccessHandlerTestAbstract#setAccessHandler()
49     */
50    public void setAccessHandler() {
51      HttpSessionAccessHandler ah = new HttpSessionAccessHandler();
52      it = ah;
53    }
54    /**
55     * Test method for {@link org.melati.login.AccessHandler#establishUser(Melati)}.
56     */
57    public void testEstablishUser() {
58      it.establishUser(m);
59      assertEquals("Melati guest user",m.getUser().displayString());
60    }
61  
62  
63  }