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.rest.api.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;
50 import org.junit.Test;
52 import static org.mockito.Mockito.mock;
53 import static org.mockito.Mockito.when;
55 public class ShowArtifactActionTest
56 extends AbstractActionTestCase
58 private static final String ACTION_HINT = "showArtifactAction";
60 private static final String TEST_VERSION = "version";
62 private static final String TEST_SNAPSHOT_VERSION = "1.0-SNAPSHOT";
64 private static final String TEST_TS_SNAPSHOT_VERSION = "1.0-20091120.111111-1";
66 private static final String TEST_NAMESPACE = "namespace";
68 private static final String OTHER_TEST_REPO = "first-repo";
70 private ShowArtifactAction action;
72 private static final List<ArtifactMetadata> TEST_SNAPSHOT_ARTIFACTS =
73 Arrays.asList( createArtifact( TEST_TS_SNAPSHOT_VERSION ),
74 createArtifact( "1.0-20091120.222222-2", "20091120.222222", 2 ),
75 createArtifact( "1.0-20091123.333333-3", "20091123.333333", 3 ) );
77 private static final long TEST_SIZE = 12345L;
79 private static final String TEST_TYPE = "jar";
86 action = (ShowArtifactAction) getActionProxy( "/showArtifact.action" ).getAction();
88 metadataResolver = new TestMetadataResolver();
89 MetadataRepository repo = mock( MetadataRepository.class );
90 RepositorySession repositorySession = mock( RepositorySession.class );
91 when( repositorySession.getResolver() ).thenReturn( metadataResolver );
92 when( repositorySession.getRepository() ).thenReturn( repo );
93 TestRepositorySessionFactory repositorySessionFactory =
94 applicationContext.getBean( "repositorySessionFactory#test", TestRepositorySessionFactory.class );
95 repositorySessionFactory.setRepositorySession( repositorySession );
97 RepositoryContentFactory factory = mock( RepositoryContentFactory.class );
99 action.setRepositoryFactory( factory );
101 ManagedRepository config = new ManagedRepository();
102 config.setId( TEST_REPO );
103 config.setLocation( new File( "target/test-repo" ).getAbsolutePath() );
105 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
106 content.setRepository( config );
107 when( factory.getManagedRepositoryContent( TEST_REPO ) ).thenReturn( content );
109 ArchivaConfiguration archivaConfig = mock( ArchivaConfiguration.class );
111 Configuration configuration = new Configuration();
112 configuration.addManagedRepository(
113 new BeanReplicator().replicateBean( config, ManagedRepositoryConfiguration.class ) );
114 when( archivaConfig.getConfiguration() ).thenReturn( configuration );
116 when( factory.getArchivaConfiguration() ).thenReturn( archivaConfig );
121 public void testInstantiation()
123 assertFalse( action == getActionProxy( "/showArtifact.action" ).getAction() );
127 public void testGetArtifactUniqueRelease()
129 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
130 createProjectModel( TEST_VERSION ) );
132 setActionParameters();
134 String result = action.artifact();
136 assertActionSuccess( action, result );
138 assertActionParameters( action );
139 ProjectVersionMetadata model = action.getModel();
140 assertDefaultModel( model );
142 assertEquals( TEST_REPO, action.getRepositoryId() );
144 assertNull( action.getDependees() );
145 assertNull( action.getDependencies() );
146 assertNull( action.getMailingLists() );
147 assertTrue( action.getArtifacts().isEmpty() );
151 public void testGetArtifactUniqueSnapshot()
153 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
154 createProjectModel( TEST_SNAPSHOT_VERSION ) );
155 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
156 TEST_SNAPSHOT_ARTIFACTS );
158 action.setGroupId( TEST_GROUP_ID );
159 action.setArtifactId( TEST_ARTIFACT_ID );
160 action.setVersion( TEST_SNAPSHOT_VERSION );
162 String result = action.artifact();
164 assertActionSuccess( action, result );
166 assertEquals( TEST_GROUP_ID, action.getGroupId() );
167 assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
168 assertEquals( TEST_SNAPSHOT_VERSION, action.getVersion() );
169 ProjectVersionMetadata model = action.getModel();
170 assertDefaultModel( model, TEST_SNAPSHOT_VERSION );
172 assertEquals( TEST_REPO, action.getRepositoryId() );
174 assertArtifacts( TEST_SNAPSHOT_ARTIFACTS, action.getArtifacts() );
176 assertNull( action.getDependees() );
177 assertNull( action.getDependencies() );
178 assertNull( action.getMailingLists() );
182 public void testGetArtifactUniqueSnapshotTimestamped()
184 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
185 createProjectModel( TEST_SNAPSHOT_VERSION ) );
186 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
187 TEST_SNAPSHOT_ARTIFACTS );
189 action.setGroupId( TEST_GROUP_ID );
190 action.setArtifactId( TEST_ARTIFACT_ID );
191 action.setVersion( TEST_TS_SNAPSHOT_VERSION );
193 String result = action.artifact();
194 assertError( result );
195 assertNoOutputFields();
199 public void testGetMissingProject()
201 setActionParameters();
203 String result = action.artifact();
204 assertError( result );
206 assertActionParameters( action );
207 assertNoOutputFields();
211 public void testGetArtifactNoObservableRepos()
213 setObservableRepos( Collections.<String>emptyList() );
215 setActionParameters();
217 String result = action.artifact();
219 // Actually, it'd be better to have an error:
220 assertError( result );
221 assertActionParameters( action );
222 assertNoOutputFields();
226 public void testGetArtifactNotInObservableRepos()
228 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
229 createProjectModel( TEST_VERSION ) );
231 setActionParameters();
233 String result = action.artifact();
234 assertError( result );
236 assertActionParameters( action );
237 assertNoOutputFields();
241 public void testGetArtifactOnlySeenInSecondObservableRepo()
243 setObservableRepos( Arrays.asList( OTHER_TEST_REPO, TEST_REPO ) );
244 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
245 createProjectModel( TEST_VERSION ) );
247 setActionParameters();
249 String result = action.artifact();
251 assertActionSuccess( action, result );
253 assertActionParameters( action );
254 ProjectVersionMetadata model = action.getModel();
255 assertDefaultModel( model );
257 assertEquals( TEST_REPO, action.getRepositoryId() );
259 assertNull( action.getDependees() );
260 assertNull( action.getDependencies() );
261 assertNull( action.getMailingLists() );
262 assertTrue( action.getArtifacts().isEmpty() );
266 public void testGetArtifactSeenInBothObservableRepo()
268 setObservableRepos( Arrays.asList( TEST_REPO, OTHER_TEST_REPO ) );
269 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
270 createProjectModel( TEST_VERSION ) );
271 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
272 createProjectModel( TEST_VERSION ) );
274 setActionParameters();
276 String result = action.artifact();
278 assertActionSuccess( action, result );
280 assertActionParameters( action );
281 ProjectVersionMetadata model = action.getModel();
282 assertDefaultModel( model );
284 assertEquals( TEST_REPO, action.getRepositoryId() );
286 assertNull( action.getDependees() );
287 assertNull( action.getDependencies() );
288 assertNull( action.getMailingLists() );
289 assertTrue( action.getArtifacts().isEmpty() );
293 public void testGetArtifactCanOnlyObserveInOneOfTwoRepos()
295 setObservableRepos( Arrays.asList( TEST_REPO ) );
296 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
297 createProjectModel( TEST_VERSION ) );
298 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
299 createProjectModel( TEST_VERSION ) );
301 setActionParameters();
303 String result = action.artifact();
305 assertActionSuccess( action, result );
307 assertActionParameters( action );
308 ProjectVersionMetadata model = action.getModel();
309 assertDefaultModel( model );
311 assertEquals( TEST_REPO, action.getRepositoryId() );
313 assertNull( action.getDependees() );
314 assertNull( action.getDependencies() );
315 assertNull( action.getMailingLists() );
316 assertTrue( action.getArtifacts().isEmpty() );
320 public void testGetArtifactNoMavenFacet()
322 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
323 versionMetadata.setId( TEST_VERSION );
324 versionMetadata.setUrl( TEST_URL );
325 versionMetadata.setName( TEST_NAME );
326 versionMetadata.setDescription( TEST_DESCRIPTION );
328 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
330 setActionParameters();
332 String result = action.artifact();
334 assertActionSuccess( action, result );
336 assertActionParameters( action );
337 ProjectVersionMetadata model = action.getModel();
338 assertEquals( TEST_VERSION, model.getVersion() );
339 assertEquals( TEST_URL, model.getUrl() );
340 assertEquals( TEST_NAME, model.getName() );
341 assertEquals( TEST_DESCRIPTION, model.getDescription() );
343 assertEquals( TEST_REPO, action.getRepositoryId() );
345 assertNull( action.getDependees() );
346 assertNull( action.getDependencies() );
347 assertNull( action.getMailingLists() );
348 assertTrue( action.getArtifacts().isEmpty() );
352 public void testMetadataHasRepositoryFacetProblem()
354 String errMsg = "Error in resolving artifact's parent POM file: Sample Parent POM not found";
355 ProjectVersionMetadata metaData = createProjectModel( TEST_SNAPSHOT_VERSION );
357 createRepositoryProblemFacet( TEST_REPO, errMsg, TEST_GROUP_ID, TEST_SNAPSHOT_VERSION, TEST_NAMESPACE ) );
359 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, metaData );
361 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
362 TEST_SNAPSHOT_ARTIFACTS );
364 action.setGroupId( TEST_GROUP_ID );
365 action.setArtifactId( TEST_ARTIFACT_ID );
366 action.setVersion( TEST_SNAPSHOT_VERSION );
368 String result = action.artifact();
370 assertEquals( Action.SUCCESS, result );
372 assertTrue( action.hasActionErrors() );
373 assertFalse( action.hasActionMessages() );
374 assertEquals( "Artifact metadata is incomplete: " + errMsg, action.getActionErrors().toArray()[0].toString() );
378 public void testMetadataIncomplete()
380 ProjectVersionMetadata metaData = createProjectModel( TEST_SNAPSHOT_VERSION );
381 metaData.setIncomplete( true );
383 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, metaData );
385 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
386 TEST_SNAPSHOT_ARTIFACTS );
388 action.setGroupId( TEST_GROUP_ID );
389 action.setArtifactId( TEST_ARTIFACT_ID );
390 action.setVersion( TEST_SNAPSHOT_VERSION );
393 String result = action.artifact();
395 assertEquals( Action.SUCCESS, result );
397 assertTrue( action.hasActionErrors() );
398 assertFalse( action.hasActionMessages() );
400 assertEquals( "Artifact metadata is incomplete.", action.getActionErrors().toArray()[0].toString() );
404 public void testGetMailingLists()
406 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
407 MailingList ml1 = createMailingList( "Users List", "users" );
408 MailingList ml2 = createMailingList( "Developers List", "dev" );
409 versionMetadata.setMailingLists( Arrays.asList( ml1, ml2 ) );
410 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
412 setActionParameters();
414 String result = action.mailingLists();
416 assertActionSuccess( action, result );
418 assertActionParameters( action );
419 ProjectVersionMetadata model = action.getModel();
420 assertDefaultModel( model );
422 assertNotNull( action.getMailingLists() );
423 assertMailingList( action.getMailingLists().get( 0 ), "Users List", "users" );
424 assertMailingList( action.getMailingLists().get( 1 ), "Developers List", "dev" );
426 assertEquals( TEST_REPO, action.getRepositoryId() );
427 assertNull( action.getDependees() );
428 assertNull( action.getDependencies() );
429 assertTrue( action.getArtifacts().isEmpty() );
433 public void testGetDependencies()
435 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
436 Dependency dependency1 = createDependencyBasic( "artifactId1" );
437 Dependency dependency2 = createDependencyExtended( "artifactId2" );
438 versionMetadata.setDependencies( Arrays.asList( dependency1, dependency2 ) );
439 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
441 setActionParameters();
443 String result = action.dependencies();
445 assertActionSuccess( action, result );
447 assertActionParameters( action );
448 ProjectVersionMetadata model = action.getModel();
449 assertDefaultModel( model );
451 assertNotNull( action.getDependencies() );
452 assertDependencyBasic( action.getDependencies().get( 0 ), "artifactId1" );
453 assertDependencyExtended( action.getDependencies().get( 1 ), "artifactId2" );
455 assertEquals( TEST_REPO, action.getRepositoryId() );
456 assertNull( action.getDependees() );
457 assertNull( action.getMailingLists() );
458 assertTrue( action.getArtifacts().isEmpty() );
462 public void testGetDependees()
465 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
466 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
467 ProjectVersionReference dependee1 = createReference( "artifactId1" );
468 ProjectVersionReference dependee2 = createReference( "artifactId2" );
469 metadataResolver.setProjectReferences( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION,
470 Arrays.asList( dependee1, dependee2 ) );
472 setActionParameters();
474 String result = action.dependees();
476 assertActionSuccess( action, result );
478 assertActionParameters( action );
479 ProjectVersionMetadata model = action.getModel();
480 assertDefaultModel( model );
482 assertNotNull( action.getDependees() );
483 assertCoordinate( action.getDependees().get( 0 ), "artifactId1" );
484 assertCoordinate( action.getDependees().get( 1 ), "artifactId2" );
486 assertEquals( TEST_REPO, action.getRepositoryId() );
487 assertNull( action.getDependencies() );
488 assertNull( action.getMailingLists() );
489 assertTrue( action.getArtifacts().isEmpty() );
493 public void testGetProjectMetadata()
495 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
497 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
499 setActionParameters();
501 String result = action.projectMetadata();
503 assertActionSuccess( action, result );
505 assertActionParameters( action );
507 Map<String, String> genericMetadata = action.getGenericMetadata();
508 assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) );
509 assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ),
510 TEST_GENERIC_METADATA_PROPERTY_VALUE );
512 assertEquals( TEST_REPO, action.getRepositoryId() );
513 assertNotNull( action.getModel() );
514 assertNull( action.getDependees() );
515 assertNull( action.getDependencies() );
516 assertNull( action.getMailingLists() );
517 assertTrue( action.getArtifacts().isEmpty() );
521 public void testAddAndDeleteMetadataProperty()
523 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
525 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
527 setActionParameters();
528 action.setPropertyName( "foo" );
529 action.setPropertyValue( "bar" );
530 action.setRepositoryId( TEST_REPO );
532 String result = action.addMetadataProperty();
534 assertActionSuccess( action, result );
535 assertActionParameters( action );
537 Map<String, String> genericMetadata = action.getGenericMetadata();
538 assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) );
539 assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ),
540 TEST_GENERIC_METADATA_PROPERTY_VALUE );
542 assertNotNull( genericMetadata.get( "foo" ) );
543 assertEquals( "bar", genericMetadata.get( "foo" ) );
545 assertEquals( TEST_REPO, action.getRepositoryId() );
546 assertNotNull( action.getModel() );
547 assertNull( action.getDependees() );
548 assertNull( action.getDependencies() );
549 assertNull( action.getMailingLists() );
550 assertTrue( action.getArtifacts().isEmpty() );
552 // test delete property
553 setActionParameters();
554 action.setDeleteItem( "foo" );
556 result = action.deleteMetadataEntry();
558 assertEquals( Action.SUCCESS, result );
559 assertActionParameters( action );
560 assertTrue( !action.getActionMessages().isEmpty() );
561 assertTrue( action.getActionMessages().contains( "Property successfully deleted." ) );
563 genericMetadata = action.getGenericMetadata();
564 assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) );
565 assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ),
566 TEST_GENERIC_METADATA_PROPERTY_VALUE );
568 assertNull( genericMetadata.get( "foo" ) );
570 assertEquals( TEST_REPO, action.getRepositoryId() );
571 assertNotNull( action.getModel() );
572 assertNull( action.getDependees() );
573 assertNull( action.getDependencies() );
574 assertNull( action.getMailingLists() );
575 assertTrue( action.getArtifacts().isEmpty() );
578 private void assertArtifacts( List<ArtifactMetadata> expectedArtifacts,
579 Map<String, List<Artifact>> artifactMap )
581 // assuming only one of each version at this point
582 assertEquals( expectedArtifacts.size(), artifactMap.size() );
583 for ( ArtifactMetadata artifact : expectedArtifacts )
585 assertTrue( artifactMap.containsKey( artifact.getVersion() ) );
586 List<Artifact> list = artifactMap.get( artifact.getVersion() );
587 Artifact actual = list.get( 0 );
588 assertEquals( artifact.getNamespace(), actual.getGroupId() );
589 assertEquals( artifact.getId(),actual.getId() );
590 // olamy test has no more sense as we reuse an other object now
591 //assertEquals( artifact.getProject(), actual.getGroupId() );
592 assertEquals( artifact.getRepositoryId(), actual.getRepositoryId() );
593 assertEquals( artifact.getVersion(), actual.getVersion() );
594 assertEquals( TEST_TYPE, actual.getPackaging() );
595 assertEquals( "12.06 K", actual.getSize() );
596 // FIXME url path test
597 //assertEquals( artifact.getNamespace() + "/" + artifact.getProject() + "/" + TEST_SNAPSHOT_VERSION + "/"
598 // + artifact.getId(), actual.getPath() );
602 private static ArtifactMetadata createArtifact( String version )
604 return createArtifact( version, null, 0 );
607 private static ArtifactMetadata createArtifact( String version, String timestamp, int buildNumber )
609 ArtifactMetadata metadata = new ArtifactMetadata();
610 metadata.setProject( TEST_ARTIFACT_ID );
611 metadata.setId( TEST_ARTIFACT_ID + "-" + version + ".jar" );
612 metadata.setNamespace( TEST_GROUP_ID );
613 metadata.setRepositoryId( TEST_REPO );
614 metadata.setSize( TEST_SIZE );
615 metadata.setProjectVersion( VersionUtil.getBaseVersion( version ) );
616 metadata.setVersion( version );
618 MavenArtifactFacet facet = new MavenArtifactFacet();
619 facet.setType( "jar" );
620 facet.setTimestamp( timestamp );
621 facet.setBuildNumber( buildNumber );
622 metadata.addFacet( facet );
627 private ProjectVersionReference createReference( String projectId )
629 ProjectVersionReference reference = new ProjectVersionReference();
630 reference.setNamespace( "groupId" );
631 reference.setProjectId( projectId );
632 reference.setProjectVersion( "version" );
633 reference.setReferenceType( ProjectVersionReference.ReferenceType.DEPENDENCY );
637 private void assertCoordinate( ProjectVersionReference dependee, String artifactId )
639 assertEquals( artifactId, dependee.getProjectId() );
640 assertEquals( "groupId", dependee.getNamespace() );
641 assertEquals( "version", dependee.getProjectVersion() );
644 private void assertDependencyBasic( Dependency dependency, String artifactId )
646 assertEquals( artifactId, dependency.getArtifactId() );
647 assertEquals( "groupId", dependency.getGroupId() );
648 assertEquals( "version", dependency.getVersion() );
651 private void assertDependencyExtended( Dependency dependency, String artifactId )
653 assertDependencyBasic( dependency, artifactId );
654 assertEquals( true, dependency.isOptional() );
655 assertEquals( "classifier", dependency.getClassifier() );
656 assertEquals( "type", dependency.getType() );
657 assertEquals( "scope", dependency.getScope() );
658 assertEquals( "systemPath", dependency.getSystemPath() );
661 private Dependency createDependencyExtended( String artifactId )
663 Dependency dependency = createDependencyBasic( artifactId );
664 dependency.setClassifier( "classifier" );
665 dependency.setOptional( true );
666 dependency.setScope( "scope" );
667 dependency.setSystemPath( "systemPath" );
668 dependency.setType( "type" );
672 private Dependency createDependencyBasic( String artifactId )
674 Dependency dependency = new Dependency();
675 dependency.setArtifactId( artifactId );
676 dependency.setGroupId( "groupId" );
677 dependency.setVersion( "version" );
681 private void assertMailingList( MailingList mailingList, String name, String prefix )
683 assertEquals( name, mailingList.getName() );
684 assertEquals( prefix + "-post@", mailingList.getPostAddress() );
685 assertEquals( prefix + "-subscribe@", mailingList.getSubscribeAddress() );
686 assertEquals( prefix + "-unsubscribe@", mailingList.getUnsubscribeAddress() );
687 assertEquals( prefix + "-archive-url", mailingList.getMainArchiveUrl() );
688 assertEquals( Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ),
689 mailingList.getOtherArchives() );
692 private MailingList createMailingList( String name, String prefix )
694 MailingList ml1 = new MailingList();
696 ml1.setPostAddress( prefix + "-post@" );
697 ml1.setSubscribeAddress( prefix + "-subscribe@" );
698 ml1.setUnsubscribeAddress( prefix + "-unsubscribe@" );
699 ml1.setMainArchiveUrl( prefix + "-archive-url" );
700 ml1.setOtherArchives(
701 Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ) );
705 private void assertNoOutputFields()
707 assertNull( action.getModel() );
708 assertNull( action.getDependees() );
709 assertNull( action.getDependencies() );
710 assertNull( action.getMailingLists() );
711 assertTrue( action.getArtifacts().isEmpty() );
714 private void assertError( String result )
716 assertEquals( Action.ERROR, result );
717 assertEquals( 1, action.getActionErrors().size() );
720 private void assertDefaultModel( ProjectVersionMetadata model )
722 assertDefaultModel( model, TEST_VERSION );
725 private void setActionParameters()
727 action.setGroupId( TEST_GROUP_ID );
728 action.setArtifactId( TEST_ARTIFACT_ID );
729 action.setVersion( TEST_VERSION );
732 private void assertActionParameters( ShowArtifactAction action )
734 assertEquals( TEST_GROUP_ID, action.getGroupId() );
735 assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
736 assertEquals( TEST_VERSION, action.getVersion() );
739 private void assertActionSuccess( ShowArtifactAction action, String result )
741 assertEquals( Action.SUCCESS, result );
742 assertTrue( action.getActionErrors().isEmpty() );
743 assertTrue( action.getActionMessages().isEmpty() );
746 private RepositoryProblemFacet createRepositoryProblemFacet( String repoId, String errMsg, String projectId,
747 String projectVersion, String namespace )
749 RepositoryProblemFacet repoProblemFacet = new RepositoryProblemFacet();
750 repoProblemFacet.setRepositoryId( repoId );
751 repoProblemFacet.setId( repoId );
752 repoProblemFacet.setMessage( errMsg );
753 repoProblemFacet.setProblem( errMsg );
754 repoProblemFacet.setProject( projectId );
755 repoProblemFacet.setVersion( projectVersion );
756 repoProblemFacet.setNamespace( namespace );
757 return repoProblemFacet;