1   /**
2    * Copyright 2005-2006 the original author or authors.
3    *
4    * Licensed under the Gnu General Pubic License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    *
8    *      http://www.opensource.org/licenses/gpl-license.php
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13   * See the Gnu General Public License for more details.
14   */
15  package org.figure8.join.businessobjects.security;
16  
17  import org.figure8.join.core.InvalidParameterException;
18  import org.figure8.join.services.security.PermissionResourceResolver;
19  
20  import junit.framework.Test;
21  import junit.framework.TestCase;
22  import junit.framework.TestSuite;
23  /**
24   * JUnit test case for Role business object.
25   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
26   * @version Revision$
27   */
28  public class RoleTest extends TestCase{
29  
30     // Constructors -------------------------------------------------------------
31  
32     /** Default constructor. Build a test case using a name. */
33     public RoleTest(String testName){
34        super(testName);
35     }
36  
37  
38     // Override of TestCase -----------------------------------------------------
39  
40     /**
41      * Make this class a TestSuite.
42      * @return A TestSuite containing this TestCase.
43      */
44     public static Test suite(){
45        TestSuite suite = new TestSuite(RoleTest.class);
46        return suite;
47     }
48     
49     
50     // Public -------------------------------------------------------------------
51  
52     /** Test the retrieval of a PermissionResourceResolver */
53     public void testGetPermissionResourceResolver(){
54        // Create the test fixture.
55        Role role = new Role("name", "description");
56        PermissionResourceResolver resolver = null;
57        try{
58           // Build and retrieve resolver.
59           role.setPermissionResourceResolverClass("org.figure8.join.services.security.PermissionResourceResolverStub");
60           resolver = role.getPermissionResourceResolver();
61        }
62        catch (Exception e){
63           fail("PermissionResourceResolver implementation is not recognized: " + e.getMessage());
64        }
65        // Assert that accessor is ready to use.
66        assertNotNull("PermissionResourceResolver is not null", resolver);
67     }
68  
69     /** Test the failure of instantiating a PermissionResourceResolver */
70     public void testPermissionResourceResolverInstantiationFailure(){
71        // Create the test fixture.
72        Role role = new Role("name", "description");
73        try{
74           // Build fake resolver.
75           role.setPermissionResourceResolverClass("org.figure8.join.services.security.MyFakeResolver");
76        }
77        catch (Exception e){
78           assertTrue("Fake PermissionResourceResolver implementation cannot be assign", (e instanceof InvalidParameterException));
79        }
80     }
81  }