/************************************************
 * Copyright (c) Shen Li. All rights reserved.  *
 * http://joyaop.sourceforge.net                *
 * -------------------------------------------- *
 * Distributable under LGPL license.            *
 * See terms of license at gnu.org.             *
 ************************************************/
package net.sf.joyaop.demo.rbac.model;

import net.sf.joyaop.extension.mock.MockObjectTestCase;
import org.jmock.Mock;

import java.util.HashSet;
import java.util.Set;

/**
 * @author Shen Li
 */
public class RoleOwnerTest extends MockObjectTestCase {
    public void testGetAllRoles() {
        Mock mockRoleOwner = mockAbstactMethods(RoleOwnerImpl.class);
        Mock mockParentRoleOwner = mock(RoleOwnerImpl.class);
        RoleOwner roleOwner = (RoleOwner) mockRoleOwner.proxy();
        RoleOwner parentRoleOwner = (RoleOwner) mockParentRoleOwner.proxy();
        Set parents = new HashSet();
        parents.add(parentRoleOwner);
        Set parentRoles = new HashSet();
        Role parentRole = (Role) mock(Role.class).proxy();
        parentRoles .add(parentRole);
        mockRoleOwner.expects(atLeastOnce()).method("getParents").will(returnValue(parents));
        mockParentRoleOwner.expects(atLeastOnce()).method("getAllRoles").will(returnValue(parentRoles));
        Role role = (Role) mock(Role.class).proxy();
        roleOwner.addRole(role);
        assertEquals(2, roleOwner.getAllRoles().size());
        assertTrue(roleOwner.getAllRoles().contains(role));
        assertTrue(roleOwner.getAllRoles().contains(parentRole));
        mockRoleOwner.verify();
        mockParentRoleOwner.verify();
    }
}
