diff options
31 files changed, 1917 insertions, 773 deletions
diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesAction.java new file mode 100644 index 000000000..9d702581e --- /dev/null +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractManagedRepositoriesAction.java @@ -0,0 +1,107 @@ +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.commons.io.FileUtils; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.codehaus.plexus.redback.role.RoleManager; +import org.codehaus.plexus.redback.role.RoleManagerException; + +import java.io.File; +import java.io.IOException; + +/** + * Abstract ManagedRepositories Action. + * + * Place for all generic methods used in Managed Repository Administration. + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + */ +public abstract class AbstractManagedRepositoriesAction + extends AbstractRepositoriesAdminAction +{ + /** + * @plexus.requirement role-hint="default" + */ + protected RoleManager roleManager; + + public RoleManager getRoleManager() + { + return roleManager; + } + + public void setRoleManager( RoleManager roleManager ) + { + this.roleManager = roleManager; + } + + protected void addRepository( ManagedRepositoryConfiguration repository, Configuration configuration ) + throws IOException + { + // Normalize the path + File file = new File( repository.getLocation() ); + repository.setLocation( file.getCanonicalPath() ); + if ( !file.exists() ) + { + file.mkdirs(); + } + if ( !file.exists() || !file.isDirectory() ) + { + throw new IOException( "unable to add repository - can not create the root directory: " + file ); + } + + configuration.addManagedRepository( repository ); + + } + + protected void addRepositoryRoles( ManagedRepositoryConfiguration newRepository ) throws RoleManagerException + { + // TODO: double check these are configured on start up + // TODO: belongs in the business logic + roleManager.createTemplatedRole( "archiva-repository-manager", newRepository.getId() ); + roleManager.createTemplatedRole( "archiva-repository-observer", newRepository.getId() ); + } + + protected void removeContents( ManagedRepositoryConfiguration existingRepository ) + throws IOException + { + FileUtils.deleteDirectory( new File( existingRepository.getLocation() ) ); + } + + protected void removeRepository( String repoId, Configuration configuration ) + { + ManagedRepositoryConfiguration toremove = configuration.findManagedRepositoryById( repoId ); + if ( toremove != null ) + { + configuration.removeManagedRepository( toremove ); + } + } + + protected void removeRepositoryRoles( ManagedRepositoryConfiguration existingRepository ) + throws RoleManagerException + { + roleManager.removeTemplatedRole( "archiva-repository-manager", existingRepository.getId() ); + roleManager.removeTemplatedRole( "archiva-repository-observer", existingRepository.getId() ); + + getLogger().debug( "removed user roles associated with repository " + existingRepository.getId() ); + } +} diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRemoteRepositoriesAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRemoteRepositoriesAction.java new file mode 100644 index 000000000..9285c24c3 --- /dev/null +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRemoteRepositoriesAction.java @@ -0,0 +1,51 @@ +package org.apache.maven.archiva.web.action.admin.repositories; + +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; +import org.codehaus.plexus.redback.role.RoleManagerException; + +import java.io.IOException; + +/* + * 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. + */ + +/** + * AbstractRemoteRepositoriesAction + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + */ +public class AbstractRemoteRepositoriesAction + extends AbstractRepositoriesAdminAction +{ + protected void addRepository( RemoteRepositoryConfiguration repository, Configuration configuration ) + throws IOException, RoleManagerException + { + configuration.addRemoteRepository( repository ); + } + + protected void removeRepository( String repoId, Configuration configuration ) + { + RemoteRepositoryConfiguration toremove = configuration.findRemoteRepositoryById( repoId ); + if ( toremove != null ) + { + configuration.removeRemoteRepository( toremove ); + } + } +} diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractConfigureRepositoryAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java index e7fc463e3..9d7660d68 100644 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractConfigureRepositoryAction.java +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AbstractRepositoriesAdminAction.java @@ -19,14 +19,12 @@ package org.apache.maven.archiva.web.action.admin.repositories; * under the License. */ -import org.apache.maven.archiva.configuration.AbstractRepositoryConfiguration; 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.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; @@ -36,32 +34,26 @@ import org.codehaus.plexus.xwork.action.PlexusActionSupport; import java.io.IOException; /** - * Base class for repository configuration actions. + * Abstract AdminRepositories Action base. + * + * Base class for all repository administrative functions. + * This should be neutral to the type of action (add/edit/delete) and type of repo (managed/remote) + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ */ -public abstract class AbstractConfigureRepositoryAction<T extends AbstractRepositoryConfiguration> +public abstract class AbstractRepositoriesAdminAction extends PlexusActionSupport implements SecureAction { /** - * The model for this action. - */ - protected T repository; - - /** * @plexus.requirement */ protected ArchivaConfiguration archivaConfiguration; - protected String repoid; - - public String getRepoid() + public ArchivaConfiguration getArchivaConfiguration() { - return repoid; - } - - public T getRepository() - { - return repository; + return archivaConfiguration; } public SecureActionBundle getSecureActionBundle() @@ -75,18 +67,21 @@ public abstract class AbstractConfigureRepositoryAction<T extends AbstractReposi return bundle; } - public void setRepoid( String repoid ) - { - this.repoid = repoid; - } - public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration ) { this.archivaConfiguration = archivaConfiguration; } + /** + * Save the configuration. + * + * @param configuration the configuration to save. + * @return the webwork result code to issue. + * @throws IOException thrown if unable to save file to disk. + * @throws InvalidConfigurationException thrown if configuration is invalid. + * @throws RegistryException thrown if configuration subsystem has a problem saving the configuration to disk. + */ protected String saveConfiguration( Configuration configuration ) - throws IOException, InvalidConfigurationException, RegistryException { try { @@ -96,85 +91,14 @@ public abstract class AbstractConfigureRepositoryAction<T extends AbstractReposi catch ( IndeterminateConfigurationException e ) { addActionError( e.getMessage() ); - return ERROR; - } - - return SUCCESS; - } - - public String add() - { - Configuration configuration = archivaConfiguration.getConfiguration(); - - String repoId = repository.getId(); - if ( configuration.getManagedRepositoriesAsMap().containsKey( repoId ) || - configuration.getRemoteRepositoriesAsMap().containsKey( repoId ) ) - { - addFieldError( "repository.id", - "Unable to add new repository with id [" + repoId + "], that id already exists." ); - return INPUT; - } - - boolean containsError = validateFields( configuration ); - if ( containsError ) - { - return INPUT; - } - - return saveRepositoryConfiguration( configuration ); - } - - public String edit() - { - Configuration configuration = archivaConfiguration.getConfiguration(); - - boolean containsError = validateFields( configuration ); - if ( containsError ) - { return INPUT; } - - removeRepository( repository.getId(), configuration ); - - return saveRepositoryConfiguration( configuration ); - } - - protected String saveRepositoryConfiguration( Configuration configuration ) - { - String result; - try - { - addRepository( repository, configuration ); - result = saveConfiguration( configuration ); - } - catch ( IOException e ) - { - addActionError( "I/O Exception: " + e.getMessage() ); - result = ERROR; - } - catch ( InvalidConfigurationException e ) - { - addActionError( "Invalid Configuration Exception: " + e.getMessage() ); - result = ERROR; - } catch ( RegistryException e ) { addActionError( "Configuration Registry Exception: " + e.getMessage() ); - result = ERROR; - } - catch ( RoleManagerException e ) - { - addActionError( "Security role creation Exception: " + e.getMessage() ); - result = ERROR; + return INPUT; } - return result; + return SUCCESS; } - - protected abstract boolean validateFields( Configuration config ); - - protected abstract void addRepository( T repository, Configuration configuration ) - throws IOException, RoleManagerException; - - protected abstract void removeRepository( String repoId, Configuration configuration ); } diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java new file mode 100644 index 000000000..a209d9da8 --- /dev/null +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction.java @@ -0,0 +1,123 @@ +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 com.opensymphony.xwork.Validateable; + +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.codehaus.plexus.redback.role.RoleManagerException; +import org.codehaus.plexus.scheduler.CronExpressionValidator; + +import java.io.IOException; + +/** + * AddManagedRepositoryAction + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="addManagedRepositoryAction" + */ +public class AddManagedRepositoryAction + extends AbstractManagedRepositoriesAction + implements Preparable, Validateable +{ + /** + * The model for this action. + */ + private ManagedRepositoryConfiguration repository; + + public void prepare() + { + this.repository = new ManagedRepositoryConfiguration(); + this.repository.setReleases( false ); + this.repository.setScanned( false ); + } + + public String input() + { + this.repository.setReleases( true ); + this.repository.setScanned( true ); + + return INPUT; + } + + public String commit() + { + Configuration configuration = archivaConfiguration.getConfiguration(); + + String result; + try + { + addRepository( repository, configuration ); + addRepositoryRoles( repository ); + result = saveConfiguration( configuration ); + } + catch ( RoleManagerException e ) + { + addActionError( "Role Manager Exception: " + e.getMessage() ); + result = INPUT; + } + catch ( IOException e ) + { + addActionError( "Role Manager Exception: " + e.getMessage() ); + result = INPUT; + } + + return result; + } + + @Override + public void validate() + { + Configuration config = archivaConfiguration.getConfiguration(); + + CronExpressionValidator validator = new CronExpressionValidator(); + String repoId = repository.getId(); + + if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) ) + { + addFieldError( "repository.id", "Unable to add new repository with id [" + repoId + + "], that id already exists as a managed repository." ); + } + else if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) ) + { + addFieldError( "repository.id", "Unable to add new repository with id [" + repoId + + "], that id already exists as a remote repository." ); + } + + if ( !validator.validate( repository.getRefreshCronExpression() ) ) + { + addFieldError( "repository.refreshCronExpression", "Invalid cron expression." ); + } + } + + public ManagedRepositoryConfiguration getRepository() + { + return repository; + } + + public void setRepository( ManagedRepositoryConfiguration repository ) + { + this.repository = repository; + } +} diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryAction.java new file mode 100644 index 000000000..921de1b88 --- /dev/null +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryAction.java @@ -0,0 +1,111 @@ +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 com.opensymphony.xwork.Validateable; + +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; +import org.codehaus.plexus.redback.role.RoleManagerException; + +import java.io.IOException; + +/** + * AddRemoteRepositoryAction + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="addRemoteRepositoryAction" + */ +public class AddRemoteRepositoryAction + extends AbstractRemoteRepositoriesAction + implements Preparable, Validateable +{ + /** + * The model for this action. + */ + private RemoteRepositoryConfiguration repository; + + public void prepare() + { + this.repository = new RemoteRepositoryConfiguration(); + } + + public String input() + { + return INPUT; + } + + public String commit() + { + Configuration configuration = archivaConfiguration.getConfiguration(); + + // Save the repository 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; + } + + return result; + } + + @Override + public void validate() + { + Configuration config = archivaConfiguration.getConfiguration(); + + String repoId = repository.getId(); + + if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) ) + { + addFieldError( "repository.id", "Unable to add new repository with id [" + repoId + + "], that id already exists as a managed repository." ); + } + else if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) ) + { + addFieldError( "repository.id", "Unable to add new repository with id [" + repoId + + "], that id already exists as a remote repository." ); + } + } + + public RemoteRepositoryConfiguration getRepository() + { + return repository; + } + + public void setRepository( RemoteRepositoryConfiguration repository ) + { + this.repository = repository; + } +} diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryAction.java deleted file mode 100644 index a34e448f8..000000000 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryAction.java +++ /dev/null @@ -1,131 +0,0 @@ -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.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<RemoteRepositoryConfiguration> - implements Preparable -{ - public String delete() - { - if ( repository == 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 = ERROR; - } - catch ( InvalidConfigurationException e ) - { - addActionError( "Unable to delete repository: " + e.getMessage() ); - result = ERROR; - } - catch ( RegistryException e ) - { - addActionError( "Unable to delete repository: " + e.getMessage() ); - result = ERROR; - } - - return result; - } - - public void prepare() - { - String id = repoid; - if ( id == null ) - { - this.repository = new RemoteRepositoryConfiguration(); - } - else - { - this.repository = archivaConfiguration.getConfiguration().findRemoteRepositoryById( id ); - } - } - - protected boolean validateFields( Configuration config ) - { - // TODO: push this into the webwork validation instead - boolean containsError = false; - String repoId = repository.getId(); - - if ( StringUtils.isBlank( repoId ) ) - { - addFieldError( "repository.id", "You must enter a repository identifier." ); - 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; - } - - protected void addRepository( RemoteRepositoryConfiguration repository, Configuration configuration ) - { - configuration.addRemoteRepository( repository ); - } - - protected void removeRepository( String repoId, Configuration configuration ) - { - RemoteRepositoryConfiguration toremove = configuration.findRemoteRepositoryById( repoId ); - if ( toremove != null ) - { - configuration.removeRemoteRepository( toremove ); - } - } - - public String input() - { - return INPUT; - } -} diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java deleted file mode 100644 index b54a11bde..000000000 --- a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryAction.java +++ /dev/null @@ -1,222 +0,0 @@ -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.io.FileUtils; -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.ManagedRepositoryConfiguration; -import org.codehaus.plexus.redback.role.RoleManager; -import org.codehaus.plexus.redback.role.RoleManagerException; -import org.codehaus.plexus.registry.RegistryException; -import org.codehaus.plexus.scheduler.CronExpressionValidator; - -import java.io.File; -import java.io.IOException; - -/** - * Configures the managed repositories. - * - * @plexus.component role="com.opensymphony.xwork.Action" role-hint="configureRepositoryAction" - */ -public class ConfigureRepositoryAction - extends AbstractConfigureRepositoryAction<ManagedRepositoryConfiguration> - implements Preparable -{ - /** - * @plexus.requirement role-hint="default" - */ - protected RoleManager roleManager; - - private String deleteMode = "delete-entry"; - - public String getDeleteMode() - { - return deleteMode; - } - - public void setDeleteMode( String deleteMode ) - { - this.deleteMode = deleteMode; - } - - public String addInput() - { - // set defaults - this.repository.setReleases( true ); - this.repository.setScanned( true ); - - return INPUT; - } - - public String editInput() - { - return INPUT; - } - - public String delete() - { - if ( repository == 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 ); - - if ( result.equals( SUCCESS ) ) - { - removeRepositoryRoles( repository ); - if ( StringUtils.equals( deleteMode, "delete-contents" ) ) - { - removeContents( repository ); - } - } - } - catch ( IOException e ) - { - addActionError( "Unable to delete repository: " + e.getMessage() ); - result = ERROR; - } - catch ( RoleManagerException e ) - { - addActionError( "Unable to delete repository: " + e.getMessage() ); - result = ERROR; - } - catch ( InvalidConfigurationException e ) - { - addActionError( "Unable to delete repository: " + e.getMessage() ); - result = ERROR; - } - catch ( RegistryException e ) - { - addActionError( "Unable to delete repository: " + e.getMessage() ); - result = ERROR; - } - - return result; - } - - public void prepare() - { - String id = repoid; - if ( id == null ) - { - this.repository = new ManagedRepositoryConfiguration(); - this.repository.setReleases( false ); - this.repository.setScanned( false ); - } - else - { - repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( id ); - } - } - - protected boolean validateFields( Configuration config ) - { - boolean containsError = false; - CronExpressionValidator validator = new CronExpressionValidator(); - String repoId = repository.getId(); - - if ( StringUtils.isBlank( repoId ) ) - { - addFieldError( "repository.id", "You must enter a repository identifier." ); - containsError = true; - } - - if ( StringUtils.isBlank( repository.getLocation() ) ) - { - addFieldError( "repository.location", "You must enter a directory." ); - containsError = true; - } - if ( StringUtils.isBlank( repository.getName() ) ) - { - addFieldError( "repository.name", "You must enter a repository name." ); - containsError = true; - } - if ( !validator.validate( repository.getRefreshCronExpression() ) ) - { - addFieldError( "repository.refreshCronExpression", "Invalid cron expression." ); - containsError = true; - } - - return containsError; - } - - protected void addRepository( ManagedRepositoryConfiguration repository, Configuration configuration ) - throws IOException, RoleManagerException - { - // Normalize the path - File file = new File( repository.getLocation() ); - repository.setLocation( file.getCanonicalPath() ); - if ( !file.exists() ) - { - file.mkdirs(); - } - if ( !file.exists() || !file.isDirectory() ) - { - throw new IOException( "unable to add repository - can not create the root directory: " + file ); - } - - configuration.addManagedRepository( repository ); - - // TODO: double check these are configured on start up - // TODO: belongs in the business logic - roleManager.createTemplatedRole( "archiva-repository-manager", repository.getId() ); - - roleManager.createTemplatedRole( "archiva-repository-observer", repository.getId() ); - } - - private void removeContents( ManagedRepositoryConfiguration existingRepository ) - throws IOException - { - FileUtils.deleteDirectory( new File( existingRepository.getLocation() ) ); - } - - protected void removeRepository( String repoId, Configuration configuration ) - { - ManagedRepositoryConfiguration toremove = configuration.findManagedRepositoryById( repoId ); - if ( toremove != null ) - { - configuration.removeManagedRepository( toremove ); - } - } - - private void removeRepositoryRoles( ManagedRepositoryConfiguration existingRepository ) - throws RoleManagerException - { - roleManager.removeTemplatedRole( "archiva-repository-manager", existingRepository.getId() ); - roleManager.removeTemplatedRole( "archiva-repository-observer", existingRepository.getId() ); - - getLogger().debug( "removed user roles associated with repository " + existingRepository.getId() ); - } - - public void setRoleManager( RoleManager roleManager ) - { - this.roleManager = roleManager; - } -} diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java new file mode 100644 index 000000000..ece130ca5 --- /dev/null +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryAction.java @@ -0,0 +1,148 @@ +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.ManagedRepositoryConfiguration; +import org.codehaus.plexus.redback.role.RoleManagerException; + +import java.io.IOException; + +/** + * DeleteManagedRepositoryAction + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="deleteManagedRepositoryAction" + */ +public class DeleteManagedRepositoryAction + extends AbstractManagedRepositoriesAction + implements Preparable +{ + private ManagedRepositoryConfiguration repository; + + private String repoid; + + public void prepare() + { + if ( StringUtils.isNotBlank( repoid ) ) + { + this.repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid ); + } + } + + public String confirmDelete() + { + if ( StringUtils.isBlank( repoid ) ) + { + addActionError( "Unable to delete managed repository: repository id was blank." ); + return ERROR; + } + + return INPUT; + } + + public String deleteEntry() + { + return deleteRepository( false ); + } + + public String deleteContents() + { + return deleteRepository( true ); + } + + private String deleteRepository( boolean deleteContents ) + { + ManagedRepositoryConfiguration existingRepository = repository; + if ( existingRepository == null ) + { + addActionError( "A repository with that id does not exist" ); + return ERROR; + } + + String result = SUCCESS; + + try + { + Configuration configuration = archivaConfiguration.getConfiguration(); + removeRepository( repoid, configuration ); + result = saveConfiguration( configuration ); + + if ( result.equals( SUCCESS ) ) + { + cleanupRepositoryData( existingRepository ); + + if ( deleteContents ) + { + removeContents( existingRepository ); + } + } + } + catch ( IOException e ) + { + addActionError( "Unable to delete repository: " + e.getMessage() ); + result = ERROR; + } + catch ( RoleManagerException e ) + { + addActionError( "Unable to delete repository: " + e.getMessage() ); + result = ERROR; + } + + return result; + } + + private void cleanupRepositoryData( ManagedRepositoryConfiguration cleanupRepository ) + throws RoleManagerException + { + removeRepositoryRoles( cleanupRepository ); + + // TODO: [MRM-382] Remove index from artifacts of deleted managed repositories. + + // TODO: [MRM-265] After removing a managed repository - Browse/Search still see it + + // TODO: [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository. + } + + public ManagedRepositoryConfiguration getRepository() + { + return repository; + } + + public void setRepository( ManagedRepositoryConfiguration repository ) + { + this.repository = repository; + } + + public String getRepoid() + { + return repoid; + } + + public void setRepoid( String repoid ) + { + this.repoid = repoid; + } +} diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java new file mode 100644 index 000000000..620c5ba3c --- /dev/null +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryAction.java @@ -0,0 +1,106 @@ +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.RemoteRepositoryConfiguration; + +/** + * DeleteRemoteRepositoryAction + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="deleteRemoteRepositoryAction" + */ +public class DeleteRemoteRepositoryAction + extends AbstractRemoteRepositoriesAction + implements Preparable +{ + private RemoteRepositoryConfiguration repository; + + private String repoid; + + public void prepare() + { + if ( StringUtils.isNotBlank( repoid ) ) + { + this.repository = archivaConfiguration.getConfiguration().findRemoteRepositoryById( repoid ); + } + } + + public String confirmDelete() + { + if ( StringUtils.isBlank( repoid ) ) + { + addActionError( "Unable to delete remote repository: repository id was blank." ); + return ERROR; + } + + return INPUT; + } + + public String delete() + { + String result = SUCCESS; + RemoteRepositoryConfiguration existingRepository = repository; + if ( existingRepository == null ) + { + addActionError( "A repository with that id does not exist" ); + return ERROR; + } + + Configuration configuration = archivaConfiguration.getConfiguration(); + removeRepository( repoid, configuration ); + result = saveConfiguration( configuration ); + + cleanupRepositoryData( existingRepository ); + + return result; + } + + private void cleanupRepositoryData( RemoteRepositoryConfiguration existingRepository ) + { + // TODO: [MRM-520] Proxy Connectors are not deleted with the deletion of a Repository. + } + + public RemoteRepositoryConfiguration getRepository() + { + return repository; + } + + public void setRepository( RemoteRepositoryConfiguration repository ) + { + this.repository = repository; + } + + public String getRepoid() + { + return repoid; + } + + public void setRepoid( String repoid ) + { + this.repoid = repoid; + } +} diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java new file mode 100644 index 000000000..9ef652190 --- /dev/null +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction.java @@ -0,0 +1,131 @@ +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 com.opensymphony.xwork.Validateable; + +import org.apache.commons.lang.StringUtils; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.codehaus.plexus.redback.role.RoleManagerException; +import org.codehaus.plexus.scheduler.CronExpressionValidator; + +import java.io.IOException; + +/** + * AddManagedRepositoryAction + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="editManagedRepositoryAction" + */ +public class EditManagedRepositoryAction + extends AbstractManagedRepositoriesAction + implements Preparable, Validateable +{ + /** + * The model for this action. + */ + private ManagedRepositoryConfiguration repository; + + private String repoid; + + public void prepare() + { + if ( StringUtils.isNotBlank( repoid ) ) + { + repository = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoid ); + } + } + + public String input() + { + if ( repository == null ) + { + addActionError( "Edit failure, unable to edit a repository with a blank repository id." ); + return ERROR; + } + + return INPUT; + } + + public String commit() + { + // Ensure that the fields are valid. + Configuration configuration = archivaConfiguration.getConfiguration(); + + // We are in edit mode, remove the old repository configuration. + removeRepository( repository.getId(), configuration ); + + // Save the repository configuration. + String result; + try + { + addRepository( repository, configuration ); + addRepositoryRoles( repository ); + result = saveConfiguration( configuration ); + } + catch ( IOException e ) + { + addActionError( "I/O Exception: " + e.getMessage() ); + result = ERROR; + } + catch ( RoleManagerException e ) + { + addActionError( "Role Manager Exception: " + e.getMessage() ); + result = ERROR; + } + + return result; + } + + @Override + public void validate() + { + CronExpressionValidator validator = new CronExpressionValidator(); + + if ( !validator.validate( repository.getRefreshCronExpression() ) ) + { + addFieldError( "repository.refreshCronExpression", "Invalid cron expression." ); + } + } + + public String getRepoid() + { + return repoid; + } + + public void setRepoid( String repoid ) + { + this.repoid = repoid; + } + + public ManagedRepositoryConfiguration getRepository() + { + return repository; + } + + public void setRepository( ManagedRepositoryConfiguration repository ) + { + this.repository = repository; + } +} diff --git a/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryAction.java b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryAction.java new file mode 100644 index 000000000..4d025ff81 --- /dev/null +++ b/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryAction.java @@ -0,0 +1,120 @@ +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.RemoteRepositoryConfiguration; +import org.codehaus.plexus.redback.role.RoleManagerException; + +import java.io.IOException; + +/** + * EditRemoteRepositoryAction + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="editRemoteRepositoryAction" + */ +public class EditRemoteRepositoryAction + extends AbstractRemoteRepositoriesAction + implements Preparable +{ + /** + * The model for this action. + */ + private RemoteRepositoryConfiguration repository; + + /** + * The repository id to edit. + */ + private String repoid; + + public void prepare() + { + String id = repoid; + if ( StringUtils.isNotBlank( repoid ) ) + { + this.repository = archivaConfiguration.getConfiguration().findRemoteRepositoryById( id ); + } + } + + public String input() + { + if ( StringUtils.isBlank( repoid ) ) + { + addActionError( "Edit failure, unable to edit a repository with a blank repository id." ); + return ERROR; + } + + return INPUT; + } + + public String commit() + { + Configuration configuration = archivaConfiguration.getConfiguration(); + + // We are in edit mode, remove the old repository configuration. + removeRepository( repository.getId(), configuration ); + + // Save the repository 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; + } + + return result; + } + + public RemoteRepositoryConfiguration getRepository() + { + return repository; + } + + public void setRepository( RemoteRepositoryConfiguration repository ) + { + this.repository = repository; + } + + public String getRepoid() + { + return repoid; + } + + public void setRepoid( String repoid ) + { + this.repoid = repoid; + } +} diff --git a/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction-validation.xml b/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction-validation.xml new file mode 100644 index 000000000..39941570d --- /dev/null +++ b/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryAction-validation.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + ~ 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. + --> + +<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" + "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> + +<validators> + <field name="repository.id"> + <field-validator type="requiredstring"> + <message>You must enter a repository identifier.</message> + </field-validator> + </field> + <field name="repository.location"> + <field-validator type="requiredstring"> + <message>You must enter a directory.</message> + </field-validator> + </field> + <field name="repository.name"> + <field-validator type="requiredstring"> + <message>You must enter a repository name.</message> + </field-validator> + </field> +</validators>
\ No newline at end of file diff --git a/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryAction-validation.xml b/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryAction-validation.xml new file mode 100644 index 000000000..7902bc532 --- /dev/null +++ b/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryAction-validation.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + ~ 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. + --> + +<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" + "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> + +<validators> + <field name="repository.id"> + <field-validator type="requiredstring"> + <message>You must enter a repository identifier.</message> + </field-validator> + </field> + <field name="repository.url"> + <field-validator type="requiredstring"> + <message>You must enter a url.</message> + </field-validator> + </field> + <field name="repository.name"> + <field-validator type="requiredstring"> + <message>You must enter a repository name.</message> + </field-validator> + </field> +</validators>
\ No newline at end of file diff --git a/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction-validation.xml b/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction-validation.xml new file mode 100644 index 000000000..39941570d --- /dev/null +++ b/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryAction-validation.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + ~ 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. + --> + +<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" + "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> + +<validators> + <field name="repository.id"> + <field-validator type="requiredstring"> + <message>You must enter a repository identifier.</message> + </field-validator> + </field> + <field name="repository.location"> + <field-validator type="requiredstring"> + <message>You must enter a directory.</message> + </field-validator> + </field> + <field name="repository.name"> + <field-validator type="requiredstring"> + <message>You must enter a repository name.</message> + </field-validator> + </field> +</validators>
\ No newline at end of file diff --git a/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryAction-validation.xml b/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryAction-validation.xml new file mode 100644 index 000000000..7902bc532 --- /dev/null +++ b/archiva-web/archiva-webapp/src/main/resources/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryAction-validation.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + ~ 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. + --> + +<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" + "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> + +<validators> + <field name="repository.id"> + <field-validator type="requiredstring"> + <message>You must enter a repository identifier.</message> + </field-validator> + </field> + <field name="repository.url"> + <field-validator type="requiredstring"> + <message>You must enter a url.</message> + </field-validator> + </field> + <field name="repository.name"> + <field-validator type="requiredstring"> + <message>You must enter a repository name.</message> + </field-validator> + </field> +</validators>
\ No newline at end of file diff --git a/archiva-web/archiva-webapp/src/main/resources/xwork.xml b/archiva-web/archiva-webapp/src/main/resources/xwork.xml index 46a519060..1c9c05c92 100644 --- a/archiva-web/archiva-webapp/src/main/resources/xwork.xml +++ b/archiva-web/archiva-webapp/src/main/resources/xwork.xml @@ -228,52 +228,52 @@ <result type="redirect-action">repositories</result> </action> - <action name="addRepository" class="configureRepositoryAction" method="add"> + <action name="addRepository" class="addManagedRepositoryAction" method="input"> <result name="input">/WEB-INF/jsp/admin/addRepository.jsp</result> <result name="error">/WEB-INF/jsp/admin/addRepository.jsp</result> <result name="success" type="redirect-action">repositories</result> <interceptor-ref name="configuredPrepareParamsStack"/> </action> - <action name="editRepository" class="configureRepositoryAction" method="edit"> + <action name="editRepository" class="editManagedRepositoryAction" method="input"> <result name="input">/WEB-INF/jsp/admin/editRepository.jsp</result> <result name="error">/WEB-INF/jsp/admin/editRepository.jsp</result> <result name="success" type="redirect-action">repositories</result> <interceptor-ref name="configuredPrepareParamsStack"/> </action> - <action name="confirmDeleteRepository" class="configureRepositoryAction"> - <result>/WEB-INF/jsp/admin/deleteRepository.jsp</result> + <action name="confirmDeleteRepository" class="deleteManagedRepositoryAction" method="confirmDelete"> + <result name="input">/WEB-INF/jsp/admin/deleteRepository.jsp</result> <interceptor-ref name="configuredPrepareParamsStack"/> </action> - <action name="deleteRepository" class="configureRepositoryAction" method="delete"> + <action name="deleteRepository" class="deleteManagedRepositoryAction" method="delete"> <result name="input">/WEB-INF/jsp/admin/deleteRepository.jsp</result> <result name="error">/WEB-INF/jsp/admin/deleteRepository.jsp</result> <result name="success" type="redirect-action">repositories</result> <interceptor-ref name="configuredPrepareParamsStack"/> </action> - <action name="addRemoteRepository" class="configureRemoteRepositoryAction" method="add"> + <action name="addRemoteRepository" class="addRemoteRepositoryAction" method="input"> <result name="input">/WEB-INF/jsp/admin/addRemoteRepository.jsp</result> <result name="error">/WEB-INF/jsp/admin/addRemoteRepository.jsp</result> <result name="success" type="redirect-action">repositories</result> <interceptor-ref name="configuredPrepareParamsStack"/> </action> - <action name="editRemoteRepository" class="configureRemoteRepositoryAction" method="edit"> + <action name="editRemoteRepository" class="editRemoteRepositoryAction" method="input"> <result name="input">/WEB-INF/jsp/admin/editRemoteRepository.jsp</result> <result name="error">/WEB-INF/jsp/admin/editRemoteRepository.jsp</result> <result name="success" type="redirect-action">repositories</result> <interceptor-ref name="configuredPrepareParamsStack"/> </action> - <action name="confirmDeleteRemoteRepository" class="configureRemoteRepositoryAction"> - <result>/WEB-INF/jsp/admin/deleteRemoteRepository.jsp</result> + <action name="confirmDeleteRemoteRepository" class="deleteRemoteRepositoryAction" method="confirmDelete"> + <result name="input">/WEB-INF/jsp/admin/deleteRemoteRepository.jsp</result> <interceptor-ref name="configuredPrepareParamsStack"/> </action> - <action name="deleteRemoteRepository" class="configureRemoteRepositoryAction" method="delete"> + <action name="deleteRemoteRepository" class="deleteRemoteRepositoryAction" method="delete"> <result name="input">/WEB-INF/jsp/admin/deleteRemoteRepository.jsp</result> <result name="error">/WEB-INF/jsp/admin/deleteRemoteRepository.jsp</result> <result name="success" type="redirect-action">repositories</result> diff --git a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRemoteRepository.jsp b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRemoteRepository.jsp index fc1bf90aa..d61bd2e1b 100644 --- a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRemoteRepository.jsp +++ b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRemoteRepository.jsp @@ -34,7 +34,7 @@ <h2>Add Repository</h2> <ww:actionmessage/> - <ww:form method="post" action="addRemoteRepository" namespace="/admin" validate="true"> + <ww:form method="post" action="addRemoteRepository!commit" namespace="/admin" validate="true"> <ww:textfield name="repository.id" label="Identifier" size="10" required="true"/> <%@ include file="/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf" %> <ww:submit value="Add Repository"/> diff --git a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRepository.jsp b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRepository.jsp index 86f2acfe6..93f8c622c 100644 --- a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRepository.jsp +++ b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/addRepository.jsp @@ -34,7 +34,7 @@ <h2>Add Repository</h2> <ww:actionmessage/> - <ww:form method="post" action="addRepository" namespace="/admin" validate="true"> + <ww:form method="post" action="addRepository!commit" namespace="/admin" validate="true"> <ww:textfield name="repository.id" label="Identifier" size="10" required="true"/> <%@ include file="/WEB-INF/jsp/admin/include/repositoryForm.jspf" %> <ww:submit value="Add Repository"/> diff --git a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRemoteRepository.jsp b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRemoteRepository.jsp index da23fdcdb..183da4d23 100644 --- a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRemoteRepository.jsp +++ b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRemoteRepository.jsp @@ -21,32 +21,51 @@ <html> <head> - <title>Admin: Delete Repository</title> + <title>Admin: Delete Remote Repository</title> <ww:head/> </head> <body> -<h1>Admin: Delete Repository</h1> +<h1>Admin: Delete Remote Repository</h1> <ww:actionerror/> <div id="contentArea"> - <h2>Delete Repository</h2> - - <blockquote> - <strong><span class="statusFailed">WARNING:</span> This operation can not be undone.</strong> - </blockquote> + <div class="warningbox"> + <p> + <strong>WARNING: This operation can not be undone.</strong> + </p> + </div> <p> - Are you sure you want to delete the repository <code>[ ${repoid} ]</code> ? + Are you sure you want to delete the following remote repository? </p> - <ww:form method="post" action="deleteRemoteRepository" namespace="/admin" validate="true"> + <div class="infobox"> + <table class="infotable"> + <tr> + <td>ID:</td> + <td><code>${repository.id}</code></td> + </tr> + <tr> + <td>Name:</td> + <td>${repository.name}</td> + </tr> + <tr> + <td>URL:</td> + <td><a href="${repository.url}">${repository.url}</a></td> + </tr> + </table> + </div> + + <ww:form method="post" action="deleteRemoteRepository" namespace="/admin" validate="true" theme="simple"> <ww:hidden name="repoid"/> - <ww:submit value="Confirm" method="delete"/> - <ww:submit value="Cancel" method="execute"/> + <div class="buttons"> + <ww:submit value="Confirm" method="delete"/> + <ww:submit value="Cancel" method="execute"/> + </div> </ww:form> </div> diff --git a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRepository.jsp b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRepository.jsp index d1f5dc589..7394e1690 100644 --- a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRepository.jsp +++ b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/deleteRepository.jsp @@ -21,31 +21,52 @@ <html> <head> - <title>Admin: Delete Repository</title> + <title>Admin: Delete Managed Repository</title> <ww:head/> </head> <body> -<h1>Admin: Delete Repository</h1> +<h1>Admin: Delete Managed Repository</h1> <ww:actionerror/> <div id="contentArea"> - <h2>Delete Repository</h2> + <div class="warningbox"> + <p> + <strong>WARNING: This operation can not be undone.</strong> + </p> + </div> + + <p> + Are you sure you want to delete the following managed repository? + </p> - <blockquote> - <strong><span class="statusFailed">WARNING:</span> This operation can not be undone.</strong> - </blockquote> + <div class="infobox"> + <table class="infotable"> + <tr> + <td>ID:</td> + <td><code>${repository.id}</code></td> + </tr> + <tr> + <td>Name:</td> + <td>${repository.name}</td> + </tr> + <tr> + <td>Directory:</td> + <td>${repository.location}</td> + </tr> + </table> + </div> - <ww:form method="post" action="deleteRepository" namespace="/admin" validate="true"> + <ww:form method="post" action="deleteRepository" namespace="/admin" validate="true" theme="simple"> <ww:hidden name="repoid"/> - <ww:radio list="#@java.util.LinkedHashMap@{'delete-contents' : 'Remove the repository and delete its contents from disk', - 'delete-entry' : 'Remove the repository from the management list, but leave the contents unmodified'}" - name="deleteMode" theme="archiva"/> - <ww:submit value="Confirm" method="delete"/> - <ww:submit value="Cancel" method="execute"/> + <div class="buttons"> + <ww:submit value="Delete Configuration Only" method="deleteEntry" /> + <ww:submit value="Delete Configuration and Contents" method="deleteContents" /> + <ww:submit value="Cancel" method="execute"/> + </div> </ww:form> </div> diff --git a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRemoteRepository.jsp b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRemoteRepository.jsp index b91189122..6fefba1dd 100644 --- a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRemoteRepository.jsp +++ b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRemoteRepository.jsp @@ -36,7 +36,7 @@ <h2>Edit Repository</h2> <ww:actionmessage/> - <ww:form method="post" action="editRemoteRepository" namespace="/admin" validate="false"> + <ww:form method="post" action="editRemoteRepository!commit" namespace="/admin" validate="false"> <ww:hidden name="repository.id"/> <%@ include file="/WEB-INF/jsp/admin/include/remoteRepositoryForm.jspf" %> <ww:submit value="Update Repository"/> diff --git a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRepository.jsp b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRepository.jsp index e7f468c5b..8d1d2fa1f 100644 --- a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRepository.jsp +++ b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/editRepository.jsp @@ -36,7 +36,7 @@ <h2>Edit Repository</h2> <ww:actionmessage/> - <ww:form method="post" action="editRepository" namespace="/admin" validate="false"> + <ww:form method="post" action="editRepository!commit" namespace="/admin" validate="false"> <ww:hidden name="repository.id"/> <%@ include file="/WEB-INF/jsp/admin/include/repositoryForm.jspf" %> <ww:submit value="Update Repository"/> diff --git a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp index 925205952..aa43b128d 100644 --- a/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp +++ b/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp @@ -40,7 +40,7 @@ <div class="admin"> <div class="controls"> <redback:ifAuthorized permission="archiva-manage-configuration"> - <ww:url id="addRepositoryUrl" action="addRepository" method="addInput"/> + <ww:url id="addRepositoryUrl" action="addRepository"/> <ww:a href="%{addRepositoryUrl}"> <img src="<c:url value="/images/icons/create.png" />" alt="" width="16" height="16"/> Add @@ -72,7 +72,7 @@ <div class="controls"> <%-- TODO: make some icons --%> <redback:ifAnyAuthorized permissions="archiva-manage-configuration"> - <ww:url id="editRepositoryUrl" action="editRepository" method="editInput"> + <ww:url id="editRepositoryUrl" action="editRepository"> <ww:param name="repoid" value="%{'${repository.id}'}"/> </ww:url> <ww:url id="deleteRepositoryUrl" action="confirmDeleteRepository"> @@ -230,7 +230,7 @@ <div class="controls"> <redback:ifAuthorized permission="archiva-manage-configuration"> - <ww:url id="addRepositoryUrl" action="addRemoteRepository" method="input"/> + <ww:url id="addRepositoryUrl" action="addRemoteRepository"/> <ww:a href="%{addRepositoryUrl}"> <img src="<c:url value="/images/icons/create.png" />" alt="" width="16" height="16"/> Add @@ -260,7 +260,7 @@ <div class="controls"> <redback:ifAnyAuthorized permissions="archiva-manage-configuration"> - <ww:url id="editRepositoryUrl" action="editRemoteRepository" method="input"> + <ww:url id="editRepositoryUrl" action="editRemoteRepository"> <ww:param name="repoid" value="%{'${repository.id}'}"/> </ww:url> <ww:a href="%{editRepositoryUrl}"> diff --git a/archiva-web/archiva-webapp/src/main/webapp/css/site.css b/archiva-web/archiva-webapp/src/main/webapp/css/site.css index b0ecaecaf..ea49fe098 100644 --- a/archiva-web/archiva-webapp/src/main/webapp/css/site.css +++ b/archiva-web/archiva-webapp/src/main/webapp/css/site.css @@ -367,3 +367,24 @@ div.admin table.consumers th { div.admin table.consumers td strong { font-size: 0.8em; } + +div.warningbox { + margin: 20px 40px 20px 40px; + border: 1px solid #CC0000; + background-color: #FFCCCC; + color: #000000; + font-size: 15pt; + padding: 20px; +} + +div.infobox { + margin: 20px 40px 20px 40px; + border: 1px solid #0000CC; + background-color: #EEEEFF; + font-size: 9pt; + padding: 20px; +} + +div.buttons { + text-align: center; +}
\ No newline at end of file diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java new file mode 100644 index 000000000..dd14d7dcf --- /dev/null +++ b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddManagedRepositoryActionTest.java @@ -0,0 +1,167 @@ +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.commons.io.FileUtils; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.redback.role.RoleManager; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException; +import org.easymock.MockControl; + +import java.io.File; +import java.util.Collections; + +/** + * AddManagedRepositoryActionTest + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + */ +public class AddManagedRepositoryActionTest + extends PlexusTestCase +{ + private AddManagedRepositoryAction action; + + private RoleManager roleManager; + + private MockControl roleManagerControl; + + private MockControl archivaConfigurationControl; + + private ArchivaConfiguration archivaConfiguration; + + private static final String REPO_ID = "repo-ident"; + + private File location; + + protected void setUp() + throws Exception + { + super.setUp(); + + action = (AddManagedRepositoryAction) lookup( Action.class.getName(), "addManagedRepositoryAction" ); + + archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); + archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); + action.setArchivaConfiguration( archivaConfiguration ); + + roleManagerControl = MockControl.createControl( RoleManager.class ); + roleManager = (RoleManager) roleManagerControl.getMock(); + action.setRoleManager( roleManager ); + location = getTestFile( "target/test/location" ); + } + + 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 testAddRepositoryInitialPage() + throws Exception + { + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( new Configuration() ); + archivaConfigurationControl.replay(); + + action.prepare(); + ManagedRepositoryConfiguration configuration = action.getRepository(); + assertNotNull( configuration ); + assertNull( configuration.getId() ); + // check all booleans are false + assertFalse( configuration.isDeleteReleasedSnapshots() ); + assertFalse( configuration.isScanned() ); + assertFalse( configuration.isReleases() ); + assertFalse( configuration.isSnapshots() ); + + String status = action.input(); + assertEquals( Action.INPUT, status ); + + // check defaults + assertFalse( configuration.isDeleteReleasedSnapshots() ); + assertTrue( configuration.isScanned() ); + assertTrue( configuration.isReleases() ); + assertFalse( configuration.isSnapshots() ); + } + + public void testAddRepository() + throws Exception + { + FileUtils.deleteDirectory( location ); + + // TODO: should be in the business model + roleManager.createTemplatedRole( "archiva-repository-manager", REPO_ID ); + roleManager.createTemplatedRole( "archiva-repository-observer", REPO_ID ); + + roleManagerControl.replay(); + + Configuration configuration = new Configuration(); + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + + archivaConfiguration.save( configuration ); + + archivaConfigurationControl.replay(); + + action.prepare(); + ManagedRepositoryConfiguration repository = action.getRepository(); + populateRepository( repository ); + + assertFalse( location.exists() ); + String status = action.commit(); + assertEquals( Action.SUCCESS, status ); + assertTrue( location.exists() ); + + assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() ); + + roleManagerControl.verify(); + archivaConfigurationControl.verify(); + } + + private void populateRepository( ManagedRepositoryConfiguration repository ) + { + repository.setId( REPO_ID ); + repository.setName( "repo name" ); + repository.setLocation( location.getAbsolutePath() ); + repository.setLayout( "default" ); + repository.setRefreshCronExpression( "* 0/5 * * * ?" ); + repository.setDaysOlder( 31 ); + repository.setRetentionCount( 20 ); + repository.setReleases( true ); + repository.setSnapshots( true ); + repository.setScanned( false ); + repository.setDeleteReleasedSnapshots( true ); + } + + // TODO: test errors during add, other actions +} diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryActionTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryActionTest.java new file mode 100644 index 000000000..ae3708f8a --- /dev/null +++ b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/AddRemoteRepositoryActionTest.java @@ -0,0 +1,124 @@ +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.RemoteRepositoryConfiguration; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException; +import org.easymock.MockControl; + +import java.util.Collections; + +/** + * AddRemoteRepositoryActionTest + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + */ +public class AddRemoteRepositoryActionTest + extends PlexusTestCase +{ + private AddRemoteRepositoryAction action; + + private MockControl archivaConfigurationControl; + + private ArchivaConfiguration archivaConfiguration; + + private static final String REPO_ID = "remote-repo-ident"; + + protected void setUp() + throws Exception + { + super.setUp(); + + action = (AddRemoteRepositoryAction) lookup( Action.class.getName(), "addRemoteRepositoryAction" ); + + 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(); + RemoteRepositoryConfiguration configuration = action.getRepository(); + assertNotNull( configuration ); + assertNull( configuration.getId() ); + + String status = action.input(); + 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(); + RemoteRepositoryConfiguration repository = action.getRepository(); + populateRepository( repository ); + + String status = action.commit(); + assertEquals( Action.SUCCESS, status ); + + assertEquals( Collections.singletonList( repository ), configuration.getRemoteRepositories() ); + + archivaConfigurationControl.verify(); + } + + 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 +} diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryActionTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java index 762f26d6a..c01efec74 100644 --- a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRepositoryActionTest.java +++ b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java @@ -20,7 +20,7 @@ package org.apache.maven.archiva.web.action.admin.repositories; */ import com.opensymphony.xwork.Action; -import org.apache.commons.io.FileUtils; + import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.IndeterminateConfigurationException; @@ -36,12 +36,15 @@ import java.io.File; import java.util.Collections; /** - * Test the repositories action returns the correct data. + * DeleteManagedRepositoryActionTest + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ */ -public class ConfigureRepositoryActionTest +public class DeleteManagedRepositoryActionTest extends PlexusTestCase { - private ConfigureRepositoryAction action; + private DeleteManagedRepositoryAction action; private RoleManager roleManager; @@ -60,10 +63,7 @@ public class ConfigureRepositoryActionTest { super.setUp(); - // TODO: purely to quiet logging - shouldn't be needed - String appserverBase = getTestFile( "target/appserver-base" ).getAbsolutePath(); - System.setProperty( "appserver.base", appserverBase ); - action = (ConfigureRepositoryAction) lookup( Action.class.getName(), "configureRepositoryAction" ); + action = (DeleteManagedRepositoryAction) lookup( Action.class.getName(), "deleteManagedRepositoryAction" ); archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); @@ -88,125 +88,6 @@ public class ConfigureRepositoryActionTest assertEquals( 1, bundle.getAuthorizationTuples().size() ); } - public void testAddRepositoryInitialPage() - throws Exception - { - archivaConfiguration.getConfiguration(); - archivaConfigurationControl.setReturnValue( new Configuration() ); - archivaConfigurationControl.replay(); - - action.prepare(); - assertNull( action.getRepoid() ); - ManagedRepositoryConfiguration configuration = action.getRepository(); - assertNotNull( configuration ); - assertNull( configuration.getId() ); - // check all booleans are false - assertFalse( configuration.isDeleteReleasedSnapshots() ); - assertFalse( configuration.isScanned() ); - assertFalse( configuration.isReleases() ); - assertFalse( configuration.isSnapshots() ); - - String status = action.addInput(); - assertEquals( Action.INPUT, status ); - - // check defaults - assertFalse( configuration.isDeleteReleasedSnapshots() ); - assertTrue( configuration.isScanned() ); - assertTrue( configuration.isReleases() ); - assertFalse( configuration.isSnapshots() ); - } - - public void testAddRepository() - throws Exception - { - FileUtils.deleteDirectory( location ); - - // TODO: should be in the business model - roleManager.createTemplatedRole( "archiva-repository-manager", REPO_ID ); - roleManager.createTemplatedRole( "archiva-repository-observer", REPO_ID ); - - roleManagerControl.replay(); - - Configuration configuration = new Configuration(); - archivaConfiguration.getConfiguration(); - archivaConfigurationControl.setReturnValue( configuration ); - - archivaConfiguration.save( configuration ); - - archivaConfigurationControl.replay(); - - action.prepare(); - ManagedRepositoryConfiguration repository = action.getRepository(); - populateRepository( repository ); - - assertFalse( location.exists() ); - String status = action.add(); - assertEquals( Action.SUCCESS, status ); - assertTrue( location.exists() ); - - assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() ); - - roleManagerControl.verify(); - archivaConfigurationControl.verify(); - } - - public void testEditRepositoryInitialPage() - throws Exception - { - Configuration configuration = createConfigurationForEditing( createRepository() ); - - archivaConfiguration.getConfiguration(); - archivaConfigurationControl.setReturnValue( configuration ); - archivaConfigurationControl.replay(); - - action.setRepoid( REPO_ID ); - - action.prepare(); - assertEquals( REPO_ID, action.getRepoid() ); - ManagedRepositoryConfiguration repository = action.getRepository(); - assertNotNull( repository ); - assertRepositoryEquals( repository, createRepository() ); - - String status = action.editInput(); - assertEquals( Action.INPUT, status ); - repository = action.getRepository(); - assertRepositoryEquals( repository, createRepository() ); - } - - public void testEditRepository() - throws Exception - { - // TODO: should be in the business model - roleManager.createTemplatedRole( "archiva-repository-manager", REPO_ID ); - roleManager.createTemplatedRole( "archiva-repository-observer", REPO_ID ); - - roleManagerControl.replay(); - - Configuration configuration = createConfigurationForEditing( createRepository() ); - archivaConfiguration.getConfiguration(); - archivaConfigurationControl.setReturnValue( configuration ); - - archivaConfiguration.save( configuration ); - - archivaConfigurationControl.replay(); - - action.prepare(); - ManagedRepositoryConfiguration repository = action.getRepository(); - populateRepository( repository ); - repository.setName( "new repo name" ); - - String status = action.edit(); - assertEquals( Action.SUCCESS, status ); - - ManagedRepositoryConfiguration newRepository = createRepository(); - newRepository.setName( "new repo name" ); - assertRepositoryEquals( repository, newRepository ); - assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() ); - - roleManagerControl.verify(); - archivaConfigurationControl.verify(); - } - public void testDeleteRepositoryConfirmation() throws Exception { @@ -227,7 +108,6 @@ public class ConfigureRepositoryActionTest String status = action.execute(); assertEquals( Action.SUCCESS, status ); - assertEquals( "delete-entry", action.getDeleteMode() ); repository = action.getRepository(); assertRepositoryEquals( repository, createRepository() ); assertEquals( Collections.singletonList( originalRepository ), configuration.getManagedRepositories() ); @@ -237,7 +117,7 @@ public class ConfigureRepositoryActionTest throws RegistryException, IndeterminateConfigurationException { Configuration configuration = prepDeletionTest( createRepository(), "delete-entry" ); - String status = action.delete(); + String status = action.deleteEntry(); assertEquals( Action.SUCCESS, status ); assertTrue( configuration.getManagedRepositories().isEmpty() ); @@ -249,7 +129,7 @@ public class ConfigureRepositoryActionTest throws RegistryException, IndeterminateConfigurationException { Configuration configuration = prepDeletionTest( createRepository(), "delete-contents" ); - String status = action.delete(); + String status = action.deleteContents(); assertEquals( Action.SUCCESS, status ); assertTrue( configuration.getManagedRepositories().isEmpty() ); @@ -288,11 +168,9 @@ public class ConfigureRepositoryActionTest archivaConfigurationControl.replay(); action.setRepoid( REPO_ID ); - action.setDeleteMode( mode ); action.prepare(); assertEquals( REPO_ID, action.getRepoid() ); - assertEquals( mode, action.getDeleteMode() ); ManagedRepositoryConfiguration repository = action.getRepository(); assertNotNull( repository ); assertRepositoryEquals( repository, createRepository() ); @@ -348,7 +226,4 @@ public class ConfigureRepositoryActionTest repository.setDeleteReleasedSnapshots( true ); } - // 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/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryActionTest.java index fb41345a6..848fb8853 100644 --- a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/ConfigureRemoteRepositoryActionTest.java +++ b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteRemoteRepositoryActionTest.java @@ -20,104 +20,51 @@ package org.apache.maven.archiva.web.action.admin.repositories; */ 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. + * DeleteRemoteRepositoryActionTest + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ */ -public class ConfigureRemoteRepositoryActionTest +public class DeleteRemoteRepositoryActionTest extends PlexusTestCase { - private ConfigureRemoteRepositoryAction action; + private static final String REPO_ID = "remote-repo-ident"; + + private DeleteRemoteRepositoryAction 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" ); + action = (DeleteRemoteRepositoryAction) lookup( Action.class.getName(), "deleteRemoteRepositoryAction" ); 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() ); - RemoteRepositoryConfiguration configuration = action.getRepository(); - assertNotNull( configuration ); - assertNull( configuration.getId() ); - - String status = action.input(); - 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(); - RemoteRepositoryConfiguration repository = action.getRepository(); - populateRepository( repository ); - - String status = action.add(); - assertEquals( Action.SUCCESS, status ); - - assertEquals( Collections.singletonList( repository ), configuration.getRemoteRepositories() ); - - archivaConfigurationControl.verify(); - } - - public void testEditRemoteRepositoryInitialPage() + public void testDeleteRemoteRepositoryConfirmation() throws Exception { - Configuration configuration = createConfigurationForEditing( createRepository() ); + RemoteRepositoryConfiguration originalRepository = createRepository(); + Configuration configuration = createConfigurationForEditing( originalRepository ); archivaConfiguration.getConfiguration(); archivaConfigurationControl.setReturnValue( configuration ); @@ -131,68 +78,36 @@ public class ConfigureRemoteRepositoryActionTest assertNotNull( repository ); assertRepositoryEquals( repository, createRepository() ); - String status = action.input(); + String status = action.confirmDelete(); assertEquals( Action.INPUT, status ); repository = action.getRepository(); assertRepositoryEquals( repository, createRepository() ); + assertEquals( Collections.singletonList( originalRepository ), configuration.getRemoteRepositories() ); } - public void testEditRemoteRepository() - throws Exception + public void testDeleteRemoteRepository() + throws RegistryException, IndeterminateConfigurationException { Configuration configuration = createConfigurationForEditing( createRepository() ); + archivaConfiguration.getConfiguration(); archivaConfigurationControl.setReturnValue( configuration ); - - archivaConfiguration.save( configuration ); - - archivaConfigurationControl.replay(); - - action.prepare(); - RemoteRepositoryConfiguration repository = action.getRepository(); - populateRepository( repository ); - repository.setName( "new repo name" ); - - String status = action.edit(); - 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() - throws Exception - { - RemoteRepositoryConfiguration originalRepository = createRepository(); - Configuration configuration = createConfigurationForEditing( originalRepository ); - archivaConfiguration.getConfiguration(); archivaConfigurationControl.setReturnValue( configuration ); + + archivaConfiguration.save( configuration ); archivaConfigurationControl.replay(); - + action.setRepoid( REPO_ID ); - + action.prepare(); assertEquals( REPO_ID, action.getRepoid() ); RemoteRepositoryConfiguration repository = action.getRepository(); assertNotNull( repository ); assertRepositoryEquals( repository, createRepository() ); - - String status = action.execute(); + + String status = action.delete(); assertEquals( Action.SUCCESS, status ); - repository = action.getRepository(); - assertRepositoryEquals( repository, createRepository() ); - assertEquals( Collections.singletonList( originalRepository ), configuration.getRemoteRepositories() ); - } - - public void testDeleteRemoteRepositoryKeepContent() - throws RegistryException, IndeterminateConfigurationException - { - Configuration configuration = executeDeletionTest( createRepository() ); assertTrue( configuration.getRemoteRepositories().isEmpty() ); } @@ -227,48 +142,13 @@ public class ConfigureRemoteRepositoryActionTest assertEquals( Collections.singletonList( originalRepository ), configuration.getRemoteRepositories() ); } - private Configuration executeDeletionTest( 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.prepare(); - assertEquals( REPO_ID, action.getRepoid() ); - 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(); @@ -276,6 +156,15 @@ public class ConfigureRemoteRepositoryActionTest populateRepository( r ); return r; } + + 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 void populateRepository( RemoteRepositoryConfiguration repository ) { @@ -284,8 +173,7 @@ public class ConfigureRemoteRepositoryActionTest 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/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java new file mode 100644 index 000000000..c3f2e910f --- /dev/null +++ b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java @@ -0,0 +1,196 @@ +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.ManagedRepositoryConfiguration; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.redback.role.RoleManager; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException; +import org.easymock.MockControl; + +import java.io.File; +import java.util.Collections; + +/** + * EditManagedRepositoryActionTest + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + */ +public class EditManagedRepositoryActionTest + extends PlexusTestCase +{ + private EditManagedRepositoryAction action; + + private RoleManager roleManager; + + private MockControl roleManagerControl; + + private MockControl archivaConfigurationControl; + + private ArchivaConfiguration archivaConfiguration; + + private static final String REPO_ID = "repo-ident"; + + private File location; + + protected void setUp() + throws Exception + { + super.setUp(); + + action = (EditManagedRepositoryAction) lookup( Action.class.getName(), "editManagedRepositoryAction" ); + + archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); + archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); + action.setArchivaConfiguration( archivaConfiguration ); + + roleManagerControl = MockControl.createControl( RoleManager.class ); + roleManager = (RoleManager) roleManagerControl.getMock(); + action.setRoleManager( roleManager ); + location = getTestFile( "target/test/location" ); + } + + 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 testEditRepositoryInitialPage() + throws Exception + { + Configuration configuration = createConfigurationForEditing( createRepository() ); + + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + archivaConfigurationControl.replay(); + + action.setRepoid( REPO_ID ); + + action.prepare(); + assertEquals( REPO_ID, action.getRepoid() ); + ManagedRepositoryConfiguration repository = action.getRepository(); + assertNotNull( repository ); + assertRepositoryEquals( repository, createRepository() ); + + String status = action.input(); + assertEquals( Action.INPUT, status ); + repository = action.getRepository(); + assertRepositoryEquals( repository, createRepository() ); + } + + public void testEditRepository() + throws Exception + { + // TODO: should be in the business model + roleManager.createTemplatedRole( "archiva-repository-manager", REPO_ID ); + roleManager.createTemplatedRole( "archiva-repository-observer", REPO_ID ); + + roleManagerControl.replay(); + + Configuration configuration = createConfigurationForEditing( createRepository() ); + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + archivaConfigurationControl.setReturnValue( configuration ); + + archivaConfiguration.save( configuration ); + + archivaConfigurationControl.replay(); + + action.setRepoid( REPO_ID ); + action.prepare(); + assertEquals( REPO_ID, action.getRepoid() ); + ManagedRepositoryConfiguration repository = action.getRepository(); + populateRepository( repository ); + repository.setName( "new repo name" ); + + String status = action.commit(); + assertEquals( Action.SUCCESS, status ); + + ManagedRepositoryConfiguration newRepository = createRepository(); + newRepository.setName( "new repo name" ); + assertRepositoryEquals( repository, newRepository ); + assertEquals( Collections.singletonList( repository ), configuration.getManagedRepositories() ); + + roleManagerControl.verify(); + archivaConfigurationControl.verify(); + } + + private void assertRepositoryEquals( ManagedRepositoryConfiguration expectedRepository, + ManagedRepositoryConfiguration actualRepository ) + { + assertEquals( expectedRepository.getDaysOlder(), actualRepository.getDaysOlder() ); + assertEquals( expectedRepository.getId(), actualRepository.getId() ); + assertEquals( expectedRepository.getIndexDir(), actualRepository.getIndexDir() ); + assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() ); + assertEquals( expectedRepository.getLocation(), actualRepository.getLocation() ); + assertEquals( expectedRepository.getName(), actualRepository.getName() ); + assertEquals( expectedRepository.getRefreshCronExpression(), actualRepository.getRefreshCronExpression() ); + assertEquals( expectedRepository.getRetentionCount(), actualRepository.getRetentionCount() ); + assertEquals( expectedRepository.isDeleteReleasedSnapshots(), actualRepository.isDeleteReleasedSnapshots() ); + assertEquals( expectedRepository.isScanned(), actualRepository.isScanned() ); + assertEquals( expectedRepository.isReleases(), actualRepository.isReleases() ); + assertEquals( expectedRepository.isSnapshots(), actualRepository.isSnapshots() ); + } + + private Configuration createConfigurationForEditing( ManagedRepositoryConfiguration repositoryConfiguration ) + { + Configuration configuration = new Configuration(); + configuration.addManagedRepository( repositoryConfiguration ); + return configuration; + } + + private ManagedRepositoryConfiguration createRepository() + { + ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration(); + r.setId( REPO_ID ); + populateRepository( r ); + return r; + } + + private void populateRepository( ManagedRepositoryConfiguration repository ) + { + repository.setId( REPO_ID ); + repository.setName( "repo name" ); + repository.setLocation( location.getAbsolutePath() ); + repository.setLayout( "default" ); + repository.setRefreshCronExpression( "* 0/5 * * * ?" ); + repository.setDaysOlder( 31 ); + repository.setRetentionCount( 20 ); + repository.setReleases( true ); + repository.setSnapshots( true ); + repository.setScanned( false ); + repository.setDeleteReleasedSnapshots( true ); + } + +} diff --git a/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryActionTest.java b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryActionTest.java new file mode 100644 index 000000000..9d6130390 --- /dev/null +++ b/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/EditRemoteRepositoryActionTest.java @@ -0,0 +1,158 @@ +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.RemoteRepositoryConfiguration; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle; +import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException; +import org.easymock.MockControl; + +import java.util.Collections; + +/** + * EditRemoteRepositoryActionTest + * + * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> + * @version $Id$ + */ +public class EditRemoteRepositoryActionTest + extends PlexusTestCase +{ + private static final String REPO_ID = "remote-repo-ident"; + + private EditRemoteRepositoryAction action; + + private MockControl archivaConfigurationControl; + + private ArchivaConfiguration archivaConfiguration; + + public void testEditRemoteRepository() + throws Exception + { + Configuration configuration = createConfigurationForEditing( createRepository() ); + archivaConfiguration.getConfiguration(); + archivaConfigurationControl.setReturnValue( configuration ); + archivaConfigurationControl.setReturnValue( configuration ); + archivaConfiguration.save( configuration ); + archivaConfigurationControl.replay(); + + action.setRepoid( REPO_ID ); + action.prepare(); + assertEquals( REPO_ID, action.getRepoid() ); + RemoteRepositoryConfiguration repository = action.getRepository(); + populateRepository( repository ); + repository.setName( "new repo name" ); + + String status = action.commit(); + 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 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() ); + RemoteRepositoryConfiguration repository = action.getRepository(); + assertNotNull( repository ); + assertRepositoryEquals( repository, createRepository() ); + + String status = action.input(); + assertEquals( Action.INPUT, status ); + repository = action.getRepository(); + assertRepositoryEquals( repository, createRepository() ); + } + + 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() ); + } + + 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" ); + } + + protected void setUp() + throws Exception + { + super.setUp(); + + action = (EditRemoteRepositoryAction) lookup( Action.class.getName(), "editRemoteRepositoryAction" ); + + archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); + archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); + action.setArchivaConfiguration( archivaConfiguration ); + } +} diff --git a/archiva-web/archiva-webapp/src/test/resources/log4j.xml b/archiva-web/archiva-webapp/src/test/resources/log4j.xml new file mode 100644 index 000000000..3c782b138 --- /dev/null +++ b/archiva-web/archiva-webapp/src/test/resources/log4j.xml @@ -0,0 +1,47 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> + +<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> + + <appender name="console" class="org.apache.log4j.ConsoleAppender"> + <param name="Target" value="System.out"/> + <layout class="org.apache.log4j.PatternLayout"> + <param name="ConversionPattern" value="%5p|%t|%5r|%-30c{1} - %m%n"/> + </layout> + </appender> + + <!-- Help identify bugs during testing --> + <logger name="org.apache.maven.archiva"> + <level value="debug"/> + </logger> + + <logger name="org.codehaus.plexus.security"> + <level value="info"/> + </logger> + + <logger name="org.codehaus.plexus.PlexusContainer"> + <level value="info"/> + </logger> + + <logger name="JPOX"> + <level value="warn"/> + </logger> + + <logger name="JPOX.MetaData"> + <level value="error"/> + </logger> + + <logger name="JPOX.RDBMS.SQL"> + <level value="error"/> + </logger> + + <logger name="SQL"> + <level value="error"/> + </logger> + + <root> + <priority value ="debug" /> + <appender-ref ref="console" /> + </root> + +</log4j:configuration> |