/* ======================================================================
   Parts Copyright 2006 University of Leeds, Oxford University, University of the Highlands and Islands.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

====================================================================== */

package org.bodington.server;

import org.bodington.server.realm.Permission;

import junit.framework.TestCase;

public class PermissionDeniedExceptionTest extends TestCase
{

    public void testSimplePermissionDenied()
    {
        PermissionDeniedException pde = new PermissionDeniedException(Permission.VIEW);
        assertEquals(Permission.VIEW, pde.getPermissions()[0]);
        assertEquals("view", pde.getPermission());
    }
    
    public void testMultiplePermissionDenied()
    {
        PermissionDeniedException pde = new PermissionDeniedException(
            new Permission[]{Permission.VIEW, Permission.SEE, Permission.EDIT});
        assertEquals(3, pde.getPermissions().length);
        assertEquals("view or see or edit", pde.getPermission());
    }
    
    public void testPermissionDeniedChecking()
    {
        try
        {
            new PermissionDeniedException((Permission)null);
            fail("Shouldn't be able to create passing null");
        }
        catch (IllegalArgumentException iae)
        {
            assertNotNull(iae);
        }
    }
    
    public void testPermissionDeniedArrayChecking()
    {
        try
        {
            new PermissionDeniedException((Permission[])null);
            fail("Shouldn't be able to create passing null");
        }
        catch (IllegalArgumentException iae)
        {
            assertNotNull(iae);
        }
        
        try
        {
            new PermissionDeniedException(new Permission[0]);
            fail("Shouldn't be able to create passing empty array");
        }
        catch (IllegalArgumentException iae)
        {
            assertNotNull(iae);
        }
    }
    
}
