fix junit ShowArtifactActionTest

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1135689 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-06-14 16:39:58 +00:00
parent 0f21fce9ac
commit d36818c0fe
3 changed files with 43 additions and 38 deletions

View File

@ -19,15 +19,14 @@ package org.apache.maven.archiva.web.action;
* under the License. * under the License.
*/ */
import java.util.Collections;
import java.util.List;
import org.apache.maven.archiva.security.AccessDeniedException; import org.apache.maven.archiva.security.AccessDeniedException;
import org.apache.maven.archiva.security.ArchivaSecurityException; import org.apache.maven.archiva.security.ArchivaSecurityException;
import org.apache.maven.archiva.security.PrincipalNotFoundException; import org.apache.maven.archiva.security.PrincipalNotFoundException;
import org.apache.maven.archiva.security.UserRepositories; import org.apache.maven.archiva.security.UserRepositories;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.Collections;
import java.util.List;
public class AbstractRepositoryBasedAction public class AbstractRepositoryBasedAction
extends AbstractActionSupport extends AbstractActionSupport
@ -42,7 +41,8 @@ public class AbstractRepositoryBasedAction
{ {
try try
{ {
return userRepositories.getObservableRepositoryIds( getPrincipal() ); List<String> ids = userRepositories.getObservableRepositoryIds( getPrincipal() );
return ids == null ? Collections.<String>emptyList() : ids;
} }
catch ( PrincipalNotFoundException e ) catch ( PrincipalNotFoundException e )
{ {

View File

@ -59,7 +59,9 @@ public class TestMetadataResolver
String repoId, String namespace, String repoId, String namespace,
String projectId, String projectVersion ) String projectId, String projectVersion )
{ {
return references.get( createMapKey( repoId, namespace, projectId, projectVersion ) ); Collection<ProjectVersionReference> projectVersionReferences =
references.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
return projectVersionReferences;
} }
public Collection<String> resolveRootNamespaces( RepositorySession repositorySession, String repoId ) public Collection<String> resolveRootNamespaces( RepositorySession repositorySession, String repoId )
@ -106,8 +108,8 @@ public class TestMetadataResolver
public Collection<ArtifactMetadata> resolveArtifacts( RepositorySession repositorySession, String repoId, public Collection<ArtifactMetadata> resolveArtifacts( RepositorySession repositorySession, String repoId,
String namespace, String projectId, String projectVersion ) String namespace, String projectId, String projectVersion )
{ {
List<ArtifactMetadata> artifacts = this.artifacts.get( createMapKey( repoId, namespace, projectId, List<ArtifactMetadata> artifacts =
projectVersion ) ); this.artifacts.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
return ( artifacts != null ? artifacts : Collections.<ArtifactMetadata>emptyList() ); return ( artifacts != null ? artifacts : Collections.<ArtifactMetadata>emptyList() );
} }

View File

@ -27,7 +27,6 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata;
import org.apache.archiva.metadata.model.ProjectVersionReference; import org.apache.archiva.metadata.model.ProjectVersionReference;
import org.apache.archiva.metadata.repository.MetadataRepository; import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.metadata.repository.memory.TestMetadataResolver; import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory; import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet; import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet;
@ -63,9 +62,10 @@ public class ShowArtifactActionTest
private ShowArtifactAction action; private ShowArtifactAction action;
private static final List<ArtifactMetadata> TEST_SNAPSHOT_ARTIFACTS = Arrays.asList( createArtifact( private static final List<ArtifactMetadata> TEST_SNAPSHOT_ARTIFACTS =
TEST_TS_SNAPSHOT_VERSION ), createArtifact( "1.0-20091120.222222-2", "20091120.222222", 2 ), createArtifact( Arrays.asList( createArtifact( TEST_TS_SNAPSHOT_VERSION ),
"1.0-20091123.333333-3", "20091123.333333", 3 ) ); createArtifact( "1.0-20091120.222222-2", "20091120.222222", 2 ),
createArtifact( "1.0-20091123.333333-3", "20091123.333333", 3 ) );
private static final long TEST_SIZE = 12345L; private static final long TEST_SIZE = 12345L;
@ -78,8 +78,8 @@ public class ShowArtifactActionTest
public void testGetArtifactUniqueRelease() public void testGetArtifactUniqueRelease()
{ {
metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
TEST_VERSION ) ); createProjectModel( TEST_VERSION ) );
setActionParameters(); setActionParameters();
@ -101,8 +101,8 @@ public class ShowArtifactActionTest
public void testGetArtifactUniqueSnapshot() public void testGetArtifactUniqueSnapshot()
{ {
metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
TEST_SNAPSHOT_VERSION ) ); createProjectModel( TEST_SNAPSHOT_VERSION ) );
metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION, metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
TEST_SNAPSHOT_ARTIFACTS ); TEST_SNAPSHOT_ARTIFACTS );
@ -131,8 +131,8 @@ public class ShowArtifactActionTest
public void testGetArtifactUniqueSnapshotTimestamped() public void testGetArtifactUniqueSnapshotTimestamped()
{ {
metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
TEST_SNAPSHOT_VERSION ) ); createProjectModel( TEST_SNAPSHOT_VERSION ) );
metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION, metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
TEST_SNAPSHOT_ARTIFACTS ); TEST_SNAPSHOT_ARTIFACTS );
@ -172,8 +172,8 @@ public class ShowArtifactActionTest
public void testGetArtifactNotInObservableRepos() public void testGetArtifactNotInObservableRepos()
{ {
metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
TEST_VERSION ) ); createProjectModel( TEST_VERSION ) );
setActionParameters(); setActionParameters();
@ -187,8 +187,8 @@ public class ShowArtifactActionTest
public void testGetArtifactOnlySeenInSecondObservableRepo() public void testGetArtifactOnlySeenInSecondObservableRepo()
{ {
setObservableRepos( Arrays.asList( OTHER_TEST_REPO, TEST_REPO ) ); setObservableRepos( Arrays.asList( OTHER_TEST_REPO, TEST_REPO ) );
metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
TEST_VERSION ) ); createProjectModel( TEST_VERSION ) );
setActionParameters(); setActionParameters();
@ -211,10 +211,10 @@ public class ShowArtifactActionTest
public void testGetArtifactSeenInBothObservableRepo() public void testGetArtifactSeenInBothObservableRepo()
{ {
setObservableRepos( Arrays.asList( TEST_REPO, OTHER_TEST_REPO ) ); setObservableRepos( Arrays.asList( TEST_REPO, OTHER_TEST_REPO ) );
metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
TEST_VERSION ) ); createProjectModel( TEST_VERSION ) );
metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
TEST_VERSION ) ); createProjectModel( TEST_VERSION ) );
setActionParameters(); setActionParameters();
@ -237,10 +237,10 @@ public class ShowArtifactActionTest
public void testGetArtifactCanOnlyObserveInOneOfTwoRepos() public void testGetArtifactCanOnlyObserveInOneOfTwoRepos()
{ {
setObservableRepos( Arrays.asList( TEST_REPO ) ); setObservableRepos( Arrays.asList( TEST_REPO ) );
metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
TEST_VERSION ) ); createProjectModel( TEST_VERSION ) );
metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, createProjectModel( metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
TEST_VERSION ) ); createProjectModel( TEST_VERSION ) );
setActionParameters(); setActionParameters();
@ -354,8 +354,8 @@ public class ShowArtifactActionTest
metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata ); metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
ProjectVersionReference dependee1 = createReference( "artifactId1" ); ProjectVersionReference dependee1 = createReference( "artifactId1" );
ProjectVersionReference dependee2 = createReference( "artifactId2" ); ProjectVersionReference dependee2 = createReference( "artifactId2" );
metadataResolver.setProjectReferences( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION, Arrays.asList( metadataResolver.setProjectReferences( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION,
dependee1, dependee2 ) ); Arrays.asList( dependee1, dependee2 ) );
setActionParameters(); setActionParameters();
@ -478,8 +478,8 @@ public class ShowArtifactActionTest
assertEquals( artifact.getVersion(), actual.getVersion() ); assertEquals( artifact.getVersion(), actual.getVersion() );
assertEquals( TEST_TYPE, actual.getType() ); assertEquals( TEST_TYPE, actual.getType() );
assertEquals( "12.06 K", actual.getSize() ); assertEquals( "12.06 K", actual.getSize() );
assertEquals( artifact.getNamespace() + "/" + artifact.getProject() + "/" + TEST_SNAPSHOT_VERSION + "/" + assertEquals( artifact.getNamespace() + "/" + artifact.getProject() + "/" + TEST_SNAPSHOT_VERSION + "/"
artifact.getId(), actual.getPath() ); + artifact.getId(), actual.getPath() );
} }
} }
@ -581,8 +581,8 @@ public class ShowArtifactActionTest
ml1.setSubscribeAddress( prefix + "-subscribe@" ); ml1.setSubscribeAddress( prefix + "-subscribe@" );
ml1.setUnsubscribeAddress( prefix + "-unsubscribe@" ); ml1.setUnsubscribeAddress( prefix + "-unsubscribe@" );
ml1.setMainArchiveUrl( prefix + "-archive-url" ); ml1.setMainArchiveUrl( prefix + "-archive-url" );
ml1.setOtherArchives( Arrays.asList( "other-" + prefix + "-archive-url-1", ml1.setOtherArchives(
"other-" + prefix + "-archive-url-2" ) ); Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ) );
return ml1; return ml1;
} }
@ -638,12 +638,12 @@ public class ShowArtifactActionTest
RepositorySession repositorySession = mock( RepositorySession.class ); RepositorySession repositorySession = mock( RepositorySession.class );
when( repositorySession.getResolver() ).thenReturn( metadataResolver ); when( repositorySession.getResolver() ).thenReturn( metadataResolver );
when( repositorySession.getRepository() ).thenReturn( repo ); when( repositorySession.getRepository() ).thenReturn( repo );
//TestRepositorySessionFactory repositorySessionFactory = (TestRepositorySessionFactory) lookup( TestRepositorySessionFactory repositorySessionFactory =
// RepositorySessionFactory.class ); applicationContext.getBean( "repositorySessionFactory#test", TestRepositorySessionFactory.class );
TestRepositorySessionFactory repositorySessionFactory = new TestRepositorySessionFactory();
repositorySessionFactory.setRepositorySession( repositorySession ); repositorySessionFactory.setRepositorySession( repositorySession );
RepositoryContentFactory factory = mock( RepositoryContentFactory.class ); RepositoryContentFactory factory = mock( RepositoryContentFactory.class );
action.setRepositoryFactory( factory ); action.setRepositoryFactory( factory );
ManagedRepositoryConfiguration config = new ManagedRepositoryConfiguration(); ManagedRepositoryConfiguration config = new ManagedRepositoryConfiguration();
@ -659,5 +659,8 @@ public class ShowArtifactActionTest
Configuration configuration = new Configuration(); Configuration configuration = new Configuration();
configuration.addManagedRepository( config ); configuration.addManagedRepository( config );
when( archivaConfig.getConfiguration() ).thenReturn( configuration ); when( archivaConfig.getConfiguration() ).thenReturn( configuration );
when( factory.getArchivaConfiguration() ).thenReturn( archivaConfig );
} }
} }