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.IssueManagement;
29 import org.apache.archiva.metadata.model.License;
30 import org.apache.archiva.metadata.model.Organization;
31 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
32 import org.apache.archiva.metadata.model.Scm;
33 import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
34 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
35 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectParent;
36 import org.apache.maven.archiva.database.ArchivaDAO;
37 import org.apache.maven.archiva.database.ArchivaDatabaseException;
38 import org.apache.maven.archiva.database.ArtifactDAO;
39 import org.apache.maven.archiva.database.ProjectModelDAO;
40 import org.apache.maven.archiva.database.constraints.ArtifactsRelatedConstraint;
41 import org.apache.maven.archiva.model.ArchivaArtifact;
42 import org.apache.maven.archiva.model.ArchivaArtifactModel;
43 import org.apache.maven.archiva.model.ArchivaProjectModel;
44 import org.apache.maven.archiva.model.MailingList;
45 import org.apache.maven.archiva.model.VersionedReference;
46 import org.apache.maven.archiva.security.UserRepositories;
47 import org.apache.maven.archiva.security.UserRepositoriesStub;
48 import org.apache.maven.archiva.web.action.admin.repositories.ArchivaDAOStub;
49 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
50 import org.easymock.MockControl;
52 public class ShowArtifactActionTest
53 extends PlexusInSpringTestCase
55 private static final String ACTION_HINT = "showArtifactAction";
57 private static final String TEST_GROUP_ID = "groupId";
59 private static final String TEST_ARTIFACT_ID = "artifactId";
61 private static final String TEST_VERSION = "version";
63 private static final String TEST_PACKAGING = "packaging";
65 private static final String TEST_ISSUE_URL = "http://jira.codehaus.org/browse/MRM";
67 private static final String TEST_ISSUE_SYSTEM = "jira";
69 private static final String TEST_CI_SYSTEM = "continuum";
71 private static final String TEST_CI_URL = "http://vmbuild.apache.org/";
73 private static final String TEST_URL = "url";
75 private static final String TEST_NAME = "name";
77 private static final String TEST_DESCRIPTION = "description";
79 private static final String TEST_PARENT_GROUP_ID = "parentGroupId";
81 private static final String TEST_PARENT_ARTIFACT_ID = "parentArtifactId";
83 private static final String TEST_PARENT_VERSION = "parentVersion";
85 private static final String TEST_ORGANIZATION_NAME = "organizationName";
87 private static final String TEST_ORGANIZATION_URL = "organizationUrl";
89 private static final String TEST_LICENSE_URL = "licenseUrl";
91 private static final String TEST_LICENSE_NAME = "licenseName";
93 private static final String TEST_LICENSE_URL_2 = "licenseUrl_2";
95 private static final String TEST_LICENSE_NAME_2 = "licenseName_2";
97 private static final String TEST_REPO = "test-repo";
99 private static final String TEST_SCM_CONNECTION = "scmConnection";
101 private static final String TEST_SCM_DEV_CONNECTION = "scmDevConnection";
103 private static final String TEST_SCM_URL = "scmUrl";
105 private static final String TEST_SNAPSHOT_VERSION = "1.0-SNAPSHOT";
107 private static final String TEST_TS_SNAPSHOT_VERSION = "1.0-20091120.111111-1";
109 private static final List<String> ALL_TEST_SNAPSHOT_VERSIONS =
110 Arrays.asList( TEST_TS_SNAPSHOT_VERSION, "1.0-20091120.222222-2", "1.0-20091123.333333-3" );
112 private static final String OTHER_TEST_REPO = "first-repo";
114 private ShowArtifactAction action;
116 private ArchivaDAOStub archivaDao;
118 private TestMetadataResolver metadataResolver;
120 public void testInstantiation()
122 assertFalse( action == lookup( Action.class, ACTION_HINT ) );
125 public void testGetArtifactUniqueRelease()
127 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
128 createProjectModel( TEST_VERSION ) );
130 setActionParameters();
132 String result = action.artifact();
134 assertActionSuccess( action, result );
136 assertActionParameters( action );
137 ArchivaProjectModel model = action.getModel();
138 assertDefaultModel( model );
140 assertEquals( TEST_REPO, action.getRepositoryId() );
142 assertNull( action.getDependees() );
143 assertNull( action.getDependencies() );
144 assertNull( action.getMailingLists() );
145 assertTrue( action.getSnapshotVersions().isEmpty() );
148 public void testGetArtifactUniqueSnapshot()
150 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
151 createProjectModel( TEST_SNAPSHOT_VERSION ) );
152 metadataResolver.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_SNAPSHOT_VERSION,
153 ALL_TEST_SNAPSHOT_VERSIONS );
155 action.setGroupId( TEST_GROUP_ID );
156 action.setArtifactId( TEST_ARTIFACT_ID );
157 action.setVersion( TEST_SNAPSHOT_VERSION );
159 String result = action.artifact();
161 assertActionSuccess( action, result );
163 assertEquals( TEST_GROUP_ID, action.getGroupId() );
164 assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
165 assertEquals( TEST_SNAPSHOT_VERSION, action.getVersion() );
166 ArchivaProjectModel model = action.getModel();
167 assertDefaultModel( model, TEST_SNAPSHOT_VERSION );
169 assertEquals( TEST_REPO, action.getRepositoryId() );
171 assertEquals( ALL_TEST_SNAPSHOT_VERSIONS, action.getSnapshotVersions() );
173 assertNull( action.getDependees() );
174 assertNull( action.getDependencies() );
175 assertNull( action.getMailingLists() );
178 public void testGetArtifactUniqueSnapshotTimestamped()
180 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
181 createProjectModel( TEST_TS_SNAPSHOT_VERSION ) );
182 metadataResolver.setArtifactVersions( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_TS_SNAPSHOT_VERSION,
183 ALL_TEST_SNAPSHOT_VERSIONS );
185 action.setGroupId( TEST_GROUP_ID );
186 action.setArtifactId( TEST_ARTIFACT_ID );
187 action.setVersion( TEST_TS_SNAPSHOT_VERSION );
189 String result = action.artifact();
191 assertActionSuccess( action, result );
193 assertEquals( TEST_GROUP_ID, action.getGroupId() );
194 assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
195 assertEquals( TEST_TS_SNAPSHOT_VERSION, action.getVersion() );
196 ArchivaProjectModel model = action.getModel();
197 assertDefaultModel( model, TEST_TS_SNAPSHOT_VERSION );
199 assertEquals( TEST_REPO, action.getRepositoryId() );
201 assertEquals( Arrays.asList( ALL_TEST_SNAPSHOT_VERSIONS.get( 1 ), ALL_TEST_SNAPSHOT_VERSIONS.get( 2 ) ),
202 action.getSnapshotVersions() );
204 assertNull( action.getDependees() );
205 assertNull( action.getDependencies() );
206 assertNull( action.getMailingLists() );
209 public void testGetMissingProject()
211 setActionParameters();
213 String result = action.artifact();
214 assertError( result );
216 assertActionParameters( action );
217 assertNoOutputFields();
220 public void testGetArtifactNoObservableRepos()
222 setObservableRepos( Collections.<String>emptyList() );
224 setActionParameters();
226 String result = action.artifact();
228 // Actually, it'd be better to have an error:
229 assertError( result );
230 assertActionParameters( action );
231 assertNoOutputFields();
234 public void testGetArtifactNotInObservableRepos()
236 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
237 createProjectModel( TEST_VERSION ) );
239 setActionParameters();
241 String result = action.artifact();
242 assertError( result );
244 assertActionParameters( action );
245 assertNoOutputFields();
248 public void testGetArtifactOnlySeenInSecondObservableRepo()
250 setObservableRepos( Arrays.asList( OTHER_TEST_REPO, TEST_REPO ) );
251 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
252 createProjectModel( TEST_VERSION ) );
254 setActionParameters();
256 String result = action.artifact();
258 assertActionSuccess( action, result );
260 assertActionParameters( action );
261 ArchivaProjectModel model = action.getModel();
262 assertDefaultModel( model );
264 assertEquals( TEST_REPO, action.getRepositoryId() );
266 assertNull( action.getDependees() );
267 assertNull( action.getDependencies() );
268 assertNull( action.getMailingLists() );
269 assertTrue( action.getSnapshotVersions().isEmpty() );
272 public void testGetArtifactSeenInBothObservableRepo()
274 setObservableRepos( Arrays.asList( TEST_REPO, OTHER_TEST_REPO ) );
275 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
276 createProjectModel( TEST_VERSION ) );
277 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
278 createProjectModel( TEST_VERSION ) );
280 setActionParameters();
282 String result = action.artifact();
284 assertActionSuccess( action, result );
286 assertActionParameters( action );
287 ArchivaProjectModel model = action.getModel();
288 assertDefaultModel( model );
290 assertEquals( TEST_REPO, action.getRepositoryId() );
292 assertNull( action.getDependees() );
293 assertNull( action.getDependencies() );
294 assertNull( action.getMailingLists() );
295 assertTrue( action.getSnapshotVersions().isEmpty() );
298 public void testGetArtifactCanOnlyObserveInOneOfTwoRepos()
300 setObservableRepos( Arrays.asList( TEST_REPO ) );
301 metadataResolver.setProjectVersion( OTHER_TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
302 createProjectModel( TEST_VERSION ) );
303 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID,
304 createProjectModel( TEST_VERSION ) );
306 setActionParameters();
308 String result = action.artifact();
310 assertActionSuccess( action, result );
312 assertActionParameters( action );
313 ArchivaProjectModel model = action.getModel();
314 assertDefaultModel( model );
316 assertEquals( TEST_REPO, action.getRepositoryId() );
318 assertNull( action.getDependees() );
319 assertNull( action.getDependencies() );
320 assertNull( action.getMailingLists() );
321 assertTrue( action.getSnapshotVersions().isEmpty() );
324 public void testGetArtifactNoMavenFacet()
326 ProjectVersionMetadata versionMetadata = new ProjectVersionMetadata();
327 versionMetadata.setId( TEST_VERSION );
328 versionMetadata.setUrl( TEST_URL );
329 versionMetadata.setName( TEST_NAME );
330 versionMetadata.setDescription( TEST_DESCRIPTION );
332 metadataResolver.setProjectVersion( TEST_REPO, TEST_GROUP_ID, TEST_ARTIFACT_ID, versionMetadata );
334 setActionParameters();
336 String result = action.artifact();
338 assertActionSuccess( action, result );
340 assertActionParameters( action );
341 ArchivaProjectModel model = action.getModel();
342 assertEquals( TEST_VERSION, model.getVersion() );
343 assertEquals( TEST_URL, model.getUrl() );
344 assertEquals( TEST_NAME, model.getName() );
345 assertEquals( TEST_DESCRIPTION, model.getDescription() );
347 assertEquals( TEST_REPO, action.getRepositoryId() );
349 assertNull( action.getDependees() );
350 assertNull( action.getDependencies() );
351 assertNull( action.getMailingLists() );
352 assertTrue( action.getSnapshotVersions().isEmpty() );
355 public void testGetMailingLists()
356 throws ArchivaDatabaseException
358 List<ArchivaArtifact> artifacts =
359 Collections.singletonList( createArtifact( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION ) );
360 MockControl artifactDaoMockControl = createArtifactDaoMock( artifacts, 1 );
361 ArchivaProjectModel legacyModel = createLegacyProjectModel( TEST_GROUP_ID, TEST_ARTIFACT_ID, TEST_VERSION );
362 MailingList ml1 = createMailingList( "Users List", "users" );
363 MailingList ml2 = createMailingList( "Developers List", "dev" );
364 legacyModel.setMailingLists( Arrays.asList( ml1, ml2 ) );
365 MockControl projectDaoMockControl = createProjectDaoMock( legacyModel );
367 setActionParameters();
369 String result = action.mailingLists();
371 artifactDaoMockControl.verify();
372 projectDaoMockControl.verify();
374 assertActionSuccess( action, result );
376 assertActionParameters( action );
377 ArchivaProjectModel model = action.getModel();
378 assertDefaultModel( model );
380 assertNotNull( action.getMailingLists() );
381 assertMailingList( action.getMailingLists().get( 0 ), "Users List", "users" );
382 assertMailingList( action.getMailingLists().get( 1 ), "Developers List", "dev" );
384 assertNull( action.getRepositoryId() );
385 assertNull( action.getDependees() );
386 assertNull( action.getDependencies() );
387 assertNull( action.getSnapshotVersions() );
390 private void assertMailingList( MailingList mailingList, String name, String prefix )
392 assertEquals( name, mailingList.getName() );
393 assertEquals( prefix + "-post@", mailingList.getPostAddress() );
394 assertEquals( prefix + "-subscribe@", mailingList.getSubscribeAddress() );
395 assertEquals( prefix + "-unsubscribe@", mailingList.getUnsubscribeAddress() );
396 assertEquals( prefix + "-archive-url", mailingList.getMainArchiveUrl() );
397 assertEquals( Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ),
398 mailingList.getOtherArchives() );
401 private MailingList createMailingList( String name, String prefix )
403 MailingList ml1 = new MailingList();
405 ml1.setPostAddress( prefix + "-post@" );
406 ml1.setSubscribeAddress( prefix + "-subscribe@" );
407 ml1.setUnsubscribeAddress( prefix + "-unsubscribe@" );
408 ml1.setMainArchiveUrl( prefix + "-archive-url" );
409 ml1.setOtherArchives(
410 Arrays.asList( "other-" + prefix + "-archive-url-1", "other-" + prefix + "-archive-url-2" ) );
414 private void assertNoOutputFields()
416 assertNull( action.getModel() );
417 assertNull( action.getDependees() );
418 assertNull( action.getDependencies() );
419 assertNull( action.getMailingLists() );
420 assertTrue( action.getSnapshotVersions().isEmpty() );
423 private void assertError( String result )
425 assertEquals( Action.ERROR, result );
426 assertEquals( 1, action.getActionErrors().size() );
429 private void setObservableRepos( List<String> repoIds )
431 UserRepositoriesStub repos = (UserRepositoriesStub) lookup( UserRepositories.class );
432 repos.setObservableRepositoryIds( repoIds );
435 private void assertDefaultModel( ArchivaProjectModel model )
437 assertDefaultModel( model, TEST_VERSION );
440 private void assertDefaultModel( ArchivaProjectModel model, String version )
442 assertEquals( TEST_GROUP_ID, model.getGroupId() );
443 assertEquals( TEST_ARTIFACT_ID, model.getArtifactId() );
444 assertEquals( version, model.getVersion() );
445 assertEquals( TEST_URL, model.getUrl() );
446 assertEquals( TEST_NAME, model.getName() );
447 assertEquals( TEST_DESCRIPTION, model.getDescription() );
448 assertEquals( TEST_ORGANIZATION_NAME, model.getOrganization().getName() );
449 assertEquals( TEST_ORGANIZATION_URL, model.getOrganization().getUrl() );
450 assertEquals( 2, model.getLicenses().size() );
451 org.apache.maven.archiva.model.License l = model.getLicenses().get( 0 );
452 assertEquals( TEST_LICENSE_NAME, l.getName() );
453 assertEquals( TEST_LICENSE_URL, l.getUrl() );
454 l = model.getLicenses().get( 1 );
455 assertEquals( TEST_LICENSE_NAME_2, l.getName() );
456 assertEquals( TEST_LICENSE_URL_2, l.getUrl() );
457 assertEquals( TEST_ISSUE_SYSTEM, model.getIssueManagement().getSystem() );
458 assertEquals( TEST_ISSUE_URL, model.getIssueManagement().getUrl() );
459 assertEquals( TEST_CI_SYSTEM, model.getCiManagement().getSystem() );
460 assertEquals( TEST_CI_URL, model.getCiManagement().getUrl() );
461 assertEquals( TEST_SCM_CONNECTION, model.getScm().getConnection() );
462 assertEquals( TEST_SCM_DEV_CONNECTION, model.getScm().getDeveloperConnection() );
463 assertEquals( TEST_SCM_URL, model.getScm().getUrl() );
465 assertEquals( TEST_PACKAGING, model.getPackaging() );
466 assertEquals( TEST_PARENT_GROUP_ID, model.getParentProject().getGroupId() );
467 assertEquals( TEST_PARENT_ARTIFACT_ID, model.getParentProject().getArtifactId() );
468 assertEquals( TEST_PARENT_VERSION, model.getParentProject().getVersion() );
471 private void setActionParameters()
473 action.setGroupId( TEST_GROUP_ID );
474 action.setArtifactId( TEST_ARTIFACT_ID );
475 action.setVersion( TEST_VERSION );
478 private void assertActionParameters( ShowArtifactAction action )
480 assertEquals( TEST_GROUP_ID, action.getGroupId() );
481 assertEquals( TEST_ARTIFACT_ID, action.getArtifactId() );
482 assertEquals( TEST_VERSION, action.getVersion() );
485 private void assertActionSuccess( ShowArtifactAction action, String result )
487 assertEquals( Action.SUCCESS, result );
488 assertTrue( action.getActionErrors().isEmpty() );
489 assertTrue( action.getActionMessages().isEmpty() );
492 private ProjectVersionMetadata createProjectModel( String version )
494 ProjectVersionMetadata model = new ProjectVersionMetadata();
495 model.setId( version );
496 model.setUrl( TEST_URL );
497 model.setName( TEST_NAME );
498 model.setDescription( TEST_DESCRIPTION );
499 CiManagement ci = new CiManagement();
500 ci.setSystem( TEST_CI_SYSTEM );
501 ci.setUrl( TEST_CI_URL );
502 model.setCiManagement( ci );
503 IssueManagement issue = new IssueManagement();
504 issue.setSystem( TEST_ISSUE_SYSTEM );
505 issue.setUrl( TEST_ISSUE_URL );
506 model.setIssueManagement( issue );
507 Organization organization = new Organization();
508 organization.setName( TEST_ORGANIZATION_NAME );
509 organization.setUrl( TEST_ORGANIZATION_URL );
510 model.setOrganization( organization );
511 License l = new License();
512 l.setName( TEST_LICENSE_NAME );
513 l.setUrl( TEST_LICENSE_URL );
514 model.addLicense( l );
516 l.setName( TEST_LICENSE_NAME_2 );
517 l.setUrl( TEST_LICENSE_URL_2 );
518 model.addLicense( l );
520 scm.setConnection( TEST_SCM_CONNECTION );
521 scm.setDeveloperConnection( TEST_SCM_DEV_CONNECTION );
522 scm.setUrl( TEST_SCM_URL );
525 MavenProjectFacet mavenProjectFacet = new MavenProjectFacet();
526 mavenProjectFacet.setGroupId( TEST_GROUP_ID );
527 mavenProjectFacet.setArtifactId( TEST_ARTIFACT_ID );
528 mavenProjectFacet.setPackaging( TEST_PACKAGING );
529 MavenProjectParent parent = new MavenProjectParent();
530 parent.setGroupId( TEST_PARENT_GROUP_ID );
531 parent.setArtifactId( TEST_PARENT_ARTIFACT_ID );
532 parent.setVersion( TEST_PARENT_VERSION );
533 mavenProjectFacet.setParent( parent );
534 model.addFacet( mavenProjectFacet );
538 private ArchivaProjectModel createLegacyProjectModel( String groupId, String artifactId, String version )
540 ArchivaProjectModel model = new ArchivaProjectModel();
541 model.setGroupId( groupId );
542 model.setArtifactId( artifactId );
543 model.setVersion( version );
544 model.setPackaging( TEST_PACKAGING );
545 model.setUrl( TEST_URL );
546 model.setName( TEST_NAME );
547 model.setDescription( TEST_DESCRIPTION );
548 VersionedReference parent = new VersionedReference();
549 parent.setGroupId( TEST_PARENT_GROUP_ID );
550 parent.setArtifactId( TEST_PARENT_ARTIFACT_ID );
551 parent.setVersion( TEST_PARENT_VERSION );
552 model.setParentProject( parent );
553 org.apache.maven.archiva.model.CiManagement ci = new org.apache.maven.archiva.model.CiManagement();
554 ci.setSystem( TEST_CI_SYSTEM );
555 ci.setUrl( TEST_CI_URL );
556 model.setCiManagement( ci );
557 org.apache.maven.archiva.model.IssueManagement issue = new org.apache.maven.archiva.model.IssueManagement();
558 issue.setSystem( TEST_ISSUE_SYSTEM );
559 issue.setUrl( TEST_ISSUE_URL );
560 model.setIssueManagement( issue );
561 org.apache.maven.archiva.model.Organization org = new org.apache.maven.archiva.model.Organization();
562 org.setName( TEST_ORGANIZATION_NAME );
563 org.setUrl( TEST_ORGANIZATION_URL );
564 model.setOrganization( org );
565 org.apache.maven.archiva.model.License l = new org.apache.maven.archiva.model.License();
566 l.setName( TEST_LICENSE_NAME );
567 l.setUrl( TEST_LICENSE_URL );
568 model.addLicense( l );
569 l = new org.apache.maven.archiva.model.License();
570 l.setName( TEST_LICENSE_NAME_2 );
571 l.setUrl( TEST_LICENSE_URL_2 );
572 model.addLicense( l );
573 org.apache.maven.archiva.model.Scm scm = new org.apache.maven.archiva.model.Scm();
574 scm.setConnection( TEST_SCM_CONNECTION );
575 scm.setDeveloperConnection( TEST_SCM_DEV_CONNECTION );
576 scm.setUrl( TEST_SCM_URL );
581 private MockControl createArtifactDaoMock( List<ArchivaArtifact> artifacts, int count )
582 throws ArchivaDatabaseException
584 return createArtifactDaoMock( artifacts, TEST_VERSION, count );
587 private MockControl createArtifactDaoMock( List<ArchivaArtifact> artifacts, String version, int count )
588 throws ArchivaDatabaseException
590 // testing deeper than normal with the mocks as we intend to replace RepositoryBrowsing, not just the database
591 // underneath it - those sections will be adjusted with a mock content repository later
592 MockControl control = MockControl.createNiceControl( ArtifactDAO.class );
593 ArtifactDAO dao = (ArtifactDAO) control.getMock();
594 archivaDao.setArtifactDao( dao );
596 ArtifactsRelatedConstraint c = new ArtifactsRelatedConstraint( TEST_GROUP_ID, TEST_ARTIFACT_ID, version );
597 dao.queryArtifacts( c );
598 control.setReturnValue( artifacts, count );
604 private MockControl createProjectDaoMock( ArchivaProjectModel project )
605 throws ArchivaDatabaseException
607 MockControl control = MockControl.createNiceControl( ProjectModelDAO.class );
608 ProjectModelDAO dao = (ProjectModelDAO) control.getMock();
609 archivaDao.setProjectDao( dao );
611 control.expectAndReturn(
612 dao.getProjectModel( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project );
618 private ArchivaArtifact createArtifact( String groupId, String artifactId, String version )
620 return createArtifact( groupId, artifactId, version, TEST_REPO );
623 private ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String repoId )
625 ArchivaArtifactModel model = new ArchivaArtifactModel();
626 model.setGroupId( groupId );
627 model.setArtifactId( artifactId );
628 model.setVersion( version );
629 model.setRepositoryId( repoId );
630 return new ArchivaArtifact( model );
633 protected void setUp()
637 action = (ShowArtifactAction) lookup( Action.class, ACTION_HINT );
638 metadataResolver = (TestMetadataResolver) action.getMetadataResolver();
639 archivaDao = (ArchivaDAOStub) lookup( ArchivaDAO.class, "jdo" );