Skip to content
Permalink
Browse files
correctly clear caches
  • Loading branch information
olamy committed Apr 11, 2014
1 parent 18eecc9 commit 7039fb8eb67075a517e3261ac84c36c039306312
Showing 1 changed file with 20 additions and 19 deletions.
@@ -20,14 +20,15 @@
*/

import net.sf.ehcache.CacheManager;
import org.apache.archiva.redback.components.jdo.DefaultConfigurableJdoFactory;
import org.apache.archiva.redback.rbac.RbacManagerException;
import org.apache.archiva.redback.common.jdo.test.StoreManagerDebug;
import org.apache.archiva.redback.components.jdo.DefaultConfigurableJdoFactory;
import org.apache.archiva.redback.rbac.RBACManager;
import org.apache.archiva.redback.rbac.RbacManagerException;
import org.apache.archiva.redback.tests.AbstractRbacManagerTestCase;
import org.jpox.AbstractPersistenceManagerFactory;
import org.jpox.SchemaTool;
import org.junit.Before;
import org.springframework.test.annotation.DirtiesContext;

import javax.inject.Inject;
import javax.inject.Named;
@@ -37,33 +38,31 @@
import java.net.URL;
import java.util.Map;
import java.util.Properties;
import org.springframework.test.annotation.DirtiesContext;

/**
* JdoRbacManagerTest:
*
* @author Jesse McConnell <jmcconnell@apache.org>
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*
*/
@DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD )
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class JdoRbacManagerTest
extends AbstractRbacManagerTestCase
{
private StoreManagerDebug storeManager;

@Inject
@Named( value = "jdoFactory#users" )
@Named(value = "jdoFactory#users")
DefaultConfigurableJdoFactory jdoFactory;

@Inject
@Named( value = "rbacManager#jdo" )
@Named(value = "rbacManager#jdo")
RBACManager rbacManager;

public static int EVENTCOUNT = 2;

@Override
public void assertEventCount()
public void assertEventCount()
{
assertEquals( EVENTCOUNT, eventTracker.initCount );
}
@@ -128,8 +127,6 @@ public void setUp()
URL[] jdoFileUrls =
new URL[]{ getClass().getResource( "/org/apache/archiva/redback/rbac/jdo/package.jdo" ) }; //$NON-NLS-1$



if ( ( jdoFileUrls == null ) || ( jdoFileUrls[0] == null ) )
{
fail( "Unable to process test " + getName() + " - missing package.jdo." );
@@ -177,6 +174,7 @@ public void testGetAssignedRoles()
public void testGetAssignedPermissionsDeep()
throws RbacManagerException
{
this.clearCache();
super.testGetAssignedPermissionsDeep();
int counter = storeManager.counter();
/* without Level 2 cache: 26 queries */
@@ -195,21 +193,15 @@ protected void afterSetup()
public void testLargeApplicationInit()
throws RbacManagerException
{
for (String cacheName : CacheManager.getInstance().getCacheNames())
{
CacheManager.getInstance().getCache( cacheName ).removeAll();
}
this.clearCache();
super.testLargeApplicationInit();
}

@Override
public void testGetRolesDeep()
throws RbacManagerException
{
for (String cacheName : CacheManager.getInstance().getCacheNames())
{
CacheManager.getInstance().getCache( cacheName ).removeAll();
}
this.clearCache();
super.testGetRolesDeep();
}

@@ -218,9 +210,18 @@ public void testGetRolesDeep()
public void testStoreInitialization()
throws Exception
{
this.clearCache();
rbacManager.eraseDatabase();
eventTracker.rbacInit( true );
super.testStoreInitialization();
assertEquals( EVENTCOUNT, eventTracker.initCount );
}

protected void clearCache()
{
for ( String cacheName : CacheManager.getInstance().getCacheNames() )
{
CacheManager.getInstance().getCache( cacheName ).removeAll();
}
}
}

0 comments on commit 7039fb8

Please sign in to comment.