01: /*
02: * $Id: TokenHelperTest.java 471756 2006-11-06 15:01:43Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21: package org.apache.struts2.util;
22:
23: import java.util.HashMap;
24: import java.util.Map;
25:
26: import junit.framework.TestCase;
27:
28: import com.opensymphony.xwork2.ActionContext;
29:
30: /**
31: * TokenHelperTest
32: *
33: */
34: public class TokenHelperTest extends TestCase {
35:
36: private Map session;
37:
38: public void testSetToken() {
39: String token = TokenHelper.setToken();
40: assertEquals(token, session.get(TokenHelper.DEFAULT_TOKEN_NAME));
41: }
42:
43: public void testSetTokenWithName() {
44: String tokenName = "myTestToken";
45: String token = TokenHelper.setToken(tokenName);
46: assertEquals(token, session.get(tokenName));
47: }
48:
49: public void testValidToken() {
50: String tokenName = "validTokenTest";
51: String token = TokenHelper.setToken(tokenName);
52: assertEquals(token, session.get(tokenName));
53: ActionContext.getContext().getParameters().put(
54: TokenHelper.TOKEN_NAME_FIELD,
55: new String[] { tokenName });
56: ActionContext.getContext().getParameters().put(tokenName,
57: new String[] { token });
58: assertTrue(TokenHelper.validToken());
59: }
60:
61: protected void setUp() throws Exception {
62: session = new HashMap();
63: Map params = new HashMap();
64: Map ctxMap = new HashMap();
65: ctxMap.put(ActionContext.SESSION, session);
66: ctxMap.put(ActionContext.PARAMETERS, params);
67: ActionContext ctx = new ActionContext(ctxMap);
68: ActionContext.setContext(ctx);
69: }
70:
71: protected void tearDown() {
72: ActionContext.setContext(null);
73: }
74: }
|