1 15 package org.apache.tapestry.web; 16 17 import java.util.List ; 18 19 import javax.servlet.http.HttpSession ; 20 21 import org.apache.tapestry.web.ServletWebSession; 22 import org.apache.tapestry.web.WebSession; 23 import org.easymock.MockControl; 24 25 31 public class TestServletWebSession extends BaseWebTestCase 32 { 33 public void testGetAttributeNames() 34 { 35 MockControl control = newControl(HttpSession .class); 36 HttpSession session = (HttpSession ) control.getMock(); 37 38 session.getAttributeNames(); 39 control.setReturnValue(newEnumeration()); 40 41 replayControls(); 42 43 WebSession ws = new ServletWebSession(session); 44 45 List l = ws.getAttributeNames(); 46 47 checkList(l); 48 49 verifyControls(); 50 } 51 52 public void testGetAttribute() 53 { 54 Object attribute = new Object (); 55 56 MockControl control = newControl(HttpSession .class); 57 HttpSession session = (HttpSession ) 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 attribute = new Object (); 74 75 MockControl control = newControl(HttpSession .class); 76 HttpSession session = (HttpSession ) 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 .class); 92 HttpSession session = (HttpSession ) 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 .class); 108 HttpSession session = (HttpSession ) 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 |