1 5 package com.opensymphony.webwork.util; 6 7 import com.mockobjects.dynamic.C; 8 import com.mockobjects.dynamic.Mock; 9 import com.opensymphony.webwork.views.jsp.WebWorkMockHttpSession; 10 import junit.framework.TestCase; 11 12 import javax.servlet.http.HttpServletRequest ; 13 import javax.servlet.http.HttpSession ; 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 18 24 public class TokenHelperTest extends TestCase { 25 27 private HttpServletRequest request; 28 private HttpSession session; 29 private Mock mockRequest; 30 31 33 public void testSetToken() { 34 String token = TokenHelper.setToken(request); 35 assertEquals(token, session.getAttribute(TokenHelper.DEFAULT_TOKEN_NAME)); 36 } 37 38 public void testSetTokenWithName() { 39 String tokenName = "myTestToken"; 40 String token = TokenHelper.setToken(tokenName, request); 41 assertEquals(token, session.getAttribute(tokenName)); 42 } 43 44 public void testValidToken() { 45 String tokenName = "validTokenTest"; 46 Map params = new HashMap (); 47 48 String token = TokenHelper.setToken(tokenName, request); 49 assertEquals(token, session.getAttribute(tokenName)); 50 params.put(TokenHelper.TOKEN_NAME_FIELD, new String []{tokenName}); 51 params.put(tokenName, new String []{token}); 52 mockRequest.matchAndReturn("getParameterMap", params); 53 assertTrue(TokenHelper.validToken(request)); 54 } 55 56 protected void setUp() throws Exception { 57 session = new WebWorkMockHttpSession(); 58 mockRequest = new Mock(HttpServletRequest .class); 59 mockRequest.matchAndReturn("getSession", C.ANY_ARGS, session); 60 request = (HttpServletRequest ) mockRequest.proxy(); 61 } 62 63 protected void tearDown() { 64 mockRequest.verify(); 65 } 66 } 67 | Popular Tags |