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.businessfacades.security;
16
17 import org.figure8.join.core.DuplicateEntityException;
18 import org.figure8.join.businessobjects.security.Role;
19 import org.figure8.join.util.SpringTestCase;
20 /**
21 * JUnit test case for testing the PermissionManager implementation
22 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
23 * @version $Revision: 1.1 $
24 */
25 public class PermissionManagerTest extends SpringTestCase{
26
27
28
29 /** Spring configuration files */
30 private String[] configLocations = new String[]{
31 "classpath:/org/figure8/join/businessfacades/security/spring.xml",
32 "classpath:/org/figure8/join/businessobjects/security/persistence/spring.xml"};
33
34
35
36
37 /** The PermissionManager implementation to test. */
38 protected PermissionManager permissionManager = null;
39
40
41
42
43 /** Retrieve permissionManager after having initialized context */
44 public void setUp(){
45 super.setUp();
46
47 permissionManager = (PermissionManager)context.getBean("permissionManager");
48 }
49
50
51
52
53 /** Test Roles related methods. */
54 public void testRoles(){
55
56 Role architect = new Role("Architect", "Architect description");
57 Role joiner = new Role("Joiner", "Joiner description");
58 Role supplier = new Role("Supplier", "Supplier description");
59 try {supplier.setPermissionResourceResolverClass("org.figure8.join.services.security.PermissionResourceResolverStub");}
60 catch (Exception e) {fail("Exception while setting the permission resource resolver.");}
61
62 try{
63 permissionManager.saveRole(joiner);
64 permissionManager.saveRole(supplier);
65 permissionManager.saveRole(architect);
66 }
67 catch (DuplicateEntityException e){
68 fail("No DuplicateEntityException should be thrown...");
69 }
70
71 assertEquals("Three Roles have been successfull created", 3, permissionManager.getRoles().size());
72
73
74 Role foundRole = permissionManager.getRole("Supplier");
75
76 assertNotNull("Found a Role", foundRole);
77 assertEquals("Found the correct Role", "Supplier", foundRole.getName());
78 assertEquals("Found the correct Role", "Supplier description", foundRole.getDescription());
79 try {assertNotNull("Found a correct Role", foundRole.getPermissionResourceResolver());}
80 catch (Exception e) {fail("Exception while retrieving permission resource resolver.");}
81
82
83 foundRole.setDescription("Supplier new description");
84 try {permissionManager.saveRole(foundRole);}
85 catch (DuplicateEntityException e) {fail("No DuplicateEntityException should be thrown...");}
86
87 assertEquals("Three Roles are enlisted", 3, permissionManager.getRoles().size());
88 }
89
90
91
92
93 /** @return configLocations inner field */
94 public String[] getConfigLocations(){
95 return configLocations;
96 }
97 }