diff options
author | Brett Porter <brett@apache.org> | 2009-11-27 04:35:59 +0000 |
---|---|---|
committer | Brett Porter <brett@apache.org> | 2009-11-27 04:35:59 +0000 |
commit | 6ea52a427d7fe7ed6de999f1320ad8e653e0b295 (patch) | |
tree | a1e502783f36c59b144a16fa443138b7ae66e359 | |
parent | e7e9b184eb0b9815de480bb8667644ff0835f3f1 (diff) | |
download | archiva-6ea52a427d7fe7ed6de999f1320ad8e653e0b295.tar.gz archiva-6ea52a427d7fe7ed6de999f1320ad8e653e0b295.zip |
add test cases for the browse action
Merged from: r884741
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@884742 13f79535-47bb-0310-9956-ffa450edef68
7 files changed, 626 insertions, 84 deletions
diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/DefaultRepositoryBrowsing.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/DefaultRepositoryBrowsing.java index d5bbfbf0c..144f8c44f 100644 --- a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/DefaultRepositoryBrowsing.java +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/browsing/DefaultRepositoryBrowsing.java @@ -122,6 +122,7 @@ public class DefaultRepositoryBrowsing // Easier to do this here, vs doing it in the SQL query. CollectionUtils.filter( groups, NotPredicate.getInstance( PredicateUtils.equalPredicate( groupId ) ) ); + results.setSelectedRepositoryIds( observableRepositoryIds ); results.setGroupIds( groups ); results.setArtifacts( artifacts ); } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java index 0f76807ba..42020f657 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/BrowseAction.java @@ -29,7 +29,10 @@ import org.apache.maven.archiva.database.ObjectNotFoundException; import org.apache.maven.archiva.database.browsing.BrowsingResults; import org.apache.maven.archiva.database.browsing.RepositoryBrowsing; import org.apache.maven.archiva.model.ArchivaProjectModel; -import org.apache.maven.archiva.security.*; +import org.apache.maven.archiva.security.AccessDeniedException; +import org.apache.maven.archiva.security.ArchivaSecurityException; +import org.apache.maven.archiva.security.PrincipalNotFoundException; +import org.apache.maven.archiva.security.UserRepositories; /** * Browse the repository. @@ -145,6 +148,7 @@ public class BrowseAction if( isFirstVersion ) { sharedModel = model; + sharedModel.setVersion( null ); } else { diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java new file mode 100644 index 000000000..67f2dfd61 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AbstractActionTestCase.java @@ -0,0 +1,119 @@ +package org.apache.maven.archiva.web.action; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.List; + +import org.apache.maven.archiva.model.ArchivaProjectModel; +import org.apache.maven.archiva.security.UserRepositories; +import org.apache.maven.archiva.security.UserRepositoriesStub; +import org.codehaus.plexus.spring.PlexusInSpringTestCase; + +public abstract class AbstractActionTestCase + extends PlexusInSpringTestCase +{ + protected static final String TEST_REPO = "test-repo"; + + protected static final String TEST_GROUP_ID = "groupId"; + + protected static final String TEST_ARTIFACT_ID = "artifactId"; + + protected static final String TEST_PACKAGING = "packaging"; + + protected static final String TEST_ISSUE_URL = "http://jira.codehaus.org/browse/MRM"; + + protected static final String TEST_ISSUE_SYSTEM = "jira"; + + protected static final String TEST_CI_SYSTEM = "continuum"; + + protected static final String TEST_CI_URL = "http://vmbuild.apache.org/"; + + protected static final String TEST_URL = "url"; + + protected static final String TEST_NAME = "name"; + + protected static final String TEST_DESCRIPTION = "description"; + + protected static final String TEST_PARENT_GROUP_ID = "parentGroupId"; + + protected static final String TEST_PARENT_ARTIFACT_ID = "parentArtifactId"; + + protected static final String TEST_PARENT_VERSION = "parentVersion"; + + protected static final String TEST_ORGANIZATION_NAME = "organizationName"; + + protected static final String TEST_ORGANIZATION_URL = "organizationUrl"; + + protected static final String TEST_LICENSE_URL = "licenseUrl"; + + protected static final String TEST_LICENSE_NAME = "licenseName"; + + protected static final String TEST_LICENSE_URL_2 = "licenseUrl_2"; + + protected static final String TEST_LICENSE_NAME_2 = "licenseName_2"; + + protected static final String TEST_SCM_CONNECTION = "scmConnection"; + + protected static final String TEST_SCM_DEV_CONNECTION = "scmDevConnection"; + + protected static final String TEST_SCM_URL = "scmUrl"; + + protected void setObservableRepos( List<String> repoIds ) + { + UserRepositoriesStub repos = (UserRepositoriesStub) lookup( UserRepositories.class ); + repos.setObservableRepositoryIds( repoIds ); + } + + protected void assertDefaultModel( ArchivaProjectModel model, String version ) + { + assertDefaultModel( model, TEST_GROUP_ID, TEST_ARTIFACT_ID, version ); + } + + protected void assertDefaultModel( ArchivaProjectModel model, String groupId, String artifactId, String version ) + { + assertEquals( groupId, model.getGroupId() ); + assertEquals( artifactId, model.getArtifactId() ); + assertEquals( version, model.getVersion() ); + assertEquals( TEST_URL, model.getUrl() ); + assertEquals( TEST_NAME, model.getName() ); + assertEquals( TEST_DESCRIPTION, model.getDescription() ); + assertEquals( TEST_ORGANIZATION_NAME, model.getOrganization().getName() ); + assertEquals( TEST_ORGANIZATION_URL, model.getOrganization().getUrl() ); + assertEquals( 2, model.getLicenses().size() ); + org.apache.maven.archiva.model.License l = model.getLicenses().get( 0 ); + assertEquals( TEST_LICENSE_NAME, l.getName() ); + assertEquals( TEST_LICENSE_URL, l.getUrl() ); + l = model.getLicenses().get( 1 ); + assertEquals( TEST_LICENSE_NAME_2, l.getName() ); + assertEquals( TEST_LICENSE_URL_2, l.getUrl() ); + assertEquals( TEST_ISSUE_SYSTEM, model.getIssueManagement().getSystem() ); + assertEquals( TEST_ISSUE_URL, model.getIssueManagement().getUrl() ); + assertEquals( TEST_CI_SYSTEM, model.getCiManagement().getSystem() ); + assertEquals( TEST_CI_URL, model.getCiManagement().getUrl() ); + assertEquals( TEST_SCM_CONNECTION, model.getScm().getConnection() ); + assertEquals( TEST_SCM_DEV_CONNECTION, model.getScm().getDeveloperConnection() ); + assertEquals( TEST_SCM_URL, model.getScm().getUrl() ); + + assertEquals( TEST_PACKAGING, model.getPackaging() ); + assertEquals( TEST_PARENT_GROUP_ID, model.getParentProject().getGroupId() ); + assertEquals( TEST_PARENT_ARTIFACT_ID, model.getParentProject().getArtifactId() ); + assertEquals( TEST_PARENT_VERSION, model.getParentProject().getVersion() ); + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java new file mode 100644 index 000000000..2fb9658d2 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/BrowseActionTest.java @@ -0,0 +1,437 @@ +package org.apache.maven.archiva.web.action; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import com.opensymphony.xwork2.Action; +import org.apache.maven.archiva.database.ArchivaDAO; +import org.apache.maven.archiva.database.ArchivaDatabaseException; +import org.apache.maven.archiva.database.ArtifactDAO; +import org.apache.maven.archiva.database.ProjectModelDAO; +import org.apache.maven.archiva.database.browsing.BrowsingResults; +import org.apache.maven.archiva.database.constraints.ArtifactsRelatedConstraint; +import org.apache.maven.archiva.model.ArchivaArtifact; +import org.apache.maven.archiva.model.ArchivaArtifactModel; +import org.apache.maven.archiva.model.ArchivaProjectModel; +import org.apache.maven.archiva.model.CiManagement; +import org.apache.maven.archiva.model.IssueManagement; +import org.apache.maven.archiva.model.License; +import org.apache.maven.archiva.model.Organization; +import org.apache.maven.archiva.model.Scm; +import org.apache.maven.archiva.model.VersionedReference; +import org.apache.maven.archiva.web.action.admin.repositories.ArchivaDAOStub; +import org.easymock.MockControl; + +public class BrowseActionTest + extends AbstractActionTestCase +{ + private static final String ACTION_HINT = "browseAction"; + + private BrowseAction action; + + private ArchivaDAOStub archivaDao; + + private static final List<String> GROUPS = + Arrays.asList( "org.apache.archiva", "commons-lang", "org.apache.maven", "com.sun", "com.oracle" ); + + public void testInstantiation() + { + assertFalse( action == lookup( Action.class, ACTION_HINT ) ); + } + + public void testBrowse() + { + archivaDao.setGroups( GROUPS ); + + String result = action.browse(); + assertSuccessResult( result ); + + BrowsingResults results = action.getResults(); + assertNotNull( results ); + assertEquals( Arrays.asList( TEST_REPO ), results.getSelectedRepositoryIds() ); + assertEquals( Arrays.asList( "com", "commons-lang", "org.apache" ), results.getGroupIds() ); + assertNull( results.getArtifacts() ); + assertNull( results.getSelectedArtifactId() ); + assertNull( results.getSelectedGroupId() ); + assertNull( results.getVersions() ); + + assertNull( action.getGroupId() ); + assertNull( action.getArtifactId() ); + assertNull( action.getRepositoryId() ); + assertNull( action.getSharedModel() ); + } + + public void testBrowseNoObservableRepos() + { + setObservableRepos( Collections.<String>emptyList() ); + + String result = action.browse(); + assertNoAccessResult( result ); + + assertNoOutputVariables(); + } + + public void testBrowseGroupNoObservableRepos() + { + setObservableRepos( Collections.<String>emptyList() ); + String selectedGroupId = "org"; + + action.setGroupId( selectedGroupId ); + String result = action.browseGroup(); + assertNoAccessResult( result ); + + assertEquals( selectedGroupId, action.getGroupId() ); + assertNull( action.getResults() ); + assertNull( action.getArtifactId() ); + assertNull( action.getRepositoryId() ); + assertNull( action.getSharedModel() ); + } + + public void testBrowseArtifactNoObservableRepos() + { + setObservableRepos( Collections.<String>emptyList() ); + String selectedGroupId = "org.apache"; + String selectedArtifactId = "apache"; + + action.setGroupId( selectedGroupId ); + action.setArtifactId( selectedArtifactId ); + String result = action.browseArtifact(); + assertNoAccessResult( result ); + + assertEquals( selectedGroupId, action.getGroupId() ); + assertEquals( selectedArtifactId, action.getArtifactId() ); + assertNull( action.getResults() ); + assertNull( action.getRepositoryId() ); + assertNull( action.getSharedModel() ); + } + + public void testBrowseGroupNoGroupId() + { + String result = action.browseGroup(); + assertErrorResult( result ); + assertNoOutputVariables(); + } + + public void testBrowseGroupNoArtifacts() + { + String selectedGroupId = "org"; + List<String> groups = Arrays.asList( "apache.archiva", "apache.maven" ); + + archivaDao.setGroups( groups ); + archivaDao.setArtifacts( Collections.<String>emptyList() ); + action.setGroupId( selectedGroupId ); + String result = action.browseGroup(); + assertSuccessResult( result ); + + BrowsingResults results = action.getResults(); + assertNotNull( results ); + assertEquals( Arrays.asList( TEST_REPO ), results.getSelectedRepositoryIds() ); + assertEquals( groups, results.getGroupIds() ); + assertEquals( Collections.<String>emptyList(), results.getArtifacts() ); + assertNull( results.getSelectedArtifactId() ); + assertEquals( selectedGroupId, results.getSelectedGroupId() ); + assertNull( results.getVersions() ); + + assertEquals( selectedGroupId, action.getGroupId() ); + assertNull( action.getArtifactId() ); + assertNull( action.getRepositoryId() ); + assertNull( action.getSharedModel() ); + } + + public void testBrowseGroupWithArtifacts() + { + String artifacts = "apache"; + String selectedGroupId = "org.apache"; + List<String> groups = Arrays.asList( "archiva", "maven" ); + + archivaDao.setGroups( groups ); + archivaDao.setArtifacts( Collections.singletonList( artifacts ) ); + action.setGroupId( selectedGroupId ); + String result = action.browseGroup(); + assertSuccessResult( result ); + + BrowsingResults results = action.getResults(); + assertNotNull( results ); + assertEquals( Arrays.asList( TEST_REPO ), results.getSelectedRepositoryIds() ); + assertEquals( groups, results.getGroupIds() ); + assertEquals( Collections.singletonList( artifacts ), results.getArtifacts() ); + assertNull( results.getSelectedArtifactId() ); + assertEquals( selectedGroupId, results.getSelectedGroupId() ); + assertNull( results.getVersions() ); + + assertEquals( selectedGroupId, action.getGroupId() ); + assertNull( action.getArtifactId() ); + assertNull( action.getRepositoryId() ); + assertNull( action.getSharedModel() ); + } + + public void testBrowseArtifactNoGroupId() + { + String selectedArtifactId = "apache"; + + action.setArtifactId( selectedArtifactId ); + String result = action.browseArtifact(); + assertErrorResult( result ); + + assertNull( action.getResults() ); + assertNull( action.getGroupId() ); + assertEquals( selectedArtifactId, action.getArtifactId() ); + assertNull( action.getRepositoryId() ); + assertNull( action.getSharedModel() ); + } + + public void testBrowseArtifactNoArtifactId() + { + String selectedGroupId = "org.apache"; + + action.setGroupId( selectedGroupId ); + String result = action.browseArtifact(); + assertErrorResult( result ); + + assertNull( action.getResults() ); + assertEquals( selectedGroupId, action.getGroupId() ); + assertNull( action.getArtifactId() ); + assertNull( action.getRepositoryId() ); + assertNull( action.getSharedModel() ); + } + + public void testBrowseArtifact() + throws ArchivaDatabaseException + { + String selectedGroupId = "org.apache"; + String selectedArtifactId = "apache"; + + List<String> versions = Arrays.asList( "1", "2", "3", "4" ); + archivaDao.setVersions( versions ); + MockControl artifactDaoMockControl = createArtifactDaoMock( selectedGroupId, selectedArtifactId, versions ); + MockControl projectDaoMockControl = createProjectDaoMock( + Arrays.asList( createProjectModel( selectedGroupId, selectedArtifactId, "1" ), + createProjectModel( selectedGroupId, selectedArtifactId, "2" ), + createProjectModel( selectedGroupId, selectedArtifactId, "3" ), + createProjectModel( selectedGroupId, selectedArtifactId, "4" ) ) ); + + action.setGroupId( selectedGroupId ); + action.setArtifactId( selectedArtifactId ); + String result = action.browseArtifact(); + assertSuccessResult( result ); + + artifactDaoMockControl.verify(); + projectDaoMockControl.verify(); + + assertEquals( selectedGroupId, action.getGroupId() ); + assertEquals( selectedArtifactId, action.getArtifactId() ); + assertNull( action.getRepositoryId() ); + + BrowsingResults results = action.getResults(); + assertNotNull( results ); + assertEquals( Arrays.asList( TEST_REPO ), results.getSelectedRepositoryIds() ); + assertNull( results.getGroupIds() ); + assertNull( results.getArtifacts() ); + assertEquals( selectedGroupId, results.getSelectedGroupId() ); + assertEquals( selectedArtifactId, results.getSelectedArtifactId() ); + assertEquals( versions, results.getVersions() ); + + ArchivaProjectModel model = action.getSharedModel(); + assertDefaultModel( model, selectedGroupId, selectedArtifactId, null ); + } + + public void testBrowseArtifactWithSnapshots() + throws ArchivaDatabaseException + { + String selectedGroupId = "org.apache"; + String selectedArtifactId = "apache"; + + List<String> versions = Arrays.asList( "1", "2", "3", "4-SNAPSHOT", "4", "5-SNAPSHOT" ); + archivaDao.setVersions( versions ); + MockControl artifactDaoMockControl = createArtifactDaoMock( selectedGroupId, selectedArtifactId, versions ); + MockControl projectDaoMockControl = createProjectDaoMock( + Arrays.asList( createProjectModel( selectedGroupId, selectedArtifactId, "1" ), + createProjectModel( selectedGroupId, selectedArtifactId, "2" ), + createProjectModel( selectedGroupId, selectedArtifactId, "3" ), + createProjectModel( selectedGroupId, selectedArtifactId, "4-SNAPSHOT" ), + createProjectModel( selectedGroupId, selectedArtifactId, "4" ), + createProjectModel( selectedGroupId, selectedArtifactId, "5-SNAPSHOT" ) ) ); + + action.setGroupId( selectedGroupId ); + action.setArtifactId( selectedArtifactId ); + String result = action.browseArtifact(); + assertSuccessResult( result ); + + artifactDaoMockControl.verify(); + projectDaoMockControl.verify(); + + assertEquals( selectedGroupId, action.getGroupId() ); + assertEquals( selectedArtifactId, action.getArtifactId() ); + assertNull( action.getRepositoryId() ); + + BrowsingResults results = action.getResults(); + assertNotNull( results ); + assertEquals( Arrays.asList( TEST_REPO ), results.getSelectedRepositoryIds() ); + assertNull( results.getGroupIds() ); + assertNull( results.getArtifacts() ); + assertEquals( selectedGroupId, results.getSelectedGroupId() ); + assertEquals( selectedArtifactId, results.getSelectedArtifactId() ); + assertEquals( versions, results.getVersions() ); + + ArchivaProjectModel model = action.getSharedModel(); + assertDefaultModel( model, selectedGroupId, selectedArtifactId, null ); + } + + // TODO: test with restricted observable repos + // not currently relevant since it is controlled at the DefaultRepositoryBrowsing level + // TODO: current behaviour is to ignore values that differ between models - instead, pick the latest and use that. + // Need to update the tests to verify this as models are currently the same + + private void assertNoAccessResult( String result ) + { + assertEquals( GlobalResults.ACCESS_TO_NO_REPOS, result ); + assertEquals( 0, action.getActionErrors().size() ); + assertEquals( 0, action.getActionMessages().size() ); + } + + private void assertSuccessResult( String result ) + { + assertEquals( Action.SUCCESS, result ); + assertEquals( 0, action.getActionErrors().size() ); + assertEquals( 0, action.getActionMessages().size() ); + } + + private void assertErrorResult( String result ) + { + assertEquals( Action.ERROR, result ); + assertEquals( 1, action.getActionErrors().size() ); + assertEquals( 0, action.getActionMessages().size() ); + } + + private void assertNoOutputVariables() + { + assertNull( action.getResults() ); + assertNull( action.getGroupId() ); + assertNull( action.getArtifactId() ); + assertNull( action.getRepositoryId() ); + assertNull( action.getSharedModel() ); + } + + private MockControl createArtifactDaoMock( String groupId, String artifactId, List<String> versions ) + throws ArchivaDatabaseException + { + // testing deeper than normal with the mocks as we intend to replace RepositoryBrowsing, not just the database + // underneath it - those sections will be adjusted with a mock content repository later + MockControl control = MockControl.createNiceControl( ArtifactDAO.class ); + ArtifactDAO dao = (ArtifactDAO) control.getMock(); + archivaDao.setArtifactDao( dao ); + + for ( String v : versions ) + { + ArtifactsRelatedConstraint c = new ArtifactsRelatedConstraint( groupId, artifactId, v ); + dao.queryArtifacts( c ); + control.setReturnValue( Collections.singletonList( createArtifact( groupId, artifactId, v ) ) ); + } + + control.replay(); + return control; + } + + private ArchivaArtifact createArtifact( String groupId, String artifactId, String version ) + { + return createArtifact( groupId, artifactId, version, TEST_REPO ); + } + + private ArchivaArtifact createArtifact( String groupId, String artifactId, String version, String repoId ) + { + ArchivaArtifactModel model = new ArchivaArtifactModel(); + model.setGroupId( groupId ); + model.setArtifactId( artifactId ); + model.setVersion( version ); + model.setRepositoryId( repoId ); + return new ArchivaArtifact( model ); + } + + private MockControl createProjectDaoMock( List<ArchivaProjectModel> projects ) + throws ArchivaDatabaseException + { + MockControl control = MockControl.createNiceControl( ProjectModelDAO.class ); + ProjectModelDAO dao = (ProjectModelDAO) control.getMock(); + archivaDao.setProjectDao( dao ); + + for ( ArchivaProjectModel project : projects ) + { + control.expectAndReturn( + dao.getProjectModel( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project ); + } + + control.replay(); + return control; + } + + protected void setUp() + throws Exception + { + super.setUp(); + action = (BrowseAction) lookup( Action.class, ACTION_HINT ); + archivaDao = (ArchivaDAOStub) lookup( ArchivaDAO.class, "jdo" ); + } + + protected ArchivaProjectModel createProjectModel( String groupId, String artifactId, String version ) + { + ArchivaProjectModel model = new ArchivaProjectModel(); + model.setGroupId( groupId ); + model.setArtifactId( artifactId ); + model.setVersion( version ); + model.setPackaging( TEST_PACKAGING ); + model.setUrl( TEST_URL ); + model.setName( TEST_NAME ); + model.setDescription( TEST_DESCRIPTION ); + VersionedReference parent = new VersionedReference(); + parent.setGroupId( TEST_PARENT_GROUP_ID ); + parent.setArtifactId( TEST_PARENT_ARTIFACT_ID ); + parent.setVersion( TEST_PARENT_VERSION ); + model.setParentProject( parent ); + CiManagement ci = new CiManagement(); + ci.setSystem( TEST_CI_SYSTEM ); + ci.setUrl( TEST_CI_URL ); + model.setCiManagement( ci ); + IssueManagement issue = new IssueManagement(); + issue.setSystem( TEST_ISSUE_SYSTEM ); + issue.setUrl( TEST_ISSUE_URL ); + model.setIssueManagement( issue ); + Organization org = new Organization(); + org.setName( TEST_ORGANIZATION_NAME ); + org.setUrl( TEST_ORGANIZATION_URL ); + model.setOrganization( org ); + License l = new License(); + l.setName( TEST_LICENSE_NAME ); + l.setUrl( TEST_LICENSE_URL ); + model.addLicense( l ); + l = new License(); + l.setName( TEST_LICENSE_NAME_2 ); + l.setUrl( TEST_LICENSE_URL_2 ); + model.addLicense( l ); + Scm scm = new Scm(); + scm.setConnection( TEST_SCM_CONNECTION ); + scm.setDeveloperConnection( TEST_SCM_DEV_CONNECTION ); + scm.setUrl( TEST_SCM_URL ); + model.setScm( scm ); + return model; + } +}
\ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java index 259121a08..4f18e6f6d 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/ShowArtifactActionTest.java @@ -45,58 +45,12 @@ import org.codehaus.plexus.spring.PlexusInSpringTestCase; import org.easymock.MockControl; public class ShowArtifactActionTest - extends PlexusInSpringTestCase + extends AbstractActionTestCase { private static final String ACTION_HINT = "showArtifactAction"; - private static final String TEST_GROUP_ID = "groupId"; - - private static final String TEST_ARTIFACT_ID = "artifactId"; - private static final String TEST_VERSION = "version"; - private static final String TEST_PACKAGING = "packaging"; - - private static final String TEST_ISSUE_URL = "http://jira.codehaus.org/browse/MRM"; - - private static final String TEST_ISSUE_SYSTEM = "jira"; - - private static final String TEST_CI_SYSTEM = "continuum"; - - private static final String TEST_CI_URL = "http://vmbuild.apache.org/"; - - private static final String TEST_URL = "url"; - - private static final String TEST_NAME = "name"; - - private static final String TEST_DESCRIPTION = "description"; - - private static final String TEST_PARENT_GROUP_ID = "parentGroupId"; - - private static final String TEST_PARENT_ARTIFACT_ID = "parentArtifactId"; - - private static final String TEST_PARENT_VERSION = "parentVersion"; - - private static final String TEST_ORGANIZATION_NAME = "organizationName"; - - private static final String TEST_ORGANIZATION_URL = "organizationUrl"; - - private static final String TEST_LICENSE_URL = "licenseUrl"; - - private static final String TEST_LICENSE_NAME = "licenseName"; - - private static final String TEST_LICENSE_URL_2 = "licenseUrl_2"; - - private static final String TEST_LICENSE_NAME_2 = "licenseName_2"; - - private static final String TEST_REPO = "test-repo"; - - private static final String TEST_SCM_CONNECTION = "scmConnection"; - - private static final String TEST_SCM_DEV_CONNECTION = "scmDevConnection"; - - private static final String TEST_SCM_URL = "scmUrl"; - private ShowArtifactAction action; private static final String TEST_SNAPSHOT_VERSION = "1.0-SNAPSHOT"; @@ -385,47 +339,11 @@ public class ShowArtifactActionTest assertEquals( 1, action.getActionErrors().size() ); } - private void setObservableRepos( List<String> repoIds ) - { - UserRepositoriesStub repos = (UserRepositoriesStub) lookup( UserRepositories.class ); - repos.setObservableRepositoryIds( repoIds ); - } - private void assertDefaultModel( ArchivaProjectModel model ) { assertDefaultModel( model, TEST_VERSION ); } - private void assertDefaultModel( ArchivaProjectModel model, String version ) - { - assertEquals( TEST_GROUP_ID, model.getGroupId() ); - assertEquals( TEST_ARTIFACT_ID, model.getArtifactId() ); - assertEquals( version, model.getVersion() ); - assertEquals( TEST_PACKAGING, model.getPackaging() ); - assertEquals( TEST_URL, model.getUrl() ); - assertEquals( TEST_NAME, model.getName() ); - assertEquals( TEST_DESCRIPTION, model.getDescription() ); - assertEquals( TEST_ORGANIZATION_NAME, model.getOrganization().getName() ); - assertEquals( TEST_ORGANIZATION_URL, model.getOrganization().getUrl() ); - assertEquals( 2, model.getLicenses().size() ); - License l = model.getLicenses().get( 0 ); - assertEquals( TEST_LICENSE_NAME, l.getName() ); - assertEquals( TEST_LICENSE_URL, l.getUrl() ); - l = model.getLicenses().get( 1 ); - assertEquals( TEST_LICENSE_NAME_2, l.getName() ); - assertEquals( TEST_LICENSE_URL_2, l.getUrl() ); - assertEquals( TEST_PARENT_GROUP_ID, model.getParentProject().getGroupId() ); - assertEquals( TEST_PARENT_ARTIFACT_ID, model.getParentProject().getArtifactId() ); - assertEquals( TEST_PARENT_VERSION, model.getParentProject().getVersion() ); - assertEquals( TEST_ISSUE_SYSTEM, model.getIssueManagement().getSystem() ); - assertEquals( TEST_ISSUE_URL, model.getIssueManagement().getUrl() ); - assertEquals( TEST_CI_SYSTEM, model.getCiManagement().getSystem() ); - assertEquals( TEST_CI_URL, model.getCiManagement().getUrl() ); - assertEquals( TEST_SCM_CONNECTION, model.getScm().getConnection() ); - assertEquals( TEST_SCM_DEV_CONNECTION, model.getScm().getDeveloperConnection() ); - assertEquals( TEST_SCM_URL, model.getScm().getUrl() ); - } - private void setActionParameters() { action.setGroupId( TEST_GROUP_ID ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java index 560f53c3d..116313905 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ArchivaDAOStub.java @@ -12,6 +12,8 @@ import org.apache.maven.archiva.database.ProjectModelDAO; import org.apache.maven.archiva.database.RepositoryContentStatisticsDAO; import org.apache.maven.archiva.database.RepositoryProblemDAO; import org.apache.maven.archiva.database.SimpleConstraint; +import org.apache.maven.archiva.database.constraints.UniqueArtifactIdConstraint; +import org.apache.maven.archiva.database.constraints.UniqueGroupIdConstraint; import org.apache.maven.archiva.database.constraints.UniqueVersionConstraint; import org.apache.maven.archiva.model.RepositoryContentStatistics; @@ -50,12 +52,24 @@ public class ArchivaDAOStub private List<String> versions; + private List<String> groups; + + private List<String> artifacts; + public List<?> query( SimpleConstraint constraint ) { if ( constraint instanceof UniqueVersionConstraint ) { return versions; } + else if ( constraint instanceof UniqueGroupIdConstraint ) + { + return groups; + } + else if ( constraint instanceof UniqueArtifactIdConstraint ) + { + return artifacts; + } else { Assert.assertEquals( RepositoryContentStatistics.class, constraint.getResultClass() ); @@ -110,4 +124,14 @@ public class ArchivaDAOStub { this.versions = versions; } + + public void setGroups( List<String> groups ) + { + this.groups = groups; + } + + public void setArtifacts( List<String> artifacts ) + { + this.artifacts = artifacts; + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/BrowseActionTest.xml b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/BrowseActionTest.xml new file mode 100644 index 000000000..cccf675cb --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/BrowseActionTest.xml @@ -0,0 +1,39 @@ +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> + +<plexus> + <components> + <component> + <role>org.apache.maven.archiva.database.ArchivaDAO</role> + <role-hint>jdo</role-hint> + <implementation>org.apache.maven.archiva.web.action.admin.repositories.ArchivaDAOStub</implementation> + <requirements> + <requirement> + <role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role> + <field-name>configuration</field-name> + </requirement> + </requirements> + </component> + <component> + <role>org.apache.maven.archiva.security.UserRepositories</role> + <role-hint>default</role-hint> + <implementation>org.apache.maven.archiva.security.UserRepositoriesStub</implementation> + </component> + </components> +</plexus> |