FileDocCategorySizeDatePackage
TokenHelperTest.javaAPI DocExample2461Mon Jul 23 13:26:26 BST 2007org.apache.struts2.util

TokenHelperTest

public class TokenHelperTest extends TestCase
TokenHelperTest

Fields Summary
private Map
session
Constructors Summary
Methods Summary
protected voidsetUp()

        session = new HashMap();
        Map params = new HashMap();
        Map ctxMap = new HashMap();
        ctxMap.put(ActionContext.SESSION, session);
        ctxMap.put(ActionContext.PARAMETERS, params);
        ActionContext ctx = new ActionContext(ctxMap);
        ActionContext.setContext(ctx);
    
protected voidtearDown()

        ActionContext.setContext(null);
    
public voidtestSetToken()

        String token = TokenHelper.setToken();
        assertEquals(token, session.get(TokenHelper.DEFAULT_TOKEN_NAME));
    
public voidtestSetTokenWithName()

        String tokenName = "myTestToken";
        String token = TokenHelper.setToken(tokenName);
        assertEquals(token, session.get(tokenName));
    
public voidtestValidToken()

        String tokenName = "validTokenTest";
        String token = TokenHelper.setToken(tokenName);
        assertEquals(token, session.get(tokenName));
        ActionContext.getContext().getParameters().put(TokenHelper.TOKEN_NAME_FIELD, new String[]{tokenName});
        ActionContext.getContext().getParameters().put(tokenName, new String[]{token});
        assertTrue(TokenHelper.validToken());