01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.util;
06:
07: import java.util.HashMap;
08: import java.util.Map;
09:
10: import junit.framework.TestCase;
11:
12: import com.opensymphony.xwork.ActionContext;
13:
14: /**
15: * TokenHelperTest
16: *
17: * @author Jason Carreira
18: * Created Apr 3, 2003 10:13:08 AM
19: */
20: public class TokenHelperTest extends TestCase {
21:
22: private Map session;
23:
24: public void testSetToken() {
25: String token = TokenHelper.setToken();
26: assertEquals(token, session.get(TokenHelper.DEFAULT_TOKEN_NAME));
27: }
28:
29: public void testSetTokenWithName() {
30: String tokenName = "myTestToken";
31: String token = TokenHelper.setToken(tokenName);
32: assertEquals(token, session.get(tokenName));
33: }
34:
35: public void testValidToken() {
36: String tokenName = "validTokenTest";
37: Map params = new HashMap();
38:
39: String token = TokenHelper.setToken(tokenName);
40: assertEquals(token, session.get(tokenName));
41: ActionContext.getContext().getParameters().put(
42: TokenHelper.TOKEN_NAME_FIELD,
43: new String[] { tokenName });
44: ActionContext.getContext().getParameters().put(tokenName,
45: new String[] { token });
46: assertTrue(TokenHelper.validToken());
47: }
48:
49: protected void setUp() throws Exception {
50: session = new HashMap();
51: Map params = new HashMap();
52: Map ctxMap = new HashMap();
53: ctxMap.put(ActionContext.SESSION, session);
54: ctxMap.put(ActionContext.PARAMETERS, params);
55: ActionContext ctx = new ActionContext(ctxMap);
56: ActionContext.setContext(ctx);
57: }
58:
59: protected void tearDown() {
60: ActionContext.setContext(null);
61: }
62: }
|