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;
51 import static org.mockito.Mockito.mock;
52 import static org.mockito.Mockito.when;
54 public class ShowArtifactActionTest
55 extends AbstractActionTestCase
57 private static final String ACTION_HINT = "showArtifactAction";
59 private static final String TEST_VERSION = "version";
61 private static final String TEST_SNAPSHOT_VERSION = "1.0-SNAPSHOT";
63 private static final String TEST_TS_SNAPSHOT_VERSION = "1.0-20091120.111111-1";
65 private static final String TEST_NAMESPACE = "namespace";
67 private static final String OTHER_TEST_REPO = "first-repo";
69 private ShowArtifactAction action;
71 private static final List<ArtifactMetadata> TEST_SNAPSHOT_ARTIFACTS =
72 Arrays.asList( createArtifact( TEST_TS_SNAPSHOT_VERSION ),
73 createArtifact( "1.0-20091120.222222-2", "20091120.222222", 2 ),
74 createArtifact( "1.0-20091123.333333-3", "20091123.333333", 3 ) );
76 private static final long TEST_SIZE = 12345L;
78 private static final String TEST_TYPE = "jar";
80 protected void setUp()
84 action = (ShowArtifactAction) getActionProxy( "/showArtifact.action" ).getAction();
86 metadataResolver = new TestMetadataResolver();
87 MetadataRepository repo = mock( MetadataRepository.class );
88 RepositorySession repositorySession = mock( RepositorySession.class );
89 when( repositorySession.getResolver() ).thenReturn( metadataResolver );
90 when( repositorySession.getRepository() ).thenReturn( repo );
91 TestRepositorySessionFactory repositorySessionFactory =
92 applicationContext.getBean( "repositorySessionFactory#test", TestRepositorySessionFactory.class );
93 repositorySessionFactory.setRepositorySession( repositorySession );
95 RepositoryContentFactory factory = mock( RepositoryContentFactory.class );
97 action.setRepositoryFactory( factory );
99 ManagedRepository config = new ManagedRepository();
100 config.setId( TEST_REPO );
101 config.setLocation( new File( "target/test-repo" ).getAbsolutePath() );
103 ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
104 content.setRepository( config );
105 when( factory.getManagedRepositoryContent( TEST_REPO ) ).thenReturn( content );
107 ArchivaConfiguration archivaConfig = mock( ArchivaConfiguration.class );
109 Configuration configuration = new Configuration();
110 configuration.addManagedRepository(
111 new BeanReplicator().replicateBean( config, ManagedRepositoryConfiguration.class ) );
112 when( archivaConfig.getConfiguration() ).thenReturn( configuration );
114 when( factory.getArchivaConfiguration() ).thenReturn( archivaConfig );
118 public void testInstantiation()
120 assertFalse( action == getActionProxy( "/showArtifact.action" ).getAction() );
123 public void testGetArtifactUniqueRelease()
125 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
126 createProjectModel( TEST_VERSION ) );
128 setActionParameters();
130 String result = action.artifact();
132 assertActionSuccess( action, result );
134 assertActionParameters( action );
135 ProjectVersionMetadata model = action.getModel();
136 assertDefaultModel( model );
138 assertEquals( TEST_REPO, action.getRepositoryId() );
140 assertNull( action.getDependees() );
141 assertNull( action.getDependencies() );
142 assertNull( action.getMailingLists() );
143 assertTrue( action.getArtifacts().isEmpty() );
146 public void testGetArtifactUniqueSnapshot()
148 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
149 createProjectModel( TEST_SNAPSHOT_VERSION ) );
150 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
151 TEST_SNAPSHOT_ARTIFACTS );
153 action.setGroupId( TEST_GROUP_ID );
154 action.setArtifactId( TEST_ARTIFACT_ID );
155 action.setVersion( TEST_SNAPSHOT_VERSION );
157 String result = action.artifact();
159 assertActionSuccess( action, result );
161 assertEquals( TEST_GROUP_ID, action.getGroupId() );
162 assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
163 assertEquals( TEST_SNAPSHOT_VERSION, action.getVersion() );
164 ProjectVersionMetadata model = action.getModel();
165 assertDefaultModel( model, TEST_SNAPSHOT_VERSION );
167 assertEquals( TEST_REPO, action.getRepositoryId() );
169 assertArtifacts( TEST_SNAPSHOT_ARTIFACTS, action.getArtifacts() );
171 assertNull( action.getDependees() );
172 assertNull( action.getDependencies() );
173 assertNull( action.getMailingLists() );
176 public void testGetArtifactUniqueSnapshotTimestamped()
178 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
179 createProjectModel( TEST_SNAPSHOT_VERSION ) );
180 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
181 TEST_SNAPSHOT_ARTIFACTS );
183 action.setGroupId( TEST_GROUP_ID );
184 action.setArtifactId( TEST_ARTIFACT_ID );
185 action.setVersion( TEST_TS_SNAPSHOT_VERSION );
187 String result = action.artifact();
188 assertError( result );
189 assertNoOutputFields();
192 public void testGetMissingProject()
194 setActionParameters();
196 String result = action.artifact();
197 assertError( result );
199 assertActionParameters( action );
200 assertNoOutputFields();
203 public void testGetArtifactNoObservableRepos()
205 setObservableRepos( Collections.<String>emptyList() );
207 setActionParameters();
209 String result = action.artifact();
211 // Actually, it'd be better to have an error:
212 assertError( result );
213 assertActionParameters( action );
214 assertNoOutputFields();
217 public void testGetArtifactNotInObservableRepos()
219 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
220 createProjectModel( TEST_VERSION ) );
222 setActionParameters();
224 String result = action.artifact();
225 assertError( result );
227 assertActionParameters( action );
228 assertNoOutputFields();
231 public void testGetArtifactOnlySeenInSecondObservableRepo()
233 setObservableRepos( Arrays.asList( OTHER_TEST_REPO, TEST_REPO ) );
234 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
235 createProjectModel( TEST_VERSION ) );
237 setActionParameters();
239 String result = action.artifact();
241 assertActionSuccess( action, result );
243 assertActionParameters( action );
244 ProjectVersionMetadata model = action.getModel();
245 assertDefaultModel( model );
247 assertEquals( TEST_REPO, action.getRepositoryId() );
249 assertNull( action.getDependees() );
250 assertNull( action.getDependencies() );
251 assertNull( action.getMailingLists() );
252 assertTrue( action.getArtifacts().isEmpty() );
255 public void testGetArtifactSeenInBothObservableRepo()
257 setObservableRepos( Arrays.asList( TEST_REPO, OTHER_TEST_REPO ) );
258 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
259 createProjectModel( TEST_VERSION ) );
260 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
261 createProjectModel( TEST_VERSION ) );
263 setActionParameters();
265 String result = action.artifact();
267 assertActionSuccess( action, result );
269 assertActionParameters( action );
270 ProjectVersionMetadata model = action.getModel();
271 assertDefaultModel( model );
273 assertEquals( TEST_REPO, action.getRepositoryId() );
275 assertNull( action.getDependees() );
276 assertNull( action.getDependencies() );
277 assertNull( action.getMailingLists() );
278 assertTrue( action.getArtifacts().isEmpty() );
281 public void testGetArtifactCanOnlyObserveInOneOfTwoRepos()
283 setObservableRepos( Arrays.asList( TEST_REPO ) );
284 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
285 createProjectModel( TEST_VERSION ) );
286 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
287 createProjectModel( TEST_VERSION ) );
289 setActionParameters();
291 String result = action.artifact();
293 assertActionSuccess( action, result );
295 assertActionParameters( action );
296 ProjectVersionMetadata model = action.getModel();
297 assertDefaultModel( model );
299 assertEquals( TEST_REPO, action.getRepositoryId() );
301 assertNull( action.getDependees() );
302 assertNull( action.getDependencies() );
303 assertNull( action.getMailingLists() );
304 assertTrue( action.getArtifacts().isEmpty() );
307 public void testGetArtifactNoMavenFacet()
309 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
310 versionMetadata.setId( TEST_VERSION );
311 versionMetadata.setUrl( TEST_URL );
312 versionMetadata.setName( TEST_NAME );
313 versionMetadata.setDescription( TEST_DESCRIPTION );
315 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
317 setActionParameters();
319 String result = action.artifact();
321 assertActionSuccess( action, result );
323 assertActionParameters( action );
324 ProjectVersionMetadata model = action.getModel();
325 assertEquals( TEST_VERSION, model.getVersion() );
326 assertEquals( TEST_URL, model.getUrl() );
327 assertEquals( TEST_NAME, model.getName() );
328 assertEquals( TEST_DESCRIPTION, model.getDescription() );
330 assertEquals( TEST_REPO, action.getRepositoryId() );
332 assertNull( action.getDependees() );
333 assertNull( action.getDependencies() );
334 assertNull( action.getMailingLists() );
335 assertTrue( action.getArtifacts().isEmpty() );
338 public void testMetadataHasRepositoryFacetProblem()
340 String errMsg = "Error in resolving artifact's parent POM file: Sample Parent POM not found";
341 ProjectVersionMetadata metaData = createProjectModel( TEST_SNAPSHOT_VERSION );
343 createRepositoryProblemFacet( TEST_REPO, errMsg, TEST_GROUP_ID, TEST_SNAPSHOT_VERSION, TEST_NAMESPACE ) );
345 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, metaData );
347 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
348 TEST_SNAPSHOT_ARTIFACTS );
350 action.setGroupId( TEST_GROUP_ID );
351 action.setArtifactId( TEST_ARTIFACT_ID );
352 action.setVersion( TEST_SNAPSHOT_VERSION );
354 String result = action.artifact();
356 assertEquals( Action.SUCCESS, result );
358 assertTrue( action.hasActionErrors() );
359 assertFalse( action.hasActionMessages() );
360 assertEquals( "Artifact metadata is incomplete: " + errMsg, action.getActionErrors().toArray()[0].toString() );
363 public void testMetadataIncomplete()
365 ProjectVersionMetadata metaData = createProjectModel( TEST_SNAPSHOT_VERSION );
366 metaData.setIncomplete( true );
368 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, metaData );
370 metadataResolver.setArtifacts( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
371 TEST_SNAPSHOT_ARTIFACTS );
373 action.setGroupId( TEST_GROUP_ID );
374 action.setArtifactId( TEST_ARTIFACT_ID );
375 action.setVersion( TEST_SNAPSHOT_VERSION );
378 String result = action.artifact();
380 assertEquals( Action.SUCCESS, result );
382 assertTrue( action.hasActionErrors() );
383 assertFalse( action.hasActionMessages() );
385 assertEquals( "Artifact metadata is incomplete.", action.getActionErrors().toArray()[0].toString() );
388 public void testGetMailingLists()
390 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
391 MailingList ml1 = createMailingList( "Users List", "users" );
392 MailingList ml2 = createMailingList( "Developers List", "dev" );
393 versionMetadata.setMailingLists( Arrays.asList( ml1, ml2 ) );
394 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
396 setActionParameters();
398 String result = action.mailingLists();
400 assertActionSuccess( action, result );
402 assertActionParameters( action );
403 ProjectVersionMetadata model = action.getModel();
404 assertDefaultModel( model );
406 assertNotNull( action.getMailingLists() );
407 assertMailingList( action.getMailingLists().get( 0 ), "Users List", "users" );
408 assertMailingList( action.getMailingLists().get( 1 ), "Developers List", "dev" );
410 assertEquals( TEST_REPO, action.getRepositoryId() );
411 assertNull( action.getDependees() );
412 assertNull( action.getDependencies() );
413 assertTrue( action.getArtifacts().isEmpty() );
416 public void testGetDependencies()
418 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
419 Dependency dependency1 = createDependencyBasic( "artifactId1" );
420 Dependency dependency2 = createDependencyExtended( "artifactId2" );
421 versionMetadata.setDependencies( Arrays.asList( dependency1, dependency2 ) );
422 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
424 setActionParameters();
426 String result = action.dependencies();
428 assertActionSuccess( action, result );
430 assertActionParameters( action );
431 ProjectVersionMetadata model = action.getModel();
432 assertDefaultModel( model );
434 assertNotNull( action.getDependencies() );
435 assertDependencyBasic( action.getDependencies().get( 0 ), "artifactId1" );
436 assertDependencyExtended( action.getDependencies().get( 1 ), "artifactId2" );
438 assertEquals( TEST_REPO, action.getRepositoryId() );
439 assertNull( action.getDependees() );
440 assertNull( action.getMailingLists() );
441 assertTrue( action.getArtifacts().isEmpty() );
444 public void testGetDependees()
447 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
448 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
449 ProjectVersionReference dependee1 = createReference( "artifactId1" );
450 ProjectVersionReference dependee2 = createReference( "artifactId2" );
451 metadataResolver.setProjectReferences( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION,
452 Arrays.asList( dependee1, dependee2 ) );
454 setActionParameters();
456 String result = action.dependees();
458 assertActionSuccess( action, result );
460 assertActionParameters( action );
461 ProjectVersionMetadata model = action.getModel();
462 assertDefaultModel( model );
464 assertNotNull( action.getDependees() );
465 assertCoordinate( action.getDependees().get( 0 ), "artifactId1" );
466 assertCoordinate( action.getDependees().get( 1 ), "artifactId2" );
468 assertEquals( TEST_REPO, action.getRepositoryId() );
469 assertNull( action.getDependencies() );
470 assertNull( action.getMailingLists() );
471 assertTrue( action.getArtifacts().isEmpty() );
474 public void testGetProjectMetadata()
476 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
478 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
480 setActionParameters();
482 String result = action.projectMetadata();
484 assertActionSuccess( action, result );
486 assertActionParameters( action );
488 Map<String, String> genericMetadata = action.getGenericMetadata();
489 assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) );
490 assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ),
491 TEST_GENERIC_METADATA_PROPERTY_VALUE );
493 assertEquals( TEST_REPO, action.getRepositoryId() );
494 assertNotNull( action.getModel() );
495 assertNull( action.getDependees() );
496 assertNull( action.getDependencies() );
497 assertNull( action.getMailingLists() );
498 assertTrue( action.getArtifacts().isEmpty() );
501 public void testAddAndDeleteMetadataProperty()
503 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
505 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
507 setActionParameters();
508 action.setPropertyName( "foo" );
509 action.setPropertyValue( "bar" );
510 action.setRepositoryId( TEST_REPO );
512 String result = action.addMetadataProperty();
514 assertActionSuccess( action, result );
515 assertActionParameters( action );
517 Map<String, String> genericMetadata = action.getGenericMetadata();
518 assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) );
519 assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ),
520 TEST_GENERIC_METADATA_PROPERTY_VALUE );
522 assertNotNull( genericMetadata.get( "foo" ) );
523 assertEquals( "bar", genericMetadata.get( "foo" ) );
525 assertEquals( TEST_REPO, action.getRepositoryId() );
526 assertNotNull( action.getModel() );
527 assertNull( action.getDependees() );
528 assertNull( action.getDependencies() );
529 assertNull( action.getMailingLists() );
530 assertTrue( action.getArtifacts().isEmpty() );
532 // test delete property
533 setActionParameters();
534 action.setDeleteItem( "foo" );
536 result = action.deleteMetadataEntry();
538 assertEquals( Action.SUCCESS, result );
539 assertActionParameters( action );
540 assertTrue( !action.getActionMessages().isEmpty() );
541 assertTrue( action.getActionMessages().contains( "Property successfully deleted." ) );
543 genericMetadata = action.getGenericMetadata();
544 assertNotNull( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ) );
545 assertEquals( genericMetadata.get( TEST_GENERIC_METADATA_PROPERTY_NAME ),
546 TEST_GENERIC_METADATA_PROPERTY_VALUE );
548 assertNull( genericMetadata.get( "foo" ) );
550 assertEquals( TEST_REPO, action.getRepositoryId() );
551 assertNotNull( action.getModel() );
552 assertNull( action.getDependees() );
553 assertNull( action.getDependencies() );
554 assertNull( action.getMailingLists() );
555 assertTrue( action.getArtifacts().isEmpty() );
558 private void assertArtifacts( List<ArtifactMetadata> expectedArtifacts,
559 Map<String, List<Artifact>> artifactMap )
561 // assuming only one of each version at this point
562 assertEquals( expectedArtifacts.size(), artifactMap.size() );
563 for ( ArtifactMetadata artifact : expectedArtifacts )
565 assertTrue( artifactMap.containsKey( artifact.getVersion() ) );
566 List<Artifact> list = artifactMap.get( artifact.getVersion() );
567 Artifact actual = list.get( 0 );
568 assertEquals( artifact.getNamespace(), actual.getGroupId() );
569 assertEquals( artifact.getId(),actual.getId() );
570 // olamy test has no more sense as we reuse an other object now
571 //assertEquals( artifact.getProject(), actual.getGroupId() );
572 assertEquals( artifact.getRepositoryId(), actual.getRepositoryId() );
573 assertEquals( artifact.getVersion(), actual.getVersion() );
574 assertEquals( TEST_TYPE, actual.getPackaging() );
575 assertEquals( "12.06 K", actual.getSize() );
576 // FIXME url path test
577 //assertEquals( artifact.getNamespace() + "/" + artifact.getProject() + "/" + TEST_SNAPSHOT_VERSION + "/"
578 // + artifact.getId(), actual.getPath() );
582 private static ArtifactMetadata createArtifact( String version )
584 return createArtifact( version, null, 0 );
587 private static ArtifactMetadata createArtifact( String version, String timestamp, int buildNumber )
589 ArtifactMetadata metadata = new ArtifactMetadata();
590 metadata.setProject( TEST_ARTIFACT_ID );
591 metadata.setId( TEST_ARTIFACT_ID + "-" + version + ".jar" );
592 metadata.setNamespace( TEST_GROUP_ID );
593 metadata.setRepositoryId( TEST_REPO );
594 metadata.setSize( TEST_SIZE );
595 metadata.setProjectVersion( VersionUtil.getBaseVersion( version ) );
596 metadata.setVersion( version );
598 MavenArtifactFacet facet = new MavenArtifactFacet();
599 facet.setType( "jar" );
600 facet.setTimestamp( timestamp );
601 facet.setBuildNumber( buildNumber );
602 metadata.addFacet( facet );
607 private ProjectVersionReference createReference( String projectId )
609 ProjectVersionReference reference = new ProjectVersionReference();
610 reference.setNamespace( "groupId" );
611 reference.setProjectId( projectId );
612 reference.setProjectVersion( "version" );
613 reference.setReferenceType( ProjectVersionReference.ReferenceType.DEPENDENCY );
617 private void assertCoordinate( ProjectVersionReference dependee, String artifactId )
619 assertEquals( artifactId, dependee.getProjectId() );
620 assertEquals( "groupId", dependee.getNamespace() );
621 assertEquals( "version", dependee.getProjectVersion() );
624 private void assertDependencyBasic( Dependency dependency, String artifactId )
626 assertEquals( artifactId, dependency.getArtifactId() );
627 assertEquals( "groupId", dependency.getGroupId() );
628 assertEquals( "version", dependency.getVersion() );
631 private void assertDependencyExtended( Dependency dependency, String artifactId )
633 assertDependencyBasic( dependency, artifactId );
634 assertEquals( true, dependency.isOptional() );
635 assertEquals( "classifier", dependency.getClassifier() );
636 assertEquals( "type", dependency.getType() );
637 assertEquals( "scope", dependency.getScope() );
638 assertEquals( "systemPath", dependency.getSystemPath() );
641 private Dependency createDependencyExtended( String artifactId )
643 Dependency dependency = createDependencyBasic( artifactId );
644 dependency.setClassifier( "classifier" );
645 dependency.setOptional( true );
646 dependency.setScope( "scope" );
647 dependency.setSystemPath( "systemPath" );
648 dependency.setType( "type" );
652 private Dependency createDependencyBasic( String artifactId )
654 Dependency dependency = new Dependency();
655 dependency.setArtifactId( artifactId );
656 dependency.setGroupId( "groupId" );
657 dependency.setVersion( "version" );
661 private void assertMailingList( MailingList mailingList, String name, String prefix )
663 assertEquals( name, mailingList.getName() );
664 assertEquals( prefix + "-post@", mailingList.getPostAddress() );
665 assertEquals( prefix + "-subscribe@", mailingList.getSubscribeAddress() );
666 assertEquals( prefix + "-unsubscribe@", mailingList.getUnsubscribeAddress() );
667 assertEquals( prefix + "-archive-url", mailingList.getMainArchiveUrl() );
668 assertEquals( Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ),
669 mailingList.getOtherArchives() );
672 private MailingList createMailingList( String name, String prefix )
674 MailingList ml1 = new MailingList();
676 ml1.setPostAddress( prefix + "-post@" );
677 ml1.setSubscribeAddress( prefix + "-subscribe@" );
678 ml1.setUnsubscribeAddress( prefix + "-unsubscribe@" );
679 ml1.setMainArchiveUrl( prefix + "-archive-url" );
680 ml1.setOtherArchives(
681 Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ) );
685 private void assertNoOutputFields()
687 assertNull( action.getModel() );
688 assertNull( action.getDependees() );
689 assertNull( action.getDependencies() );
690 assertNull( action.getMailingLists() );
691 assertTrue( action.getArtifacts().isEmpty() );
694 private void assertError( String result )
696 assertEquals( Action.ERROR, result );
697 assertEquals( 1, action.getActionErrors().size() );
700 private void assertDefaultModel( ProjectVersionMetadata model )
702 assertDefaultModel( model, TEST_VERSION );
705 private void setActionParameters()
707 action.setGroupId( TEST_GROUP_ID );
708 action.setArtifactId( TEST_ARTIFACT_ID );
709 action.setVersion( TEST_VERSION );
712 private void assertActionParameters( ShowArtifactAction action )
714 assertEquals( TEST_GROUP_ID, action.getGroupId() );
715 assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
716 assertEquals( TEST_VERSION, action.getVersion() );
719 private void assertActionSuccess( ShowArtifactAction action, String result )
721 assertEquals( Action.SUCCESS, result );
722 assertTrue( action.getActionErrors().isEmpty() );
723 assertTrue( action.getActionMessages().isEmpty() );
726 private RepositoryProblemFacet createRepositoryProblemFacet( String repoId, String errMsg, String projectId,
727 String projectVersion, String namespace )
729 RepositoryProblemFacet repoProblemFacet = new RepositoryProblemFacet();
730 repoProblemFacet.setRepositoryId( repoId );
731 repoProblemFacet.setId( repoId );
732 repoProblemFacet.setMessage( errMsg );
733 repoProblemFacet.setProblem( errMsg );
734 repoProblemFacet.setProject( projectId );
735 repoProblemFacet.setVersion( projectVersion );
736 repoProblemFacet.setNamespace( namespace );
737 return repoProblemFacet;