From 726573275537c3605abaac11fa852fe796bd9917 Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Mon, 12 May 2008 07:57:06 +0000 Subject: [PATCH] [MRM-694] patch submitted by Maria Catherine Tan -UI for repository groups -test cases for action classes git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@655432 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/mdo/configuration.mdo | 60 ++- .../DeleteRepositoryGroupAction.java | 96 +++++ .../repositories/RepositoryGroupsAction.java | 231 +++++++++++ .../repositories/SortRepositoriesAction.java | 122 ++++++ .../src/main/resources/xwork.xml | 53 +++ .../jsp/admin/deleteRepositoryGroup.jsp | 65 +++ .../WEB-INF/jsp/admin/repositoryGroups.jsp | 149 +++++++ .../webapp/WEB-INF/jsp/decorators/default.jsp | 3 + .../src/main/webapp/css/site.css | 33 +- .../DeleteRepositoryGroupActionTest.java | 156 +++++++ .../RepositoryGroupsActionTest.java | 380 ++++++++++++++++++ .../SortRepositoriesActionTest.java | 225 +++++++++++ 12 files changed, 1565 insertions(+), 8 deletions(-) create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupAction.java create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsAction.java create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/SortRepositoriesAction.java create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRepositoryGroup.jsp create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositoryGroups.jsp create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupActionTest.java create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsActionTest.java create mode 100644 archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/SortRepositoriesActionTest.java diff --git a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo index 57770b885..1455d9f71 100644 --- a/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo +++ b/archiva-modules/archiva-base/archiva-configuration/src/main/mdo/configuration.mdo @@ -167,7 +167,7 @@ public java.util.Map> getRepositoryToGroupMap() { - if ( repositoryToGroupMap == null ) + if ( repositoryGroups != null ) { java.util.Map> map = new java.util.HashMap>(); @@ -189,6 +189,64 @@ } return repositoryToGroupMap; } + + public java.util.Map getRepositoryGroupsAsMap() + { + java.util.Map map = new java.util.HashMap(); + if ( repositoryGroups != null ) + { + for ( RepositoryGroupConfiguration group : (java.util.List) repositoryGroups ) + { + map.put( group.getId(), group ); + } + } + return map; + } + + public RepositoryGroupConfiguration findRepositoryGroupById( String id ) + { + if ( repositoryGroups != null ) + { + for ( RepositoryGroupConfiguration group : (java.util.List) repositoryGroups ) + { + if ( group.getId().equals( id ) ) + { + return group; + } + } + } + return null; + } + + private java.util.Map> groupToRepositoryMap; + + public java.util.Map> getGroupToRepositoryMap() + { + if ( repositoryGroups != null && managedRepositories != null ) + { + java.util.Map> map = new java.util.HashMap>(); + + for ( ManagedRepositoryConfiguration repo : (java.util.List) managedRepositories ) + { + for ( RepositoryGroupConfiguration group : (java.util.List) repositoryGroups ) + { + if ( !group.getRepositories().contains( repo.getId() ) ) + { + String groupId = group.getId(); + java.util.List repos = map.get( groupId ); + if ( repos == null ) + { + repos = new java.util.ArrayList(); + map.put( groupId, repos ); + } + repos.add( repo.getId() ); + } + } + } + groupToRepositoryMap = map; + } + return groupToRepositoryMap; + } ]]> diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupAction.java new file mode 100644 index 000000000..653a29318 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupAction.java @@ -0,0 +1,96 @@ +package org.apache.maven.archiva.web.action.admin.repositories; + +/* + * 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 com.opensymphony.xwork.Preparable; + +import org.apache.commons.lang.StringUtils; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration; + +/** + * DeleteRepositoryGroupAction + * + * @author + * @version + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="deleteRepositoryGroupAction" + */ +public class DeleteRepositoryGroupAction + extends AbstractRepositoriesAdminAction + implements Preparable +{ + private RepositoryGroupConfiguration repositoryGroup; + + private String repoGroupId; + + public void prepare() + { + if ( StringUtils.isNotBlank( repoGroupId ) ) + { + this.repositoryGroup = archivaConfiguration.getConfiguration().findRepositoryGroupById( repoGroupId ); + } + } + + public String confirmDelete() + { + if ( StringUtils.isBlank( repoGroupId ) ) + { + addActionError( "Unable to delete repository group: repository id was blank." ); + return ERROR; + } + + return INPUT; + } + + public String delete() + { + Configuration config = archivaConfiguration.getConfiguration(); + + RepositoryGroupConfiguration group = config.findRepositoryGroupById( repoGroupId ); + if ( group == null ) + { + addActionError( "A repository group with that id does not exist." ); + return ERROR; + } + + config.removeRepositoryGroup( group ); + return saveConfiguration( config ); + } + + public RepositoryGroupConfiguration getRepositoryGroup() + { + return repositoryGroup; + } + + public void setRepositoryGroup( RepositoryGroupConfiguration repositoryGroup ) + { + this.repositoryGroup = repositoryGroup; + } + + public String getRepoGroupId() + { + return repoGroupId; + } + + public void setRepoGroupId( String repoGroupId ) + { + this.repoGroupId = repoGroupId; + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsAction.java new file mode 100644 index 000000000..d01cc9b98 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsAction.java @@ -0,0 +1,231 @@ +package org.apache.maven.archiva.web.action.admin.repositories; + +/* + * 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.ArrayList; +import java.util.List; +import java.util.Map; +import javax.servlet.http.HttpServletRequest; + +import com.opensymphony.webwork.interceptor.ServletRequestAware; +import com.opensymphony.xwork.Preparable; + +import org.apache.commons.lang.StringUtils; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration; +import org.apache.maven.archiva.security.ArchivaRoleConstants; +import org.apache.maven.archiva.web.util.ContextUtils; + +/** + * RepositoryGroupsAction + * + * @author + * @version + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="repositoryGroupsAction" + */ +public class RepositoryGroupsAction + extends AbstractRepositoriesAdminAction + implements ServletRequestAware, Preparable +{ + private RepositoryGroupConfiguration repositoryGroup; + + private Map repositoryGroups; + + private Map managedRepositories; + + private Map> groupToRepositoryMap; + + private String repoGroupId; + + private String repoId; + + /** + * Used to construct the repository WebDAV URL in the repository action. + */ + private String baseUrl; + + public void setServletRequest( HttpServletRequest request ) + { + this.baseUrl = ContextUtils.getBaseURL( request, "repository" ); + } + + public void prepare() + { + Configuration config = archivaConfiguration.getConfiguration(); + + repositoryGroup = new RepositoryGroupConfiguration(); + repositoryGroups = config.getRepositoryGroupsAsMap(); + managedRepositories = config.getManagedRepositoriesAsMap(); + groupToRepositoryMap = config.getGroupToRepositoryMap(); + } + + public String addRepositoryGroup() + { + Configuration configuration = archivaConfiguration.getConfiguration(); + + String repoGroupId = repositoryGroup.getId(); + + if ( StringUtils.isBlank( repoGroupId ) ) + { + addActionError( "You must enter a repository group id." ); + return ERROR; + } + + if ( configuration.getRepositoryGroupsAsMap().containsKey( repoGroupId ) ) + { + addActionError( "Unable to add new repository group with id [" + repoGroupId + + "], that id already exists." ); + return ERROR; + } + + configuration.addRepositoryGroup( repositoryGroup ); + return saveConfiguration( configuration ); + } + + public String addRepositoryToGroup() + { + Configuration config = archivaConfiguration.getConfiguration(); + RepositoryGroupConfiguration group = config.findRepositoryGroupById( repoGroupId ); + + validateRepository(); + + if ( hasErrors() ) + { + return ERROR; + } + + if ( group.getRepositories().contains( repoId ) ) + { + addActionError( "Repository with id [" + repoId + "] is already in the group" ); + return ERROR; + } + + // remove the old repository group configuration + config.removeRepositoryGroup( group ); + + // save repository group configuration + group.addRepository( repoId ); + config.addRepositoryGroup( group ); + + return saveConfiguration( config ); + } + + public String removeRepositoryFromGroup() + { + Configuration config = archivaConfiguration.getConfiguration(); + RepositoryGroupConfiguration group = config.findRepositoryGroupById( repoGroupId ); + + validateRepository(); + + if( hasErrors() ) + { + return ERROR; + } + + if ( !group.getRepositories().contains( repoId ) ) + { + addActionError( "No repository with id[" + repoId + "] found in the group" ); + return ERROR; + } + + // remove the old repository group configuration + config.removeRepositoryGroup( group ); + + // save repository group configuration + group.removeRepository( repoId ); + config.addRepositoryGroup( group ); + + return saveConfiguration( config ); + } + + public void validateRepository() + { + Configuration config = archivaConfiguration.getConfiguration(); + RepositoryGroupConfiguration group = config.findRepositoryGroupById( repoGroupId ); + ManagedRepositoryConfiguration repo = config.findManagedRepositoryById( repoId ); + + if ( group == null ) + { + addActionError( "A repository group with that id does not exist." ); + } + + if ( repo == null ) + { + addActionError( "A repository with that id does not exist." ); + } + } + + public RepositoryGroupConfiguration getRepositoryGroup() + { + return repositoryGroup; + } + + public void setRepositoryGroup( RepositoryGroupConfiguration repositoryGroup ) + { + this.repositoryGroup = repositoryGroup; + } + + public Map getRepositoryGroups() + { + return repositoryGroups; + } + + public void setRepositoryGroups( Map repositoryGroups ) + { + this.repositoryGroups = repositoryGroups; + } + + public Map getManagedRepositories() + { + return managedRepositories; + } + + public Map> getGroupToRepositoryMap() + { + return this.groupToRepositoryMap; + } + + public String getRepoGroupId() + { + return repoGroupId; + } + + public void setRepoGroupId( String repoGroupId ) + { + this.repoGroupId = repoGroupId; + } + + public String getRepoId() + { + return repoId; + } + + public void setRepoId( String repoId ) + { + this.repoId = repoId; + } + + public String getBaseUrl() + { + return baseUrl; + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/SortRepositoriesAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/SortRepositoriesAction.java new file mode 100644 index 000000000..4ac5c3ddc --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/SortRepositoriesAction.java @@ -0,0 +1,122 @@ +package org.apache.maven.archiva.web.action.admin.repositories; + +/* + * 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.commons.lang.StringUtils; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration; + +/** + * SortRepositoriesAction + * + * @author + * @version + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="sortRepositoriesAction" + */ +public class SortRepositoriesAction + extends AbstractRepositoriesAdminAction +{ + private String repoGroupId; + + private String targetRepo; + + public String sortDown() + { + Configuration config = archivaConfiguration.getConfiguration(); + + List repositories = getRepositoriesFromGroup(); + + int idx = findTargetRepository( repositories, targetRepo ); + + if ( idx >= 0 && validIndex( repositories, idx + 1 ) ) + { + repositories.remove( idx ); + repositories.add( idx + 1, targetRepo ); + } + + return saveConfiguration( config ); + } + + public String sortUp() + { + Configuration config = archivaConfiguration.getConfiguration(); + + List repositories = getRepositoriesFromGroup(); + + int idx = findTargetRepository( repositories, targetRepo ); + + if ( idx >= 0 && validIndex( repositories, idx - 1 ) ) + { + repositories.remove( idx ); + repositories.add( idx - 1, targetRepo ); + } + + return saveConfiguration( config ); + } + + public String getRepoGroupId() + { + return repoGroupId; + } + + public void setRepoGroupId( String repoGroupId ) + { + this.repoGroupId = repoGroupId; + } + + public String getTargetRepo() + { + return targetRepo; + } + + public void setTargetRepo( String targetRepo ) + { + this.targetRepo = targetRepo; + } + + private int findTargetRepository( List repositories, String targetRepository ) + { + int idx = ( -1 ); + + for ( int i = 0; i < repositories.size(); i++ ) + { + if ( StringUtils.equals( targetRepository, repositories.get(i) ) ) + { + idx = i; + break; + } + } + return idx; + } + + private List getRepositoriesFromGroup() + { + Configuration config = archivaConfiguration.getConfiguration(); + RepositoryGroupConfiguration repoGroup = config.findRepositoryGroupById( repoGroupId ); + return repoGroup.getRepositories(); + } + + private boolean validIndex( List repositories, int idx ) + { + return ( idx >= 0 ) && ( idx < repositories.size() ); + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/xwork.xml b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/xwork.xml index 24933e253..b8309df61 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/xwork.xml +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/xwork.xml @@ -223,6 +223,59 @@ /WEB-INF/jsp/admin/repositories.jsp + + + + + /WEB-INF/jsp/admin/repositoryGroups.jsp + + + + /WEB-INF/jsp/admin/repositoryGroups.jsp + /WEB-INF/jsp/admin/repositoryGroups.jsp + repositoryGroups + + + + + /WEB-INF/jsp/admin/deleteRepositoryGroup.jsp + + + + + /WEB-INF/jsp/admin/deleteRepositoryGroup.jsp + /WEB-INF/jsp/admin/deleteRepositoryGroup.jsp + repositoryGroups + + + + + /WEB-INF/jsp/admin/repositoryGroups.jsp + /WEB-INF/jsp/admin/repositoryGroups.jsp + repositoryGroups + + + + + /WEB-INF/jsp/admin/repositoryGroups.jsp + /WEB-INF/jsp/admin/repositoryGroups.jsp + repositoryGroups + + + + + /WEB-INF/jsp/admin/repositoryGroups.jsp + /WEB-INF/jsp/admin/repositoryGroups.jsp + repositoryGroups + + + + + /WEB-INF/jsp/admin/repositoryGroups.jsp + /WEB-INF/jsp/admin/repositoryGroups.jsp + repositoryGroups + + diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRepositoryGroup.jsp b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRepositoryGroup.jsp new file mode 100644 index 000000000..fa1892686 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRepositoryGroup.jsp @@ -0,0 +1,65 @@ +<%-- + ~ 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> + + + + Admin: Delete Repository Group + + + + + +

Admin: Delete Repository Group

+ + + +
+ +
+

+ WARNING: This operation can not be undone. +

+
+ +

+ Are you sure you want to delete the following repository group? +

+ +
+ + + + + +
ID:${repositoryGroup.id}
+
+ + + +
+ + +
+
+
+ + + \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositoryGroups.jsp b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositoryGroups.jsp new file mode 100644 index 000000000..ebfbacddc --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositoryGroups.jsp @@ -0,0 +1,149 @@ +<%-- + ~ 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. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> +<%@ taglib prefix="redback" uri="http://plexus.codehaus.org/redback/taglib-1.0" %> +<%@ taglib prefix="archiva" uri="http://maven.apache.org/archiva" %> + + + + Administration - Repository Groups + + + + + +

Administration - Repository Groups

+ + + + + + + +
+ + + + +
+ + + Identifier*: + + + + +
+ +

Repository Groups

+ + + + No Repository Groups Defined. + + + +
+ + + +
+
+ +
+ + + + + + +
+ + "/> +

${repositoryGroup.key}

+
+ + +
+ + + + + +
+
+ + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+ +

Repository

+ +
+ "/> +

${repository}

+

${managedRepositories[repository].name}

+

${baseUrl}/${managedRepositories[repository].id}

+
+
<%-- repository --%> +
+ +
<%-- repository group --%> +
+
<%-- admin --%> + +
+
\ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp index 679645c80..ad98bb07e 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp @@ -134,6 +134,9 @@
Administration
    +
  • + Repository Groups +
  • Repositories
  • diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/css/site.css b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/css/site.css index 195420b67..114580c0f 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/css/site.css +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/webapp/css/site.css @@ -245,14 +245,16 @@ div.repository { border-bottom: 1px solid #DFDEDE; } -div.proxyConfig { +div.proxyConfig, +div.repoGroup { border: 1px dashed #DFDEDE; margin-bottom: 15px; padding: 5px; } div.proxyConfig div.managedRepo, -div.proxyConfig div.remoteRepo { +div.proxyConfig div.remoteRepo, +div.repoGroup div.managedRepo { border: 1px dotted gray; padding: 5px; background-color: white; @@ -263,7 +265,8 @@ div.proxyConfig div.remoteRepo { } div.proxyConfig div.managedRepo img, -div.proxyConfig div.remoteRepo img { +div.proxyConfig div.remoteRepo img, +div.repoGroup div.managedRepo img { float: left; border: 0px; } @@ -275,12 +278,20 @@ div.proxyConfig div.remoteRepo p { padding: 0px; } +div.repoGroup div.managedRepo p { + margin: 8px; + margin-left: 40px; + padding: 0px; +} + div.proxyConfig div.managedRepo p.id, -div.proxyConfig div.remoteRepo p.id { +div.proxyConfig div.remoteRepo p.id, +div.repoGroup div.managedRepo p.id { font-family: monospace; } -div.proxyConfig div.connector { +div.proxyConfig div.connector, +div.repoGroup div.connector { border: 1px solid #aaaaff; margin-top: 10px; margin-left: 40px !important; @@ -291,11 +302,13 @@ div.proxyConfig a.expand { color: gray; } -div.proxyConfig div.controls { +div.proxyConfig div.controls, +div.repoGroup div.controls { float: right; } -div.proxyConfig div.connector h4 { +div.proxyConfig div.connector h4, +div.repoGroup div.connector h4 { padding: 3px; font-size: 8pt; margin: 0px; @@ -321,6 +334,12 @@ div.proxyConfig div.connector table p { margin: 0px; padding: 0px; } + +div.repoGroup div.repos { + text-align: right; + padding: 4px 0px 0px 0px; +} + div.admin div.dark, div.admin div.lite { border: 1px solid #aaaaaa; diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupActionTest.java new file mode 100644 index 000000000..46efd31ae --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRepositoryGroupActionTest.java @@ -0,0 +1,156 @@ +package org.apache.maven.archiva.web.action.admin.repositories; + +/* + * 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.Collections; + +import com.opensymphony.xwork.Action; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException; +import org.codehaus.plexus.spring.PlexusInSpringTestCase; +import org.easymock.MockControl; + +/** + * DeleteRepositoryGroupActionTest + * + * @author + * @version + */ +public class DeleteRepositoryGroupActionTest + extends PlexusInSpringTestCase +{ + private static final String REPO_GROUP_ID = "repo-group-ident"; + + private DeleteRepositoryGroupAction action; + + private MockControl archivaConfigurationControl; + + private ArchivaConfiguration archivaConfiguration; + + protected void setUp() + throws Exception + { + super.setUp(); + + action = (DeleteRepositoryGroupAction) lookup ( Action.class.getName(), "deleteRepositoryGroupAction" ); + + archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); + archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); + action.setArchivaConfiguration( archivaConfiguration ); + } + + public void testSecureActionBundle() + throws SecureActionException + { + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( new Configuration() ); + archivaConfigurationControl.replay(); + + action.prepare(); + SecureActionBundle bundle = action.getSecureActionBundle(); + assertTrue( bundle.requiresAuthentication() ); + assertEquals( 1, bundle.getAuthorizationTuples().size() ); + } + + public void testDeleteRepositoryGroupConfirmation() + throws Exception + { + RepositoryGroupConfiguration origRepoGroup = createRepositoryGroup(); + Configuration configuration = createConfigurationForEditing( origRepoGroup ); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + archivaConfigurationControl.replay(); + + action.setRepoGroupId( REPO_GROUP_ID ); + + action.prepare(); + assertEquals( REPO_GROUP_ID, action.getRepoGroupId() ); + RepositoryGroupConfiguration repoGroup = action.getRepositoryGroup(); + assertNotNull( repoGroup ); + assertEquals( repoGroup.getId(), action.getRepoGroupId() ); + assertEquals( Collections.singletonList( origRepoGroup ), configuration.getRepositoryGroups() ); + } + + public void testDeleteRepositoryGroup() + throws Exception + { + Configuration configuration = createConfigurationForEditing( createRepositoryGroup() ); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration, 3 ); + archivaConfiguration.save( configuration ); + archivaConfigurationControl.replay(); + + action.setRepoGroupId( REPO_GROUP_ID ); + + action.prepare(); + assertEquals( REPO_GROUP_ID, action.getRepoGroupId() ); + RepositoryGroupConfiguration repoGroup = action.getRepositoryGroup(); + assertNotNull( repoGroup ); + assertEquals( Collections.singletonList( repoGroup ), configuration.getRepositoryGroups() ); + + String status = action.delete(); + assertEquals( Action.SUCCESS, status ); + assertTrue( configuration.getRepositoryGroups().isEmpty() ); + } + + public void testDeleteRepositoryGroupCancelled() + throws Exception + { + RepositoryGroupConfiguration origRepoGroup = createRepositoryGroup(); + Configuration configuration = createConfigurationForEditing ( origRepoGroup ); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration, 2 ); + + archivaConfiguration.save( configuration ); + archivaConfigurationControl.replay(); + + action.setRepoGroupId( REPO_GROUP_ID ); + + action.prepare(); + assertEquals( REPO_GROUP_ID, action.getRepoGroupId() ); + RepositoryGroupConfiguration repoGroup = action.getRepositoryGroup(); + assertNotNull( repoGroup ); + + String status = action.execute(); + assertEquals( Action.SUCCESS, status ); + assertEquals( Collections.singletonList( repoGroup ), configuration.getRepositoryGroups() ); + } + + private Configuration createConfigurationForEditing( RepositoryGroupConfiguration repoGroup ) + { + Configuration configuration = new Configuration(); + configuration.addRepositoryGroup( repoGroup ); + return configuration; + } + + private RepositoryGroupConfiguration createRepositoryGroup() + { + RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration(); + repoGroup.setId( REPO_GROUP_ID ); + + return repoGroup; + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsActionTest.java new file mode 100644 index 000000000..5b12e8ea2 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsActionTest.java @@ -0,0 +1,380 @@ +package org.apache.maven.archiva.web.action.admin.repositories; + +/* + * 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.Collections; + +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException; +import org.codehaus.plexus.spring.PlexusInSpringTestCase; +import org.easymock.MockControl; + +import com.meterware.servletunit.ServletRunner; +import com.meterware.servletunit.ServletUnitClient; +import com.opensymphony.xwork.Action; + +/** + * RepositoryGroupsActionTest + * + * @author + * @version + */ +public class RepositoryGroupsActionTest + extends PlexusInSpringTestCase +{ + private static final String REPO_GROUP_ID = "repo-group-ident"; + + private static final String REPO1_ID = "managed-repo-ident-1"; + + private static final String REPO2_ID = "managed-repo-ident-2"; + + private RepositoryGroupsAction action; + + private MockControl archivaConfigurationControl; + + private ArchivaConfiguration archivaConfiguration; + + protected void setUp() + throws Exception + { + super.setUp(); + + action = (RepositoryGroupsAction) lookup( Action.class.getName(), "repositoryGroupsAction" ); + + archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); + archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); + action.setArchivaConfiguration( archivaConfiguration ); + } + + public void testSecureActionBundle() + throws SecureActionException + { + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( new Configuration() ); + archivaConfigurationControl.replay(); + + action.prepare(); + SecureActionBundle bundle = action.getSecureActionBundle(); + assertTrue( bundle.requiresAuthentication() ); + assertEquals( 1, bundle.getAuthorizationTuples().size() ); + } + + public void testAddRepositoryGroup() + throws Exception + { + Configuration configuration = new Configuration(); + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration, 2 ); + + archivaConfiguration.save( configuration ); + archivaConfigurationControl.replay(); + + action.prepare(); + RepositoryGroupConfiguration repositoryGroup = action.getRepositoryGroup(); + repositoryGroup.setId( REPO_GROUP_ID ); + + String status = action.addRepositoryGroup(); + assertEquals( Action.SUCCESS, status ); + + assertEquals( Collections.singletonList( repositoryGroup ), configuration.getRepositoryGroups() ); + + archivaConfigurationControl.verify(); + } + + public void testAddEmptyRepositoryGroup() + throws Exception + { + Configuration configuration = new Configuration(); + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration, 2 ); + + archivaConfiguration.save( configuration ); + + archivaConfigurationControl.replay(); + + action.prepare(); + + String status = action.addRepositoryGroup(); + assertEquals( Action.ERROR, status ); + + assertEquals( 0, configuration.getRepositoryGroups().size() ); + } + + public void testAddDuplicateRepositoryGroup() + throws Exception + { + Configuration configuration = new Configuration(); + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration, 3 ); + + archivaConfiguration.save( configuration ); + + archivaConfigurationControl.replay(); + + action.prepare(); + RepositoryGroupConfiguration repositoryGroup = action.getRepositoryGroup(); + repositoryGroup.setId( REPO_GROUP_ID ); + + String status = action.addRepositoryGroup(); + assertEquals( Action.SUCCESS, status ); + + assertEquals( Collections.singletonList( repositoryGroup ), configuration.getRepositoryGroups() ); + + repositoryGroup.setId( REPO_GROUP_ID ); + status = action.addRepositoryGroup(); + + assertEquals( Action.ERROR, status ); + assertEquals( Collections.singletonList( repositoryGroup ), configuration.getRepositoryGroups() ); + } + + public void testGetRepositoryGroups() + throws Exception + { + ServletRunner sr = new ServletRunner(); + ServletUnitClient sc = sr.newClient(); + + Configuration configuration = createInitialConfiguration(); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + archivaConfigurationControl.replay(); + + action.setServletRequest( sc.newInvocation( "http://localhost/admin/repositoryGroups.action" ).getRequest() ); + action.prepare(); + String result = action.execute(); + assertEquals( Action.SUCCESS, result ); + + assertEquals( "http://localhost:0/repository", action.getBaseUrl() ); + + assertNotNull( action.getRepositoryGroups() ); + assertEquals( 1, action.getRepositoryGroups().size() ); + assertEquals( 2, action.getManagedRepositories().size() ); + + RepositoryGroupConfiguration repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID ); + + assertEquals( 1, repoGroup.getRepositories().size() ); + assertEquals( REPO1_ID, repoGroup.getRepositories().get( 0 ) ); + assertNotNull( action.getGroupToRepositoryMap() ); + assertEquals( 1, action.getGroupToRepositoryMap().size() ); + + java.util.List repos = action.getGroupToRepositoryMap().get( repoGroup.getId() ); + assertEquals( 1, repos.size() ); + assertEquals( REPO2_ID, repos.get( 0 ) ); + } + + public void testAddRepositoryToGroup() + throws Exception + { + Configuration configuration = createInitialConfiguration(); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration, 6 ); + archivaConfiguration.save( configuration ); + archivaConfigurationControl.replay(); + + action.prepare(); + String result = action.execute(); + assertEquals( Action.SUCCESS, result ); + + assertNotNull( action.getRepositoryGroups() ); + assertEquals( 1, action.getRepositoryGroups().size() ); + assertEquals( 2, action.getManagedRepositories().size() ); + + RepositoryGroupConfiguration repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID ); + assertEquals( 1 , repoGroup.getRepositories().size() ); + assertEquals( REPO1_ID, repoGroup.getRepositories().get( 0 ) ); + + assertNotNull( action.getGroupToRepositoryMap() ); + assertEquals( 1, action.getGroupToRepositoryMap().size() ); + + java.util.List repos = action.getGroupToRepositoryMap().get( repoGroup.getId() ); + assertEquals( 1, repos.size() ); + assertEquals( REPO2_ID, repos.get( 0 ) ); + + action.setRepoGroupId( REPO_GROUP_ID ); + action.setRepoId( REPO2_ID ); + + result = action.addRepositoryToGroup(); + assertEquals( Action.SUCCESS, result ); + + action.prepare(); + result = action.execute(); + assertEquals( Action.SUCCESS, result ); + + assertEquals( 1, action.getRepositoryGroups().size() ); + repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID ); + assertEquals( 2, repoGroup.getRepositories().size() ); + assertEquals( REPO1_ID, repoGroup.getRepositories().get( 0 ) ); + assertEquals( REPO2_ID, repoGroup.getRepositories().get( 1 ) ); + + assertEquals( 0, action.getGroupToRepositoryMap().size() ); + assertNull( action.getGroupToRepositoryMap().get( repoGroup.getId() ) ); + } + + public void testRemoveRepositoryFromGroup() + throws Exception + { + Configuration configuration = createInitialConfiguration(); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration, 6 ); + archivaConfiguration.save( configuration ); + archivaConfigurationControl.replay(); + + action.prepare(); + String result = action.execute(); + assertEquals( Action.SUCCESS, result ); + + assertNotNull( action.getRepositoryGroups() ); + assertEquals( 1, action.getRepositoryGroups().size() ); + assertEquals( 2, action.getManagedRepositories().size() ); + + RepositoryGroupConfiguration repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID ); + assertEquals( 1 , repoGroup.getRepositories().size() ); + assertEquals( REPO1_ID, repoGroup.getRepositories().get( 0 ) ); + + assertNotNull( action.getGroupToRepositoryMap() ); + assertEquals( 1, action.getGroupToRepositoryMap().size() ); + + java.util.List repos = action.getGroupToRepositoryMap().get( repoGroup.getId() ); + assertEquals( 1, repos.size() ); + assertEquals( REPO2_ID, repos.get( 0 ) ); + + action.setRepoGroupId( REPO_GROUP_ID ); + action.setRepoId( REPO1_ID ); + + result = action.removeRepositoryFromGroup(); + assertEquals( Action.SUCCESS, result ); + + action.prepare(); + result = action.execute(); + assertEquals( Action.SUCCESS, result ); + + repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID ); + assertEquals( 0, repoGroup.getRepositories().size() ); + + assertNotNull( action.getGroupToRepositoryMap() ); + assertEquals( 1, action.getGroupToRepositoryMap().size() ); + + repos = action.getGroupToRepositoryMap().get( repoGroup.getId() ); + assertEquals( 2, repos.size() ); + assertEquals( REPO1_ID, repos.get( 0 ) ); + assertEquals( REPO2_ID, repos.get( 1 ) ); + } + + public void testAddDuplicateRepositoryToGroup() + throws Exception + { + Configuration configuration = createInitialConfiguration(); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration, 6 ); + archivaConfiguration.save( configuration ); + archivaConfigurationControl.replay(); + + action.prepare(); + String result = action.execute(); + assertEquals( Action.SUCCESS, result ); + + assertNotNull( action.getRepositoryGroups() ); + assertEquals( 1, action.getRepositoryGroups().size() ); + assertEquals( 2, action.getManagedRepositories().size() ); + + RepositoryGroupConfiguration repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID ); + assertEquals( 1 , repoGroup.getRepositories().size() ); + assertEquals( REPO1_ID, repoGroup.getRepositories().get( 0 ) ); + + assertNotNull( action.getGroupToRepositoryMap() ); + assertEquals( 1, action.getGroupToRepositoryMap().size() ); + + java.util.List repos = action.getGroupToRepositoryMap().get( repoGroup.getId() ); + assertEquals( 1, repos.size() ); + assertEquals( REPO2_ID, repos.get( 0 ) ); + + action.setRepoGroupId( REPO_GROUP_ID ); + action.setRepoId( REPO1_ID ); + + result = action.addRepositoryToGroup(); + assertEquals( Action.ERROR, result ); + } + + public void testRemoveRepositoryNotInGroup() + throws Exception + { + Configuration configuration = createInitialConfiguration(); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration, 6 ); + archivaConfiguration.save( configuration ); + archivaConfigurationControl.replay(); + + action.prepare(); + String result = action.execute(); + assertEquals( Action.SUCCESS, result ); + + assertNotNull( action.getRepositoryGroups() ); + assertEquals( 1, action.getRepositoryGroups().size() ); + assertEquals( 2, action.getManagedRepositories().size() ); + + RepositoryGroupConfiguration repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID ); + assertEquals( 1 , repoGroup.getRepositories().size() ); + assertEquals( REPO1_ID, repoGroup.getRepositories().get( 0 ) ); + + assertNotNull( action.getGroupToRepositoryMap() ); + assertEquals( 1, action.getGroupToRepositoryMap().size() ); + + java.util.List repos = action.getGroupToRepositoryMap().get( repoGroup.getId() ); + assertEquals( 1, repos.size() ); + assertEquals( REPO2_ID, repos.get( 0 ) ); + + action.setRepoGroupId( REPO_GROUP_ID ); + action.setRepoId( REPO2_ID ); + + result = action.removeRepositoryFromGroup(); + assertEquals( Action.ERROR, result ); + } + + private Configuration createInitialConfiguration() + { + Configuration config = new Configuration(); + + ManagedRepositoryConfiguration managedRepo1 = new ManagedRepositoryConfiguration(); + managedRepo1.setId( REPO1_ID ); + + config.addManagedRepository( managedRepo1 ); + + ManagedRepositoryConfiguration managedRepo2 = new ManagedRepositoryConfiguration(); + managedRepo2.setId( REPO2_ID ); + + config.addManagedRepository( managedRepo2 ); + + RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration(); + repoGroup.setId( REPO_GROUP_ID ); + repoGroup.addRepository( REPO1_ID ); + + config.addRepositoryGroup( repoGroup ); + + return config; + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/SortRepositoriesActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/SortRepositoriesActionTest.java new file mode 100644 index 000000000..9cd360640 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/SortRepositoriesActionTest.java @@ -0,0 +1,225 @@ +package org.apache.maven.archiva.web.action.admin.repositories; + +/* + * 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 org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException; +import org.codehaus.plexus.spring.PlexusInSpringTestCase; +import org.easymock.MockControl; + +import com.opensymphony.xwork.Action; + +/** + * SortRepositoriesActionTest + * + * @author + * @version + */ +public class SortRepositoriesActionTest + extends PlexusInSpringTestCase +{ + private static final String REPO_GROUP_ID = "repo-group-ident"; + + private static final String REPO1_ID = "managed-repo-ident-1"; + + private static final String REPO2_ID = "managed-repo-ident-2"; + + private static final String REPO3_ID = "managed-repo-ident-3"; + + private MockControl archivaConfigurationControl; + + private ArchivaConfiguration archivaConfiguration; + + private SortRepositoriesAction action; + + protected void setUp() + throws Exception + { + super.setUp(); + + action = (SortRepositoriesAction) lookup( Action.class.getName(), "sortRepositoriesAction" ); + + archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); + archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); + action.setArchivaConfiguration( archivaConfiguration ); + } + + public void testSecureActionBundle() + throws SecureActionException + { + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( new Configuration() ); + archivaConfigurationControl.replay(); + + SecureActionBundle bundle = action.getSecureActionBundle(); + assertTrue( bundle.requiresAuthentication() ); + assertEquals( 1, bundle.getAuthorizationTuples().size() ); + } + + public void testSortDownFirstRepository() + throws Exception + { + Configuration configuration = createInitialConfiguration(); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration, 4 ); + archivaConfiguration.save( configuration ); + archivaConfigurationControl.replay(); + + RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 ); + java.util.List repositories = repoGroup.getRepositories(); + + assertEquals( 3, repositories.size() ); + assertEquals( REPO1_ID, repositories.get( 0 ) ); + assertEquals( REPO2_ID, repositories.get( 1 ) ); + assertEquals( REPO3_ID, repositories.get( 2 ) ); + + // sort down first repo + action.setRepoGroupId( repoGroup.getId() ); + action.setTargetRepo( REPO1_ID ); + + String result = action.sortDown(); + assertEquals( Action.SUCCESS, result ); + + repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 ); + repositories = repoGroup.getRepositories(); + assertEquals( 3, repositories.size() ); + assertEquals( REPO2_ID, repositories.get( 0 ) ); + assertEquals( REPO1_ID, repositories.get( 1 ) ); + assertEquals( REPO3_ID, repositories.get( 2 ) ); + } + + public void testSortDownLastRepository() + throws Exception + { + Configuration configuration = createInitialConfiguration(); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration, 4 ); + archivaConfiguration.save( configuration ); + archivaConfigurationControl.replay(); + + RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 ); + java.util.List repositories = repoGroup.getRepositories(); + + assertEquals( 3, repositories.size() ); + assertEquals( REPO1_ID, repositories.get( 0 ) ); + assertEquals( REPO2_ID, repositories.get( 1 ) ); + assertEquals( REPO3_ID, repositories.get( 2 ) ); + + // sort down last repo + action.setRepoGroupId( repoGroup.getId() ); + action.setTargetRepo( REPO3_ID ); + + String result = action.sortDown(); + assertEquals( Action.SUCCESS, result ); + + repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 ); + repositories = repoGroup.getRepositories(); + assertEquals( 3, repositories.size() ); + assertEquals( REPO1_ID, repositories.get( 0 ) ); + assertEquals( REPO2_ID, repositories.get( 1 ) ); + assertEquals( REPO3_ID, repositories.get( 2 ) ); + } + + public void testSortUpLastRepository() + throws Exception + { + Configuration configuration = createInitialConfiguration(); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration, 4 ); + archivaConfiguration.save( configuration ); + archivaConfigurationControl.replay(); + + RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 ); + java.util.List repositories = repoGroup.getRepositories(); + + assertEquals( 3, repositories.size() ); + assertEquals( REPO1_ID, repositories.get( 0 ) ); + assertEquals( REPO2_ID, repositories.get( 1 ) ); + assertEquals( REPO3_ID, repositories.get( 2 ) ); + + // sort up last repo + action.setRepoGroupId( repoGroup.getId() ); + action.setTargetRepo( REPO3_ID ); + + String result = action.sortUp(); + assertEquals( Action.SUCCESS, result ); + + repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 ); + repositories = repoGroup.getRepositories(); + assertEquals( 3, repositories.size() ); + assertEquals( REPO1_ID, repositories.get( 0 ) ); + assertEquals( REPO3_ID, repositories.get( 1 ) ); + assertEquals( REPO2_ID, repositories.get( 2 ) ); + } + + public void testSortUpFirstRepository() + throws Exception + { + Configuration configuration = createInitialConfiguration(); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration, 4 ); + archivaConfiguration.save( configuration ); + archivaConfigurationControl.replay(); + + RepositoryGroupConfiguration repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 ); + java.util.List repositories = repoGroup.getRepositories(); + + assertEquals( 3, repositories.size() ); + assertEquals( REPO1_ID, repositories.get( 0 ) ); + assertEquals( REPO2_ID, repositories.get( 1 ) ); + assertEquals( REPO3_ID, repositories.get( 2 ) ); + + // sort up first repo + action.setRepoGroupId( repoGroup.getId() ); + action.setTargetRepo( REPO1_ID ); + + String result = action.sortUp(); + assertEquals( Action.SUCCESS, result ); + + repoGroup = (RepositoryGroupConfiguration) configuration.getRepositoryGroups().get( 0 ); + repositories = repoGroup.getRepositories(); + assertEquals( 3, repositories.size() ); + assertEquals( REPO1_ID, repositories.get( 0 ) ); + assertEquals( REPO2_ID, repositories.get( 1 ) ); + assertEquals( REPO3_ID, repositories.get( 2 ) ); + } + + private Configuration createInitialConfiguration() + { + Configuration config = new Configuration(); + + RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration(); + repoGroup.setId( REPO_GROUP_ID ); + repoGroup.addRepository( REPO1_ID ); + repoGroup.addRepository( REPO2_ID ); + repoGroup.addRepository( REPO3_ID ); + + config.addRepositoryGroup( repoGroup ); + + return config; + } +} -- 2.39.5