From: Brett Porter Date: Wed, 12 Sep 2007 05:52:25 +0000 (+0000) Subject: [MRM-462] restore management of remote repositories X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3ea81a75b529c6f71d59e3ace9e13504d250a27e;p=archiva.git [MRM-462] restore management of remote repositories git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches@574791 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractConfigureRepositoryAction.java b/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractConfigureRepositoryAction.java new file mode 100644 index 000000000..779250ca5 --- /dev/null +++ b/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractConfigureRepositoryAction.java @@ -0,0 +1,118 @@ +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.IndeterminateConfigurationException; +import org.apache.maven.archiva.configuration.InvalidConfigurationException; +import org.apache.maven.archiva.security.ArchivaRoleConstants; +import org.codehaus.plexus.redback.rbac.Resource; +import org.codehaus.plexus.redback.xwork.interceptor.SecureAction; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException; +import org.codehaus.plexus.registry.RegistryException; +import org.codehaus.plexus.xwork.action.PlexusActionSupport; + +import java.io.IOException; + +/** + * Base class for repository configuration actions. + */ +public class AbstractConfigureRepositoryAction + extends PlexusActionSupport + implements SecureAction +{ + /** + * @plexus.requirement + */ + protected ArchivaConfiguration archivaConfiguration; + + protected String repoid; + + // TODO! consider removing? was just meant to be for delete... + protected String mode; + + // TODO: rename to confirmDelete + public String confirm() + { + return INPUT; + } + + public String getMode() + { + return this.mode; + } + + public String getRepoid() + { + return repoid; + } + + public SecureActionBundle getSecureActionBundle() + throws SecureActionException + { + SecureActionBundle bundle = new SecureActionBundle(); + + bundle.setRequiresAuthentication( true ); + bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL ); + + return bundle; + } + + public void setMode( String mode ) + { + this.mode = mode; + } + + public void setRepoid( String repoid ) + { + this.repoid = repoid; + } + + public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration ) + { + this.archivaConfiguration = archivaConfiguration; + } + + public String edit() + { + this.mode = "edit"; + + return INPUT; + } + + protected String saveConfiguration( Configuration configuration ) + throws IOException, InvalidConfigurationException, RegistryException + { + try + { + archivaConfiguration.save( configuration ); + addActionMessage( "Successfully saved configuration" ); + } + catch ( IndeterminateConfigurationException e ) + { + addActionError( e.getMessage() ); + return INPUT; + } + + return SUCCESS; + } +} diff --git a/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryAction.java b/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryAction.java new file mode 100644 index 000000000..4e131ba0d --- /dev/null +++ b/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryAction.java @@ -0,0 +1,207 @@ +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.InvalidConfigurationException; +import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; +import org.codehaus.plexus.redback.role.RoleManagerException; +import org.codehaus.plexus.registry.RegistryException; + +import java.io.IOException; + +/** + * Configures the application repositories. + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureRemoteRepositoryAction" + */ +public class ConfigureRemoteRepositoryAction + extends AbstractConfigureRepositoryAction + implements Preparable +{ + /** + * The model for this action. + */ + private RemoteRepositoryConfiguration repository; + + public String add() + { + this.mode = "add"; + + return INPUT; + } + + public String delete() + { + RemoteRepositoryConfiguration existingRepository = repository; + if ( existingRepository == null ) + { + addActionError( "A repository with that id does not exist" ); + return ERROR; + } + + String result; + try + { + Configuration configuration = archivaConfiguration.getConfiguration(); + removeRepository( repoid, configuration ); + result = saveConfiguration( configuration ); + } + catch ( IOException e ) + { + addActionError( "Unable to delete repository: " + e.getMessage() ); + result = INPUT; + } + catch ( InvalidConfigurationException e ) + { + addActionError( "Unable to delete repository: " + e.getMessage() ); + result = INPUT; + } + catch ( RegistryException e ) + { + addActionError( "Unable to delete repository: " + e.getMessage() ); + result = INPUT; + } + + return result; + } + + public RemoteRepositoryConfiguration getRepository() + { + return repository; + } + + public void prepare() + { + String id = repoid; + if ( id == null ) + { + this.repository = new RemoteRepositoryConfiguration(); + } + else + { + this.repository = archivaConfiguration.getConfiguration().findRemoteRepositoryById( id ); + } + } + + public String save() + { + // TODO! share + String repoId = repository.getId(); + + Configuration configuration = archivaConfiguration.getConfiguration(); + boolean containsError = validateFields( configuration ); + + if ( containsError && StringUtils.equalsIgnoreCase( "add", mode ) ) + { + return INPUT; + } + else if ( containsError && StringUtils.equalsIgnoreCase( "edit", this.mode ) ) + { + return ERROR; + } + + if ( StringUtils.equalsIgnoreCase( "edit", this.mode ) ) + { + removeRepository( repoId, configuration ); + } + + String result; + try + { + addRepository( repository, configuration ); + result = saveConfiguration( configuration ); + } + catch ( IOException e ) + { + addActionError( "I/O Exception: " + e.getMessage() ); + result = INPUT; + } + catch ( RoleManagerException e ) + { + addActionError( "Role Manager Exception: " + e.getMessage() ); + result = INPUT; + } + catch ( InvalidConfigurationException e ) + { + addActionError( "Invalid Configuration Exception: " + e.getMessage() ); + result = INPUT; + } + catch ( RegistryException e ) + { + addActionError( "Configuration Registry Exception: " + e.getMessage() ); + result = INPUT; + } + + return result; + } + + private boolean validateFields( Configuration config ) + { + // TODO! share + boolean containsError = false; + String repoId = repository.getId(); + + if ( StringUtils.isBlank( repoId ) ) + { + addFieldError( "repository.id", "You must enter a repository identifier." ); + containsError = true; + } + //if edit mode, do not validate existence of repoId + else if ( ( config.getManagedRepositoriesAsMap().containsKey( repoId ) || + config.getRemoteRepositoriesAsMap().containsKey( repoId ) ) && + !StringUtils.equalsIgnoreCase( mode, "edit" ) ) + { + addFieldError( "repository.id", + "Unable to add new repository with id [" + repoId + "], that id already exists." ); + containsError = true; + } + + if ( StringUtils.isBlank( repository.getUrl() ) ) + { + addFieldError( "repository.url", "You must enter a URL." ); + containsError = true; + } + if ( StringUtils.isBlank( repository.getName() ) ) + { + addFieldError( "repository.name", "You must enter a repository name." ); + containsError = true; + } + + return containsError; + } + + private void addRepository( RemoteRepositoryConfiguration repository, Configuration configuration ) + throws IOException, RoleManagerException + { + configuration.addRemoteRepository( repository ); + } + + private void removeRepository( String repoId, Configuration configuration ) + { + RemoteRepositoryConfiguration toremove = configuration.findRemoteRepositoryById( repoId ); + if ( toremove != null ) + { + configuration.removeRemoteRepository( toremove ); + } + } +} diff --git a/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java b/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java index 1a522b65e..437ef009a 100644 --- a/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java +++ b/MRM-462/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java @@ -22,21 +22,13 @@ package org.apache.maven.archiva.web.action.admin.repositories; import com.opensymphony.xwork.Preparable; import org.apache.commons.io.FileUtils; 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.IndeterminateConfigurationException; import org.apache.maven.archiva.configuration.InvalidConfigurationException; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; -import org.apache.maven.archiva.security.ArchivaRoleConstants; -import org.codehaus.plexus.redback.rbac.Resource; import org.codehaus.plexus.redback.role.RoleManager; import org.codehaus.plexus.redback.role.RoleManagerException; -import org.codehaus.plexus.redback.xwork.interceptor.SecureAction; -import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle; -import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException; import org.codehaus.plexus.registry.RegistryException; import org.codehaus.plexus.scheduler.CronExpressionValidator; -import org.codehaus.plexus.xwork.action.PlexusActionSupport; import java.io.File; import java.io.IOException; @@ -47,28 +39,18 @@ import java.io.IOException; * @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureRepositoryAction" */ public class ConfigureRepositoryAction - extends PlexusActionSupport - implements Preparable, SecureAction + extends AbstractConfigureRepositoryAction + implements Preparable { /** - * @plexus.requirement role-hint="default" - */ - private RoleManager roleManager; - - /** - * @plexus.requirement + * The model for this action. */ - private ArchivaConfiguration archivaConfiguration; - - private String repoid; - - // TODO! consider removing? was just meant to be for delete... - private String mode; + private AdminRepositoryConfiguration repository; /** - * The model for this action. + * @plexus.requirement role-hint="default" */ - private AdminRepositoryConfiguration repository; + protected RoleManager roleManager; public String add() { @@ -80,12 +62,6 @@ public class ConfigureRepositoryAction return INPUT; } - // TODO: rename to confirmDelete - public String confirm() - { - return INPUT; - } - public String delete() { String result = SUCCESS; @@ -140,39 +116,11 @@ public class ConfigureRepositoryAction return result; } - public String edit() - { - this.mode = "edit"; - - return INPUT; - } - - public String getMode() - { - return this.mode; - } - - public String getRepoid() - { - return repoid; - } - public AdminRepositoryConfiguration getRepository() { return repository; } - public SecureActionBundle getSecureActionBundle() - throws SecureActionException - { - SecureActionBundle bundle = new SecureActionBundle(); - - bundle.setRequiresAuthentication( true ); - bundle.addRequiredAuthorization( ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION, Resource.GLOBAL ); - - return bundle; - } - public void prepare() { String id = repoid; @@ -183,7 +131,6 @@ public class ConfigureRepositoryAction this.repository.setIndexed( false ); } - // TODO! others? ManagedRepositoryConfiguration repoconfig = archivaConfiguration.getConfiguration().findManagedRepositoryById( id ); if ( repoconfig != null ) @@ -264,7 +211,6 @@ public class ConfigureRepositoryAction containsError = true; } - // TODO! split if ( StringUtils.isBlank( repository.getLocation() ) ) { addFieldError( "repository.location", "You must enter a directory." ); @@ -284,16 +230,6 @@ public class ConfigureRepositoryAction return containsError; } - public void setMode( String mode ) - { - this.mode = mode; - } - - public void setRepoid( String repoid ) - { - this.repoid = repoid; - } - private void addRepository( AdminRepositoryConfiguration repository, Configuration configuration ) throws IOException, RoleManagerException { @@ -306,7 +242,6 @@ public class ConfigureRepositoryAction // TODO: error handling when this fails, or is not a directory! } - // TODO! others configuration.addManagedRepository( repository ); // TODO: double check these are configured on start up @@ -324,7 +259,6 @@ public class ConfigureRepositoryAction private void removeRepository( String repoId, Configuration configuration ) { - // TODO! what about others? ManagedRepositoryConfiguration toremove = configuration.findManagedRepositoryById( repoId ); if ( toremove != null ) { @@ -341,31 +275,8 @@ public class ConfigureRepositoryAction getLogger().debug( "removed user roles associated with repository " + existingRepository.getId() ); } - private String saveConfiguration( Configuration configuration ) - throws IOException, InvalidConfigurationException, RegistryException - { - try - { - archivaConfiguration.save( configuration ); - addActionMessage( "Successfully saved configuration" ); - } - catch ( IndeterminateConfigurationException e ) - { - addActionError( e.getMessage() ); - return INPUT; - } - - return SUCCESS; - } - public void setRoleManager( RoleManager roleManager ) { this.roleManager = roleManager; } - - public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration ) - { - this.archivaConfiguration = archivaConfiguration; - } - } diff --git a/MRM-462/archiva-web/archiva-webapp/src/main/resources/xwork.xml b/MRM-462/archiva-web/archiva-webapp/src/main/resources/xwork.xml index f196c655c..b993d7dfb 100644 --- a/MRM-462/archiva-web/archiva-webapp/src/main/resources/xwork.xml +++ b/MRM-462/archiva-web/archiva-webapp/src/main/resources/xwork.xml @@ -254,6 +254,32 @@ + + /WEB-INF/jsp/admin/addRemoteRepository.jsp + repositories + + + + + /WEB-INF/jsp/admin/editRemoteRepository.jsp + repositories + repositories + + + + + repositories + /WEB-INF/jsp/admin/editRemoteRepository.jsp + /WEB-INF/jsp/admin/editRemoteRepository.jsp + + + + + /WEB-INF/jsp/admin/deleteRemoteRepository.jsp + repositories + + + diff --git a/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRemoteRepository.jsp b/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRemoteRepository.jsp new file mode 100644 index 000000000..d117df164 --- /dev/null +++ b/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRemoteRepository.jsp @@ -0,0 +1,51 @@ +<%-- + ~ 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: Add Repository + + + + + +

Admin: Add Repository

+ +
+ +

Add Repository

+ + + + + + <%@ include file="/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf" %> + + + + + +
+ + + diff --git a/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRemoteRepository.jsp b/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRemoteRepository.jsp new file mode 100644 index 000000000..da23fdcdb --- /dev/null +++ b/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRemoteRepository.jsp @@ -0,0 +1,54 @@ +<%-- + ~ 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 + + + + + +

Admin: Delete Repository

+ + + +
+ +

Delete Repository

+ +
+ WARNING: This operation can not be undone. +
+ +

+ Are you sure you want to delete the repository [ ${repoid} ] ? +

+ + + + + + +
+ + + \ No newline at end of file diff --git a/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRemoteRepository.jsp b/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRemoteRepository.jsp new file mode 100644 index 000000000..545d51360 --- /dev/null +++ b/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRemoteRepository.jsp @@ -0,0 +1,53 @@ +<%-- + ~ 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: Edit Repository + + + + + +

Admin: Edit Repository

+ + + +
+ +

Edit Repository

+ + + + + + <%@ include file="/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf" %> + + + + + +
+ + + \ No newline at end of file diff --git a/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf b/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf new file mode 100644 index 000000000..d5316de8e --- /dev/null +++ b/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf @@ -0,0 +1,25 @@ +<%-- + ~ 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" %> + + + + diff --git a/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp b/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp index 4cca99fde..484f60d0f 100644 --- a/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp +++ b/MRM-462/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp @@ -43,7 +43,7 @@ " alt="" width="16" height="16"/> - Add Repository + Add @@ -80,11 +80,11 @@ " alt="" width="16" height="16"/> - Edit Repository + Edit " alt="" width="16" height="16"/> - Delete Repository + Delete @@ -226,6 +226,15 @@ +
+ + + + " alt="" width="16" height="16"/> + Add + + +

Remote Repositories

@@ -235,7 +244,6 @@ <%-- Display the repositories. --%> - @@ -250,19 +258,19 @@
- + - + " alt="" width="16" height="16"/> - Edit Repository + Edit " alt="" width="16" height="16"/> - Delete Repository + Delete
diff --git a/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.java b/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.java new file mode 100644 index 000000000..3200bf57f --- /dev/null +++ b/MRM-462/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.java @@ -0,0 +1,299 @@ +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.Action; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; +import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException; +import org.codehaus.plexus.registry.RegistryException; +import org.easymock.MockControl; + +import java.util.Collections; + +/** + * Test the repositories action returns the correct data. + */ +public class ConfigureRemoteRepositoryActionTest + extends PlexusTestCase +{ + private ConfigureRemoteRepositoryAction action; + + private MockControl archivaConfigurationControl; + + private ArchivaConfiguration archivaConfiguration; + + private static final String REPO_ID = "remote-repo-ident"; + + protected void setUp() + throws Exception + { + super.setUp(); + + // TODO: purely to quiet logging - shouldn't be needed + String appserverBase = getTestFile( "target/appserver-base" ).getAbsolutePath(); + System.setProperty( "appserver.base", appserverBase ); + action = (ConfigureRemoteRepositoryAction) lookup( Action.class.getName(), "configureRemoteRepositoryAction" ); + + 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 testAddRemoteRepositoryInitialPage() + throws Exception + { + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( new Configuration() ); + archivaConfigurationControl.replay(); + + action.prepare(); + assertNull( action.getRepoid() ); + assertNull( action.getMode() ); + RemoteRepositoryConfiguration configuration = action.getRepository(); + assertNotNull( configuration ); + assertNull( configuration.getId() ); + + String status = action.add(); + assertEquals( Action.INPUT, status ); + } + + public void testAddRemoteRepository() + throws Exception + { + Configuration configuration = new Configuration(); + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + + archivaConfiguration.save( configuration ); + + archivaConfigurationControl.replay(); + + action.prepare(); + action.setMode( "add" ); + RemoteRepositoryConfiguration repository = action.getRepository(); + populateRepository( repository ); + + String status = action.save(); + assertEquals( Action.SUCCESS, status ); + + assertEquals( Collections.singletonList( repository ), configuration.getRemoteRepositories() ); + + archivaConfigurationControl.verify(); + } + + public void testEditRemoteRepositoryInitialPage() + throws Exception + { + Configuration configuration = createConfigurationForEditing( createRepository() ); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + archivaConfigurationControl.replay(); + + action.setRepoid( REPO_ID ); + + action.prepare(); + assertEquals( REPO_ID, action.getRepoid() ); + assertNull( action.getMode() ); + RemoteRepositoryConfiguration repository = action.getRepository(); + assertNotNull( repository ); + assertRepositoryEquals( repository, createRepository() ); + + String status = action.edit(); + assertEquals( Action.INPUT, status ); + repository = action.getRepository(); + assertRepositoryEquals( repository, createRepository() ); + } + + public void testEditRemoteRepository() + throws Exception + { + Configuration configuration = createConfigurationForEditing( createRepository() ); + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + + archivaConfiguration.save( configuration ); + + archivaConfigurationControl.replay(); + + action.prepare(); + action.setMode( "edit" ); + RemoteRepositoryConfiguration repository = action.getRepository(); + populateRepository( repository ); + repository.setName( "new repo name" ); + + String status = action.save(); + assertEquals( Action.SUCCESS, status ); + + RemoteRepositoryConfiguration newRepository = createRepository(); + newRepository.setName( "new repo name" ); + assertRepositoryEquals( repository, newRepository ); + assertEquals( Collections.singletonList( repository ), configuration.getRemoteRepositories() ); + + archivaConfigurationControl.verify(); + } + + public void testDeleteRemoteRepositoryConfirmation() + { + RemoteRepositoryConfiguration originalRepository = createRepository(); + Configuration configuration = createConfigurationForEditing( originalRepository ); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + archivaConfigurationControl.replay(); + + action.setRepoid( REPO_ID ); + + action.prepare(); + assertEquals( REPO_ID, action.getRepoid() ); + assertNull( action.getMode() ); + RemoteRepositoryConfiguration repository = action.getRepository(); + assertNotNull( repository ); + assertRepositoryEquals( repository, createRepository() ); + + String status = action.confirm(); + assertEquals( Action.INPUT, status ); + repository = action.getRepository(); + assertRepositoryEquals( repository, createRepository() ); + assertEquals( Collections.singletonList( originalRepository ), configuration.getRemoteRepositories() ); + } + + public void testDeleteRemoteRepositoryKeepContent() + throws RegistryException, IndeterminateConfigurationException + { + Configuration configuration = executeDeletionTest( "delete-entry", createRepository() ); + + assertTrue( configuration.getRemoteRepositories().isEmpty() ); + } + + public void testDeleteRemoteRepositoryCancelled() + throws Exception + { + RemoteRepositoryConfiguration originalRepository = createRepository(); + Configuration configuration = createConfigurationForEditing( originalRepository ); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + + archivaConfiguration.save( configuration ); + archivaConfigurationControl.replay(); + + action.setRepoid( REPO_ID ); + action.setMode( "unmodified" ); // TODO! remove + + action.prepare(); + assertEquals( REPO_ID, action.getRepoid() ); + assertEquals( "unmodified", action.getMode() ); + RemoteRepositoryConfiguration repositoryConfiguration = action.getRepository(); + assertNotNull( repositoryConfiguration ); + assertRepositoryEquals( repositoryConfiguration, createRepository() ); + + String status = action.execute(); + assertEquals( Action.SUCCESS, status ); + + RemoteRepositoryConfiguration repository = action.getRepository(); + assertRepositoryEquals( repository, createRepository() ); + assertEquals( Collections.singletonList( originalRepository ), configuration.getRemoteRepositories() ); + } + + private Configuration executeDeletionTest( String mode, RemoteRepositoryConfiguration originalRepository ) + throws RegistryException, IndeterminateConfigurationException + { + Configuration configuration = createConfigurationForEditing( originalRepository ); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + + archivaConfiguration.save( configuration ); + archivaConfigurationControl.replay(); + + action.setRepoid( REPO_ID ); + action.setMode( mode ); // TODO! remove + + action.prepare(); + assertEquals( REPO_ID, action.getRepoid() ); + assertEquals( mode, action.getMode() ); + RemoteRepositoryConfiguration repository = action.getRepository(); + assertNotNull( repository ); + assertRepositoryEquals( repository, createRepository() ); + + String status = action.delete(); + assertEquals( Action.SUCCESS, status ); + return configuration; + } + + private void assertRepositoryEquals( RemoteRepositoryConfiguration expectedRepository, + RemoteRepositoryConfiguration actualRepository ) + { + assertEquals( expectedRepository.getId(), actualRepository.getId() ); + assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() ); + assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() ); + assertEquals( expectedRepository.getName(), actualRepository.getName() ); + } + + private Configuration createConfigurationForEditing( RemoteRepositoryConfiguration repositoryConfiguration ) + { + Configuration configuration = new Configuration(); + configuration.addRemoteRepository( repositoryConfiguration ); + return configuration; + } + + private RemoteRepositoryConfiguration createRepository() + { + RemoteRepositoryConfiguration r = new RemoteRepositoryConfiguration(); + r.setId( REPO_ID ); + populateRepository( r ); + return r; + } + + private void populateRepository( RemoteRepositoryConfiguration repository ) + { + repository.setId( REPO_ID ); + repository.setName( "repo name" ); + repository.setUrl( "url" ); + repository.setLayout( "default" ); + } + + // TODO: test errors during add, other actions + // TODO: what if there are proxy connectors attached to a deleted repository? + // TODO: what about removing proxied content if a proxy is removed? +} diff --git a/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.xml b/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.xml new file mode 100644 index 000000000..ed67e65aa --- /dev/null +++ b/MRM-462/archiva-web/archiva-webapp/src/test/resources/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.xml @@ -0,0 +1,35 @@ + + + + + + org.codehaus.plexus.logging.LoggerManager + org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager + basic + + + com.opensymphony.xwork.Action + configureRemoteRepositoryAction + org.apache.maven.archiva.web.action.admin.repositories.ConfigureRemoteRepositoryAction + + per-lookup + + +