mirror of https://github.com/apache/archiva.git
[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:
parent
cd252dc729
commit
fcaaaa56a5
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
@ -62,47 +94,55 @@ public class RepositoriesActionTest
|
|||
public void testGetRepositories()
|
||||
throws Exception
|
||||
{
|
||||
MockControl control = MockControl.createControl( MetadataRepository.class );
|
||||
MetadataRepository metadataRepository = (MetadataRepository) control.getMock();
|
||||
control.expectAndReturn( metadataRepository.getMetadataFacets( "internal", RepositoryStatistics.FACET_ID ),
|
||||
Arrays.asList( "20091125.123456.678" ) );
|
||||
control.expectAndReturn(
|
||||
metadataRepository.getMetadataFacet( "internal", RepositoryStatistics.FACET_ID, "20091125.123456.678" ),
|
||||
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" ),
|
||||
new RepositoryStatistics() );
|
||||
control.replay();
|
||||
try
|
||||
{
|
||||
MockControl control = MockControl.createControl( MetadataRepository.class );
|
||||
MetadataRepository metadataRepository = (MetadataRepository) control.getMock();
|
||||
control.expectAndReturn( metadataRepository.getMetadataFacets( "internal", RepositoryStatistics.FACET_ID ),
|
||||
Arrays.asList( "20091125.123456.678" ) );
|
||||
control.expectAndReturn(
|
||||
metadataRepository.getMetadataFacet( "internal", RepositoryStatistics.FACET_ID, "20091125.123456.678" ),
|
||||
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" ),
|
||||
new RepositoryStatistics() );
|
||||
control.replay();
|
||||
|
||||
RepositorySession session = mock( RepositorySession.class );
|
||||
when( session.getRepository() ).thenReturn( metadataRepository );
|
||||
TestRepositorySessionFactory factory =
|
||||
applicationContext.getBean( "repositorySessionFactory#test", TestRepositorySessionFactory.class );
|
||||
factory.setRepositorySession( session );
|
||||
RepositorySession session = mock( RepositorySession.class );
|
||||
when( session.getRepository() ).thenReturn( metadataRepository );
|
||||
TestRepositorySessionFactory factory =
|
||||
applicationContext.getBean( "repositorySessionFactory#test", TestRepositorySessionFactory.class );
|
||||
factory.setRepositorySession( session );
|
||||
|
||||
ServletRunner sr = new ServletRunner();
|
||||
ServletUnitClient sc = sr.newClient();
|
||||
ServletRunner sr = new ServletRunner();
|
||||
ServletUnitClient sc = sr.newClient();
|
||||
|
||||
action.setServletRequest( sc.newInvocation( "http://localhost/admin/repositories.action" ).getRequest() );
|
||||
action.setServletRequest( sc.newInvocation( "http://localhost/admin/repositories.action" ).getRequest() );
|
||||
|
||||
action.prepare();
|
||||
String result = action.execute();
|
||||
assertEquals( Action.SUCCESS, result );
|
||||
action.prepare();
|
||||
String result = action.execute();
|
||||
assertEquals( Action.SUCCESS, result );
|
||||
|
||||
// TODO: for some reason servletunit is not populating the port of the servlet request
|
||||
assertEquals( "http://localhost:0/repository", action.getBaseUrl() );
|
||||
// TODO: for some reason servletunit is not populating the port of the servlet request
|
||||
assertEquals( "http://localhost:0/repository", action.getBaseUrl() );
|
||||
|
||||
assertNotNull( action.getManagedRepositories() );
|
||||
assertNotNull( action.getRemoteRepositories() );
|
||||
assertNotNull( action.getRepositoryStatistics() );
|
||||
assertNotNull( action.getManagedRepositories() );
|
||||
assertNotNull( action.getRemoteRepositories() );
|
||||
assertNotNull( action.getRepositoryStatistics() );
|
||||
|
||||
assertEquals( 2, action.getManagedRepositories().size() );
|
||||
assertEquals( 2, action.getRemoteRepositories().size() );
|
||||
assertEquals( 2, action.getRepositoryStatistics().size() );
|
||||
assertEquals( 2, action.getManagedRepositories().size() );
|
||||
assertEquals( 2, action.getRemoteRepositories().size() );
|
||||
assertEquals( 2, action.getRepositoryStatistics().size() );
|
||||
|
||||
control.verify();
|
||||
control.verify();
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
log.error( e.getMessage(), e );
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public void testSecureActionBundle()
|
||||
|
|
|
@ -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,28 +28,26 @@ 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
|
||||
public class SortRepositoriesActionTest
|
||||
extends StrutsSpringTestCase
|
||||
{
|
||||
private static final String REPO_GROUP_ID = "repo-group-ident";
|
||||
|
||||
|
||||
private static final String REPO1_ID = "managed-repo-ident-1";
|
||||
|
||||
|
||||
private static final String REPO2_ID = "managed-repo-ident-2";
|
||||
|
||||
|
||||
private static final String REPO3_ID = "managed-repo-ident-3";
|
||||
|
||||
|
||||
private MockControl archivaConfigurationControl;
|
||||
|
||||
private ArchivaConfiguration archivaConfiguration;
|
||||
|
||||
|
||||
private ArchivaConfiguration originalArchivaConfiguration;
|
||||
|
||||
private SortRepositoriesAction action;
|
||||
|
||||
@Override
|
||||
|
@ -61,52 +60,59 @@ 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
|
||||
{
|
||||
archivaConfiguration.getConfiguration();
|
||||
archivaConfigurationControl.setReturnValue( new Configuration() );
|
||||
archivaConfigurationControl.replay();
|
||||
|
||||
|
||||
SecureActionBundle bundle = action.getSecureActionBundle();
|
||||
assertTrue( bundle.requiresAuthentication() );
|
||||
assertEquals( 1, bundle.getAuthorizationTuples().size() );
|
||||
}
|
||||
|
||||
|
||||
public void testSortDownFirstRepository()
|
||||
throws Exception
|
||||
{
|
||||
Configuration configuration = createInitialConfiguration();
|
||||
|
||||
|
||||
archivaConfiguration.getConfiguration();
|
||||
archivaConfigurationControl.setReturnValue( configuration, 4 );
|
||||
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() );
|
||||
assertEquals( REPO1_ID, repositories.get( 0 ) );
|
||||
assertEquals( REPO2_ID, repositories.get( 1 ) );
|
||||
assertEquals( REPO3_ID, repositories.get( 2 ) );
|
||||
|
||||
|
||||
// sort down first repo
|
||||
action.setRepoGroupId( repoGroup.getId() );
|
||||
action.setTargetRepo( REPO1_ID );
|
||||
|
||||
|
||||
String result = action.sortDown();
|
||||
assertEquals( Action.SUCCESS, result );
|
||||
|
||||
|
||||
repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
|
||||
repositories = repoGroup.getRepositories();
|
||||
assertEquals( 3, repositories.size() );
|
||||
|
@ -114,32 +120,33 @@ public class SortRepositoriesActionTest
|
|||
assertEquals( REPO1_ID, repositories.get( 1 ) );
|
||||
assertEquals( REPO3_ID, repositories.get( 2 ) );
|
||||
}
|
||||
|
||||
|
||||
public void testSortDownLastRepository()
|
||||
throws Exception
|
||||
{
|
||||
Configuration configuration = createInitialConfiguration();
|
||||
|
||||
|
||||
archivaConfiguration.getConfiguration();
|
||||
archivaConfigurationControl.setReturnValue( configuration, 4 );
|
||||
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() );
|
||||
assertEquals( REPO1_ID, repositories.get( 0 ) );
|
||||
assertEquals( REPO2_ID, repositories.get( 1 ) );
|
||||
assertEquals( REPO3_ID, repositories.get( 2 ) );
|
||||
|
||||
|
||||
// sort down last repo
|
||||
action.setRepoGroupId( repoGroup.getId() );
|
||||
action.setTargetRepo( REPO3_ID );
|
||||
|
||||
|
||||
String result = action.sortDown();
|
||||
assertEquals( Action.SUCCESS, result );
|
||||
|
||||
|
||||
repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
|
||||
repositories = repoGroup.getRepositories();
|
||||
assertEquals( 3, repositories.size() );
|
||||
|
@ -147,32 +154,33 @@ public class SortRepositoriesActionTest
|
|||
assertEquals( REPO2_ID, repositories.get( 1 ) );
|
||||
assertEquals( REPO3_ID, repositories.get( 2 ) );
|
||||
}
|
||||
|
||||
|
||||
public void testSortUpLastRepository()
|
||||
throws Exception
|
||||
{
|
||||
Configuration configuration = createInitialConfiguration();
|
||||
|
||||
|
||||
archivaConfiguration.getConfiguration();
|
||||
archivaConfigurationControl.setReturnValue( configuration, 4 );
|
||||
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() );
|
||||
assertEquals( REPO1_ID, repositories.get( 0 ) );
|
||||
assertEquals( REPO2_ID, repositories.get( 1 ) );
|
||||
assertEquals( REPO3_ID, repositories.get( 2 ) );
|
||||
|
||||
|
||||
// sort up last repo
|
||||
action.setRepoGroupId( repoGroup.getId() );
|
||||
action.setTargetRepo( REPO3_ID );
|
||||
|
||||
|
||||
String result = action.sortUp();
|
||||
assertEquals( Action.SUCCESS, result );
|
||||
|
||||
|
||||
repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
|
||||
repositories = repoGroup.getRepositories();
|
||||
assertEquals( 3, repositories.size() );
|
||||
|
@ -180,32 +188,33 @@ public class SortRepositoriesActionTest
|
|||
assertEquals( REPO3_ID, repositories.get( 1 ) );
|
||||
assertEquals( REPO2_ID, repositories.get( 2 ) );
|
||||
}
|
||||
|
||||
|
||||
public void testSortUpFirstRepository()
|
||||
throws Exception
|
||||
{
|
||||
Configuration configuration = createInitialConfiguration();
|
||||
|
||||
|
||||
archivaConfiguration.getConfiguration();
|
||||
archivaConfigurationControl.setReturnValue( configuration, 4 );
|
||||
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() );
|
||||
assertEquals( REPO1_ID, repositories.get( 0 ) );
|
||||
assertEquals( REPO2_ID, repositories.get( 1 ) );
|
||||
assertEquals( REPO3_ID, repositories.get( 2 ) );
|
||||
|
||||
|
||||
// sort up first repo
|
||||
action.setRepoGroupId( repoGroup.getId() );
|
||||
action.setTargetRepo( REPO1_ID );
|
||||
|
||||
|
||||
String result = action.sortUp();
|
||||
assertEquals( Action.SUCCESS, result );
|
||||
|
||||
|
||||
repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 );
|
||||
repositories = repoGroup.getRepositories();
|
||||
assertEquals( 3, repositories.size() );
|
||||
|
@ -213,19 +222,19 @@ public class SortRepositoriesActionTest
|
|||
assertEquals( REPO2_ID, repositories.get( 1 ) );
|
||||
assertEquals( REPO3_ID, repositories.get( 2 ) );
|
||||
}
|
||||
|
||||
|
||||
private Configuration createInitialConfiguration()
|
||||
{
|
||||
Configuration config = new Configuration();
|
||||
|
||||
|
||||
RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
|
||||
repoGroup.setId( REPO_GROUP_ID );
|
||||
repoGroup.addRepository( REPO1_ID );
|
||||
repoGroup.addRepository( REPO2_ID );
|
||||
repoGroup.addRepository( REPO3_ID );
|
||||
|
||||
|
||||
config.addRepositoryGroup( repoGroup );
|
||||
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue