1 package org.apache.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 net.sf.beanlib.provider.replicator.BeanReplicator;
24 import org.apache.archiva.admin.model.beans.ManagedRepository;
25 import org.apache.archiva.metadata.model.ArtifactMetadata;
26 import org.apache.archiva.metadata.model.Dependency;
27 import org.apache.archiva.metadata.model.MailingList;
28 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
29 import org.apache.archiva.metadata.model.ProjectVersionReference;
30 import org.apache.archiva.metadata.repository.MetadataRepository;
31 import org.apache.archiva.metadata.repository.RepositorySession;
32 import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
33 import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
34 import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet;
35 import org.apache.archiva.reports.RepositoryProblemFacet;
36 import org.apache.archiva.common.utils.VersionUtil;
37 import org.apache.archiva.configuration.ArchivaConfiguration;
38 import org.apache.archiva.configuration.Configuration;
39 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
40 import org.apache.archiva.repository.ManagedRepositoryContent;
41 import org.apache.archiva.repository.RepositoryContentFactory;
42 import org.apache.archiva.repository.content.ManagedDefaultRepositoryContent;
45 import java.util.Arrays;
46 import java.util.Collections;
47 import java.util.List;
50 import static org.mockito.Mockito.mock;
51 import static org.mockito.Mockito.when;
53 public class ShowArtifactActionTest
54 extends AbstractActionTestCase
56 private static final String ACTION_HINT = "showArtifactAction";
58 private static final String TEST_VERSION = "version";
60 private static final String TEST_SNAPSHOT_VERSION = "1.0-SNAPSHOT";
62 private static final String TEST_TS_SNAPSHOT_VERSION = "1.0-20091120.111111-1";
64 private static final String TEST_NAMESPACE = "namespace";
66 private static final String OTHER_TEST_REPO = "first-repo";
68 private ShowArtifactAction action;
70 private static final List<ArtifactMetadata> TEST_SNAPSHOT_ARTIFACTS =
71 Arrays.asList( createArtifact( TEST_TS_SNAPSHOT_VERSION ),
72 createArtifact( "1.0-20091120.222222-2", "20091120.222222", 2 ),
73 createArtifact( "1.0-20091123.333333-3", "20091123.333333", 3 ) );
75 private static final long TEST_SIZE = 12345L;
77 private static final String TEST_TYPE = "jar";
79 protected void setUp()
83 action = (ShowArtifactAction) getActionProxy( "/showArtifact.action" ).getAction();
85 metadataResolver = new TestMetadataResolver();
86 MetadataRepository repo = mock( MetadataRepository.class );
87 RepositorySession repositorySession = mock( RepositorySession.class );
88 when( repositorySession.getResolver() ).thenReturn( metadataResolver );
89 when( repositorySession.getRepository() ).thenReturn( repo );
90 TestRepositorySessionFactory repositorySessionFactory =
91 applicationContext.getBean( "repositorySessionFactory#test", TestRepositorySessionFactory.class );
92 repositorySessionFactory.setRepositorySession( repositorySession );
94 RepositoryContentFactory factory = mock( RepositoryContentFactory.class );
96 action.setRepositoryFactory( factory );
98 ManagedRepository config = new ManagedRepository();
99 config.setId( TEST_REPO );
100 config.setLocation( new File( "target/test-repo" ).getAbsolutePath() );
102 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
103 content.setRepository( config );
104 when( factory.getManagedRepositoryContent( TEST_REPO ) ).thenReturn( content );
106 ArchivaConfiguration archivaConfig = mock( ArchivaConfiguration.class );
108 Configuration configuration = new Configuration();
109 configuration.addManagedRepository(
110 new BeanReplicator().replicateBean( config, ManagedRepositoryConfiguration.class ) );
111 when( archivaConfig.getConfiguration() ).thenReturn( configuration );
113 when( factory.getArchivaConfiguration() ).thenReturn( archivaConfig );
117 public void testInstantiation()
119 assertFalse( action == getActionProxy( "/showArtifact.action" ).getAction() );
122 public void testGetArtifactUniqueRelease()
124 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
125 createProjectModel( TEST_VERSION ) );
127 setActionParameters();
129 String result = action.artifact();
131 assertActionSuccess( action, result );
133 assertActionParameters( action );
134 ProjectVersionMetadata model = action.getModel();
135 assertDefaultModel( model );
137 assertEquals( TEST_REPO, action.getRepositoryId() );
139 assertNull( action.getDependees() );
140 assertNull( action.getDependencies() );
141 assertNull( action.getMailingLists() );
142 assertTrue( action.getArtifacts().isEmpty() );
145 public void testGetArtifactUniqueSnapshot()
147 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
148 createProjectModel( TEST_SNAPSHOT_VERSION ) );
149 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
150 TEST_SNAPSHOT_ARTIFACTS );
152 action.setGroupId( TEST_GROUP_ID );
153 action.setArtifactId( TEST_ARTIFACT_ID );
154 action.setVersion( TEST_SNAPSHOT_VERSION );
156 String result = action.artifact();
158 assertActionSuccess( action, result );
160 assertEquals( TEST_GROUP_ID, action.getGroupId() );
161 assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
162 assertEquals( TEST_SNAPSHOT_VERSION, action.getVersion() );
163 ProjectVersionMetadata model = action.getModel();
164 assertDefaultModel( model, TEST_SNAPSHOT_VERSION );
166 assertEquals( TEST_REPO, action.getRepositoryId() );
168 assertArtifacts( TEST_SNAPSHOT_ARTIFACTS, action.getArtifacts() );
170 assertNull( action.getDependees() );
171 assertNull( action.getDependencies() );
172 assertNull( action.getMailingLists() );
175 public void testGetArtifactUniqueSnapshotTimestamped()
177 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
178 createProjectModel( TEST_SNAPSHOT_VERSION ) );
179 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
180 TEST_SNAPSHOT_ARTIFACTS );
182 action.setGroupId( TEST_GROUP_ID );
183 action.setArtifactId( TEST_ARTIFACT_ID );
184 action.setVersion( TEST_TS_SNAPSHOT_VERSION );
186 String result = action.artifact();
187 assertError( result );
188 assertNoOutputFields();
191 public void testGetMissingProject()
193 setActionParameters();
195 String result = action.artifact();
196 assertError( result );
198 assertActionParameters( action );
199 assertNoOutputFields();
202 public void testGetArtifactNoObservableRepos()
204 setObservableRepos( Collections.<String>emptyList() );
206 setActionParameters();
208 String result = action.artifact();
210 // Actually, it'd be better to have an error:
211 assertError( result );
212 assertActionParameters( action );
213 assertNoOutputFields();
216 public void testGetArtifactNotInObservableRepos()
218 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
219 createProjectModel( TEST_VERSION ) );
221 setActionParameters();
223 String result = action.artifact();
224 assertError( result );
226 assertActionParameters( action );
227 assertNoOutputFields();
230 public void testGetArtifactOnlySeenInSecondObservableRepo()
232 setObservableRepos( Arrays.asList( OTHER_TEST_REPO, TEST_REPO ) );
233 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
234 createProjectModel( TEST_VERSION ) );
236 setActionParameters();
238 String result = action.artifact();
240 assertActionSuccess( action, result );
242 assertActionParameters( action );
243 ProjectVersionMetadata model = action.getModel();
244 assertDefaultModel( model );
246 assertEquals( TEST_REPO, action.getRepositoryId() );
248 assertNull( action.getDependees() );
249 assertNull( action.getDependencies() );
250 assertNull( action.getMailingLists() );
251 assertTrue( action.getArtifacts().isEmpty() );
254 public void testGetArtifactSeenInBothObservableRepo()
256 setObservableRepos( Arrays.asList( TEST_REPO, OTHER_TEST_REPO ) );
257 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
258 createProjectModel( TEST_VERSION ) );
259 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
260 createProjectModel( TEST_VERSION ) );
262 setActionParameters();
264 String result = action.artifact();
266 assertActionSuccess( action, result );
268 assertActionParameters( action );
269 ProjectVersionMetadata model = action.getModel();
270 assertDefaultModel( model );
272 assertEquals( TEST_REPO, action.getRepositoryId() );
274 assertNull( action.getDependees() );
275 assertNull( action.getDependencies() );
276 assertNull( action.getMailingLists() );
277 assertTrue( action.getArtifacts().isEmpty() );
280 public void testGetArtifactCanOnlyObserveInOneOfTwoRepos()
282 setObservableRepos( Arrays.asList( TEST_REPO ) );
283 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
284 createProjectModel( TEST_VERSION ) );
285 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
286 createProjectModel( TEST_VERSION ) );
288 setActionParameters();
290 String result = action.artifact();
292 assertActionSuccess( action, result );
294 assertActionParameters( action );
295 ProjectVersionMetadata model = action.getModel();
296 assertDefaultModel( model );
298 assertEquals( TEST_REPO, action.getRepositoryId() );
300 assertNull( action.getDependees() );
301 assertNull( action.getDependencies() );
302 assertNull( action.getMailingLists() );
303 assertTrue( action.getArtifacts().isEmpty() );
306 public void testGetArtifactNoMavenFacet()
308 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
309 versionMetadata.setId( TEST_VERSION );
310 versionMetadata.setUrl( TEST_URL );
311 versionMetadata.setName( TEST_NAME );
312 versionMetadata.setDescription( TEST_DESCRIPTION );
314 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
316 setActionParameters();
318 String result = action.artifact();
320 assertActionSuccess( action, result );
322 assertActionParameters( action );
323 ProjectVersionMetadata model = action.getModel();
324 assertEquals( TEST_VERSION, model.getVersion() );
325 assertEquals( TEST_URL, model.getUrl() );
326 assertEquals( TEST_NAME, model.getName() );
327 assertEquals( TEST_DESCRIPTION, model.getDescription() );
329 assertEquals( TEST_REPO, action.getRepositoryId() );
331 assertNull( action.getDependees() );
332 assertNull( action.getDependencies() );
333 assertNull( action.getMailingLists() );
334 assertTrue( action.getArtifacts().isEmpty() );
337 public void testMetadataHasRepositoryFacetProblem()
339 String errMsg = "Error in resolving artifact's parent POM file: Sample Parent POM not found";
340 ProjectVersionMetadata metaData = createProjectModel( TEST_SNAPSHOT_VERSION );
342 createRepositoryProblemFacet( TEST_REPO, errMsg, TEST_GROUP_ID, TEST_SNAPSHOT_VERSION, TEST_NAMESPACE ) );
344 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, metaData );
346 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
347 TEST_SNAPSHOT_ARTIFACTS );
349 action.setGroupId( TEST_GROUP_ID );
350 action.setArtifactId( TEST_ARTIFACT_ID );
351 action.setVersion( TEST_SNAPSHOT_VERSION );
353 String result = action.artifact();
355 assertEquals( Action.SUCCESS, result );
357 assertTrue( action.hasActionErrors() );
358 assertFalse( action.hasActionMessages() );
359 assertEquals( "Artifact metadata is incomplete: " + errMsg, action.getActionErrors().toArray()[0].toString() );
362 public void testMetadataIncomplete()
364 ProjectVersionMetadata metaData = createProjectModel( TEST_SNAPSHOT_VERSION );
365 metaData.setIncomplete( true );
367 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, metaData );
369 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
370 TEST_SNAPSHOT_ARTIFACTS );
372 action.setGroupId( TEST_GROUP_ID );
373 action.setArtifactId( TEST_ARTIFACT_ID );
374 action.setVersion( TEST_SNAPSHOT_VERSION );
377 String result = action.artifact();
379 assertEquals( Action.SUCCESS, result );
381 assertTrue( action.hasActionErrors() );
382 assertFalse( action.hasActionMessages() );
384 assertEquals( "Artifact metadata is incomplete.", action.getActionErrors().toArray()[0].toString() );
387 public void testGetMailingLists()
389 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
390 MailingList ml1 = createMailingList( "Users List", "users" );
391 MailingList ml2 = createMailingList( "Developers List", "dev" );
392 versionMetadata.setMailingLists( Arrays.asList( ml1, ml2 ) );
393 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
395 setActionParameters();
397 String result = action.mailingLists();
399 assertActionSuccess( action, result );
401 assertActionParameters( action );
402 ProjectVersionMetadata model = action.getModel();
403 assertDefaultModel( model );
405 assertNotNull( action.getMailingLists() );
406 assertMailingList( action.getMailingLists().get( 0 ), "Users List", "users" );
407 assertMailingList( action.getMailingLists().get( 1 ), "Developers List", "dev" );
409 assertEquals( TEST_REPO, action.getRepositoryId() );
410 assertNull( action.getDependees() );
411 assertNull( action.getDependencies() );
412 assertTrue( action.getArtifacts().isEmpty() );
415 public void testGetDependencies()
417 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
418 Dependency dependency1 = createDependencyBasic( "artifactId1" );
419 Dependency dependency2 = createDependencyExtended( "artifactId2" );
420 versionMetadata.setDependencies( Arrays.asList( dependency1, dependency2 ) );
421 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
423 setActionParameters();
425 String result = action.dependencies();
427 assertActionSuccess( action, result );
429 assertActionParameters( action );
430 ProjectVersionMetadata model = action.getModel();
431 assertDefaultModel( model );
433 assertNotNull( action.getDependencies() );
434 assertDependencyBasic( action.getDependencies().get( 0 ), "artifactId1" );
435 assertDependencyExtended( action.getDependencies().get( 1 ), "artifactId2" );
437 assertEquals( TEST_REPO, action.getRepositoryId() );
438 assertNull( action.getDependees() );
439 assertNull( action.getMailingLists() );
440 assertTrue( action.getArtifacts().isEmpty() );
443 public void testGetDependees()
446 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
447 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
448 ProjectVersionReference dependee1 = createReference( "artifactId1" );
449 ProjectVersionReference dependee2 = createReference( "artifactId2" );
450 metadataResolver.setProjectReferences( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION,
451 Arrays.asList( dependee1, dependee2 ) );
453 setActionParameters();
455 String result = action.dependees();
457 assertActionSuccess( action, result );
459 assertActionParameters( action );
460 ProjectVersionMetadata model = action.getModel();
461 assertDefaultModel( model );
463 assertNotNull( action.getDependees() );
464 assertCoordinate( action.getDependees().get( 0 ), "artifactId1" );
465 assertCoordinate( action.getDependees().get( 1 ), "artifactId2" );
467 assertEquals( TEST_REPO, action.getRepositoryId() );
468 assertNull( action.getDependencies() );
469 assertNull( action.getMailingLists() );
470 assertTrue( action.getArtifacts().isEmpty() );
473 public void testGetProjectMetadata()
475 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
477 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
479 setActionParameters();
481 String result = action.projectMetadata();
483 assertActionSuccess( action, result );
485 assertActionParameters( action );
487 Map<String, String> genericMetadata = action.getGenericMetadata();
488 assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) );
489 assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ),
490 TEST_GENERIC_METADATA_PROPERTY_VALUE );
492 assertEquals( TEST_REPO, action.getRepositoryId() );
493 assertNotNull( action.getModel() );
494 assertNull( action.getDependees() );
495 assertNull( action.getDependencies() );
496 assertNull( action.getMailingLists() );
497 assertTrue( action.getArtifacts().isEmpty() );
500 public void testAddAndDeleteMetadataProperty()
502 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
504 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
506 setActionParameters();
507 action.setPropertyName( "foo" );
508 action.setPropertyValue( "bar" );
509 action.setRepositoryId( TEST_REPO );
511 String result = action.addMetadataProperty();
513 assertActionSuccess( action, result );
514 assertActionParameters( action );
516 Map<String, String> genericMetadata = action.getGenericMetadata();
517 assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) );
518 assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ),
519 TEST_GENERIC_METADATA_PROPERTY_VALUE );
521 assertNotNull( genericMetadata.get( "foo" ) );
522 assertEquals( "bar", genericMetadata.get( "foo" ) );
524 assertEquals( TEST_REPO, action.getRepositoryId() );
525 assertNotNull( action.getModel() );
526 assertNull( action.getDependees() );
527 assertNull( action.getDependencies() );
528 assertNull( action.getMailingLists() );
529 assertTrue( action.getArtifacts().isEmpty() );
531 // test delete property
532 setActionParameters();
533 action.setDeleteItem( "foo" );
535 result = action.deleteMetadataEntry();
537 assertEquals( Action.SUCCESS, result );
538 assertActionParameters( action );
539 assertTrue( !action.getActionMessages().isEmpty() );
540 assertTrue( action.getActionMessages().contains( "Property successfully deleted." ) );
542 genericMetadata = action.getGenericMetadata();
543 assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) );
544 assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ),
545 TEST_GENERIC_METADATA_PROPERTY_VALUE );
547 assertNull( genericMetadata.get( "foo" ) );
549 assertEquals( TEST_REPO, action.getRepositoryId() );
550 assertNotNull( action.getModel() );
551 assertNull( action.getDependees() );
552 assertNull( action.getDependencies() );
553 assertNull( action.getMailingLists() );
554 assertTrue( action.getArtifacts().isEmpty() );
557 private void assertArtifacts( List<ArtifactMetadata> expectedArtifacts,
558 Map<String, List<ShowArtifactAction.ArtifactDownloadInfo>> artifactMap )
560 // assuming only one of each version at this point
561 assertEquals( expectedArtifacts.size(), artifactMap.size() );
562 for ( ArtifactMetadata artifact : expectedArtifacts )
564 assertTrue( artifactMap.containsKey( artifact.getVersion() ) );
565 List<ShowArtifactAction.ArtifactDownloadInfo> list = artifactMap.get( artifact.getVersion() );
566 ShowArtifactAction.ArtifactDownloadInfo actual = list.get( 0 );
567 assertEquals( artifact.getNamespace(), actual.getNamespace() );
568 assertEquals( artifact.getId(), actual.getId() );
569 assertEquals( artifact.getProject(), actual.getProject() );
570 assertEquals( artifact.getRepositoryId(), actual.getRepositoryId() );
571 assertEquals( artifact.getVersion(), actual.getVersion() );
572 assertEquals( TEST_TYPE, actual.getType() );
573 assertEquals( "12.06 K", actual.getSize() );
574 assertEquals( artifact.getNamespace() + "/" + artifact.getProject() + "/" + TEST_SNAPSHOT_VERSION + "/"
575 + artifact.getId(), actual.getPath() );
579 private static ArtifactMetadata createArtifact( String version )
581 return createArtifact( version, null, 0 );
584 private static ArtifactMetadata createArtifact( String version, String timestamp, int buildNumber )
586 ArtifactMetadata metadata = new ArtifactMetadata();
587 metadata.setProject( TEST_ARTIFACT_ID );
588 metadata.setId( TEST_ARTIFACT_ID + "-" + version + ".jar" );
589 metadata.setNamespace( TEST_GROUP_ID );
590 metadata.setRepositoryId( TEST_REPO );
591 metadata.setSize( TEST_SIZE );
592 metadata.setProjectVersion( VersionUtil.getBaseVersion( version ) );
593 metadata.setVersion( version );
595 MavenArtifactFacet facet = new MavenArtifactFacet();
596 facet.setType( "jar" );
597 facet.setTimestamp( timestamp );
598 facet.setBuildNumber( buildNumber );
599 metadata.addFacet( facet );
604 private ProjectVersionReference createReference( String projectId )
606 ProjectVersionReference reference = new ProjectVersionReference();
607 reference.setNamespace( "groupId" );
608 reference.setProjectId( projectId );
609 reference.setProjectVersion( "version" );
610 reference.setReferenceType( ProjectVersionReference.ReferenceType.DEPENDENCY );
614 private void assertCoordinate( ProjectVersionReference dependee, String artifactId )
616 assertEquals( artifactId, dependee.getProjectId() );
617 assertEquals( "groupId", dependee.getNamespace() );
618 assertEquals( "version", dependee.getProjectVersion() );
621 private void assertDependencyBasic( Dependency dependency, String artifactId )
623 assertEquals( artifactId, dependency.getArtifactId() );
624 assertEquals( "groupId", dependency.getGroupId() );
625 assertEquals( "version", dependency.getVersion() );
628 private void assertDependencyExtended( Dependency dependency, String artifactId )
630 assertDependencyBasic( dependency, artifactId );
631 assertEquals( true, dependency.isOptional() );
632 assertEquals( "classifier", dependency.getClassifier() );
633 assertEquals( "type", dependency.getType() );
634 assertEquals( "scope", dependency.getScope() );
635 assertEquals( "systemPath", dependency.getSystemPath() );
638 private Dependency createDependencyExtended( String artifactId )
640 Dependency dependency = createDependencyBasic( artifactId );
641 dependency.setClassifier( "classifier" );
642 dependency.setOptional( true );
643 dependency.setScope( "scope" );
644 dependency.setSystemPath( "systemPath" );
645 dependency.setType( "type" );
649 private Dependency createDependencyBasic( String artifactId )
651 Dependency dependency = new Dependency();
652 dependency.setArtifactId( artifactId );
653 dependency.setGroupId( "groupId" );
654 dependency.setVersion( "version" );
658 private void assertMailingList( MailingList mailingList, String name, String prefix )
660 assertEquals( name, mailingList.getName() );
661 assertEquals( prefix + "-post@", mailingList.getPostAddress() );
662 assertEquals( prefix + "-subscribe@", mailingList.getSubscribeAddress() );
663 assertEquals( prefix + "-unsubscribe@", mailingList.getUnsubscribeAddress() );
664 assertEquals( prefix + "-archive-url", mailingList.getMainArchiveUrl() );
665 assertEquals( Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ),
666 mailingList.getOtherArchives() );
669 private MailingList createMailingList( String name, String prefix )
671 MailingList ml1 = new MailingList();
673 ml1.setPostAddress( prefix + "-post@" );
674 ml1.setSubscribeAddress( prefix + "-subscribe@" );
675 ml1.setUnsubscribeAddress( prefix + "-unsubscribe@" );
676 ml1.setMainArchiveUrl( prefix + "-archive-url" );
677 ml1.setOtherArchives(
678 Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ) );
682 private void assertNoOutputFields()
684 assertNull( action.getModel() );
685 assertNull( action.getDependees() );
686 assertNull( action.getDependencies() );
687 assertNull( action.getMailingLists() );
688 assertTrue( action.getArtifacts().isEmpty() );
691 private void assertError( String result )
693 assertEquals( Action.ERROR, result );
694 assertEquals( 1, action.getActionErrors().size() );
697 private void assertDefaultModel( ProjectVersionMetadata model )
699 assertDefaultModel( model, TEST_VERSION );
702 private void setActionParameters()
704 action.setGroupId( TEST_GROUP_ID );
705 action.setArtifactId( TEST_ARTIFACT_ID );
706 action.setVersion( TEST_VERSION );
709 private void assertActionParameters( ShowArtifactAction action )
711 assertEquals( TEST_GROUP_ID, action.getGroupId() );
712 assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
713 assertEquals( TEST_VERSION, action.getVersion() );
716 private void assertActionSuccess( ShowArtifactAction action, String result )
718 assertEquals( Action.SUCCESS, result );
719 assertTrue( action.getActionErrors().isEmpty() );
720 assertTrue( action.getActionMessages().isEmpty() );
723 private RepositoryProblemFacet createRepositoryProblemFacet( String repoId, String errMsg, String projectId,
724 String projectVersion, String namespace )
726 RepositoryProblemFacet repoProblemFacet = new RepositoryProblemFacet();
727 repoProblemFacet.setRepositoryId( repoId );
728 repoProblemFacet.setId( repoId );
729 repoProblemFacet.setMessage( errMsg );
730 repoProblemFacet.setProblem( errMsg );
731 repoProblemFacet.setProject( projectId );
732 repoProblemFacet.setVersion( projectVersion );
733 repoProblemFacet.setNamespace( namespace );
734 return repoProblemFacet;