1 package org.apache.maven.archiva.web.action;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import com.opensymphony.xwork2.Action;
23 import org.apache.archiva.metadata.model.ArtifactMetadata;
24 import org.apache.archiva.metadata.model.Dependency;
25 import org.apache.archiva.metadata.model.MailingList;
26 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
27 import org.apache.archiva.metadata.model.ProjectVersionReference;
28 import org.apache.archiva.metadata.repository.MetadataRepository;
29 import org.apache.archiva.metadata.repository.RepositorySession;
30 import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
31 import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
32 import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet;
33 import org.apache.archiva.reports.RepositoryProblemFacet;
34 import org.apache.maven.archiva.common.utils.VersionUtil;
35 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
36 import org.apache.maven.archiva.configuration.Configuration;
37 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
38 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
39 import org.apache.maven.archiva.repository.RepositoryContentFactory;
40 import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
43 import java.util.Arrays;
44 import java.util.Collections;
45 import java.util.List;
48 import static org.mockito.Mockito.mock;
49 import static org.mockito.Mockito.when;
51 public class ShowArtifactActionTest
52 extends AbstractActionTestCase
54 private static final String ACTION_HINT = "showArtifactAction";
56 private static final String TEST_VERSION = "version";
58 private static final String TEST_SNAPSHOT_VERSION = "1.0-SNAPSHOT";
60 private static final String TEST_TS_SNAPSHOT_VERSION = "1.0-20091120.111111-1";
62 private static final String TEST_NAMESPACE = "namespace";
64 private static final String OTHER_TEST_REPO = "first-repo";
66 private ShowArtifactAction action;
68 private static final List<ArtifactMetadata> TEST_SNAPSHOT_ARTIFACTS =
69 Arrays.asList( createArtifact( TEST_TS_SNAPSHOT_VERSION ),
70 createArtifact( "1.0-20091120.222222-2", "20091120.222222", 2 ),
71 createArtifact( "1.0-20091123.333333-3", "20091123.333333", 3 ) );
73 private static final long TEST_SIZE = 12345L;
75 private static final String TEST_TYPE = "jar";
77 public void testInstantiation()
79 assertFalse( action == getActionProxy( "/showArtifact.action" ).getAction() );
82 public void testGetArtifactUniqueRelease()
84 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
85 createProjectModel( TEST_VERSION ) );
87 setActionParameters();
89 String result = action.artifact();
91 assertActionSuccess( action, result );
93 assertActionParameters( action );
94 ProjectVersionMetadata model = action.getModel();
95 assertDefaultModel( model );
97 assertEquals( TEST_REPO, action.getRepositoryId() );
99 assertNull( action.getDependees() );
100 assertNull( action.getDependencies() );
101 assertNull( action.getMailingLists() );
102 assertTrue( action.getArtifacts().isEmpty() );
105 public void testGetArtifactUniqueSnapshot()
107 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
108 createProjectModel( TEST_SNAPSHOT_VERSION ) );
109 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
110 TEST_SNAPSHOT_ARTIFACTS );
112 action.setGroupId( TEST_GROUP_ID );
113 action.setArtifactId( TEST_ARTIFACT_ID );
114 action.setVersion( TEST_SNAPSHOT_VERSION );
116 String result = action.artifact();
118 assertActionSuccess( action, result );
120 assertEquals( TEST_GROUP_ID, action.getGroupId() );
121 assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
122 assertEquals( TEST_SNAPSHOT_VERSION, action.getVersion() );
123 ProjectVersionMetadata model = action.getModel();
124 assertDefaultModel( model, TEST_SNAPSHOT_VERSION );
126 assertEquals( TEST_REPO, action.getRepositoryId() );
128 assertArtifacts( TEST_SNAPSHOT_ARTIFACTS, action.getArtifacts() );
130 assertNull( action.getDependees() );
131 assertNull( action.getDependencies() );
132 assertNull( action.getMailingLists() );
135 public void testGetArtifactUniqueSnapshotTimestamped()
137 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
138 createProjectModel( TEST_SNAPSHOT_VERSION ) );
139 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
140 TEST_SNAPSHOT_ARTIFACTS );
142 action.setGroupId( TEST_GROUP_ID );
143 action.setArtifactId( TEST_ARTIFACT_ID );
144 action.setVersion( TEST_TS_SNAPSHOT_VERSION );
146 String result = action.artifact();
147 assertError( result );
148 assertNoOutputFields();
151 public void testGetMissingProject()
153 setActionParameters();
155 String result = action.artifact();
156 assertError( result );
158 assertActionParameters( action );
159 assertNoOutputFields();
162 public void testGetArtifactNoObservableRepos()
164 setObservableRepos( Collections.<String>emptyList() );
166 setActionParameters();
168 String result = action.artifact();
170 // Actually, it'd be better to have an error:
171 assertError( result );
172 assertActionParameters( action );
173 assertNoOutputFields();
176 public void testGetArtifactNotInObservableRepos()
178 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
179 createProjectModel( TEST_VERSION ) );
181 setActionParameters();
183 String result = action.artifact();
184 assertError( result );
186 assertActionParameters( action );
187 assertNoOutputFields();
190 public void testGetArtifactOnlySeenInSecondObservableRepo()
192 setObservableRepos( Arrays.asList( OTHER_TEST_REPO, TEST_REPO ) );
193 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
194 createProjectModel( TEST_VERSION ) );
196 setActionParameters();
198 String result = action.artifact();
200 assertActionSuccess( action, result );
202 assertActionParameters( action );
203 ProjectVersionMetadata model = action.getModel();
204 assertDefaultModel( model );
206 assertEquals( TEST_REPO, action.getRepositoryId() );
208 assertNull( action.getDependees() );
209 assertNull( action.getDependencies() );
210 assertNull( action.getMailingLists() );
211 assertTrue( action.getArtifacts().isEmpty() );
214 public void testGetArtifactSeenInBothObservableRepo()
216 setObservableRepos( Arrays.asList( TEST_REPO, OTHER_TEST_REPO ) );
217 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
218 createProjectModel( TEST_VERSION ) );
219 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
220 createProjectModel( TEST_VERSION ) );
222 setActionParameters();
224 String result = action.artifact();
226 assertActionSuccess( action, result );
228 assertActionParameters( action );
229 ProjectVersionMetadata model = action.getModel();
230 assertDefaultModel( model );
232 assertEquals( TEST_REPO, action.getRepositoryId() );
234 assertNull( action.getDependees() );
235 assertNull( action.getDependencies() );
236 assertNull( action.getMailingLists() );
237 assertTrue( action.getArtifacts().isEmpty() );
240 public void testGetArtifactCanOnlyObserveInOneOfTwoRepos()
242 setObservableRepos( Arrays.asList( TEST_REPO ) );
243 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
244 createProjectModel( TEST_VERSION ) );
245 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
246 createProjectModel( TEST_VERSION ) );
248 setActionParameters();
250 String result = action.artifact();
252 assertActionSuccess( action, result );
254 assertActionParameters( action );
255 ProjectVersionMetadata model = action.getModel();
256 assertDefaultModel( model );
258 assertEquals( TEST_REPO, action.getRepositoryId() );
260 assertNull( action.getDependees() );
261 assertNull( action.getDependencies() );
262 assertNull( action.getMailingLists() );
263 assertTrue( action.getArtifacts().isEmpty() );
266 public void testGetArtifactNoMavenFacet()
268 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
269 versionMetadata.setId( TEST_VERSION );
270 versionMetadata.setUrl( TEST_URL );
271 versionMetadata.setName( TEST_NAME );
272 versionMetadata.setDescription( TEST_DESCRIPTION );
274 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
276 setActionParameters();
278 String result = action.artifact();
280 assertActionSuccess( action, result );
282 assertActionParameters( action );
283 ProjectVersionMetadata model = action.getModel();
284 assertEquals( TEST_VERSION, model.getVersion() );
285 assertEquals( TEST_URL, model.getUrl() );
286 assertEquals( TEST_NAME, model.getName() );
287 assertEquals( TEST_DESCRIPTION, model.getDescription() );
289 assertEquals( TEST_REPO, action.getRepositoryId() );
291 assertNull( action.getDependees() );
292 assertNull( action.getDependencies() );
293 assertNull( action.getMailingLists() );
294 assertTrue( action.getArtifacts().isEmpty() );
297 public void testMetadataHasRepositoryFacetProblem()
299 String errMsg = "Error in resolving artifact's parent POM file: Sample Parent POM not found";
300 ProjectVersionMetadata metaData = createProjectModel(TEST_SNAPSHOT_VERSION);
301 metaData.addFacet( createRepositoryProblemFacet( TEST_REPO, errMsg,
302 TEST_GROUP_ID, TEST_SNAPSHOT_VERSION, TEST_NAMESPACE ) );
305 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, metaData );
307 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
308 TEST_SNAPSHOT_ARTIFACTS );
310 action.setGroupId( TEST_GROUP_ID );
311 action.setArtifactId( TEST_ARTIFACT_ID );
312 action.setVersion( TEST_SNAPSHOT_VERSION );
314 String result = action.artifact();
316 assertEquals( Action.SUCCESS, result );
318 assertTrue( action.hasActionErrors() );
319 assertFalse( action.hasActionMessages() );
320 assertEquals( "Artifact metadata is incomplete: " + errMsg, action.getActionErrors().toArray()[0].toString() );
323 public void testMetadataIncomplete()
325 ProjectVersionMetadata metaData = createProjectModel(TEST_SNAPSHOT_VERSION);
326 metaData.setIncomplete( true );
328 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, metaData );
330 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
331 TEST_SNAPSHOT_ARTIFACTS );
333 action.setGroupId( TEST_GROUP_ID );
334 action.setArtifactId( TEST_ARTIFACT_ID );
335 action.setVersion( TEST_SNAPSHOT_VERSION );;
337 String result = action.artifact();
339 assertEquals( Action.SUCCESS, result );
341 assertTrue( action.hasActionErrors() );
342 assertFalse( action.hasActionMessages() );
344 assertEquals( "Artifact metadata is incomplete.", action.getActionErrors().toArray()[0].toString() );
347 public void testGetMailingLists()
349 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
350 MailingList ml1 = createMailingList( "Users List", "users" );
351 MailingList ml2 = createMailingList( "Developers List", "dev" );
352 versionMetadata.setMailingLists( Arrays.asList( ml1, ml2 ) );
353 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
355 setActionParameters();
357 String result = action.mailingLists();
359 assertActionSuccess( action, result );
361 assertActionParameters( action );
362 ProjectVersionMetadata model = action.getModel();
363 assertDefaultModel( model );
365 assertNotNull( action.getMailingLists() );
366 assertMailingList( action.getMailingLists().get( 0 ), "Users List", "users" );
367 assertMailingList( action.getMailingLists().get( 1 ), "Developers List", "dev" );
369 assertEquals( TEST_REPO, action.getRepositoryId() );
370 assertNull( action.getDependees() );
371 assertNull( action.getDependencies() );
372 assertTrue( action.getArtifacts().isEmpty() );
375 public void testGetDependencies()
377 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
378 Dependency dependency1 = createDependencyBasic( "artifactId1" );
379 Dependency dependency2 = createDependencyExtended( "artifactId2" );
380 versionMetadata.setDependencies( Arrays.asList( dependency1, dependency2 ) );
381 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
383 setActionParameters();
385 String result = action.dependencies();
387 assertActionSuccess( action, result );
389 assertActionParameters( action );
390 ProjectVersionMetadata model = action.getModel();
391 assertDefaultModel( model );
393 assertNotNull( action.getDependencies() );
394 assertDependencyBasic( action.getDependencies().get( 0 ), "artifactId1" );
395 assertDependencyExtended( action.getDependencies().get( 1 ), "artifactId2" );
397 assertEquals( TEST_REPO, action.getRepositoryId() );
398 assertNull( action.getDependees() );
399 assertNull( action.getMailingLists() );
400 assertTrue( action.getArtifacts().isEmpty() );
403 public void testGetDependees()
406 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
407 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
408 ProjectVersionReference dependee1 = createReference( "artifactId1" );
409 ProjectVersionReference dependee2 = createReference( "artifactId2" );
410 metadataResolver.setProjectReferences( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION,
411 Arrays.asList( dependee1, dependee2 ) );
413 setActionParameters();
415 String result = action.dependees();
417 assertActionSuccess( action, result );
419 assertActionParameters( action );
420 ProjectVersionMetadata model = action.getModel();
421 assertDefaultModel( model );
423 assertNotNull( action.getDependees() );
424 assertCoordinate( action.getDependees().get( 0 ), "artifactId1" );
425 assertCoordinate( action.getDependees().get( 1 ), "artifactId2" );
427 assertEquals( TEST_REPO, action.getRepositoryId() );
428 assertNull( action.getDependencies() );
429 assertNull( action.getMailingLists() );
430 assertTrue( action.getArtifacts().isEmpty() );
433 public void testGetProjectMetadata()
435 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
437 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
439 setActionParameters();
441 String result = action.projectMetadata();
443 assertActionSuccess( action, result );
445 assertActionParameters( action );
447 Map<String, String> genericMetadata = action.getGenericMetadata();
448 assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) );
449 assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ),
450 TEST_GENERIC_METADATA_PROPERTY_VALUE );
452 assertEquals( TEST_REPO, action.getRepositoryId() );
453 assertNotNull( action.getModel() );
454 assertNull( action.getDependees() );
455 assertNull( action.getDependencies() );
456 assertNull( action.getMailingLists() );
457 assertTrue( action.getArtifacts().isEmpty() );
460 public void testAddAndDeleteMetadataProperty()
462 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
464 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
466 setActionParameters();
467 action.setPropertyName( "foo" );
468 action.setPropertyValue( "bar" );
469 action.setRepositoryId( TEST_REPO );
471 String result = action.addMetadataProperty();
473 assertActionSuccess( action, result );
474 assertActionParameters( action );
476 Map<String, String> genericMetadata = action.getGenericMetadata();
477 assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) );
478 assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ),
479 TEST_GENERIC_METADATA_PROPERTY_VALUE );
481 assertNotNull( genericMetadata.get( "foo" ) );
482 assertEquals( "bar", genericMetadata.get( "foo" ) );
484 assertEquals( TEST_REPO, action.getRepositoryId() );
485 assertNotNull( action.getModel() );
486 assertNull( action.getDependees() );
487 assertNull( action.getDependencies() );
488 assertNull( action.getMailingLists() );
489 assertTrue( action.getArtifacts().isEmpty() );
491 // test delete property
492 setActionParameters();
493 action.setDeleteItem( "foo" );
495 result = action.deleteMetadataEntry();
497 assertEquals( Action.SUCCESS, result );
498 assertActionParameters( action );
499 assertTrue( !action.getActionMessages().isEmpty() );
500 assertTrue( action.getActionMessages().contains( "Property successfully deleted." ) );
502 genericMetadata = action.getGenericMetadata();
503 assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) );
504 assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ),
505 TEST_GENERIC_METADATA_PROPERTY_VALUE );
507 assertNull( genericMetadata.get( "foo" ) );
509 assertEquals( TEST_REPO, action.getRepositoryId() );
510 assertNotNull( action.getModel() );
511 assertNull( action.getDependees() );
512 assertNull( action.getDependencies() );
513 assertNull( action.getMailingLists() );
514 assertTrue( action.getArtifacts().isEmpty() );
517 private void assertArtifacts( List<ArtifactMetadata> expectedArtifacts,
518 Map<String, List<ShowArtifactAction.ArtifactDownloadInfo>> artifactMap )
520 // assuming only one of each version at this point
521 assertEquals( expectedArtifacts.size(), artifactMap.size() );
522 for ( ArtifactMetadata artifact : expectedArtifacts )
524 assertTrue( artifactMap.containsKey( artifact.getVersion() ) );
525 List<ShowArtifactAction.ArtifactDownloadInfo> list = artifactMap.get( artifact.getVersion() );
526 ShowArtifactAction.ArtifactDownloadInfo actual = list.get( 0 );
527 assertEquals( artifact.getNamespace(), actual.getNamespace() );
528 assertEquals( artifact.getId(), actual.getId() );
529 assertEquals( artifact.getProject(), actual.getProject() );
530 assertEquals( artifact.getRepositoryId(), actual.getRepositoryId() );
531 assertEquals( artifact.getVersion(), actual.getVersion() );
532 assertEquals( TEST_TYPE, actual.getType() );
533 assertEquals( "12.06 K", actual.getSize() );
534 assertEquals( artifact.getNamespace() + "/" + artifact.getProject() + "/" + TEST_SNAPSHOT_VERSION + "/"
535 + artifact.getId(), actual.getPath() );
539 private static ArtifactMetadata createArtifact( String version )
541 return createArtifact( version, null, 0 );
544 private static ArtifactMetadata createArtifact( String version, String timestamp, int buildNumber )
546 ArtifactMetadata metadata = new ArtifactMetadata();
547 metadata.setProject( TEST_ARTIFACT_ID );
548 metadata.setId( TEST_ARTIFACT_ID + "-" + version + ".jar" );
549 metadata.setNamespace( TEST_GROUP_ID );
550 metadata.setRepositoryId( TEST_REPO );
551 metadata.setSize( TEST_SIZE );
552 metadata.setProjectVersion( VersionUtil.getBaseVersion( version ) );
553 metadata.setVersion( version );
555 MavenArtifactFacet facet = new MavenArtifactFacet();
556 facet.setType( "jar" );
557 facet.setTimestamp( timestamp );
558 facet.setBuildNumber( buildNumber );
559 metadata.addFacet( facet );
564 private ProjectVersionReference createReference( String projectId )
566 ProjectVersionReference reference = new ProjectVersionReference();
567 reference.setNamespace( "groupId" );
568 reference.setProjectId( projectId );
569 reference.setProjectVersion( "version" );
570 reference.setReferenceType( ProjectVersionReference.ReferenceType.DEPENDENCY );
574 private void assertCoordinate( ProjectVersionReference dependee, String artifactId )
576 assertEquals( artifactId, dependee.getProjectId() );
577 assertEquals( "groupId", dependee.getNamespace() );
578 assertEquals( "version", dependee.getProjectVersion() );
581 private void assertDependencyBasic( Dependency dependency, String artifactId )
583 assertEquals( artifactId, dependency.getArtifactId() );
584 assertEquals( "groupId", dependency.getGroupId() );
585 assertEquals( "version", dependency.getVersion() );
588 private void assertDependencyExtended( Dependency dependency, String artifactId )
590 assertDependencyBasic( dependency, artifactId );
591 assertEquals( true, dependency.isOptional() );
592 assertEquals( "classifier", dependency.getClassifier() );
593 assertEquals( "type", dependency.getType() );
594 assertEquals( "scope", dependency.getScope() );
595 assertEquals( "systemPath", dependency.getSystemPath() );
598 private Dependency createDependencyExtended( String artifactId )
600 Dependency dependency = createDependencyBasic( artifactId );
601 dependency.setClassifier( "classifier" );
602 dependency.setOptional( true );
603 dependency.setScope( "scope" );
604 dependency.setSystemPath( "systemPath" );
605 dependency.setType( "type" );
609 private Dependency createDependencyBasic( String artifactId )
611 Dependency dependency = new Dependency();
612 dependency.setArtifactId( artifactId );
613 dependency.setGroupId( "groupId" );
614 dependency.setVersion( "version" );
618 private void assertMailingList( MailingList mailingList, String name, String prefix )
620 assertEquals( name, mailingList.getName() );
621 assertEquals( prefix + "-post@", mailingList.getPostAddress() );
622 assertEquals( prefix + "-subscribe@", mailingList.getSubscribeAddress() );
623 assertEquals( prefix + "-unsubscribe@", mailingList.getUnsubscribeAddress() );
624 assertEquals( prefix + "-archive-url", mailingList.getMainArchiveUrl() );
625 assertEquals( Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ),
626 mailingList.getOtherArchives() );
629 private MailingList createMailingList( String name, String prefix )
631 MailingList ml1 = new MailingList();
633 ml1.setPostAddress( prefix + "-post@" );
634 ml1.setSubscribeAddress( prefix + "-subscribe@" );
635 ml1.setUnsubscribeAddress( prefix + "-unsubscribe@" );
636 ml1.setMainArchiveUrl( prefix + "-archive-url" );
637 ml1.setOtherArchives(
638 Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ) );
642 private void assertNoOutputFields()
644 assertNull( action.getModel() );
645 assertNull( action.getDependees() );
646 assertNull( action.getDependencies() );
647 assertNull( action.getMailingLists() );
648 assertTrue( action.getArtifacts().isEmpty() );
651 private void assertError( String result )
653 assertEquals( Action.ERROR, result );
654 assertEquals( 1, action.getActionErrors().size() );
657 private void assertDefaultModel( ProjectVersionMetadata model )
659 assertDefaultModel( model, TEST_VERSION );
662 private void setActionParameters()
664 action.setGroupId( TEST_GROUP_ID );
665 action.setArtifactId( TEST_ARTIFACT_ID );
666 action.setVersion( TEST_VERSION );
669 private void assertActionParameters( ShowArtifactAction action )
671 assertEquals( TEST_GROUP_ID, action.getGroupId() );
672 assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
673 assertEquals( TEST_VERSION, action.getVersion() );
676 private void assertActionSuccess( ShowArtifactAction action, String result )
678 assertEquals( Action.SUCCESS, result );
679 assertTrue( action.getActionErrors().isEmpty() );
680 assertTrue( action.getActionMessages().isEmpty() );
683 private RepositoryProblemFacet createRepositoryProblemFacet( String repoId, String errMsg, String projectId, String projectVersion, String namespace )
685 RepositoryProblemFacet repoProblemFacet = new RepositoryProblemFacet();
686 repoProblemFacet.setRepositoryId( repoId );
687 repoProblemFacet.setId( repoId );
688 repoProblemFacet.setMessage( errMsg );
689 repoProblemFacet.setProblem( errMsg );
690 repoProblemFacet.setProject( projectId );
691 repoProblemFacet.setVersion( projectVersion );
692 repoProblemFacet.setNamespace( namespace );
693 return repoProblemFacet;
696 protected void setUp()
700 action = (ShowArtifactAction) getActionProxy( "/showArtifact.action" ).getAction();
702 metadataResolver = new TestMetadataResolver();
703 MetadataRepository repo = mock( MetadataRepository.class );
704 RepositorySession repositorySession = mock( RepositorySession.class );
705 when( repositorySession.getResolver() ).thenReturn( metadataResolver );
706 when( repositorySession.getRepository() ).thenReturn( repo );
707 TestRepositorySessionFactory repositorySessionFactory =
708 applicationContext.getBean( "repositorySessionFactory#test", TestRepositorySessionFactory.class );
709 repositorySessionFactory.setRepositorySession( repositorySession );
711 RepositoryContentFactory factory = mock( RepositoryContentFactory.class );
713 action.setRepositoryFactory( factory );
715 ManagedRepositoryConfiguration config = new ManagedRepositoryConfiguration();
716 config.setId( TEST_REPO );
717 config.setLocation( new File( "target/test-repo" ).getAbsolutePath() );
719 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
720 content.setRepository( config );
721 when( factory.getManagedRepositoryContent( TEST_REPO ) ).thenReturn( content );
723 ArchivaConfiguration archivaConfig = mock( ArchivaConfiguration.class );
725 Configuration configuration = new Configuration();
726 configuration.addManagedRepository( config );
727 when( archivaConfig.getConfiguration() ).thenReturn( configuration );
729 when( factory.getArchivaConfiguration() ).thenReturn( archivaConfig );