KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > web > TestServletWebSession


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.web;
16
17 import java.util.List JavaDoc;
18
19 import javax.servlet.http.HttpSession JavaDoc;
20
21 import org.apache.tapestry.web.ServletWebSession;
22 import org.apache.tapestry.web.WebSession;
23 import org.easymock.MockControl;
24
25 /**
26  * Tests for {@link org.apache.tapestry.web.ServletWebSession}.
27  *
28  * @author Howard M. Lewis Ship
29  * @since 4.0
30  */

31 public class TestServletWebSession extends BaseWebTestCase
32 {
33     public void testGetAttributeNames()
34     {
35         MockControl control = newControl(HttpSession JavaDoc.class);
36         HttpSession JavaDoc session = (HttpSession JavaDoc) control.getMock();
37
38         session.getAttributeNames();
39         control.setReturnValue(newEnumeration());
40
41         replayControls();
42
43         WebSession ws = new ServletWebSession(session);
44
45         List JavaDoc l = ws.getAttributeNames();
46
47         checkList(l);
48
49         verifyControls();
50     }
51
52     public void testGetAttribute()
53     {
54         Object JavaDoc attribute = new Object JavaDoc();
55
56         MockControl control = newControl(HttpSession JavaDoc.class);
57         HttpSession JavaDoc session = (HttpSession JavaDoc) control.getMock();
58
59         session.getAttribute("attr");
60         control.setReturnValue(attribute);
61
62         replayControls();
63
64         WebSession ws = new ServletWebSession(session);
65
66         assertSame(attribute, ws.getAttribute("attr"));
67
68         verifyControls();
69     }
70
71     public void testSetAttribute()
72     {
73         Object JavaDoc attribute = new Object JavaDoc();
74
75         MockControl control = newControl(HttpSession JavaDoc.class);
76         HttpSession JavaDoc session = (HttpSession JavaDoc) control.getMock();
77
78         session.setAttribute("name", attribute);
79
80         replayControls();
81
82         WebSession ws = new ServletWebSession(session);
83
84         ws.setAttribute("name", attribute);
85
86         verifyControls();
87     }
88
89     public void testSetAttributeToNull()
90     {
91         MockControl control = newControl(HttpSession JavaDoc.class);
92         HttpSession JavaDoc session = (HttpSession JavaDoc) control.getMock();
93
94         session.removeAttribute("tonull");
95
96         replayControls();
97
98         WebSession ws = new ServletWebSession(session);
99
100         ws.setAttribute("tonull", null);
101
102         verifyControls();
103     }
104
105     public void testGetId()
106     {
107         MockControl control = newControl(HttpSession JavaDoc.class);
108         HttpSession JavaDoc session = (HttpSession JavaDoc) control.getMock();
109
110         session.getId();
111         control.setReturnValue("abc");
112
113         replayControls();
114
115         WebSession ws = new ServletWebSession(session);
116
117         assertEquals("abc", ws.getId());
118
119         verifyControls();
120     }
121 }
Popular Tags