/*
 * WeberLoginCheckActionTest.java
 *
 * Created on 2007/03/26, 17:28
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package test.weber_4_0_sample.org.itscool.weber;

import org.itscool.weber.controller.Globals;
import org.itscool.weber.testcase.WeberDbTestCase;
import org.itscool.weber.user.RoleException;
import org.itscool.weber.user.User;
import weber_4_0_sample.org.itscool.weber.WeberLoginCheckAction;

/**
 *
 * @author ios
 */
public class WeberLoginCheckActionTest extends WeberDbTestCase{
    public void setUp(){
        this.initTables("test/weber_4_0_sample/org/itscool/weber/test-db-data.xml");
    }
    
    public void testDoExecute(){
        WeberLoginCheckAction action = new WeberLoginCheckAction();
//modify 2007/03/26 kano start 純粋に業務ロジックのみをテスト対象とする
//        User user = new User();
//        user.setName("admin");
//        user.setPwd("admin");
//        
//        bucket.setAttributeFromSession(Globals.REQ_PARAM_USER, user);
//modify 2007/03/26 kano end
        try{
            this.assertDoExecute(action, null, "login_success");
        }catch(Exception e){
            fail(e.getMessage());
        }
    }
    
    public void testCheckUserRole(){
        WeberLoginCheckAction action = new WeberLoginCheckAction();
        
        User user = new User();
        user.setName("admin");
        user.setPwd("admin");
        
        this.assertCheckUserRole(action, user, true);
    }
    
    public void testCheckUserRole2(){
        WeberLoginCheckAction action = new WeberLoginCheckAction();
        
        User user = new User();
        user.setName("guest");
        user.setPwd("guest");
        
        this.assertCheckUserRole(action, user, true);
    }
    
    public void testCheckUserRole3(){
        WeberLoginCheckAction action = new WeberLoginCheckAction();
        
        User user = new User();
        user.setName("guest");
        user.setPwd("hoge");
        
        this.assertCheckUserRole(action, user, false);
    }
    
    public void testCheckUserRole4(){
        WeberLoginCheckAction action = new WeberLoginCheckAction();
        
        this.assertCheckUserRole(action, null, false);
    }
}
