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.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.MailingList;
+import org.apache.maven.archiva.model.VersionedReference;
import org.apache.maven.archiva.security.UserRepositories;
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.easymock.MockControl;
public class ShowArtifactActionTest
extends PlexusInSpringTestCase
private ShowArtifactAction action;
+ private ArchivaDAOStub archivaDao;
+
private TestMetadataResolver metadataResolver;
public void testInstantiation()
metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
createProjectModel( 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.setArtifactId( TEST_ARTIFACT_ID );
metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
createProjectModel( 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.setArtifactId( TEST_ARTIFACT_ID );
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()
{
assertNull( action.getModel() );
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()
throws Exception
{
super.setUp();
action = (ShowArtifactAction) lookup( Action.class, ACTION_HINT );
metadataResolver = (TestMetadataResolver) action.getMetadataResolver();
+ archivaDao = (ArchivaDAOStub) lookup( ArchivaDAO.class, "jdo" );
}
}