[MRM-1508] api to managed repository group : use it in webapp fix unit tests

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1165848 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-09-06 21:07:30 +00:00
parent cd252dc729
commit fcaaaa56a5
3 changed files with 135 additions and 88 deletions

View File

@ -115,8 +115,6 @@ public class RepositoriesAction
public void prepare()
throws RepositoryAdminException
{
Configuration config = archivaConfiguration.getConfiguration();
remoteRepositories = new ArrayList<RemoteRepository>( getRemoteRepositoryAdmin().getRemoteRepositories() );
managedRepositories = new ArrayList<ManagedRepository>( getManagedRepositoryAdmin().getManagedRepositories() );
repositoryToGroupMap = getRepositoryGroupAdmin().getRepositoryToGroupMap();

View File

@ -22,15 +22,20 @@ package org.apache.maven.archiva.web.action.admin.repositories;
import com.meterware.servletunit.ServletRunner;
import com.meterware.servletunit.ServletUnitClient;
import com.opensymphony.xwork2.Action;
import org.apache.archiva.admin.repository.group.DefaultRepositoryGroupAdmin;
import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.struts2.StrutsSpringTestCase;
import org.codehaus.redback.integration.interceptor.SecureActionBundle;
import org.codehaus.redback.integration.interceptor.SecureActionException;
import org.easymock.MockControl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
@ -43,14 +48,41 @@ import static org.mockito.Mockito.when;
public class RepositoriesActionTest
extends StrutsSpringTestCase
{
private Logger log = LoggerFactory.getLogger( getClass() );
private RepositoriesAction action;
ArchivaConfiguration originalArchivaConfiguration;
protected void setUp()
throws Exception
{
super.setUp();
action = (RepositoriesAction) getActionProxy( "/admin/index.action" ).getAction();
super.setUp();
action = (RepositoriesAction) getActionProxy( "/admin/index.action" ).getAction();
originalArchivaConfiguration =
( (DefaultRepositoryGroupAdmin) action.getRepositoryGroupAdmin() ).getArchivaConfiguration();
// some other test are modifying archivaConfiguration with a mocked instance : this test need the real one
// so use the real one from spring, backup the mock and restore it at the end (tearDown)
ArchivaConfiguration real = applicationContext.getBean( ArchivaConfiguration.class );
( (DefaultRepositoryGroupAdmin) action.getRepositoryGroupAdmin() ).setArchivaConfiguration( real );
( (DefaultManagedRepositoryAdmin) action.getManagedRepositoryAdmin() ).setArchivaConfiguration( real );
( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration( real );
}
@Override
protected void tearDown()
throws Exception
{
super.tearDown();
( (DefaultRepositoryGroupAdmin) action.getRepositoryGroupAdmin() ).setArchivaConfiguration(
originalArchivaConfiguration );
( (DefaultManagedRepositoryAdmin) action.getManagedRepositoryAdmin() ).setArchivaConfiguration(
originalArchivaConfiguration );
( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
originalArchivaConfiguration );
}
@Override
@ -61,6 +93,8 @@ public class RepositoriesActionTest
public void testGetRepositories()
throws Exception
{
try
{
MockControl control = MockControl.createControl( MetadataRepository.class );
MetadataRepository metadataRepository = (MetadataRepository) control.getMock();
@ -71,8 +105,8 @@ public class RepositoriesActionTest
new RepositoryStatistics() );
control.expectAndReturn( metadataRepository.getMetadataFacets( "snapshots", RepositoryStatistics.FACET_ID ),
Arrays.asList( "20091112.012345.012" ) );
control.expectAndReturn(
metadataRepository.getMetadataFacet( "snapshots", RepositoryStatistics.FACET_ID, "20091112.012345.012" ),
control.expectAndReturn( metadataRepository.getMetadataFacet( "snapshots", RepositoryStatistics.FACET_ID,
"20091112.012345.012" ),
new RepositoryStatistics() );
control.replay();
@ -104,6 +138,12 @@ public class RepositoriesActionTest
control.verify();
}
catch ( Exception e )
{
log.error( e.getMessage(), e );
throw e;
}
}
public void testSecureActionBundle()
throws SecureActionException

View File

@ -19,6 +19,7 @@ package org.apache.maven.archiva.web.action.admin.repositories;
* under the License.
*/
import com.opensymphony.xwork2.Action;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
@ -27,12 +28,8 @@ import org.codehaus.redback.integration.interceptor.SecureActionBundle;
import org.codehaus.redback.integration.interceptor.SecureActionException;
import org.easymock.MockControl;
import com.opensymphony.xwork2.Action;
/**
* SortRepositoriesActionTest
*
* @version
*/
public class SortRepositoriesActionTest
extends StrutsSpringTestCase
@ -49,6 +46,8 @@ public class SortRepositoriesActionTest
private ArchivaConfiguration archivaConfiguration;
private ArchivaConfiguration originalArchivaConfiguration;
private SortRepositoriesAction action;
@Override
@ -61,15 +60,21 @@ public class SortRepositoriesActionTest
throws Exception
{
super.setUp();
//action = (SortRepositoriesAction) lookup( Action.class.getName(), "sortRepositoriesAction" );
action = (SortRepositoriesAction) getActionProxy( "/admin/sortDownRepositoryFromGroup.action" ).getAction();
archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
originalArchivaConfiguration = action.archivaConfiguration;
action.setArchivaConfiguration( archivaConfiguration );
}
@Override
protected void tearDown()
throws Exception
{
super.tearDown();
action.archivaConfiguration = originalArchivaConfiguration;
}
public void testSecureActionBundle()
throws SecureActionException
{
@ -92,7 +97,8 @@ public class SortRepositoriesActionTest
archivaConfiguration.save( configuration );
archivaConfigurationControl.replay();
RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
RepositoryGroupConfiguration repoGroup =
(RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
java.util.List<String> repositories = repoGroup.getRepositories();
assertEquals( 3, repositories.size() );
@ -125,7 +131,8 @@ public class SortRepositoriesActionTest
archivaConfiguration.save( configuration );
archivaConfigurationControl.replay();
RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
RepositoryGroupConfiguration repoGroup =
(RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
java.util.List<String> repositories = repoGroup.getRepositories();
assertEquals( 3, repositories.size() );
@ -158,7 +165,8 @@ public class SortRepositoriesActionTest
archivaConfiguration.save( configuration );
archivaConfigurationControl.replay();
RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
RepositoryGroupConfiguration repoGroup =
(RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
java.util.List<String> repositories = repoGroup.getRepositories();
assertEquals( 3, repositories.size() );
@ -191,7 +199,8 @@ public class SortRepositoriesActionTest
archivaConfiguration.save( configuration );
archivaConfigurationControl.replay();
RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
RepositoryGroupConfiguration repoGroup =
(RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
java.util.List<String> repositories = repoGroup.getRepositories();
assertEquals( 3, repositories.size() );