import org.apache.archiva.redback.tests.utils.RBACDefaults;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.Collections;
import java.util.List;
import java.util.Set;
+
import org.springframework.test.annotation.DirtiesContext;
/**
* AbstractRbacManagerTestCase
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- *
*/
-@RunWith( SpringJUnit4ClassRunner.class )
-@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
-@DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD )
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" })
+@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public abstract class AbstractRbacManagerTestCase
extends TestCase
{
private RBACDefaults rbacDefaults;
+ protected Logger log = LoggerFactory.getLogger( getClass() );
+
public void setRbacManager( RBACManager store )
{
this.rbacManager = store;
}
public abstract void assertEventCount();
-
- private void assertEventTracker(int addedRoleNameCount, int removedRoleNameCount,
- int addedPermissionNames, int removedPermissionNames,
- boolean freshness, boolean eventCount )
+
+ private void assertEventTracker( int addedRoleNameCount, int removedRoleNameCount, int addedPermissionNames,
+ int removedPermissionNames, boolean freshness, boolean eventCount )
{
assertNotNull( eventTracker );
- if ( eventCount )
+ if ( eventCount )
{
assertEventCount();
}
assertEquals( removedPermissionNames, eventTracker.removedPermissionNames.size() );
if ( freshness )
{
- assertTrue( eventTracker.lastDbFreshness.booleanValue() );
+ assertTrue( eventTracker.lastDbFreshness.booleanValue() );
}
}
-
+
@Test
public void testStoreInitialization()
throws Exception
/* Assert some event tracker stuff */
assertEventTracker( 0, 0, 0, 0, true, true );
-
+
}
@Test
assertNotNull( fetched );
/* Assert some event tracker stuff */
- assertEventTracker( 2, 0, 3, 0, true, true);
+ assertEventTracker( 2, 0, 3, 0, true, true );
}
assertEquals( develRole, actualDevel );
/* Assert some event tracker stuff */
- assertEventTracker( 2, 0, 2, 0, true, true);
+ assertEventTracker( 2, 0, 2, 0, true, true );
}
@Test
assertEquals( 0, rbacManager.getAllPermissions().size() );
/* Assert some event tracker stuff */
- assertEventTracker( 1, 0, 0, 0, true, true);
+ assertEventTracker( 1, 0, 0, 0, true, true );
}
@Test
assertEquals( 3, manager.getAllRoles().size() );
/* Assert some event tracker stuff */
- assertEventTracker( 3, 0, 3, 0, true, true);
+ assertEventTracker( 3, 0, 3, 0, true, true );
}
@Test
assertEquals( 3, manager.getAllRoles().size() );
/* Assert some event tracker stuff */
- assertEventTracker( 3, 0, 3, 0, true, true);
+ assertEventTracker( 3, 0, 3, 0, true, true );
}
@Test
assertNotNull( fetched );
/* Assert some event tracker stuff */
- assertEventTracker( 1, 0, 1, 0, true, true);
+ assertEventTracker( 1, 0, 1, 0, true, true );
}
@Test
assertEquals( 1, assignedPermissions.size() );
/* Assert some event tracker stuff */
- assertEventTracker( 1, 0, 1, 0, true, true);
+ assertEventTracker( 1, 0, 1, 0, true, true );
}
@Test
assertEquals( 1, manager.getAllResources().size() );
/* Assert some event tracker stuff */
- assertEventTracker( 0, 0, 2, 0, true, true);
+ assertEventTracker( 0, 0, 2, 0, true, true );
}
@Test
manager.createPermission( "Delete Configuration", "delete-configuration", Resource.GLOBAL ) );
/* Assert some event tracker stuff */
- assertEventTracker( 0, 0, 2, 0, true, true);
+ assertEventTracker( 0, 0, 2, 0, true, true );
}
@Test
assertEquals( "Should have 2 assignable roles.", 2, manager.getUnassignedRoles( bob.getPrincipal() ).size() );
/* Assert some event tracker stuff */
- assertEventTracker( 2, 0, 2, 0, true, true);
+ assertEventTracker( 2, 0, 2, 0, true, true );
}
assertEquals( 1, assignment.getRoleNames().size() );
/* Assert some event tracker stuff */
- assertEventTracker( 1, 0, 1, 0, true, true);
+ assertEventTracker( 1, 0, 1, 0, true, true );
}
assertEquals( 1, assignment.getRoleNames().size() );
/* Assert some event tracker stuff */
- assertEventTracker( 2, 0, 1, 0, true, true );
+ assertEventTracker( 2, 0, 1, 0, true, true );
}
@Test
}
/* Assert some event tracker stuff */
- assertEventTracker( 2, 0, 2, 0, true, true);
+ assertEventTracker( 2, 0, 2, 0, true, true );
}
-
+
@Test
public void testGetRolesDeep()
throws RbacManagerException
assertEquals( 1, rbacManager.getAllUserAssignments().size() );
assertEquals( 4, rbacManager.getAllRoles().size() );
assertEquals( 6, rbacManager.getAllPermissions().size() );
-
+
// Get the List of Assigned Roles for user bob.
Role devel = rbacManager.getRole( "Developer" );
assertNotNull( devel );
}
// Assert some event tracker stuff
- assertEventTracker( 2, 0, 3, 0, true, true);
+ assertEventTracker( 2, 0, 3, 0, true, true );
}
}
// Assert some event tracker stuff
- assertEventTracker( 2, 0, 3, 0, true, true);
+ assertEventTracker( 2, 0, 3, 0, true, true );
}