Package com.pugh.sockso.web.action.api

Source Code of com.pugh.sockso.web.action.api.SessionActionTest

package com.pugh.sockso.web.action.api;

import com.pugh.sockso.tests.SocksoTestCase;
import com.pugh.sockso.tests.TestResponse;
import com.pugh.sockso.web.User;

public class SessionActionTest extends SocksoTestCase {

    private SessionAction action;
   
    private TestResponse res;
   
    @Override
    protected void setUp() {
        res = new TestResponse();
        action = new SessionAction();
        action.setResponse( res );
    }
   
    public void testActionDoesNotRequireLogin() {
        assertFalse( action.requiresLogin() );
    }
   
    public void testCanhandleReturnsTrueForValidUrls() {
        assertTrue( action.canHandle(getRequest("/api/session")) );
        assertTrue( action.canHandle(getRequest("/api/session?foo=bar")) );
    }
   
    public void testCanhandleReturnsFalseForInvalidUrls() {
        assertFalse( action.canHandle(getRequest("/api/sessions")) );
        assertFalse( action.canHandle(getRequest("/api")) );
        assertFalse( action.canHandle(getRequest("/api/session/create")) );
    }
   
    public void test1ReturnedWhenUserHasSession() throws Exception {
        action.setUser( new User(1,"me") );
        action.handleRequest();
        assertEndsWith( res.getOutput(), "1" );
    }
   
    public void test0ReturnedWhenUserDoesNotHaveSession() throws Exception {
        action.setUser( null );
        action.handleRequest();
        assertEndsWith( res.getOutput(), "0" );
    }
   
}
TOP

Related Classes of com.pugh.sockso.web.action.api.SessionActionTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.