package edu.columbia.gemma.common.auditAndSecurity;

import java.util.Collection;
import java.util.HashSet;

import org.easymock.MockControl;

import edu.columbia.gemma.BaseServiceTestCase;
import edu.columbia.gemma.expression.arrayDesign.ArrayDesignDao;

/**
 * <hr>
 * <p>
 * Copyright (c) 2004-2005 Columbia University
 * 
 * @author pavlidis
 * @version $Id$
 */
public class UserRoleServiceImplTest extends BaseServiceTestCase {

    private UserRoleServiceImpl userRoleService = new UserRoleServiceImpl();
    private UserRoleDao userRoleDaoMock;
    private MockControl control;

    /*
     * @see TestCase#setUp()
     */
    protected void setUp() throws Exception {
        super.setUp();
        control = MockControl.createControl( UserRoleDao.class );
        userRoleDaoMock = ( UserRoleDao ) control.getMock();
        userRoleService.setUserRoleDao(userRoleDaoMock);
    }

    /*
     * @see TestCase#tearDown()
     */
    protected void tearDown() throws Exception {
        super.tearDown();
    }

    public void testHandleGetRoles() {
        Collection allRoles = new HashSet();
        for(int i = 0; i < 5; i++ ) {
            UserRole ur = UserRole.Factory.newInstance();
            ur.setName("admin" + i);
            ur.setUserName("paul" + i);
            allRoles.add(ur);
        }
        
        userRoleDaoMock.findAllRoles();
        control.setReturnValue(allRoles);
        
        control.replay();
        userRoleService.getRoles();
        control.verify();
        
    }

    public void testHandleGetRole() {
        UserRole ur = UserRole.Factory.newInstance();
        ur.setName("admin");
        ur.setUserName("paul");
        Collection allRoles = new HashSet();
        allRoles.add(ur);
        userRoleDaoMock.findRolesByRoleName("admin");
        control.setReturnValue(allRoles);
        
        control.replay();
        userRoleService.getRole("admin");
        control.verify();
    }

    public void testHandleSaveRole() {
        UserRole ur = UserRole.Factory.newInstance();
        ur.setName("admin");
        ur.setUserName("paul");
        userRoleDaoMock.create(ur);
        control.setReturnValue(ur);
        
        control.replay();
        userRoleService.saveRole(ur);
        control.verify();
    }

    public void testHandleRemoveRole() {
    }

}

@@ -1506,32 +1506,112 @@
         %0A    %7D%0A%0A
+    // this commented out because the getRole method no longer calls the Dao.%0A//
     public void 
@@ -1624,32 +1624,34 @@
 ndleGetRole() %7B%0A
+//
         UserRole
@@ -1680,32 +1680,34 @@
 .newInstance();%0A
+//
         ur.setNa
@@ -1711,35 +1711,39 @@
 tName(%22admin%22);%0A
+//
    
+//
      ur.setUserN
@@ -1747,32 +1747,34 @@
 erName(%22paul%22);%0A
+//
         Collecti
@@ -1794,32 +1794,34 @@
  new HashSet();%0A
+//
         allRoles
@@ -1822,32 +1822,34 @@
 lRoles.add(ur);%0A
+//
         userRole
@@ -1878,32 +1878,34 @@
 eName(%22admin%22);%0A
+//
         control.
@@ -1922,32 +1922,34 @@
 alue(allRoles);%0A
+//
         %0A       
@@ -1933,32 +1933,34 @@
 es);%0A//        %0A
+//
         control.
@@ -1961,32 +1961,34 @@
 ntrol.replay();%0A
+//
         userRole
@@ -2005,32 +2005,34 @@
 tRole(%22admin%22);%0A
+//
         control.
@@ -2033,32 +2033,34 @@
 ntrol.verify();%0A
+//
     %7D%0A%0A    publi

remove test that isn't needed (doesn't use dao)