[MRM-1283] restore other testing infrastructure and add test for existing mailingLists method

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@884396 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2009-11-26 04:37:47 +00:00
parent e9962a70d5
commit 869f965da6
1 changed files with 170 additions and 2 deletions

View File

@ -33,10 +33,21 @@ import org.apache.archiva.metadata.model.Scm;
import org.apache.archiva.metadata.repository.memory.TestMetadataResolver; import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet; import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectParent; import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectParent;
import org.apache.maven.archiva.database.ArchivaDAO;
import org.apache.maven.archiva.database.ArchivaDatabaseException;
import org.apache.maven.archiva.database.ArtifactDAO;
import org.apache.maven.archiva.database.ProjectModelDAO;
import org.apache.maven.archiva.database.constraints.ArtifactsRelatedConstraint;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArchivaArtifactModel;
import org.apache.maven.archiva.model.ArchivaProjectModel; import org.apache.maven.archiva.model.ArchivaProjectModel;
import org.apache.maven.archiva.model.MailingList;
import org.apache.maven.archiva.model.VersionedReference;
import org.apache.maven.archiva.security.UserRepositories; import org.apache.maven.archiva.security.UserRepositories;
import org.apache.maven.archiva.security.UserRepositoriesStub; import org.apache.maven.archiva.security.UserRepositoriesStub;
import org.apache.maven.archiva.web.action.admin.repositories.ArchivaDAOStub;
import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.codehaus.plexus.spring.PlexusInSpringTestCase;
import org.easymock.MockControl;
public class ShowArtifactActionTest public class ShowArtifactActionTest
extends PlexusInSpringTestCase extends PlexusInSpringTestCase
@ -102,6 +113,8 @@ public class ShowArtifactActionTest
private ShowArtifactAction action; private ShowArtifactAction action;
private ArchivaDAOStub archivaDao;
private TestMetadataResolver metadataResolver; private TestMetadataResolver metadataResolver;
public void testInstantiation() public void testInstantiation()
@ -137,7 +150,7 @@ public class ShowArtifactActionTest
metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
createProjectModel( TEST_SNAPSHOT_VERSION ) ); createProjectModel( TEST_SNAPSHOT_VERSION ) );
metadataResolver.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION, metadataResolver.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
ALL_TEST_SNAPSHOT_VERSIONS ); ALL_TEST_SNAPSHOT_VERSIONS );
action.setGroupId( TEST_GROUP_ID ); action.setGroupId( TEST_GROUP_ID );
action.setArtifactId( TEST_ARTIFACT_ID ); action.setArtifactId( TEST_ARTIFACT_ID );
@ -167,7 +180,7 @@ public class ShowArtifactActionTest
metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
createProjectModel( TEST_TS_SNAPSHOT_VERSION ) ); createProjectModel( TEST_TS_SNAPSHOT_VERSION ) );
metadataResolver.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_TS_SNAPSHOT_VERSION, metadataResolver.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_TS_SNAPSHOT_VERSION,
ALL_TEST_SNAPSHOT_VERSIONS ); ALL_TEST_SNAPSHOT_VERSIONS );
action.setGroupId( TEST_GROUP_ID ); action.setGroupId( TEST_GROUP_ID );
action.setArtifactId( TEST_ARTIFACT_ID ); action.setArtifactId( TEST_ARTIFACT_ID );
@ -339,6 +352,65 @@ public class ShowArtifactActionTest
assertTrue( action.getSnapshotVersions().isEmpty() ); assertTrue( action.getSnapshotVersions().isEmpty() );
} }
public void testGetMailingLists()
throws ArchivaDatabaseException
{
List<ArchivaArtifact> artifacts =
Collections.singletonList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) );
MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, 1 );
ArchivaProjectModel legacyModel = createLegacyProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION );
MailingList ml1 = createMailingList( "Users List", "users" );
MailingList ml2 = createMailingList( "Developers List", "dev" );
legacyModel.setMailingLists( Arrays.asList( ml1, ml2 ) );
MockControl projectDaoMockControl = createProjectDaoMock( legacyModel );
setActionParameters();
String result = action.mailingLists();
artifactDaoMockControl.verify();
projectDaoMockControl.verify();
assertActionSuccess( action, result );
assertActionParameters( action );
ArchivaProjectModel model = action.getModel();
assertDefaultModel( model );
assertNotNull( action.getMailingLists() );
assertMailingList( action.getMailingLists().get( 0 ), "Users List", "users" );
assertMailingList( action.getMailingLists().get( 1 ), "Developers List", "dev" );
assertNull( action.getRepositoryId() );
assertNull( action.getDependees() );
assertNull( action.getDependencies() );
assertNull( action.getSnapshotVersions() );
}
private void assertMailingList( MailingList mailingList, String name, String prefix )
{
assertEquals( name, mailingList.getName() );
assertEquals( prefix + "-post@", mailingList.getPostAddress() );
assertEquals( prefix + "-subscribe@", mailingList.getSubscribeAddress() );
assertEquals( prefix + "-unsubscribe@", mailingList.getUnsubscribeAddress() );
assertEquals( prefix + "-archive-url", mailingList.getMainArchiveUrl() );
assertEquals( Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ),
mailingList.getOtherArchives() );
}
private MailingList createMailingList( String name, String prefix )
{
MailingList ml1 = new MailingList();
ml1.setName( name );
ml1.setPostAddress( prefix + "-post@" );
ml1.setSubscribeAddress( prefix + "-subscribe@" );
ml1.setUnsubscribeAddress( prefix + "-unsubscribe@" );
ml1.setMainArchiveUrl( prefix + "-archive-url" );
ml1.setOtherArchives(
Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ) );
return ml1;
}
private void assertNoOutputFields() private void assertNoOutputFields()
{ {
assertNull( action.getModel() ); assertNull( action.getModel() );
@ -463,11 +535,107 @@ public class ShowArtifactActionTest
return model; return model;
} }
private ArchivaProjectModel createLegacyProjectModel( String groupId, String artifactId, String version )
{
ArchivaProjectModel model = new ArchivaProjectModel();
model.setGroupId( groupId );
model.setArtifactId( artifactId );
model.setVersion( version );
model.setPackaging( TEST_PACKAGING );
model.setUrl( TEST_URL );
model.setName( TEST_NAME );
model.setDescription( TEST_DESCRIPTION );
VersionedReference parent = new VersionedReference();
parent.setGroupId( TEST_PARENT_GROUP_ID );
parent.setArtifactId( TEST_PARENT_ARTIFACT_ID );
parent.setVersion( TEST_PARENT_VERSION );
model.setParentProject( parent );
org.apache.maven.archiva.model.CiManagement ci = new org.apache.maven.archiva.model.CiManagement();
ci.setSystem( TEST_CI_SYSTEM );
ci.setUrl( TEST_CI_URL );
model.setCiManagement( ci );
org.apache.maven.archiva.model.IssueManagement issue = new org.apache.maven.archiva.model.IssueManagement();
issue.setSystem( TEST_ISSUE_SYSTEM );
issue.setUrl( TEST_ISSUE_URL );
model.setIssueManagement( issue );
org.apache.maven.archiva.model.Organization org = new org.apache.maven.archiva.model.Organization();
org.setName( TEST_ORGANIZATION_NAME );
org.setUrl( TEST_ORGANIZATION_URL );
model.setOrganization( org );
org.apache.maven.archiva.model.License l = new org.apache.maven.archiva.model.License();
l.setName( TEST_LICENSE_NAME );
l.setUrl( TEST_LICENSE_URL );
model.addLicense( l );
l = new org.apache.maven.archiva.model.License();
l.setName( TEST_LICENSE_NAME_2 );
l.setUrl( TEST_LICENSE_URL_2 );
model.addLicense( l );
org.apache.maven.archiva.model.Scm scm = new org.apache.maven.archiva.model.Scm();
scm.setConnection( TEST_SCM_CONNECTION );
scm.setDeveloperConnection( TEST_SCM_DEV_CONNECTION );
scm.setUrl( TEST_SCM_URL );
model.setScm( scm );
return model;
}
private MockControl createArtifactDaoMock( List<ArchivaArtifact> artifacts, int count )
throws ArchivaDatabaseException
{
return createArtifactDaoMock( artifacts, TEST_VERSION, count );
}
private MockControl createArtifactDaoMock( List<ArchivaArtifact> artifacts, String version, int count )
throws ArchivaDatabaseException
{
// testing deeper than normal with the mocks as we intend to replace RepositoryBrowsing, not just the database
// underneath it - those sections will be adjusted with a mock content repository later
MockControl control = MockControl.createNiceControl( ArtifactDAO.class );
ArtifactDAO dao = (ArtifactDAO) control.getMock();
archivaDao.setArtifactDao( dao );
ArtifactsRelatedConstraint c = new ArtifactsRelatedConstraint( TEST_GROUP_ID, TEST_ARTIFACT_ID, version );
dao.queryArtifacts( c );
control.setReturnValue( artifacts, count );
control.replay();
return control;
}
private MockControl createProjectDaoMock( ArchivaProjectModel project )
throws ArchivaDatabaseException
{
MockControl control = MockControl.createNiceControl( ProjectModelDAO.class );
ProjectModelDAO dao = (ProjectModelDAO) control.getMock();
archivaDao.setProjectDao( dao );
control.expectAndReturn(
dao.getProjectModel( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project );
control.replay();
return control;
}
private ArchivaArtifact createArtifact( String groupId, String artifactId, String version )
{
return createArtifact( groupId, artifactId, version, TEST_REPO );
}
private ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String repoId )
{
ArchivaArtifactModel model = new ArchivaArtifactModel();
model.setGroupId( groupId );
model.setArtifactId( artifactId );
model.setVersion( version );
model.setRepositoryId( repoId );
return new ArchivaArtifact( model );
}
protected void setUp() protected void setUp()
throws Exception throws Exception
{ {
super.setUp(); super.setUp();
action = (ShowArtifactAction) lookup( Action.class, ACTION_HINT ); action = (ShowArtifactAction) lookup( Action.class, ACTION_HINT );
metadataResolver = (TestMetadataResolver) action.getMetadataResolver(); metadataResolver = (TestMetadataResolver) action.getMetadataResolver();
archivaDao = (ArchivaDAOStub) lookup( ArchivaDAO.class, "jdo" );
} }
} }