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.maven2.model.Artifact;
33 import org.apache.archiva.webtest.memory.TestMetadataResolver;
34 import org.apache.archiva.webtest.memory.TestRepositorySessionFactory;
35 import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet;
36 import org.apache.archiva.reports.RepositoryProblemFacet;
37 import org.apache.archiva.common.utils.VersionUtil;
38 import org.apache.archiva.configuration.ArchivaConfiguration;
39 import org.apache.archiva.configuration.Configuration;
40 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
41 import org.apache.archiva.repository.ManagedRepositoryContent;
42 import org.apache.archiva.repository.RepositoryContentFactory;
43 import org.apache.archiva.repository.content.ManagedDefaultRepositoryContent;
46 import java.util.Arrays;
47 import java.util.Collections;
48 import java.util.List;
51 import org.junit.Before;
52 import org.junit.Test;
54 import static org.mockito.Mockito.mock;
55 import static org.mockito.Mockito.when;
57 public class ShowArtifactActionTest
58 extends AbstractActionTestCase
60 private static final String ACTION_HINT = "showArtifactAction";
62 private static final String TEST_VERSION = "version";
64 private static final String TEST_SNAPSHOT_VERSION = "1.0-SNAPSHOT";
66 private static final String TEST_TS_SNAPSHOT_VERSION = "1.0-20091120.111111-1";
68 private static final String TEST_NAMESPACE = "namespace";
70 private static final String OTHER_TEST_REPO = "first-repo";
72 private ShowArtifactAction action;
74 private static final List<ArtifactMetadata> TEST_SNAPSHOT_ARTIFACTS =
75 Arrays.asList( createArtifact( TEST_TS_SNAPSHOT_VERSION ),
76 createArtifact( "1.0-20091120.222222-2", "20091120.222222", 2 ),
77 createArtifact( "1.0-20091123.333333-3", "20091123.333333", 3 ) );
79 private static final long TEST_SIZE = 12345L;
81 private static final String TEST_TYPE = "jar";
89 action = (ShowArtifactAction) getActionProxy( "/showArtifact.action" ).getAction();
91 metadataResolver = new TestMetadataResolver();
92 MetadataRepository repo = mock( MetadataRepository.class );
93 RepositorySession repositorySession = mock( RepositorySession.class );
94 when( repositorySession.getResolver() ).thenReturn( metadataResolver );
95 when( repositorySession.getRepository() ).thenReturn( repo );
96 TestRepositorySessionFactory repositorySessionFactory =
97 applicationContext.getBean( "repositorySessionFactory#test", TestRepositorySessionFactory.class );
98 repositorySessionFactory.setRepositorySession( repositorySession );
100 RepositoryContentFactory factory = mock( RepositoryContentFactory.class );
102 action.setRepositoryFactory( factory );
104 ManagedRepository config = new ManagedRepository();
105 config.setId( TEST_REPO );
106 config.setLocation( new File( "target/test-repo" ).getAbsolutePath() );
108 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
109 content.setRepository( config );
110 when( factory.getManagedRepositoryContent( TEST_REPO ) ).thenReturn( content );
112 ArchivaConfiguration archivaConfig = mock( ArchivaConfiguration.class );
114 Configuration configuration = new Configuration();
115 configuration.addManagedRepository(
116 new BeanReplicator().replicateBean( config, ManagedRepositoryConfiguration.class ) );
117 when( archivaConfig.getConfiguration() ).thenReturn( configuration );
119 when( factory.getArchivaConfiguration() ).thenReturn( archivaConfig );
124 public void testInstantiation()
126 assertFalse( action == getActionProxy( "/showArtifact.action" ).getAction() );
130 public void testGetArtifactUniqueRelease()
132 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
133 createProjectModel( TEST_VERSION ) );
135 setActionParameters();
137 String result = action.artifact();
139 assertActionSuccess( action, result );
141 assertActionParameters( action );
142 ProjectVersionMetadata model = action.getModel();
143 assertDefaultModel( model );
145 assertEquals( TEST_REPO, action.getRepositoryId() );
147 assertNull( action.getDependees() );
148 assertNull( action.getDependencies() );
149 assertNull( action.getMailingLists() );
150 assertTrue( action.getArtifacts().isEmpty() );
154 public void testGetArtifactUniqueSnapshot()
156 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
157 createProjectModel( TEST_SNAPSHOT_VERSION ) );
158 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
159 TEST_SNAPSHOT_ARTIFACTS );
161 action.setGroupId( TEST_GROUP_ID );
162 action.setArtifactId( TEST_ARTIFACT_ID );
163 action.setVersion( TEST_SNAPSHOT_VERSION );
165 String result = action.artifact();
167 assertActionSuccess( action, result );
169 assertEquals( TEST_GROUP_ID, action.getGroupId() );
170 assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
171 assertEquals( TEST_SNAPSHOT_VERSION, action.getVersion() );
172 ProjectVersionMetadata model = action.getModel();
173 assertDefaultModel( model, TEST_SNAPSHOT_VERSION );
175 assertEquals( TEST_REPO, action.getRepositoryId() );
177 assertArtifacts( TEST_SNAPSHOT_ARTIFACTS, action.getArtifacts() );
179 assertNull( action.getDependees() );
180 assertNull( action.getDependencies() );
181 assertNull( action.getMailingLists() );
185 public void testGetArtifactUniqueSnapshotTimestamped()
187 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
188 createProjectModel( TEST_SNAPSHOT_VERSION ) );
189 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
190 TEST_SNAPSHOT_ARTIFACTS );
192 action.setGroupId( TEST_GROUP_ID );
193 action.setArtifactId( TEST_ARTIFACT_ID );
194 action.setVersion( TEST_TS_SNAPSHOT_VERSION );
196 String result = action.artifact();
197 assertError( result );
198 assertNoOutputFields();
202 public void testGetMissingProject()
204 setActionParameters();
206 String result = action.artifact();
207 assertError( result );
209 assertActionParameters( action );
210 assertNoOutputFields();
214 public void testGetArtifactNoObservableRepos()
216 setObservableRepos( Collections.<String>emptyList() );
218 setActionParameters();
220 String result = action.artifact();
222 // Actually, it'd be better to have an error:
223 assertError( result );
224 assertActionParameters( action );
225 assertNoOutputFields();
229 public void testGetArtifactNotInObservableRepos()
231 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
232 createProjectModel( TEST_VERSION ) );
234 setActionParameters();
236 String result = action.artifact();
237 assertError( result );
239 assertActionParameters( action );
240 assertNoOutputFields();
244 public void testGetArtifactOnlySeenInSecondObservableRepo()
246 setObservableRepos( Arrays.asList( OTHER_TEST_REPO, TEST_REPO ) );
247 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
248 createProjectModel( TEST_VERSION ) );
250 setActionParameters();
252 String result = action.artifact();
254 assertActionSuccess( action, result );
256 assertActionParameters( action );
257 ProjectVersionMetadata model = action.getModel();
258 assertDefaultModel( model );
260 assertEquals( TEST_REPO, action.getRepositoryId() );
262 assertNull( action.getDependees() );
263 assertNull( action.getDependencies() );
264 assertNull( action.getMailingLists() );
265 assertTrue( action.getArtifacts().isEmpty() );
269 public void testGetArtifactSeenInBothObservableRepo()
271 setObservableRepos( Arrays.asList( TEST_REPO, OTHER_TEST_REPO ) );
272 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
273 createProjectModel( TEST_VERSION ) );
274 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
275 createProjectModel( TEST_VERSION ) );
277 setActionParameters();
279 String result = action.artifact();
281 assertActionSuccess( action, result );
283 assertActionParameters( action );
284 ProjectVersionMetadata model = action.getModel();
285 assertDefaultModel( model );
287 assertEquals( TEST_REPO, action.getRepositoryId() );
289 assertNull( action.getDependees() );
290 assertNull( action.getDependencies() );
291 assertNull( action.getMailingLists() );
292 assertTrue( action.getArtifacts().isEmpty() );
296 public void testGetArtifactCanOnlyObserveInOneOfTwoRepos()
298 setObservableRepos( Arrays.asList( TEST_REPO ) );
299 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
300 createProjectModel( TEST_VERSION ) );
301 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
302 createProjectModel( TEST_VERSION ) );
304 setActionParameters();
306 String result = action.artifact();
308 assertActionSuccess( action, result );
310 assertActionParameters( action );
311 ProjectVersionMetadata model = action.getModel();
312 assertDefaultModel( model );
314 assertEquals( TEST_REPO, action.getRepositoryId() );
316 assertNull( action.getDependees() );
317 assertNull( action.getDependencies() );
318 assertNull( action.getMailingLists() );
319 assertTrue( action.getArtifacts().isEmpty() );
323 public void testGetArtifactNoMavenFacet()
325 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
326 versionMetadata.setId( TEST_VERSION );
327 versionMetadata.setUrl( TEST_URL );
328 versionMetadata.setName( TEST_NAME );
329 versionMetadata.setDescription( TEST_DESCRIPTION );
331 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
333 setActionParameters();
335 String result = action.artifact();
337 assertActionSuccess( action, result );
339 assertActionParameters( action );
340 ProjectVersionMetadata model = action.getModel();
341 assertEquals( TEST_VERSION, model.getVersion() );
342 assertEquals( TEST_URL, model.getUrl() );
343 assertEquals( TEST_NAME, model.getName() );
344 assertEquals( TEST_DESCRIPTION, model.getDescription() );
346 assertEquals( TEST_REPO, action.getRepositoryId() );
348 assertNull( action.getDependees() );
349 assertNull( action.getDependencies() );
350 assertNull( action.getMailingLists() );
351 assertTrue( action.getArtifacts().isEmpty() );
355 public void testMetadataHasRepositoryFacetProblem()
357 String errMsg = "Error in resolving artifact's parent POM file: Sample Parent POM not found";
358 ProjectVersionMetadata metaData = createProjectModel( TEST_SNAPSHOT_VERSION );
360 createRepositoryProblemFacet( TEST_REPO, errMsg, TEST_GROUP_ID, TEST_SNAPSHOT_VERSION, TEST_NAMESPACE ) );
362 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, metaData );
364 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
365 TEST_SNAPSHOT_ARTIFACTS );
367 action.setGroupId( TEST_GROUP_ID );
368 action.setArtifactId( TEST_ARTIFACT_ID );
369 action.setVersion( TEST_SNAPSHOT_VERSION );
371 String result = action.artifact();
373 assertEquals( Action.SUCCESS, result );
375 assertTrue( action.hasActionErrors() );
376 assertFalse( action.hasActionMessages() );
377 assertEquals( "Artifact metadata is incomplete: " + errMsg, action.getActionErrors().toArray()[0].toString() );
381 public void testMetadataIncomplete()
383 ProjectVersionMetadata metaData = createProjectModel( TEST_SNAPSHOT_VERSION );
384 metaData.setIncomplete( true );
386 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, metaData );
388 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
389 TEST_SNAPSHOT_ARTIFACTS );
391 action.setGroupId( TEST_GROUP_ID );
392 action.setArtifactId( TEST_ARTIFACT_ID );
393 action.setVersion( TEST_SNAPSHOT_VERSION );
395 String result = action.artifact();
397 assertEquals( Action.SUCCESS, result );
399 assertTrue( action.hasActionErrors() );
400 assertFalse( action.hasActionMessages() );
402 assertEquals( "Artifact metadata is incomplete.", action.getActionErrors().toArray()[0].toString() );
406 public void testGetMailingLists()
408 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
409 MailingList ml1 = createMailingList( "Users List", "users" );
410 MailingList ml2 = createMailingList( "Developers List", "dev" );
411 versionMetadata.setMailingLists( Arrays.asList( ml1, ml2 ) );
412 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
414 setActionParameters();
416 String result = action.mailingLists();
418 assertActionSuccess( action, result );
420 assertActionParameters( action );
421 ProjectVersionMetadata model = action.getModel();
422 assertDefaultModel( model );
424 assertNotNull( action.getMailingLists() );
425 assertMailingList( action.getMailingLists().get( 0 ), "Users List", "users" );
426 assertMailingList( action.getMailingLists().get( 1 ), "Developers List", "dev" );
428 assertEquals( TEST_REPO, action.getRepositoryId() );
429 assertNull( action.getDependees() );
430 assertNull( action.getDependencies() );
431 assertTrue( action.getArtifacts().isEmpty() );
435 public void testGetDependencies()
437 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
438 Dependency dependency1 = createDependencyBasic( "artifactId1" );
439 Dependency dependency2 = createDependencyExtended( "artifactId2" );
440 versionMetadata.setDependencies( Arrays.asList( dependency1, dependency2 ) );
441 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
443 setActionParameters();
445 String result = action.dependencies();
447 assertActionSuccess( action, result );
449 assertActionParameters( action );
450 ProjectVersionMetadata model = action.getModel();
451 assertDefaultModel( model );
453 assertNotNull( action.getDependencies() );
454 assertDependencyBasic( action.getDependencies().get( 0 ), "artifactId1" );
455 assertDependencyExtended( action.getDependencies().get( 1 ), "artifactId2" );
457 assertEquals( TEST_REPO, action.getRepositoryId() );
458 assertNull( action.getDependees() );
459 assertNull( action.getMailingLists() );
460 assertTrue( action.getArtifacts().isEmpty() );
464 public void testGetDependees()
467 setObservableRepos( Arrays.asList( TEST_REPO ) );
468 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
469 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
470 ProjectVersionReference dependee1 = createReference( "artifactId1" );
471 ProjectVersionReference dependee2 = createReference( "artifactId2" );
472 metadataResolver.setProjectReferences( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION,
473 Arrays.asList( dependee1, dependee2 ) );
475 setActionParameters();
477 String result = action.dependees();
479 assertActionSuccess( action, result );
481 assertActionParameters( action );
482 ProjectVersionMetadata model = action.getModel();
483 assertDefaultModel( model );
485 assertNotNull( action.getDependees() );
486 assertCoordinate( action.getDependees().get( 0 ), "artifactId1" );
487 assertCoordinate( action.getDependees().get( 1 ), "artifactId2" );
489 assertEquals( TEST_REPO, action.getRepositoryId() );
490 assertNull( action.getDependencies() );
491 assertNull( action.getMailingLists() );
492 assertTrue( action.getArtifacts().isEmpty() );
496 public void testGetProjectMetadata()
498 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
500 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
502 setActionParameters();
504 String result = action.projectMetadata();
506 assertActionSuccess( action, result );
508 assertActionParameters( action );
510 Map<String, String> genericMetadata = action.getGenericMetadata();
511 assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) );
512 assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ),
513 TEST_GENERIC_METADATA_PROPERTY_VALUE );
515 assertEquals( TEST_REPO, action.getRepositoryId() );
516 assertNotNull( action.getModel() );
517 assertNull( action.getDependees() );
518 assertNull( action.getDependencies() );
519 assertNull( action.getMailingLists() );
520 assertTrue( action.getArtifacts().isEmpty() );
524 public void testAddAndDeleteMetadataProperty()
526 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
528 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
530 setActionParameters();
531 action.setPropertyName( "foo" );
532 action.setPropertyValue( "bar" );
533 action.setRepositoryId( TEST_REPO );
535 String result = action.addMetadataProperty();
537 assertActionSuccess( action, result );
538 assertActionParameters( action );
540 Map<String, String> genericMetadata = action.getGenericMetadata();
541 assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) );
542 assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ),
543 TEST_GENERIC_METADATA_PROPERTY_VALUE );
545 assertNotNull( genericMetadata.get( "foo" ) );
546 assertEquals( "bar", genericMetadata.get( "foo" ) );
548 assertEquals( TEST_REPO, action.getRepositoryId() );
549 assertNotNull( action.getModel() );
550 assertNull( action.getDependees() );
551 assertNull( action.getDependencies() );
552 assertNull( action.getMailingLists() );
553 assertTrue( action.getArtifacts().isEmpty() );
555 // test delete property
556 setActionParameters();
557 action.setDeleteItem( "foo" );
559 result = action.deleteMetadataEntry();
561 assertEquals( Action.SUCCESS, result );
562 assertActionParameters( action );
563 assertTrue( !action.getActionMessages().isEmpty() );
564 assertTrue( action.getActionMessages().contains( "Property successfully deleted." ) );
566 genericMetadata = action.getGenericMetadata();
567 assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) );
568 assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ),
569 TEST_GENERIC_METADATA_PROPERTY_VALUE );
571 assertNull( genericMetadata.get( "foo" ) );
573 assertEquals( TEST_REPO, action.getRepositoryId() );
574 assertNotNull( action.getModel() );
575 assertNull( action.getDependees() );
576 assertNull( action.getDependencies() );
577 assertNull( action.getMailingLists() );
578 assertTrue( action.getArtifacts().isEmpty() );
581 private void assertArtifacts( List<ArtifactMetadata> expectedArtifacts,
582 Map<String, List<Artifact>> artifactMap )
584 // assuming only one of each version at this point
585 assertEquals( expectedArtifacts.size(), artifactMap.size() );
586 for ( ArtifactMetadata artifact : expectedArtifacts )
588 assertTrue( artifactMap.containsKey( artifact.getVersion() ) );
589 List<Artifact> list = artifactMap.get( artifact.getVersion() );
590 Artifact actual = list.get( 0 );
591 assertEquals( artifact.getNamespace(), actual.getGroupId() );
592 assertEquals( artifact.getId(),actual.getId() );
593 // olamy test has no more sense as we reuse an other object now
594 //assertEquals( artifact.getProject(), actual.getGroupId() );
595 assertEquals( artifact.getRepositoryId(), actual.getRepositoryId() );
596 assertEquals( artifact.getVersion(), actual.getVersion() );
597 assertEquals( TEST_TYPE, actual.getPackaging() );
598 assertEquals( "12.06 K", actual.getSize() );
599 // FIXME url path test
600 //assertEquals( artifact.getNamespace() + "/" + artifact.getProject() + "/" + TEST_SNAPSHOT_VERSION + "/"
601 // + artifact.getId(), actual.getPath() );
605 private static ArtifactMetadata createArtifact( String version )
607 return createArtifact( version, null, 0 );
610 private static ArtifactMetadata createArtifact( String version, String timestamp, int buildNumber )
612 ArtifactMetadata metadata = new ArtifactMetadata();
613 metadata.setProject( TEST_ARTIFACT_ID );
614 metadata.setId( TEST_ARTIFACT_ID + "-" + version + ".jar" );
615 metadata.setNamespace( TEST_GROUP_ID );
616 metadata.setRepositoryId( TEST_REPO );
617 metadata.setSize( TEST_SIZE );
618 metadata.setProjectVersion( VersionUtil.getBaseVersion( version ) );
619 metadata.setVersion( version );
621 MavenArtifactFacet facet = new MavenArtifactFacet();
622 facet.setType( "jar" );
623 facet.setTimestamp( timestamp );
624 facet.setBuildNumber( buildNumber );
625 metadata.addFacet( facet );
630 private ProjectVersionReference createReference( String projectId )
632 ProjectVersionReference reference = new ProjectVersionReference();
633 reference.setNamespace( "groupId" );
634 reference.setProjectId( projectId );
635 reference.setProjectVersion( "version" );
636 reference.setReferenceType( ProjectVersionReference.ReferenceType.DEPENDENCY );
640 private void assertCoordinate( ProjectVersionReference dependee, String artifactId )
642 assertEquals( artifactId, dependee.getProjectId() );
643 assertEquals( "groupId", dependee.getNamespace() );
644 assertEquals( "version", dependee.getProjectVersion() );
647 private void assertDependencyBasic( Dependency dependency, String artifactId )
649 assertEquals( artifactId, dependency.getArtifactId() );
650 assertEquals( "groupId", dependency.getGroupId() );
651 assertEquals( "version", dependency.getVersion() );
654 private void assertDependencyExtended( Dependency dependency, String artifactId )
656 assertDependencyBasic( dependency, artifactId );
657 assertEquals( true, dependency.isOptional() );
658 assertEquals( "classifier", dependency.getClassifier() );
659 assertEquals( "type", dependency.getType() );
660 assertEquals( "scope", dependency.getScope() );
661 assertEquals( "systemPath", dependency.getSystemPath() );
664 private Dependency createDependencyExtended( String artifactId )
666 Dependency dependency = createDependencyBasic( artifactId );
667 dependency.setClassifier( "classifier" );
668 dependency.setOptional( true );
669 dependency.setScope( "scope" );
670 dependency.setSystemPath( "systemPath" );
671 dependency.setType( "type" );
675 private Dependency createDependencyBasic( String artifactId )
677 Dependency dependency = new Dependency();
678 dependency.setArtifactId( artifactId );
679 dependency.setGroupId( "groupId" );
680 dependency.setVersion( "version" );
684 private void assertMailingList( MailingList mailingList, String name, String prefix )
686 assertEquals( name, mailingList.getName() );
687 assertEquals( prefix + "-post@", mailingList.getPostAddress() );
688 assertEquals( prefix + "-subscribe@", mailingList.getSubscribeAddress() );
689 assertEquals( prefix + "-unsubscribe@", mailingList.getUnsubscribeAddress() );
690 assertEquals( prefix + "-archive-url", mailingList.getMainArchiveUrl() );
691 assertEquals( Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ),
692 mailingList.getOtherArchives() );
695 private MailingList createMailingList( String name, String prefix )
697 MailingList ml1 = new MailingList();
699 ml1.setPostAddress( prefix + "-post@" );
700 ml1.setSubscribeAddress( prefix + "-subscribe@" );
701 ml1.setUnsubscribeAddress( prefix + "-unsubscribe@" );
702 ml1.setMainArchiveUrl( prefix + "-archive-url" );
703 ml1.setOtherArchives(
704 Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ) );
708 private void assertNoOutputFields()
710 assertNull( action.getModel() );
711 assertNull( action.getDependees() );
712 assertNull( action.getDependencies() );
713 assertNull( action.getMailingLists() );
714 assertTrue( action.getArtifacts().isEmpty() );
717 private void assertError( String result )
719 assertEquals( Action.ERROR, result );
720 assertEquals( 1, action.getActionErrors().size() );
723 private void assertDefaultModel( ProjectVersionMetadata model )
725 assertDefaultModel( model, TEST_VERSION );
728 private void setActionParameters()
730 action.setGroupId( TEST_GROUP_ID );
731 action.setArtifactId( TEST_ARTIFACT_ID );
732 action.setVersion( TEST_VERSION );
735 private void assertActionParameters( ShowArtifactAction action )
737 assertEquals( TEST_GROUP_ID, action.getGroupId() );
738 assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
739 assertEquals( TEST_VERSION, action.getVersion() );
742 private void assertActionSuccess( ShowArtifactAction action, String result )
744 assertEquals( Action.SUCCESS, result );
745 assertTrue( action.getActionErrors().isEmpty() );
746 assertTrue( action.getActionMessages().isEmpty() );
749 private RepositoryProblemFacet createRepositoryProblemFacet( String repoId, String errMsg, String projectId,
750 String projectVersion, String namespace )
752 RepositoryProblemFacet repoProblemFacet = new RepositoryProblemFacet();
753 repoProblemFacet.setRepositoryId( repoId );
754 repoProblemFacet.setId( repoId );
755 repoProblemFacet.setMessage( errMsg );
756 repoProblemFacet.setProblem( errMsg );
757 repoProblemFacet.setProject( projectId );
758 repoProblemFacet.setVersion( projectVersion );
759 repoProblemFacet.setNamespace( namespace );
760 return repoProblemFacet;