HEAD test/build fix (AuthorityServiceTest)

- tweak existing tests to be less susceptible to existing site=>group data (should now work with more than one default site)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28667 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2011-06-28 14:49:42 +00:00
parent 6fd9628330
commit eb25afcd95

View File

@@ -51,6 +51,7 @@ import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.service.cmr.security.MutableAuthenticationService; import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.service.transaction.TransactionService; import org.alfresco.service.transaction.TransactionService;
@@ -62,29 +63,28 @@ public class AuthorityServiceTest extends TestCase
private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); private static ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
private AuthenticationComponent authenticationComponent; private AuthenticationComponent authenticationComponent;
private MutableAuthenticationService authenticationService; private MutableAuthenticationService authenticationService;
private MutableAuthenticationDao authenticationDAO; private MutableAuthenticationDao authenticationDAO;
private AuthorityService authorityService; private AuthorityService authorityService;
private AuthorityService pubAuthorityService; private AuthorityService pubAuthorityService;
private PersonService personService; private PersonService personService;
private UserTransaction tx; private UserTransaction tx;
private AclDAO aclDaoComponent; private AclDAO aclDaoComponent;
private NodeService nodeService; private NodeService nodeService;
public AuthorityServiceTest() public AuthorityServiceTest()
{ {
super(); super();
} }
private static final int DEFAULT_SITE_GRP_CNT = 5; // default number of groups per site
private static final int DEFAULT_SITE_ROOT_GRP_CNT = 1; // default number of root groups per site
private static final int DEFAULT_GRP_CNT = 2; // default (non-site) bootstrap groups - eg. GROUP_ALFRESCO_ADMINISTRATORS, GROUP_EMAIL_CONTRIBUTORS
private int SITE_CNT = 0;
private int GRP_CNT = 0;
private int ROOT_GRP_CNT = 0;
public void setUp() throws Exception public void setUp() throws Exception
{ {
if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE) if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
@@ -103,7 +103,14 @@ public class AuthorityServiceTest extends TestCase
aclDaoComponent = (AclDAO) ctx.getBean("aclDAO"); aclDaoComponent = (AclDAO) ctx.getBean("aclDAO");
nodeService = (NodeService) ctx.getBean("nodeService"); nodeService = (NodeService) ctx.getBean("nodeService");
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); String defaultAdminUser = AuthenticationUtil.getAdminUserName();
AuthenticationUtil.setFullyAuthenticatedUser(defaultAdminUser);
// note: currently depends on any existing (and/or bootstrap) group data - eg. default site "swsdp" (Sample Web Site Design Project)
SiteService siteService = (SiteService) ctx.getBean("SiteService");
SITE_CNT = siteService.listSites(defaultAdminUser).size();
GRP_CNT = DEFAULT_GRP_CNT + (DEFAULT_SITE_GRP_CNT * SITE_CNT);
ROOT_GRP_CNT = DEFAULT_GRP_CNT + (DEFAULT_SITE_ROOT_GRP_CNT * SITE_CNT);
TransactionService transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE.getLocalName()); TransactionService transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE.getLocalName());
tx = transactionService.getUserTransaction(); tx = transactionService.getUserTransaction();
@@ -362,7 +369,7 @@ public class AuthorityServiceTest extends TestCase
assertTrue(authorityService.hasAdminAuthority()); assertTrue(authorityService.hasAdminAuthority());
assertTrue(pubAuthorityService.hasAdminAuthority()); assertTrue(pubAuthorityService.hasAdminAuthority());
Set<String> authorities = authorityService.getAuthorities(); Set<String> authorities = authorityService.getAuthorities();
assertEquals("Unexpected result: " + authorities, 6, authorityService.getAuthorities().size()); assertEquals("Unexpected result: " + authorities, 4 + (SITE_CNT*2), authorityService.getAuthorities().size());
} }
public void testAuthorities() public void testAuthorities()
@@ -372,7 +379,7 @@ public class AuthorityServiceTest extends TestCase
assertEquals(1, getAllAuthorities(AuthorityType.EVERYONE).size()); assertEquals(1, getAllAuthorities(AuthorityType.EVERYONE).size());
assertTrue(getAllAuthorities(AuthorityType.EVERYONE).contains(PermissionService.ALL_AUTHORITIES)); assertTrue(getAllAuthorities(AuthorityType.EVERYONE).contains(PermissionService.ALL_AUTHORITIES));
// groups added for email and admin // groups added for email and admin
assertEquals(7, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT, getAllAuthorities(AuthorityType.GROUP).size());
assertFalse(getAllAuthorities(AuthorityType.GROUP).contains(PermissionService.ALL_AUTHORITIES)); assertFalse(getAllAuthorities(AuthorityType.GROUP).contains(PermissionService.ALL_AUTHORITIES));
assertEquals(1, getAllAuthorities(AuthorityType.GUEST).size()); assertEquals(1, getAllAuthorities(AuthorityType.GUEST).size());
assertTrue(getAllAuthorities(AuthorityType.GUEST).contains(PermissionService.GUEST_AUTHORITY)); assertTrue(getAllAuthorities(AuthorityType.GUEST).contains(PermissionService.GUEST_AUTHORITY));
@@ -452,14 +459,14 @@ public class AuthorityServiceTest extends TestCase
{ {
String auth; String auth;
assertEquals(7, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(3, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth = pubAuthorityService.createAuthority(AuthorityType.GROUP, "woof"); auth = pubAuthorityService.createAuthority(AuthorityType.GROUP, "woof");
assertEquals(8, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+1, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(4, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+1, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
pubAuthorityService.deleteAuthority(auth); pubAuthorityService.deleteAuthority(auth);
assertEquals(7, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(3, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
assertEquals(0, getAllAuthorities(AuthorityType.ROLE).size()); assertEquals(0, getAllAuthorities(AuthorityType.ROLE).size());
assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size()); assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
@@ -480,43 +487,43 @@ public class AuthorityServiceTest extends TestCase
String auth5; String auth5;
assertFalse(pubAuthorityService.authorityExists(pubAuthorityService.getName(AuthorityType.GROUP, "one"))); assertFalse(pubAuthorityService.authorityExists(pubAuthorityService.getName(AuthorityType.GROUP, "one")));
assertEquals(7, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(3, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth1 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "one"); auth1 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "one");
assertTrue(pubAuthorityService.authorityExists(auth1)); assertTrue(pubAuthorityService.authorityExists(auth1));
assertEquals(8, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+1, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(4, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+1, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth2 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "two"); auth2 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "two");
assertEquals(9, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+2, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth3 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "three"); auth3 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "three");
pubAuthorityService.addAuthority(auth1, auth3); pubAuthorityService.addAuthority(auth1, auth3);
assertEquals(10, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+3, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth4 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "four"); auth4 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "four");
pubAuthorityService.addAuthority(auth1, auth4); pubAuthorityService.addAuthority(auth1, auth4);
assertEquals(11, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+4, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth5 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "five"); auth5 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "five");
pubAuthorityService.addAuthority(auth2, auth5); pubAuthorityService.addAuthority(auth2, auth5);
assertEquals(12, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
pubAuthorityService.deleteAuthority(auth5); pubAuthorityService.deleteAuthority(auth5);
assertEquals(11, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+4, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
pubAuthorityService.deleteAuthority(auth4); pubAuthorityService.deleteAuthority(auth4);
assertEquals(10, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+3, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
pubAuthorityService.deleteAuthority(auth3); pubAuthorityService.deleteAuthority(auth3);
assertEquals(9, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+2, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
pubAuthorityService.deleteAuthority(auth2); pubAuthorityService.deleteAuthority(auth2);
assertEquals(8, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+1, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(4, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+1, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
pubAuthorityService.deleteAuthority(auth1); pubAuthorityService.deleteAuthority(auth1);
assertEquals(7, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(3, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
assertEquals(0, getAllAuthorities(AuthorityType.ROLE).size()); assertEquals(0, getAllAuthorities(AuthorityType.ROLE).size());
assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size()); assertEquals(0, pubAuthorityService.getAllRootAuthorities(AuthorityType.ROLE).size());
@@ -576,37 +583,37 @@ public class AuthorityServiceTest extends TestCase
String auth4; String auth4;
String auth5; String auth5;
assertEquals(7, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(3, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth1 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "one"); auth1 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "one");
assertEquals("GROUP_one", auth1); assertEquals("GROUP_one", auth1);
assertEquals(8, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+1, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(4, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+1, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth2 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "two"); auth2 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "two");
assertEquals("GROUP_two", auth2); assertEquals("GROUP_two", auth2);
assertEquals(9, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+2, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth3 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "three"); auth3 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "three");
pubAuthorityService.addAuthority(auth1, auth3); pubAuthorityService.addAuthority(auth1, auth3);
assertEquals("GROUP_three", auth3); assertEquals("GROUP_three", auth3);
assertEquals(10, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+3, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth4 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "four"); auth4 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "four");
pubAuthorityService.addAuthority(auth1, auth4); pubAuthorityService.addAuthority(auth1, auth4);
assertEquals("GROUP_four", auth4); assertEquals("GROUP_four", auth4);
assertEquals(11, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+4, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth5 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "five"); auth5 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "five");
pubAuthorityService.addAuthority(auth2, auth5); pubAuthorityService.addAuthority(auth2, auth5);
assertEquals("GROUP_five", auth5); assertEquals("GROUP_five", auth5);
assertEquals(12, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
//System.out.println("Users: "+ getAllAuthorities(AuthorityType.USER)); //System.out.println("Users: "+ getAllAuthorities(AuthorityType.USER));
checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER); checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER);
pubAuthorityService.addAuthority(auth5, "andy"); pubAuthorityService.addAuthority(auth5, "andy");
assertEquals(12, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
// The next call looks for people not users :-) // The next call looks for people not users :-)
checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER); checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER);
assertEquals(2, pubAuthorityService.getContainingAuthorities(null, "andy", false).size()); assertEquals(2, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
@@ -623,8 +630,8 @@ public class AuthorityServiceTest extends TestCase
assertTrue(pubAuthorityService.getContainedAuthorities(null, auth5, false).contains("andy")); assertTrue(pubAuthorityService.getContainedAuthorities(null, auth5, false).contains("andy"));
pubAuthorityService.removeAuthority(auth5, "andy"); pubAuthorityService.removeAuthority(auth5, "andy");
assertEquals(12, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
// The next call looks for people not users :-) // The next call looks for people not users :-)
checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER); checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER);
assertEquals(0, pubAuthorityService.getContainingAuthorities(null, "andy", false).size()); assertEquals(0, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
@@ -647,33 +654,33 @@ public class AuthorityServiceTest extends TestCase
String auth4; String auth4;
String auth5; String auth5;
assertEquals(7, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(3, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth1 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "one"); auth1 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "one");
assertEquals(8, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+1, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(4, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+1, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth2 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "two"); auth2 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "two");
assertEquals(9, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+2, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth3 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "three"); auth3 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "three");
pubAuthorityService.addAuthority(auth1, auth3); pubAuthorityService.addAuthority(auth1, auth3);
assertEquals(10, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+3, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth4 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "four"); auth4 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "four");
pubAuthorityService.addAuthority(auth1, auth4); pubAuthorityService.addAuthority(auth1, auth4);
assertEquals(11, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+4, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth5 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "five"); auth5 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "five");
pubAuthorityService.addAuthority(auth2, auth5); pubAuthorityService.addAuthority(auth2, auth5);
assertEquals(12, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
assertEquals(3, getAllAuthorities(AuthorityType.USER).size()); assertEquals(3, getAllAuthorities(AuthorityType.USER).size());
pubAuthorityService.addAuthority(auth5, "andy"); pubAuthorityService.addAuthority(auth5, "andy");
pubAuthorityService.addAuthority(auth1, "andy"); pubAuthorityService.addAuthority(auth1, "andy");
assertEquals(12, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
// The next call looks for people not users :-) // The next call looks for people not users :-)
checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER); checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER);
assertEquals(3, pubAuthorityService.getContainingAuthorities(null, "andy", false).size()); assertEquals(3, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
@@ -691,8 +698,8 @@ public class AuthorityServiceTest extends TestCase
pubAuthorityService.removeAuthority(auth1, "andy"); pubAuthorityService.removeAuthority(auth1, "andy");
assertEquals(12, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
// The next call looks for people not users :-) // The next call looks for people not users :-)
checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER); checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER);
assertEquals(2, pubAuthorityService.getContainingAuthorities(null, "andy", false).size()); assertEquals(2, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
@@ -717,33 +724,33 @@ public class AuthorityServiceTest extends TestCase
String auth4; String auth4;
String auth5; String auth5;
assertEquals(7, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(3, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth1 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "one"); auth1 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "one");
assertEquals(8, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+1, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(4, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+1, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth2 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "two"); auth2 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "two");
assertEquals(9, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+2, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth3 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "three"); auth3 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "three");
pubAuthorityService.addAuthority(auth1, auth3); pubAuthorityService.addAuthority(auth1, auth3);
assertEquals(10, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+3, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth4 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "four"); auth4 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "four");
pubAuthorityService.addAuthority(auth1, auth4); pubAuthorityService.addAuthority(auth1, auth4);
assertEquals(11, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+4, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
auth5 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "five"); auth5 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "five");
pubAuthorityService.addAuthority(auth2, auth5); pubAuthorityService.addAuthority(auth2, auth5);
assertEquals(12, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER); checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER);
pubAuthorityService.addAuthority(auth5, "andy"); pubAuthorityService.addAuthority(auth5, "andy");
pubAuthorityService.addAuthority(auth1, "andy"); pubAuthorityService.addAuthority(auth1, "andy");
assertEquals(12, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(5, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
// The next call looks for people not users :-) // The next call looks for people not users :-)
checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER); checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER);
assertEquals(3, pubAuthorityService.getContainingAuthorities(null, "andy", false).size()); assertEquals(3, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
@@ -761,10 +768,10 @@ public class AuthorityServiceTest extends TestCase
pubAuthorityService.addAuthority(auth3, auth2); pubAuthorityService.addAuthority(auth3, auth2);
assertEquals(12, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT+5, getAllAuthorities(AuthorityType.GROUP).size());
// Number of root authorities has been reduced since auth2 is no longer an orphan // Number of root authorities has been reduced since auth2 is no longer an orphan
assertEquals(4, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT+1, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
// The next call looks for people not users :-) // The next call looks for people not users :-)
checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER); checkAuthorityCollectionSize(3, getAllAuthorities(AuthorityType.USER), AuthorityType.USER);
assertEquals(4, pubAuthorityService.getContainingAuthorities(null, "andy", false).size()); assertEquals(4, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
@@ -782,7 +789,6 @@ public class AuthorityServiceTest extends TestCase
assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains(auth2)); assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains(auth2));
assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains(auth5)); assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains(auth5));
assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains("andy")); assertTrue(pubAuthorityService.getContainedAuthorities(null, auth1, false).contains("andy"));
} }
public void testGetAuthorityNodeRef() public void testGetAuthorityNodeRef()
@@ -852,8 +858,8 @@ public class AuthorityServiceTest extends TestCase
personService.getPerson("andy4"); personService.getPerson("andy4");
personService.getPerson("andy5"); personService.getPerson("andy5");
personService.getPerson("andy6"); personService.getPerson("andy6");
assertEquals(7, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(3, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
String auth1 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "one"); String auth1 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "one");
pubAuthorityService.addAuthority(auth1, "andy1"); pubAuthorityService.addAuthority(auth1, "andy1");
String auth2 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "two"); String auth2 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "two");
@@ -1030,8 +1036,8 @@ public class AuthorityServiceTest extends TestCase
personService.getPerson("an3dy"); personService.getPerson("an3dy");
assertTrue(personService.personExists("an3dy")); assertTrue(personService.personExists("an3dy"));
assertEquals(7, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(3, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
String auth1 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "one"); String auth1 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "one");
pubAuthorityService.addAuthority(auth1, "1234"); pubAuthorityService.addAuthority(auth1, "1234");
String auth2 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "two"); String auth2 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "two");
@@ -1070,13 +1076,12 @@ public class AuthorityServiceTest extends TestCase
assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy2", false).contains(auth5)); assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy2", false).contains(auth5));
assertEquals(1, pubAuthorityService.getContainingAuthorities(null, "an3dy", false).size()); assertEquals(1, pubAuthorityService.getContainingAuthorities(null, "an3dy", false).size());
assertTrue(pubAuthorityService.getContainingAuthorities(null, "an3dy", false).contains(auth6)); assertTrue(pubAuthorityService.getContainingAuthorities(null, "an3dy", false).contains(auth6));
} }
public void testGroupNameTokenisation() public void testGroupNameTokenisation()
{ {
assertEquals(7, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(3, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
String auth1234 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "1234"); String auth1234 = pubAuthorityService.createAuthority(AuthorityType.GROUP, "1234");
assertEquals(0, pubAuthorityService.getContainedAuthorities(AuthorityType.GROUP, auth1234, false).size()); assertEquals(0, pubAuthorityService.getContainedAuthorities(AuthorityType.GROUP, auth1234, false).size());
@@ -1109,8 +1114,8 @@ public class AuthorityServiceTest extends TestCase
pubAuthorityService.deleteAuthority(authC1); pubAuthorityService.deleteAuthority(authC1);
pubAuthorityService.deleteAuthority(auth1234); pubAuthorityService.deleteAuthority(auth1234);
assertEquals(7, getAllAuthorities(AuthorityType.GROUP).size()); assertEquals(GRP_CNT, getAllAuthorities(AuthorityType.GROUP).size());
assertEquals(3, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size()); assertEquals(ROOT_GRP_CNT, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
} }
public void testAdminGroup() public void testAdminGroup()