1 package org.apache.maven.archiva.web.action;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import java.util.Arrays;
23 import java.util.Collections;
24 import java.util.List;
26 import com.opensymphony.xwork2.Action;
27 import org.apache.archiva.metadata.model.CiManagement;
28 import org.apache.archiva.metadata.model.Dependency;
29 import org.apache.archiva.metadata.model.IssueManagement;
30 import org.apache.archiva.metadata.model.License;
31 import org.apache.archiva.metadata.model.MailingList;
32 import org.apache.archiva.metadata.model.Organization;
33 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
34 import org.apache.archiva.metadata.model.Scm;
35 import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
36 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
37 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectParent;
38 import org.apache.maven.archiva.database.ArchivaDAO;
39 import org.apache.maven.archiva.database.ArchivaDatabaseException;
40 import org.apache.maven.archiva.database.ArtifactDAO;
41 import org.apache.maven.archiva.database.ProjectModelDAO;
42 import org.apache.maven.archiva.database.constraints.ArtifactsRelatedConstraint;
43 import org.apache.maven.archiva.database.constraints.ProjectsByArtifactUsageConstraint;
44 import org.apache.maven.archiva.model.ArchivaArtifact;
45 import org.apache.maven.archiva.model.ArchivaArtifactModel;
46 import org.apache.maven.archiva.model.ArchivaProjectModel;
47 import org.apache.maven.archiva.model.VersionedReference;
48 import org.apache.maven.archiva.security.UserRepositories;
49 import org.apache.maven.archiva.security.UserRepositoriesStub;
50 import org.apache.maven.archiva.web.action.admin.repositories.ArchivaDAOStub;
51 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
52 import org.easymock.MockControl;
54 public class ShowArtifactActionTest
55 extends PlexusInSpringTestCase
57 private static final String ACTION_HINT = "showArtifactAction";
59 private static final String TEST_GROUP_ID = "groupId";
61 private static final String TEST_ARTIFACT_ID = "artifactId";
63 private static final String TEST_VERSION = "version";
65 private static final String TEST_PACKAGING = "packaging";
67 private static final String TEST_ISSUE_URL = "http://jira.codehaus.org/browse/MRM";
69 private static final String TEST_ISSUE_SYSTEM = "jira";
71 private static final String TEST_CI_SYSTEM = "continuum";
73 private static final String TEST_CI_URL = "http://vmbuild.apache.org/";
75 private static final String TEST_URL = "url";
77 private static final String TEST_NAME = "name";
79 private static final String TEST_DESCRIPTION = "description";
81 private static final String TEST_PARENT_GROUP_ID = "parentGroupId";
83 private static final String TEST_PARENT_ARTIFACT_ID = "parentArtifactId";
85 private static final String TEST_PARENT_VERSION = "parentVersion";
87 private static final String TEST_ORGANIZATION_NAME = "organizationName";
89 private static final String TEST_ORGANIZATION_URL = "organizationUrl";
91 private static final String TEST_LICENSE_URL = "licenseUrl";
93 private static final String TEST_LICENSE_NAME = "licenseName";
95 private static final String TEST_LICENSE_URL_2 = "licenseUrl_2";
97 private static final String TEST_LICENSE_NAME_2 = "licenseName_2";
99 private static final String TEST_REPO = "test-repo";
101 private static final String TEST_SCM_CONNECTION = "scmConnection";
103 private static final String TEST_SCM_DEV_CONNECTION = "scmDevConnection";
105 private static final String TEST_SCM_URL = "scmUrl";
107 private static final String TEST_SNAPSHOT_VERSION = "1.0-SNAPSHOT";
109 private static final String TEST_TS_SNAPSHOT_VERSION = "1.0-20091120.111111-1";
111 private static final List<String> ALL_TEST_SNAPSHOT_VERSIONS =
112 Arrays.asList( TEST_TS_SNAPSHOT_VERSION, "1.0-20091120.222222-2", "1.0-20091123.333333-3" );
114 private static final String OTHER_TEST_REPO = "first-repo";
116 private ShowArtifactAction action;
118 private ArchivaDAOStub archivaDao;
120 private TestMetadataResolver metadataResolver;
122 public void testInstantiation()
124 assertFalse( action == lookup( Action.class, ACTION_HINT ) );
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 ArchivaProjectModel 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.getSnapshotVersions().isEmpty() );
150 public void testGetArtifactUniqueSnapshot()
152 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
153 createProjectModel( TEST_SNAPSHOT_VERSION ) );
154 metadataResolver.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
155 ALL_TEST_SNAPSHOT_VERSIONS );
157 action.setGroupId( TEST_GROUP_ID );
158 action.setArtifactId( TEST_ARTIFACT_ID );
159 action.setVersion( TEST_SNAPSHOT_VERSION );
161 String result = action.artifact();
163 assertActionSuccess( action, result );
165 assertEquals( TEST_GROUP_ID, action.getGroupId() );
166 assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
167 assertEquals( TEST_SNAPSHOT_VERSION, action.getVersion() );
168 ArchivaProjectModel model = action.getModel();
169 assertDefaultModel( model, TEST_SNAPSHOT_VERSION );
171 assertEquals( TEST_REPO, action.getRepositoryId() );
173 assertEquals( ALL_TEST_SNAPSHOT_VERSIONS, action.getSnapshotVersions() );
175 assertNull( action.getDependees() );
176 assertNull( action.getDependencies() );
177 assertNull( action.getMailingLists() );
180 public void testGetArtifactUniqueSnapshotTimestamped()
182 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
183 createProjectModel( TEST_TS_SNAPSHOT_VERSION ) );
184 metadataResolver.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_TS_SNAPSHOT_VERSION,
185 ALL_TEST_SNAPSHOT_VERSIONS );
187 action.setGroupId( TEST_GROUP_ID );
188 action.setArtifactId( TEST_ARTIFACT_ID );
189 action.setVersion( TEST_TS_SNAPSHOT_VERSION );
191 String result = action.artifact();
193 assertActionSuccess( action, result );
195 assertEquals( TEST_GROUP_ID, action.getGroupId() );
196 assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
197 assertEquals( TEST_TS_SNAPSHOT_VERSION, action.getVersion() );
198 ArchivaProjectModel model = action.getModel();
199 assertDefaultModel( model, TEST_TS_SNAPSHOT_VERSION );
201 assertEquals( TEST_REPO, action.getRepositoryId() );
203 assertEquals( Arrays.asList( ALL_TEST_SNAPSHOT_VERSIONS.get( 1 ), ALL_TEST_SNAPSHOT_VERSIONS.get( 2 ) ),
204 action.getSnapshotVersions() );
206 assertNull( action.getDependees() );
207 assertNull( action.getDependencies() );
208 assertNull( action.getMailingLists() );
211 public void testGetMissingProject()
213 setActionParameters();
215 String result = action.artifact();
216 assertError( result );
218 assertActionParameters( action );
219 assertNoOutputFields();
222 public void testGetArtifactNoObservableRepos()
224 setObservableRepos( Collections.<String>emptyList() );
226 setActionParameters();
228 String result = action.artifact();
230 // Actually, it'd be better to have an error:
231 assertError( result );
232 assertActionParameters( action );
233 assertNoOutputFields();
236 public void testGetArtifactNotInObservableRepos()
238 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
239 createProjectModel( TEST_VERSION ) );
241 setActionParameters();
243 String result = action.artifact();
244 assertError( result );
246 assertActionParameters( action );
247 assertNoOutputFields();
250 public void testGetArtifactOnlySeenInSecondObservableRepo()
252 setObservableRepos( Arrays.asList( OTHER_TEST_REPO, TEST_REPO ) );
253 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
254 createProjectModel( TEST_VERSION ) );
256 setActionParameters();
258 String result = action.artifact();
260 assertActionSuccess( action, result );
262 assertActionParameters( action );
263 ArchivaProjectModel model = action.getModel();
264 assertDefaultModel( model );
266 assertEquals( TEST_REPO, action.getRepositoryId() );
268 assertNull( action.getDependees() );
269 assertNull( action.getDependencies() );
270 assertNull( action.getMailingLists() );
271 assertTrue( action.getSnapshotVersions().isEmpty() );
274 public void testGetArtifactSeenInBothObservableRepo()
276 setObservableRepos( Arrays.asList( TEST_REPO, OTHER_TEST_REPO ) );
277 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
278 createProjectModel( TEST_VERSION ) );
279 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
280 createProjectModel( TEST_VERSION ) );
282 setActionParameters();
284 String result = action.artifact();
286 assertActionSuccess( action, result );
288 assertActionParameters( action );
289 ArchivaProjectModel model = action.getModel();
290 assertDefaultModel( model );
292 assertEquals( TEST_REPO, action.getRepositoryId() );
294 assertNull( action.getDependees() );
295 assertNull( action.getDependencies() );
296 assertNull( action.getMailingLists() );
297 assertTrue( action.getSnapshotVersions().isEmpty() );
300 public void testGetArtifactCanOnlyObserveInOneOfTwoRepos()
302 setObservableRepos( Arrays.asList( TEST_REPO ) );
303 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
304 createProjectModel( TEST_VERSION ) );
305 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
306 createProjectModel( TEST_VERSION ) );
308 setActionParameters();
310 String result = action.artifact();
312 assertActionSuccess( action, result );
314 assertActionParameters( action );
315 ArchivaProjectModel model = action.getModel();
316 assertDefaultModel( model );
318 assertEquals( TEST_REPO, action.getRepositoryId() );
320 assertNull( action.getDependees() );
321 assertNull( action.getDependencies() );
322 assertNull( action.getMailingLists() );
323 assertTrue( action.getSnapshotVersions().isEmpty() );
326 public void testGetArtifactNoMavenFacet()
328 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
329 versionMetadata.setId( TEST_VERSION );
330 versionMetadata.setUrl( TEST_URL );
331 versionMetadata.setName( TEST_NAME );
332 versionMetadata.setDescription( TEST_DESCRIPTION );
334 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
336 setActionParameters();
338 String result = action.artifact();
340 assertActionSuccess( action, result );
342 assertActionParameters( action );
343 ArchivaProjectModel model = action.getModel();
344 assertEquals( TEST_VERSION, model.getVersion() );
345 assertEquals( TEST_URL, model.getUrl() );
346 assertEquals( TEST_NAME, model.getName() );
347 assertEquals( TEST_DESCRIPTION, model.getDescription() );
349 assertEquals( TEST_REPO, action.getRepositoryId() );
351 assertNull( action.getDependees() );
352 assertNull( action.getDependencies() );
353 assertNull( action.getMailingLists() );
354 assertTrue( action.getSnapshotVersions().isEmpty() );
357 public void testGetMailingLists()
358 throws ArchivaDatabaseException
360 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
361 MailingList ml1 = createMailingList( "Users List", "users" );
362 MailingList ml2 = createMailingList( "Developers List", "dev" );
363 versionMetadata.setMailingLists( Arrays.asList( ml1, ml2 ) );
364 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
366 setActionParameters();
368 String result = action.mailingLists();
370 assertActionSuccess( action, result );
372 assertActionParameters( action );
373 ArchivaProjectModel model = action.getModel();
374 assertDefaultModel( model );
376 assertNotNull( action.getMailingLists() );
377 assertMailingList( action.getMailingLists().get( 0 ), "Users List", "users" );
378 assertMailingList( action.getMailingLists().get( 1 ), "Developers List", "dev" );
380 assertNull( action.getRepositoryId() );
381 assertNull( action.getDependees() );
382 assertNull( action.getDependencies() );
383 assertNull( action.getSnapshotVersions() );
386 public void testGetDependencies()
387 throws ArchivaDatabaseException
389 ProjectVersionMetadata versionMetadata = createProjectModel( TEST_VERSION );
390 Dependency dependency1 = createDependencyBasic( "artifactId1" );
391 Dependency dependency2 = createDependencyExtended( "artifactId2" );
392 versionMetadata.setDependencies( Arrays.asList( dependency1, dependency2 ) );
393 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
395 setActionParameters();
397 String result = action.dependencies();
399 assertActionSuccess( action, result );
401 assertActionParameters( action );
402 ArchivaProjectModel model = action.getModel();
403 assertDefaultModel( model );
405 assertNotNull( action.getDependencies() );
406 assertDependencyBasic( action.getDependencies().get( 0 ), "artifactId1" );
407 assertDependencyExtended( action.getDependencies().get( 1 ), "artifactId2" );
409 assertNull( action.getRepositoryId() );
410 assertNull( action.getDependees() );
411 assertNull( action.getMailingLists() );
412 assertNull( action.getSnapshotVersions() );
415 public void testGetDependees()
416 throws ArchivaDatabaseException
418 List<ArchivaArtifact> artifacts =
419 Collections.singletonList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) );
420 MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, 1 );
421 ArchivaProjectModel legacyModel = createLegacyProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION );
423 MockControl projectDaoMockControl = MockControl.createNiceControl( ProjectModelDAO.class );
424 ProjectModelDAO dao = (ProjectModelDAO) projectDaoMockControl.getMock();
425 archivaDao.setProjectDao( dao );
427 projectDaoMockControl.expectAndReturn(
428 dao.getProjectModel( legacyModel.getGroupId(), legacyModel.getArtifactId(), legacyModel.getVersion() ),
431 ArchivaProjectModel dependee1 = createBasicLegacyModel( "groupId", "artifactId1", "version" );
432 ArchivaProjectModel dependee2 = createBasicLegacyModel( "groupId", "artifactId2", "version" );
433 projectDaoMockControl.expectAndReturn( dao.queryProjectModels(
434 new ProjectsByArtifactUsageConstraint( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) ),
435 Arrays.asList( dependee1, dependee2 ) );
437 projectDaoMockControl.replay();
439 setActionParameters();
441 String result = action.dependees();
443 artifactDaoMockControl.verify();
444 projectDaoMockControl.verify();
446 assertActionSuccess( action, result );
448 assertActionParameters( action );
449 ArchivaProjectModel model = action.getModel();
450 assertDefaultModel( model );
452 assertNotNull( action.getDependees() );
453 assertCoordinate( action.getDependees().get( 0 ), "artifactId1" );
454 assertCoordinate( action.getDependees().get( 1 ), "artifactId2" );
456 assertNull( action.getRepositoryId() );
457 assertNull( action.getDependencies() );
458 assertNull( action.getMailingLists() );
459 assertNull( action.getSnapshotVersions() );
462 private void assertCoordinate( ArchivaProjectModel dependee, String artifactId )
464 assertEquals( artifactId, dependee.getArtifactId() );
465 assertEquals( "groupId", dependee.getGroupId() );
466 assertEquals( "version", dependee.getVersion() );
469 private void assertDependencyBasic( org.apache.maven.archiva.model.Dependency dependency, String artifactId )
471 assertEquals( artifactId, dependency.getArtifactId() );
472 assertEquals( "groupId", dependency.getGroupId() );
473 assertEquals( "version", dependency.getVersion() );
476 private void assertDependencyExtended( org.apache.maven.archiva.model.Dependency dependency, String artifactId )
478 assertDependencyBasic( dependency, artifactId );
479 assertEquals( true, dependency.isOptional() );
480 assertEquals( "classifier", dependency.getClassifier() );
481 assertEquals( "type", dependency.getType() );
482 assertEquals( "scope", dependency.getScope() );
483 assertEquals( "systemPath", dependency.getSystemPath() );
486 private Dependency createDependencyExtended( String artifactId )
488 Dependency dependency = createDependencyBasic( artifactId );
489 dependency.setClassifier( "classifier" );
490 dependency.setOptional( true );
491 dependency.setScope( "scope" );
492 dependency.setSystemPath( "systemPath" );
493 dependency.setType( "type" );
497 private Dependency createDependencyBasic( String artifactId )
499 Dependency dependency = new Dependency();
500 dependency.setArtifactId( artifactId );
501 dependency.setGroupId( "groupId" );
502 dependency.setVersion( "version" );
506 private void assertMailingList( org.apache.maven.archiva.model.MailingList mailingList, String name, String prefix )
508 assertEquals( name, mailingList.getName() );
509 assertEquals( prefix + "-post@", mailingList.getPostAddress() );
510 assertEquals( prefix + "-subscribe@", mailingList.getSubscribeAddress() );
511 assertEquals( prefix + "-unsubscribe@", mailingList.getUnsubscribeAddress() );
512 assertEquals( prefix + "-archive-url", mailingList.getMainArchiveUrl() );
513 assertEquals( Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ),
514 mailingList.getOtherArchives() );
517 private MailingList createMailingList( String name, String prefix )
519 MailingList ml1 = new MailingList();
521 ml1.setPostAddress( prefix + "-post@" );
522 ml1.setSubscribeAddress( prefix + "-subscribe@" );
523 ml1.setUnsubscribeAddress( prefix + "-unsubscribe@" );
524 ml1.setMainArchiveUrl( prefix + "-archive-url" );
525 ml1.setOtherArchives(
526 Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ) );
530 private void assertNoOutputFields()
532 assertNull( action.getModel() );
533 assertNull( action.getDependees() );
534 assertNull( action.getDependencies() );
535 assertNull( action.getMailingLists() );
536 assertTrue( action.getSnapshotVersions().isEmpty() );
539 private void assertError( String result )
541 assertEquals( Action.ERROR, result );
542 assertEquals( 1, action.getActionErrors().size() );
545 private void setObservableRepos( List<String> repoIds )
547 UserRepositoriesStub repos = (UserRepositoriesStub) lookup( UserRepositories.class );
548 repos.setObservableRepositoryIds( repoIds );
551 private void assertDefaultModel( ArchivaProjectModel model )
553 assertDefaultModel( model, TEST_VERSION );
556 private void assertDefaultModel( ArchivaProjectModel model, String version )
558 assertEquals( TEST_GROUP_ID, model.getGroupId() );
559 assertEquals( TEST_ARTIFACT_ID, model.getArtifactId() );
560 assertEquals( version, model.getVersion() );
561 assertEquals( TEST_URL, model.getUrl() );
562 assertEquals( TEST_NAME, model.getName() );
563 assertEquals( TEST_DESCRIPTION, model.getDescription() );
564 assertEquals( TEST_ORGANIZATION_NAME, model.getOrganization().getName() );
565 assertEquals( TEST_ORGANIZATION_URL, model.getOrganization().getUrl() );
566 assertEquals( 2, model.getLicenses().size() );
567 org.apache.maven.archiva.model.License l = model.getLicenses().get( 0 );
568 assertEquals( TEST_LICENSE_NAME, l.getName() );
569 assertEquals( TEST_LICENSE_URL, l.getUrl() );
570 l = model.getLicenses().get( 1 );
571 assertEquals( TEST_LICENSE_NAME_2, l.getName() );
572 assertEquals( TEST_LICENSE_URL_2, l.getUrl() );
573 assertEquals( TEST_ISSUE_SYSTEM, model.getIssueManagement().getSystem() );
574 assertEquals( TEST_ISSUE_URL, model.getIssueManagement().getUrl() );
575 assertEquals( TEST_CI_SYSTEM, model.getCiManagement().getSystem() );
576 assertEquals( TEST_CI_URL, model.getCiManagement().getUrl() );
577 assertEquals( TEST_SCM_CONNECTION, model.getScm().getConnection() );
578 assertEquals( TEST_SCM_DEV_CONNECTION, model.getScm().getDeveloperConnection() );
579 assertEquals( TEST_SCM_URL, model.getScm().getUrl() );
581 assertEquals( TEST_PACKAGING, model.getPackaging() );
582 assertEquals( TEST_PARENT_GROUP_ID, model.getParentProject().getGroupId() );
583 assertEquals( TEST_PARENT_ARTIFACT_ID, model.getParentProject().getArtifactId() );
584 assertEquals( TEST_PARENT_VERSION, model.getParentProject().getVersion() );
587 private void setActionParameters()
589 action.setGroupId( TEST_GROUP_ID );
590 action.setArtifactId( TEST_ARTIFACT_ID );
591 action.setVersion( TEST_VERSION );
594 private void assertActionParameters( ShowArtifactAction action )
596 assertEquals( TEST_GROUP_ID, action.getGroupId() );
597 assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
598 assertEquals( TEST_VERSION, action.getVersion() );
601 private void assertActionSuccess( ShowArtifactAction action, String result )
603 assertEquals( Action.SUCCESS, result );
604 assertTrue( action.getActionErrors().isEmpty() );
605 assertTrue( action.getActionMessages().isEmpty() );
608 private ProjectVersionMetadata createProjectModel( String version )
610 ProjectVersionMetadata model = new ProjectVersionMetadata();
611 model.setId( version );
612 model.setUrl( TEST_URL );
613 model.setName( TEST_NAME );
614 model.setDescription( TEST_DESCRIPTION );
615 CiManagement ci = new CiManagement();
616 ci.setSystem( TEST_CI_SYSTEM );
617 ci.setUrl( TEST_CI_URL );
618 model.setCiManagement( ci );
619 IssueManagement issue = new IssueManagement();
620 issue.setSystem( TEST_ISSUE_SYSTEM );
621 issue.setUrl( TEST_ISSUE_URL );
622 model.setIssueManagement( issue );
623 Organization organization = new Organization();
624 organization.setName( TEST_ORGANIZATION_NAME );
625 organization.setUrl( TEST_ORGANIZATION_URL );
626 model.setOrganization( organization );
627 License l = new License();
628 l.setName( TEST_LICENSE_NAME );
629 l.setUrl( TEST_LICENSE_URL );
630 model.addLicense( l );
632 l.setName( TEST_LICENSE_NAME_2 );
633 l.setUrl( TEST_LICENSE_URL_2 );
634 model.addLicense( l );
636 scm.setConnection( TEST_SCM_CONNECTION );
637 scm.setDeveloperConnection( TEST_SCM_DEV_CONNECTION );
638 scm.setUrl( TEST_SCM_URL );
641 MavenProjectFacet mavenProjectFacet = new MavenProjectFacet();
642 mavenProjectFacet.setGroupId( TEST_GROUP_ID );
643 mavenProjectFacet.setArtifactId( TEST_ARTIFACT_ID );
644 mavenProjectFacet.setPackaging( TEST_PACKAGING );
645 MavenProjectParent parent = new MavenProjectParent();
646 parent.setGroupId( TEST_PARENT_GROUP_ID );
647 parent.setArtifactId( TEST_PARENT_ARTIFACT_ID );
648 parent.setVersion( TEST_PARENT_VERSION );
649 mavenProjectFacet.setParent( parent );
650 model.addFacet( mavenProjectFacet );
654 private ArchivaProjectModel createLegacyProjectModel( String groupId, String artifactId, String version )
656 ArchivaProjectModel model = createBasicLegacyModel( groupId, artifactId, version );
657 model.setPackaging( TEST_PACKAGING );
658 model.setUrl( TEST_URL );
659 model.setName( TEST_NAME );
660 model.setDescription( TEST_DESCRIPTION );
661 VersionedReference parent = new VersionedReference();
662 parent.setGroupId( TEST_PARENT_GROUP_ID );
663 parent.setArtifactId( TEST_PARENT_ARTIFACT_ID );
664 parent.setVersion( TEST_PARENT_VERSION );
665 model.setParentProject( parent );
666 org.apache.maven.archiva.model.CiManagement ci = new org.apache.maven.archiva.model.CiManagement();
667 ci.setSystem( TEST_CI_SYSTEM );
668 ci.setUrl( TEST_CI_URL );
669 model.setCiManagement( ci );
670 org.apache.maven.archiva.model.IssueManagement issue = new org.apache.maven.archiva.model.IssueManagement();
671 issue.setSystem( TEST_ISSUE_SYSTEM );
672 issue.setUrl( TEST_ISSUE_URL );
673 model.setIssueManagement( issue );
674 org.apache.maven.archiva.model.Organization org = new org.apache.maven.archiva.model.Organization();
675 org.setName( TEST_ORGANIZATION_NAME );
676 org.setUrl( TEST_ORGANIZATION_URL );
677 model.setOrganization( org );
678 org.apache.maven.archiva.model.License l = new org.apache.maven.archiva.model.License();
679 l.setName( TEST_LICENSE_NAME );
680 l.setUrl( TEST_LICENSE_URL );
681 model.addLicense( l );
682 l = new org.apache.maven.archiva.model.License();
683 l.setName( TEST_LICENSE_NAME_2 );
684 l.setUrl( TEST_LICENSE_URL_2 );
685 model.addLicense( l );
686 org.apache.maven.archiva.model.Scm scm = new org.apache.maven.archiva.model.Scm();
687 scm.setConnection( TEST_SCM_CONNECTION );
688 scm.setDeveloperConnection( TEST_SCM_DEV_CONNECTION );
689 scm.setUrl( TEST_SCM_URL );
694 private ArchivaProjectModel createBasicLegacyModel( String groupId, String artifactId, String version )
696 ArchivaProjectModel model = new ArchivaProjectModel();
697 model.setGroupId( groupId );
698 model.setArtifactId( artifactId );
699 model.setVersion( version );
703 private MockControl createArtifactDaoMock( List<ArchivaArtifact> artifacts, int count )
704 throws ArchivaDatabaseException
706 return createArtifactDaoMock( artifacts, TEST_VERSION, count );
709 private MockControl createArtifactDaoMock( List<ArchivaArtifact> artifacts, String version, int count )
710 throws ArchivaDatabaseException
712 // testing deeper than normal with the mocks as we intend to replace RepositoryBrowsing, not just the database
713 // underneath it - those sections will be adjusted with a mock content repository later
714 MockControl control = MockControl.createNiceControl( ArtifactDAO.class );
715 ArtifactDAO dao = (ArtifactDAO) control.getMock();
716 archivaDao.setArtifactDao( dao );
718 ArtifactsRelatedConstraint c = new ArtifactsRelatedConstraint( TEST_GROUP_ID, TEST_ARTIFACT_ID, version );
719 dao.queryArtifacts( c );
720 control.setReturnValue( artifacts, count );
726 private ArchivaArtifact createArtifact( String groupId, String artifactId, String version )
728 return createArtifact( groupId, artifactId, version, TEST_REPO );
731 private ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String repoId )
733 ArchivaArtifactModel model = new ArchivaArtifactModel();
734 model.setGroupId( groupId );
735 model.setArtifactId( artifactId );
736 model.setVersion( version );
737 model.setRepositoryId( repoId );
738 return new ArchivaArtifact( model );
741 protected void setUp()
745 action = (ShowArtifactAction) lookup( Action.class, ACTION_HINT );
746 metadataResolver = (TestMetadataResolver) action.getMetadataResolver();
747 archivaDao = (ArchivaDAOStub) lookup( ArchivaDAO.class, "jdo" );