more cleanup of direct use of archiva-configuration

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1170514 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-09-14 10:23:09 +00:00
parent 2459cfd7a8
commit 808aa92aa0
2 changed files with 64 additions and 10 deletions

View File

@ -20,6 +20,8 @@ package org.apache.maven.archiva.web.action.reports;
*/
import com.opensymphony.xwork2.Preparable;
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.MetadataRepositoryException;
import org.apache.archiva.metadata.repository.RepositorySession;
@ -30,7 +32,6 @@ import org.apache.archiva.security.common.ArchivaRoleConstants;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.web.action.AbstractRepositoryBasedAction;
import org.codehaus.plexus.redback.rbac.Resource;
import org.codehaus.redback.integration.interceptor.SecureAction;
@ -78,7 +79,7 @@ public class GenerateReportAction
private Logger log = LoggerFactory.getLogger( GenerateReportAction.class );
@Inject
private ArchivaConfiguration archivaConfiguration;
private ManagedRepositoryAdmin managedRepositoryAdmin;
@Inject
private RepositoryStatisticsManager repositoryStatisticsManager;
@ -99,7 +100,7 @@ public class GenerateReportAction
private int numPages;
private Collection<String> repositoryIds;
private List<String> repositoryIds;
private Map<String, List<RepositoryProblemFacet>> repositoriesMap =
new TreeMap<String, List<RepositoryProblemFacet>>();
@ -114,6 +115,7 @@ public class GenerateReportAction
@SuppressWarnings( "unchecked" )
public void prepare()
throws RepositoryAdminException
{
repositoryIds = new ArrayList<String>();
repositoryIds.add( ALL_REPOSITORIES ); // comes first to be first in the list
@ -122,7 +124,7 @@ public class GenerateReportAction
availableRepositories = new ArrayList<String>();
// remove selected repositories in the option for the statistics report
availableRepositories.addAll( archivaConfiguration.getConfiguration().getManagedRepositoriesAsMap().keySet() );
availableRepositories.addAll( managedRepositoryAdmin.getManagedRepositoriesAsMap().keySet() );
for ( String repo : selectedRepositories )
{
if ( availableRepositories.contains( repo ) )
@ -630,7 +632,7 @@ public class GenerateReportAction
return bundle;
}
public Collection<String> getRepositoryIds()
public List<String> getRepositoryIds()
{
return repositoryIds;
}
@ -759,4 +761,14 @@ public class GenerateReportAction
{
this.repositoryStatisticsManager = repositoryStatisticsManager;
}
public ManagedRepositoryAdmin getManagedRepositoryAdmin()
{
return managedRepositoryAdmin;
}
public void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin )
{
this.managedRepositoryAdmin = managedRepositoryAdmin;
}
}

View File

@ -21,6 +21,8 @@ package org.apache.maven.archiva.web.action.reports;
import com.google.common.collect.Lists;
import com.opensymphony.xwork2.Action;
import org.apache.archiva.admin.model.managed.ManagedRepository;
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.metadata.model.MetadataFacet;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.RepositorySession;
@ -28,8 +30,8 @@ import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactor
import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
import org.apache.archiva.reports.RepositoryProblemFacet;
import org.apache.commons.io.IOUtils;
import org.apache.archiva.security.UserRepositoriesStub;
import org.apache.commons.io.IOUtils;
import org.apache.maven.archiva.web.action.AbstractActionTestCase;
import org.easymock.MockControl;
import org.junit.After;
@ -39,7 +41,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -70,14 +74,13 @@ public class GenerateReportActionTest
private static final String PROBLEM = "problem";
@Override
protected void setUp()
throws Exception
{
super.setUp();
//action = (GenerateReportAction) lookup( Action.class, "generateReport" );
UserRepositoriesStub stub = applicationContext.getBean( "userRepositories", UserRepositoriesStub.class );
stub.setRepoIds( Lists.<String>newArrayList( "internal", "snapshots" ) );
@ -104,21 +107,50 @@ public class GenerateReportActionTest
{
UserRepositoriesStub stub = applicationContext.getBean( "userRepositories", UserRepositoriesStub.class );
stub.setRepoIds( Lists.<String>newArrayList( "test-repo" ) );
super.tearDown();
}
private void prepareAction( List<String> selectedRepositories, List<String> availableRepositories )
throws Exception
{
MockControl managedRepositoryControl = MockControl.createControl( ManagedRepositoryAdmin.class );
ManagedRepositoryAdmin managedRepositoryAdmin = (ManagedRepositoryAdmin) managedRepositoryControl.getMock();
Map<String, ManagedRepository> map = new HashMap<String, ManagedRepository>( availableRepositories.size() );
for ( String repoId : availableRepositories )
{
map.put( repoId, new ManagedRepository() );
}
managedRepositoryControl.expectAndReturn( managedRepositoryAdmin.getManagedRepositoriesAsMap(), map, 1, 10 );
managedRepositoryControl.replay();
action.setManagedRepositoryAdmin( managedRepositoryAdmin );
action.setSelectedRepositories( selectedRepositories );
action.prepare();
assertEquals( Arrays.asList( GenerateReportAction.ALL_REPOSITORIES, INTERNAL, SNAPSHOTS ),
action.getRepositoryIds() );
List<String> repos = Arrays.asList( GenerateReportAction.ALL_REPOSITORIES, INTERNAL, SNAPSHOTS );
Collections.sort( repos );
Collections.sort( action.getRepositoryIds() );
assertEquals( repos, action.getRepositoryIds() );
Collections.sort( action.getAvailableRepositories() );
availableRepositories = new ArrayList<String>( availableRepositories );
Collections.sort( availableRepositories );
assertEquals( availableRepositories, action.getAvailableRepositories() );
}
public void testGenerateStatisticsInvalidRowCount()
throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
@ -131,6 +163,7 @@ public class GenerateReportActionTest
}
public void testGenerateStatisticsInvalidEndDate()
throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
@ -144,6 +177,7 @@ public class GenerateReportActionTest
}
public void testGenerateStatisticsMalformedEndDate()
throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
@ -158,6 +192,7 @@ public class GenerateReportActionTest
}
public void testGenerateStatisticsInvalidEndDateMultiRepo()
throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
@ -171,6 +206,7 @@ public class GenerateReportActionTest
}
public void testGenerateStatisticsMalformedEndDateMultiRepo()
throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
@ -185,6 +221,7 @@ public class GenerateReportActionTest
}
public void testGenerateStatisticsNoRepos()
throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
@ -329,6 +366,7 @@ public class GenerateReportActionTest
}
public void testDownloadStatisticsMalformedEndDateMultiRepo()
throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
@ -343,6 +381,7 @@ public class GenerateReportActionTest
}
public void testDownloadStatisticsMalformedEndDateSingleRepo()
throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Arrays.asList( SNAPSHOTS ), Arrays.asList( INTERNAL ) );
@ -357,6 +396,7 @@ public class GenerateReportActionTest
}
public void testDownloadStatisticsInvalidEndDateMultiRepo()
throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
@ -370,6 +410,7 @@ public class GenerateReportActionTest
}
public void testDownloadStatisticsInvalidEndDateSingleRepo()
throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Arrays.asList( SNAPSHOTS ), Arrays.asList( INTERNAL ) );
@ -399,6 +440,7 @@ public class GenerateReportActionTest
}
public void testDownloadStatisticsNoRepos()
throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );