fix unit test
This commit is contained in:
parent
7039fb8eb6
commit
4f547460cf
@ -19,7 +19,6 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import org.apache.archiva.redback.common.jdo.test.StoreManagerDebug;
|
||||
import org.apache.archiva.redback.components.jdo.DefaultConfigurableJdoFactory;
|
||||
import org.apache.archiva.redback.rbac.RBACManager;
|
||||
@ -174,7 +173,6 @@ public void testGetAssignedRoles()
|
||||
public void testGetAssignedPermissionsDeep()
|
||||
throws RbacManagerException
|
||||
{
|
||||
this.clearCache();
|
||||
super.testGetAssignedPermissionsDeep();
|
||||
int counter = storeManager.counter();
|
||||
/* without Level 2 cache: 26 queries */
|
||||
@ -217,11 +215,5 @@ public void testStoreInitialization()
|
||||
assertEquals( EVENTCOUNT, eventTracker.initCount );
|
||||
}
|
||||
|
||||
protected void clearCache()
|
||||
{
|
||||
for ( String cacheName : CacheManager.getInstance().getCacheNames() )
|
||||
{
|
||||
CacheManager.getInstance().getCache( cacheName ).removeAll();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,14 +19,14 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import org.apache.archiva.redback.components.apacheds.ApacheDs;
|
||||
import org.apache.archiva.redback.policy.PasswordEncoder;
|
||||
import org.apache.archiva.redback.policy.encoders.SHA1PasswordEncoder;
|
||||
import org.apache.archiva.redback.rbac.RBACManager;
|
||||
import org.apache.archiva.redback.rbac.ldap.LdapRbacManager;
|
||||
import org.apache.archiva.redback.rbac.Role;
|
||||
import org.apache.archiva.redback.tests.AbstractRbacManagerTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
@ -40,14 +40,8 @@
|
||||
import javax.naming.directory.InitialDirContext;
|
||||
import javax.naming.directory.SearchControls;
|
||||
import javax.naming.directory.SearchResult;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.BeforeClass;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -82,13 +76,15 @@ public void setUp()
|
||||
throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
CacheManager.getInstance().clearAll();
|
||||
this.clearCache();
|
||||
setRbacManager( rbacManager );
|
||||
|
||||
assertTrue( getRbacManager() instanceof LdapRbacManager );
|
||||
|
||||
rbacManager.setWritableLdap( true );
|
||||
|
||||
rbacManager.getRbacImpl().eraseDatabase();
|
||||
|
||||
passwordEncoder = new SHA1PasswordEncoder();
|
||||
|
||||
usersPerGroup = new HashMap<String, List<String>>( 3 );
|
||||
@ -125,9 +121,6 @@ public void setUp()
|
||||
|
||||
apacheDs.getAdminContext().createSubcontext( suffix, attributes );
|
||||
|
||||
//makeUsers();
|
||||
|
||||
//createGroups();
|
||||
}
|
||||
|
||||
@After
|
||||
@ -270,8 +263,12 @@ private void assertExist( DirContext context, String dn, String attribute, Strin
|
||||
public void testStoreInitialization()
|
||||
throws Exception
|
||||
{
|
||||
CacheManager.getInstance().clearAll();
|
||||
//rbacManager.eraseDatabase();
|
||||
this.clearCache();
|
||||
for ( Role role : rbacManager.getAllRoles() )
|
||||
{
|
||||
rbacManager.removeRole( role );
|
||||
}
|
||||
eventTracker.clear();
|
||||
super.testStoreInitialization();
|
||||
}
|
||||
|
||||
|
@ -17,16 +17,17 @@
|
||||
*/
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import org.apache.archiva.redback.rbac.Operation;
|
||||
import org.apache.archiva.redback.rbac.Permission;
|
||||
import org.apache.archiva.redback.rbac.RBACManager;
|
||||
import org.apache.archiva.redback.rbac.RbacManagerException;
|
||||
import org.apache.archiva.redback.rbac.RbacPermanentException;
|
||||
import org.apache.archiva.redback.rbac.Resource;
|
||||
import org.apache.archiva.redback.rbac.Role;
|
||||
import org.apache.archiva.redback.rbac.UserAssignment;
|
||||
import org.apache.archiva.redback.rbac.Permission;
|
||||
import org.apache.archiva.redback.rbac.RbacPermanentException;
|
||||
import org.apache.archiva.redback.tests.utils.RBACDefaults;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
@ -39,15 +40,15 @@
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* 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" } )
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" })
|
||||
public abstract class AbstractRbacManagerTestCase
|
||||
extends TestCase
|
||||
{
|
||||
@ -158,6 +159,7 @@ private void assertEventTracker( int addedRoleNameCount, int removedRoleNameCoun
|
||||
public void testStoreInitialization()
|
||||
throws Exception
|
||||
{
|
||||
|
||||
assertNotNull( rbacManager );
|
||||
|
||||
Role role = getAdminRole();
|
||||
@ -680,8 +682,7 @@ public void testGetAssignedRoles()
|
||||
assignment = manager.saveUserAssignment( assignment );
|
||||
|
||||
assertThat( assignment.getRoleNames() ).isNotNull().isNotEmpty().hasSize( 3 );
|
||||
assertThat( manager.getAllUserAssignments() ).isNotNull().isNotEmpty().hasSize(
|
||||
incAssignements( 1 ) );
|
||||
assertThat( manager.getAllUserAssignments() ).isNotNull().isNotEmpty().hasSize( incAssignements( 1 ) );
|
||||
|
||||
assertThat( manager.getAllRoles() ).isNotNull().isNotEmpty().hasSize( 3 );
|
||||
|
||||
@ -727,8 +728,7 @@ public void testGetAssignedPermissions()
|
||||
assignment.addRoleName( roleName );
|
||||
manager.saveUserAssignment( assignment );
|
||||
|
||||
assertThat( manager.getAllUserAssignments() ).isNotNull().isNotEmpty().hasSize(
|
||||
incAssignements( 1 ) );
|
||||
assertThat( manager.getAllUserAssignments() ).isNotNull().isNotEmpty().hasSize( incAssignements( 1 ) );
|
||||
assertThat( manager.getAllRoles() ).isNotNull().isNotEmpty().hasSize( 3 );
|
||||
assertThat( manager.getAllPermissions() ).isNotNull().isNotEmpty().hasSize( 3 );
|
||||
|
||||
@ -839,7 +839,9 @@ public void testGetRolesDeep()
|
||||
public void testGetAssignedPermissionsDeep()
|
||||
throws RbacManagerException
|
||||
{
|
||||
this.clearCache();
|
||||
assertNotNull( rbacManager );
|
||||
rbacManager.eraseDatabase();
|
||||
rbacDefaults.createDefaults();
|
||||
|
||||
// Setup User / Assignment with 1 role.
|
||||
@ -850,8 +852,11 @@ public void testGetAssignedPermissionsDeep()
|
||||
rbacManager.saveUserAssignment( assignment );
|
||||
|
||||
assertEquals( incAssignements( 1 ), rbacManager.getAllUserAssignments().size() );
|
||||
assertEquals( 6, rbacManager.getAllPermissions().size() );
|
||||
assertEquals( 4, rbacManager.getAllRoles().size() );
|
||||
List<Permission> permissions = rbacManager.getAllPermissions();
|
||||
Assertions.assertThat( permissions ).isNotNull().isNotEmpty().hasSize( 6 );
|
||||
|
||||
List<Role> roles = rbacManager.getAllRoles();
|
||||
Assertions.assertThat( roles ).isNotNull().isNotEmpty().hasSize( 4 );
|
||||
|
||||
afterSetup();
|
||||
|
||||
@ -986,7 +991,8 @@ public void testAddRemovePermanentOperation()
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitialize() throws Exception
|
||||
public void testInitialize()
|
||||
throws Exception
|
||||
{
|
||||
rbacManager.initialize();
|
||||
}
|
||||
@ -998,4 +1004,12 @@ protected void afterSetup()
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
protected void clearCache()
|
||||
{
|
||||
for ( String cacheName : CacheManager.getInstance().getCacheNames() )
|
||||
{
|
||||
CacheManager.getInstance().getCache( cacheName ).removeAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,8 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.archiva.redback.rbac.RBACManagerListener;
|
||||
import org.apache.archiva.redback.rbac.Permission;
|
||||
import org.apache.archiva.redback.rbac.RBACManagerListener;
|
||||
import org.apache.archiva.redback.rbac.Role;
|
||||
import org.apache.archiva.redback.rbac.UserAssignment;
|
||||
import org.slf4j.Logger;
|
||||
@ -33,7 +33,6 @@
|
||||
* RbacManagerEventTracker
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
*
|
||||
*/
|
||||
public class RbacManagerEventTracker
|
||||
implements RBACManagerListener
|
||||
@ -59,6 +58,17 @@ public void rbacInit( boolean freshdb )
|
||||
lastDbFreshness = Boolean.valueOf( freshdb );
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
this.addedRoleNames = new ArrayList<String>();
|
||||
|
||||
this.removedRoleNames = new ArrayList<String>();
|
||||
|
||||
this.addedPermissionNames = new ArrayList<String>();
|
||||
|
||||
this.removedPermissionNames = new ArrayList<String>();
|
||||
}
|
||||
|
||||
public void rbacPermissionRemoved( Permission permission )
|
||||
{
|
||||
log( "Permission Removed: " + permission.getName() );
|
||||
|
Loading…
x
Reference in New Issue
Block a user