}
}
public void testGetRoles() throws Exception
{
WikiSession session;
Principal[] principals;
// Create a new "asserted" session for Bob
session = WikiSessionTest.assertedSession( m_engine, Users.BOB );
// Set up a group without Bob in it
Group test = m_groupMgr.parseGroup( "Test", "Alice \n Charlie", true );
m_groupMgr.setGroup( m_session, test );
// Bob should have two roles: ASSERTED and ALL
principals = session.getRoles();
assertTrue( "Bob in ALL", ArrayUtils.contains( principals, Role.ALL ) );
assertTrue( "Bob in ASSERTED", ArrayUtils.contains( principals, Role.ASSERTED ) );
assertFalse( "Bob not in ANONYMOUS", ArrayUtils.contains( principals, Role.ANONYMOUS ) );
assertFalse( "Bob not in Test", ArrayUtils.contains( principals, test.getPrincipal() ) );
// Re-save group "Test" with Bob as a member
test = m_groupMgr.parseGroup( "Test", "Alice \n Bob \nCharlie", true );
m_groupMgr.setGroup( m_session, test );
// Bob not authenticated: should still have only two romes
principals = session.getRoles();
assertTrue( "Bob in ALL", ArrayUtils.contains( principals, Role.ALL ) );
assertTrue( "Bob in ASSERTED", ArrayUtils.contains( principals, Role.ASSERTED ) );
assertFalse( "Bob not in ANONYMOUS", ArrayUtils.contains( principals, Role.ANONYMOUS ) );
assertFalse( "Bob in Test", ArrayUtils.contains( principals, test.getPrincipal() ) );
// Elevate Bob to "authenticated" status
session = WikiSessionTest.authenticatedSession( m_engine, Users.BOB, Users.BOB_PASS );
// Re-save the group; Bob should possess the role now
test = m_groupMgr.parseGroup( "Test", "Alice \n Bob \n Charlie", true );
m_groupMgr.setGroup( m_session, test );
principals = session.getRoles();
assertTrue( "Bob in ALL", ArrayUtils.contains( principals, Role.ALL ) );
assertFalse( "Bob in ASSERTED", ArrayUtils.contains( principals, Role.ASSERTED ) );
assertFalse( "Bob not in ANONYMOUS", ArrayUtils.contains( principals, Role.ANONYMOUS ) );
assertTrue( "Bob in Test", ArrayUtils.contains( principals, test.getPrincipal() ) );