*/
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;
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;
private Logger log = LoggerFactory.getLogger( GenerateReportAction.class );
@Inject
- private ArchivaConfiguration archivaConfiguration;
+ private ManagedRepositoryAdmin managedRepositoryAdmin;
@Inject
private RepositoryStatisticsManager repositoryStatisticsManager;
private int numPages;
- private Collection<String> repositoryIds;
+ private List<String> repositoryIds;
private Map<String, List<RepositoryProblemFacet>> repositoriesMap =
new TreeMap<String, List<RepositoryProblemFacet>>();
@SuppressWarnings( "unchecked" )
public void prepare()
+ throws RepositoryAdminException
{
repositoryIds = new ArrayList<String>();
repositoryIds.add( ALL_REPOSITORIES ); // comes first to be first in the list
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 ) )
return bundle;
}
- public Collection<String> getRepositoryIds()
+ public List<String> getRepositoryIds()
{
return repositoryIds;
}
{
this.repositoryStatisticsManager = repositoryStatisticsManager;
}
+
+ public ManagedRepositoryAdmin getManagedRepositoryAdmin()
+ {
+ return managedRepositoryAdmin;
+ }
+
+ public void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin )
+ {
+ this.managedRepositoryAdmin = managedRepositoryAdmin;
+ }
}
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;
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;
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;
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" ) );
{
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 ) );
}
public void testGenerateStatisticsInvalidEndDate()
+ throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
}
public void testGenerateStatisticsMalformedEndDate()
+ throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Collections.singletonList( INTERNAL ), Collections.singletonList( SNAPSHOTS ) );
}
public void testGenerateStatisticsInvalidEndDateMultiRepo()
+ throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
}
public void testGenerateStatisticsMalformedEndDateMultiRepo()
+ throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
}
public void testGenerateStatisticsNoRepos()
+ throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );
}
public void testDownloadStatisticsMalformedEndDateMultiRepo()
+ throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
}
public void testDownloadStatisticsMalformedEndDateSingleRepo()
+ throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Arrays.asList( SNAPSHOTS ), Arrays.asList( INTERNAL ) );
}
public void testDownloadStatisticsInvalidEndDateMultiRepo()
+ throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Arrays.asList( SNAPSHOTS, INTERNAL ), Collections.<String>emptyList() );
}
public void testDownloadStatisticsInvalidEndDateSingleRepo()
+ throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Arrays.asList( SNAPSHOTS ), Arrays.asList( INTERNAL ) );
}
public void testDownloadStatisticsNoRepos()
+ throws Exception
{
repositoryStatisticsManagerControl.replay();
prepareAction( Collections.<String>emptyList(), Arrays.asList( SNAPSHOTS, INTERNAL ) );