From: Olivier Lamy Date: Tue, 6 Sep 2011 21:06:11 +0000 (+0000) Subject: [MRM-1508] api to managed repository group X-Git-Tag: archiva-1.4-M1~375 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=64bf00a0317c3c8a06b33fe0f4a1230c6de3e06e;p=archiva.git [MRM-1508] api to managed repository group git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1165844 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java new file mode 100644 index 000000000..8cd535d14 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/group/DefaultRepositoryGroupAdmin.java @@ -0,0 +1,262 @@ +package org.apache.archiva.admin.repository.group; +/* + * 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.archiva.admin.AuditInformation; +import org.apache.archiva.admin.repository.AbstractRepositoryAdmin; +import org.apache.archiva.admin.repository.RepositoryAdminException; +import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin; +import org.apache.archiva.audit.AuditEvent; +import org.apache.commons.lang.StringUtils; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @author Olivier Lamy + */ +@Service( "repositoryGroupAdmin#default" ) +public class DefaultRepositoryGroupAdmin + extends AbstractRepositoryAdmin + implements RepositoryGroupAdmin +{ + + private Logger log = LoggerFactory.getLogger( getClass() ); + + private static final Pattern REPO_GROUP_ID_PATTERN = Pattern.compile( "[A-Za-z0-9\\._\\-]+" ); + + @Inject + private ManagedRepositoryAdmin managedRepositoryAdmin; + + public List getRepositoriesGroups() + throws RepositoryAdminException + { + List repositoriesGroups = new ArrayList(); + + for ( RepositoryGroupConfiguration repositoryGroupConfiguration : getArchivaConfiguration().getConfiguration().getRepositoryGroups() ) + { + repositoriesGroups.add( new RepositoryGroup( repositoryGroupConfiguration.getId(), new ArrayList( + repositoryGroupConfiguration.getRepositories() ) ) ); + } + + return repositoriesGroups; + } + + public RepositoryGroup getRepositoryGroup( String repositoryGroupId ) + throws RepositoryAdminException + { + List repositoriesGroups = getRepositoriesGroups(); + for ( RepositoryGroup repositoryGroup : repositoriesGroups ) + { + if ( StringUtils.equals( repositoryGroupId, repositoryGroup.getId() ) ) + { + return repositoryGroup; + } + } + return null; + } + + public Boolean addRepositoryGroup( RepositoryGroup repositoryGroup, AuditInformation auditInformation ) + throws RepositoryAdminException + { + validateRepositoryGroup( repositoryGroup, false ); + validateManagedRepositoriesExists( repositoryGroup.getRepositories() ); + RepositoryGroupConfiguration repositoryGroupConfiguration = new RepositoryGroupConfiguration(); + repositoryGroupConfiguration.setId( repositoryGroup.getId() ); + repositoryGroupConfiguration.setRepositories( repositoryGroup.getRepositories() ); + Configuration configuration = getArchivaConfiguration().getConfiguration(); + configuration.addRepositoryGroup( repositoryGroupConfiguration ); + saveConfiguration( configuration ); + triggerAuditEvent( repositoryGroup.getId(), null, AuditEvent.ADD_REPO_GROUP, auditInformation ); + return Boolean.TRUE; + } + + public Boolean deleteRepositoryGroup( String repositoryGroupId, AuditInformation auditInformation ) + throws RepositoryAdminException + { + Configuration configuration = getArchivaConfiguration().getConfiguration(); + RepositoryGroupConfiguration repositoryGroupConfiguration = + configuration.getRepositoryGroupsAsMap().get( repositoryGroupId ); + if ( repositoryGroupConfiguration == null ) + { + throw new RepositoryAdminException( + "repositoryGroup with id " + repositoryGroupId + " doesn't not exists so cannot remove" ); + } + configuration.removeRepositoryGroup( repositoryGroupConfiguration ); + triggerAuditEvent( repositoryGroupId, null, AuditEvent.DELETE_REPO_GROUP, auditInformation ); + return Boolean.TRUE; + } + + public Boolean updateRepositoryGroup( RepositoryGroup repositoryGroup, AuditInformation auditInformation ) + throws RepositoryAdminException + { + return updateRepositoryGroup( repositoryGroup, auditInformation, true ); + } + + private Boolean updateRepositoryGroup( RepositoryGroup repositoryGroup, AuditInformation auditInformation, + boolean triggerAuditEvent ) + throws RepositoryAdminException + { + validateRepositoryGroup( repositoryGroup, true ); + validateManagedRepositoriesExists( repositoryGroup.getRepositories() ); + Configuration configuration = getArchivaConfiguration().getConfiguration(); + + RepositoryGroupConfiguration repositoryGroupConfiguration = + configuration.getRepositoryGroupsAsMap().get( repositoryGroup.getId() ); + + configuration.removeRepositoryGroup( repositoryGroupConfiguration ); + + repositoryGroupConfiguration.setRepositories( repositoryGroup.getRepositories() ); + configuration.addRepositoryGroup( repositoryGroupConfiguration ); + + saveConfiguration( configuration ); + if ( triggerAuditEvent ) + { + triggerAuditEvent( repositoryGroup.getId(), null, AuditEvent.MODIFY_REPO_GROUP, auditInformation ); + } + return Boolean.TRUE; + } + + + public Boolean addRepositoryToGroup( String repositoryGroupId, String repositoryId, + AuditInformation auditInformation ) + throws RepositoryAdminException + { + RepositoryGroup repositoryGroup = getRepositoryGroup( repositoryGroupId ); + if ( repositoryGroup == null ) + { + throw new RepositoryAdminException( + "repositoryGroup with id " + repositoryGroupId + " doesn't not exists so cannot add repository to it" ); + } + + if ( repositoryGroup.getRepositories().contains( repositoryId ) ) + { + log.info( "repositoryGroup {} already contains repository {} so skip adding it" ); + return Boolean.TRUE; + } + validateManagedRepositoriesExists( Arrays.asList( repositoryId ) ); + + repositoryGroup.addRepository( repositoryId ); + updateRepositoryGroup( repositoryGroup, auditInformation, false ); + triggerAuditEvent( repositoryGroup.getId(), null, AuditEvent.ADD_REPO_TO_GROUP, auditInformation ); + return Boolean.TRUE; + } + + public Boolean deleteRepositoryFromGroup( String repositoryGroupId, String repositoryId, + AuditInformation auditInformation ) + throws RepositoryAdminException + { + RepositoryGroup repositoryGroup = getRepositoryGroup( repositoryGroupId ); + if ( repositoryGroup == null ) + { + throw new RepositoryAdminException( "repositoryGroup with id " + repositoryGroupId + + " doesn't not exists so cannot remove repository from it" ); + } + + if ( !repositoryGroup.getRepositories().contains( repositoryId ) ) + { + log.info( "repositoryGroup {} already contains repository {} so skip removing it" ); + return Boolean.TRUE; + } + + repositoryGroup.removeRepository( repositoryId ); + updateRepositoryGroup( repositoryGroup, auditInformation, false ); + triggerAuditEvent( repositoryGroup.getId(), null, AuditEvent.DELETE_REPO_FROM_GROUP, auditInformation ); + return Boolean.TRUE; + } + + public Boolean validateRepositoryGroup( RepositoryGroup repositoryGroup, boolean updateMode ) + throws RepositoryAdminException + { + String repoGroupId = repositoryGroup.getId(); + if ( StringUtils.isBlank( repoGroupId ) ) + { + throw new RepositoryAdminException( "repositoryGroup id cannot be empty" ); + } + + if ( repoGroupId.length() > 100 ) + { + throw new RepositoryAdminException( + "Identifier [" + repoGroupId + "] is over the maximum limit of 100 characters" ); + + } + + Matcher matcher = REPO_GROUP_ID_PATTERN.matcher( repoGroupId ); + if ( !matcher.matches() ) + { + throw new RepositoryAdminException( + "Invalid character(s) found in identifier. Only the following characters are allowed: alphanumeric, '.', '-' and '_'" ); + } + + Configuration configuration = getArchivaConfiguration().getConfiguration(); + + if ( configuration.getRepositoryGroupsAsMap().containsKey( repoGroupId ) ) + { + if ( !updateMode ) + { + throw new RepositoryAdminException( "Unable to add new repository group with id [" + repoGroupId + + "], that id already exists as a repository group." ); + } + } + else if ( configuration.getManagedRepositoriesAsMap().containsKey( repoGroupId ) ) + { + throw new RepositoryAdminException( "Unable to add new repository group with id [" + repoGroupId + + "], that id already exists as a managed repository." ); + } + else if ( configuration.getRemoteRepositoriesAsMap().containsKey( repoGroupId ) ) + { + throw new RepositoryAdminException( "Unable to add new repository group with id [" + repoGroupId + + "], that id already exists as a remote repository." ); + } + + return Boolean.TRUE; + } + + private void validateManagedRepositoriesExists( List managedRepositoriesIds ) + throws RepositoryAdminException + { + for ( String id : managedRepositoriesIds ) + { + if ( getManagedRepositoryAdmin().getManagedRepository( id ) == null ) + { + throw new RepositoryAdminException( + "managedRepository with id " + id + " not exists so cannot be used in a repositoryGroup" ); + } + } + } + + public ManagedRepositoryAdmin getManagedRepositoryAdmin() + { + return managedRepositoryAdmin; + } + + public void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin ) + { + this.managedRepositoryAdmin = managedRepositoryAdmin; + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/group/RepositoryGroup.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/group/RepositoryGroup.java new file mode 100644 index 000000000..0173d396b --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/group/RepositoryGroup.java @@ -0,0 +1,117 @@ +package org.apache.archiva.admin.repository.group; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Olivier Lamy + * @since 1.4 + */ +public class RepositoryGroup + implements Serializable +{ + /** + * repository group Id + */ + private String id; + + /** + * repositories ids + */ + private List repositories; + + public RepositoryGroup() + { + // no op + } + + public RepositoryGroup( String id, List repositories ) + { + this.id = id; + this.repositories = repositories; + } + + /** + * Method addRepository. + * + * @param string + */ + public void addRepository( String string ) + { + getRepositories().add( string ); + } + + /** + * Get the id of the repository group. + * + * @return String + */ + public String getId() + { + return this.id; + } + + /** + * Method getRepositories. + * + * @return List + */ + public java.util.List getRepositories() + { + if ( this.repositories == null ) + { + this.repositories = new ArrayList(); + } + + return this.repositories; + } + + /** + * Method removeRepository. + * + * @param string + */ + public void removeRepository( String string ) + { + getRepositories().remove( string ); + } + + /** + * Set the id of the repository group. + * + * @param id + */ + public void setId( String id ) + { + this.id = id; + } + + /** + * Set the list of repository ids under the group. + * + * @param repositories + */ + public void setRepositories( List repositories ) + { + this.repositories = repositories; + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdmin.java new file mode 100644 index 000000000..b51af7975 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdmin.java @@ -0,0 +1,53 @@ +package org.apache.archiva.admin.repository.group; +/* + * 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.archiva.admin.AuditInformation; +import org.apache.archiva.admin.repository.RepositoryAdminException; + +import java.util.List; + +/** + * @author Olivier Lamy + * @since 1.4 + */ +public interface RepositoryGroupAdmin +{ + List getRepositoriesGroups() + throws RepositoryAdminException; + + RepositoryGroup getRepositoryGroup( String repositoryGroupId ) + throws RepositoryAdminException; + + Boolean addRepositoryGroup( RepositoryGroup repositoryGroup, AuditInformation auditInformation ) + throws RepositoryAdminException; + + Boolean updateRepositoryGroup( RepositoryGroup repositoryGroup, AuditInformation auditInformation ) + throws RepositoryAdminException; + + Boolean deleteRepositoryGroup( String repositoryGroupId, AuditInformation auditInformation ) + throws RepositoryAdminException; + + Boolean addRepositoryToGroup( String repositoryGroupId, String repositoryId, AuditInformation auditInformation ) + throws RepositoryAdminException; + + Boolean deleteRepositoryFromGroup( String repositoryGroupId, String repositoryId, + AuditInformation auditInformation ) + throws RepositoryAdminException; +} diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java index 692669f2b..42568b216 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java @@ -36,6 +36,7 @@ import org.apache.commons.validator.GenericValidator; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; +import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration; import org.codehaus.plexus.redback.role.RoleManager; import org.codehaus.plexus.redback.role.RoleManagerException; import org.codehaus.plexus.taskqueue.TaskQueueException; @@ -50,6 +51,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -110,6 +112,19 @@ public class DefaultManagedRepositoryAdmin return managedRepos; } + public Map getManagedRepositoriesAsMap() + throws RepositoryAdminException + { + List managedRepositories = getManagedRepositories(); + Map repositoriesMap = + new HashMap( managedRepositories.size() ); + for ( ManagedRepository managedRepository : managedRepositories ) + { + repositoriesMap.put( managedRepository.getId(), managedRepository ); + } + return repositoriesMap; + } + public ManagedRepository getManagedRepository( String repositoryId ) throws RepositoryAdminException { @@ -238,6 +253,7 @@ public class DefaultManagedRepositoryAdmin } + // FIXME cleanup repositoryGroups when deleting a ManagedRepo public Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation, boolean deleteContent ) throws RepositoryAdminException @@ -332,7 +348,13 @@ public class DefaultManagedRepositoryAdmin List repoGroups = repoToGroupMap.get( repository.getId() ); for ( String repoGroup : repoGroups ) { - config.findRepositoryGroupById( repoGroup ).removeRepository( repository.getId() ); + // copy to prevent UnsupportedOperationException + RepositoryGroupConfiguration repositoryGroupConfiguration = config.findRepositoryGroupById( repoGroup ); + List repos = new ArrayList( repositoryGroupConfiguration.getRepositories() ); + config.removeRepositoryGroup( repositoryGroupConfiguration ); + repos.remove( repository.getId() ); + repositoryGroupConfiguration.setRepositories( repos ); + config.addRepositoryGroup( repositoryGroupConfiguration ); } } } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdmin.java index 775e2f13a..8f9e2cd6f 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdmin.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdmin.java @@ -23,6 +23,7 @@ import org.apache.archiva.admin.AuditInformation; import org.apache.archiva.admin.repository.RepositoryAdminException; import java.util.List; +import java.util.Map; /** * @author Olivier Lamy @@ -33,6 +34,9 @@ public interface ManagedRepositoryAdmin List getManagedRepositories() throws RepositoryAdminException; + Map getManagedRepositoriesAsMap() + throws RepositoryAdminException; + ManagedRepository getManagedRepository( String repositoryId ) throws RepositoryAdminException; diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java index 2c5ae5cab..27da863ed 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java @@ -21,6 +21,12 @@ package org.apache.archiva.admin.repository; import junit.framework.TestCase; import org.apache.archiva.admin.AuditInformation; import org.apache.archiva.admin.mock.MockAuditListener; +import org.apache.archiva.admin.repository.managed.ManagedRepository; +import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin; +import org.apache.archiva.admin.repository.remote.RemoteRepositoryAdmin; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; +import org.codehaus.plexus.redback.role.RoleManager; import org.codehaus.plexus.redback.users.User; import org.codehaus.plexus.redback.users.memory.SimpleUser; import org.junit.runner.RunWith; @@ -30,6 +36,8 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.inject.Inject; +import java.io.File; +import java.util.List; /** * @author Olivier Lamy @@ -46,6 +54,15 @@ public abstract class AbstractRepositoryAdminTest @Inject protected MockAuditListener mockAuditListener; + @Inject + protected RoleManager roleManager; + + @Inject + protected RemoteRepositoryAdmin remoteRepositoryAdmin; + + @Inject + protected ManagedRepositoryAdmin managedRepositoryAdmin; + protected AuditInformation getFakeAuditInformation() { AuditInformation auditInformation = new AuditInformation( getFakeUser(), "archiva-localhost" ); @@ -68,4 +85,34 @@ public abstract class AbstractRepositoryAdminTest user.setFullName( "The top user" ); return user; } + + protected ManagedRepository getTestManagedRepository( String repoId, String repoLocation ) + { + return new ManagedRepository( repoId, "test repo", repoLocation, "default", false, true, true, "0 0 * * * ?", + repoLocation + "/.index", false, 1, 2, true ); + } + + protected File clearRepoLocation( String path ) + throws Exception + { + File repoDir = new File( path ); + if ( repoDir.exists() ) + { + FileUtils.deleteDirectory( repoDir ); + } + assertFalse( repoDir.exists() ); + return repoDir; + } + + protected ManagedRepository findManagedRepoById( List repos, String id ) + { + for ( ManagedRepository repo : repos ) + { + if ( StringUtils.equals( id, repo.getId() ) ) + { + return repo; + } + } + return null; + } } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdminTest.java new file mode 100644 index 000000000..7079a9caa --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/group/RepositoryGroupAdminTest.java @@ -0,0 +1,200 @@ +package org.apache.archiva.admin.repository.group; +/* + * 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.archiva.admin.repository.AbstractRepositoryAdminTest; +import org.apache.archiva.admin.repository.managed.ManagedRepository; +import org.apache.archiva.audit.AuditEvent; +import org.junit.Test; + +import javax.inject.Inject; +import java.io.File; +import java.util.Arrays; + +/** + * @author Olivier Lamy + */ +public class RepositoryGroupAdminTest + extends AbstractRepositoryAdminTest +{ + @Inject + RepositoryGroupAdmin repositoryGroupAdmin; + + @Test + public void addAndDeleteGroup() + throws Exception + { + try + { + ManagedRepository managedRepositoryOne = + getTestManagedRepository( "test-new-one", APPSERVER_BASE_PATH + File.separator + "test-new-one" ); + + ManagedRepository managedRepositoryTwo = + getTestManagedRepository( "test-new-two", APPSERVER_BASE_PATH + File.separator + "test-new-two" ); + + managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() ); + + managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() ); + + RepositoryGroup repositoryGroup = + new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) ); + + mockAuditListener.clearEvents(); + + repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() ); + + assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() ); + assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() ); + assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() ); + assertEquals( Arrays.asList( "test-new-one", "test-new-two" ), + repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() ); + + repositoryGroupAdmin.deleteRepositoryGroup( "repo-group-one", getFakeAuditInformation() ); + + assertEquals( 0, repositoryGroupAdmin.getRepositoriesGroups().size() ); + + assertEquals( 2, mockAuditListener.getAuditEvents().size() ); + + assertEquals( AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get( 0 ).getAction() ); + assertEquals( AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get( 1 ).getAction() ); + } + finally + { + mockAuditListener.clearEvents(); + managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true ); + managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true ); + } + } + + @Test + public void addAndUpdateAndDeleteGroup() + throws Exception + { + try + { + ManagedRepository managedRepositoryOne = + getTestManagedRepository( "test-new-one", APPSERVER_BASE_PATH + File.separator + "test-new-one" ); + + ManagedRepository managedRepositoryTwo = + getTestManagedRepository( "test-new-two", APPSERVER_BASE_PATH + File.separator + "test-new-two" ); + + managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() ); + + managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() ); + + RepositoryGroup repositoryGroup = new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one" ) ); + + mockAuditListener.clearEvents(); + + repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() ); + + assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() ); + assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() ); + assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() ); + assertEquals( Arrays.asList( "test-new-one" ), + repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() ); + + repositoryGroup = repositoryGroupAdmin.getRepositoryGroup( "repo-group-one" ); + assertNotNull( repositoryGroup ); + + repositoryGroup.addRepository( managedRepositoryTwo.getId() ); + + repositoryGroupAdmin.updateRepositoryGroup( repositoryGroup, getFakeAuditInformation() ); + + assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() ); + assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() ); + assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() ); + assertEquals( Arrays.asList( "test-new-one", "test-new-two" ), + repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() ); + + repositoryGroupAdmin.deleteRepositoryGroup( "repo-group-one", getFakeAuditInformation() ); + + assertEquals( 0, repositoryGroupAdmin.getRepositoriesGroups().size() ); + + assertEquals( 3, mockAuditListener.getAuditEvents().size() ); + + assertEquals( AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get( 0 ).getAction() ); + assertEquals( AuditEvent.MODIFY_REPO_GROUP, mockAuditListener.getAuditEvents().get( 1 ).getAction() ); + assertEquals( AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get( 2 ).getAction() ); + } + finally + { + mockAuditListener.clearEvents(); + managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true ); + managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true ); + } + } + + + @Test + public void addAndDeleteGroupWithRemowingManagedRepo() + throws Exception + { + try + { + ManagedRepository managedRepositoryOne = + getTestManagedRepository( "test-new-one", APPSERVER_BASE_PATH + File.separator + "test-new-one" ); + + ManagedRepository managedRepositoryTwo = + getTestManagedRepository( "test-new-two", APPSERVER_BASE_PATH + File.separator + "test-new-two" ); + + managedRepositoryAdmin.addManagedRepository( managedRepositoryOne, false, getFakeAuditInformation() ); + + managedRepositoryAdmin.addManagedRepository( managedRepositoryTwo, false, getFakeAuditInformation() ); + + RepositoryGroup repositoryGroup = + new RepositoryGroup( "repo-group-one", Arrays.asList( "test-new-one", "test-new-two" ) ); + + mockAuditListener.clearEvents(); + + repositoryGroupAdmin.addRepositoryGroup( repositoryGroup, getFakeAuditInformation() ); + + assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() ); + assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() ); + assertEquals( 2, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() ); + assertEquals( Arrays.asList( "test-new-one", "test-new-two" ), + repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() ); + + // deleting a managed repo to validate repogroup correctly updated ! + managedRepositoryAdmin.deleteManagedRepository( "test-new-one", getFakeAuditInformation(), true ); + + assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().size() ); + assertEquals( "repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getId() ); + assertEquals( 1, repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories().size() ); + assertEquals( Arrays.asList( "test-new-two" ), + repositoryGroupAdmin.getRepositoriesGroups().get( 0 ).getRepositories() ); + + repositoryGroupAdmin.deleteRepositoryGroup( "repo-group-one", getFakeAuditInformation() ); + + assertEquals( 0, repositoryGroupAdmin.getRepositoriesGroups().size() ); + + assertEquals( 3, mockAuditListener.getAuditEvents().size() ); + + assertEquals( AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get( 0 ).getAction() ); + assertEquals( AuditEvent.DELETE_MANAGED_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() ); + assertEquals( AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get( 2 ).getAction() ); + } + finally + { + mockAuditListener.clearEvents(); + + managedRepositoryAdmin.deleteManagedRepository( "test-new-two", getFakeAuditInformation(), true ); + } + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java index cedbc98a4..66dd71b5d 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java @@ -23,10 +23,8 @@ import org.apache.archiva.audit.AuditEvent; import org.apache.archiva.security.common.ArchivaRoleConstants; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; -import org.codehaus.plexus.redback.role.RoleManager; import org.junit.Test; -import javax.inject.Inject; import java.io.File; import java.util.List; @@ -36,15 +34,6 @@ import java.util.List; public class ManagedRepositoryAdminTest extends AbstractRepositoryAdminTest { - - @Inject - private ManagedRepositoryAdmin managedRepositoryAdmin; - - - - @Inject - protected RoleManager roleManager; - public static final String STAGE_REPO_ID_END = DefaultManagedRepositoryAdmin.STAGE_REPO_ID_END; @Test @@ -262,8 +251,6 @@ public class ManagedRepositoryAdminTest ManagedRepository repo = getTestManagedRepository( repoId, repoLocation ); - - managedRepositoryAdmin.addManagedRepository( repo, false, getFakeAuditInformation() ); assertTemplateRoleExists( repoId ); @@ -387,36 +374,6 @@ public class ManagedRepositoryAdminTest } - private File clearRepoLocation( String path ) - throws Exception - { - File repoDir = new File( path ); - if ( repoDir.exists() ) - { - FileUtils.deleteDirectory( repoDir ); - } - assertFalse( repoDir.exists() ); - return repoDir; - } - - private ManagedRepository findManagedRepoById( List repos, String id ) - { - for ( ManagedRepository repo : repos ) - { - if ( StringUtils.equals( id, repo.getId() ) ) - { - return repo; - } - } - return null; - } - - - ManagedRepository getTestManagedRepository( String repoId, String repoLocation ) - { - return new ManagedRepository( repoId, "test repo", repoLocation, "default", false, true, true, "0 0 * * * ?", - repoLocation + "/.index", false, 1, 2, true ); - } } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdminTest.java index fd294ce60..44c5c12fe 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdminTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/remote/RemoteRepositoryAdminTest.java @@ -22,7 +22,6 @@ import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest; import org.apache.archiva.audit.AuditEvent; import org.junit.Test; -import javax.inject.Inject; import java.util.List; /** @@ -32,9 +31,6 @@ public class RemoteRepositoryAdminTest extends AbstractRepositoryAdminTest { - @Inject - private RemoteRepositoryAdmin remoteRepositoryAdmin; - @Test public void getAll() throws Exception @@ -122,18 +118,14 @@ public class RemoteRepositoryAdminTest repo.setPassword( "titi" ); repo.setUrl( "http://foo.com/maven-really-rocks" ); - remoteRepositoryAdmin.updateRemoteRepository( repo, getFakeAuditInformation() ); - repo = remoteRepositoryAdmin.getRemoteRepository( "foo" ); assertEquals( "foo-name-changed", repo.getUserName() ); assertEquals( "titi", repo.getPassword() ); assertEquals( "http://foo.com/maven-really-rocks", repo.getUrl() ); - - remoteRepositoryAdmin.deleteRemoteRepository( "foo", getFakeAuditInformation() ); assertEquals( initialSize, remoteRepositoryAdmin.getRemoteRepositories().size() ); @@ -149,7 +141,7 @@ public class RemoteRepositoryAdminTest assertEquals( AuditEvent.MODIFY_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() ); assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() ); - assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get(1 ).getRemoteIP() ); + assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 1 ).getRemoteIP() ); assertEquals( AuditEvent.DELETE_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 2 ).getAction() ); assertEquals( "root", mockAuditListener.getAuditEvents().get( 2 ).getUserId() ); diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsAction.java index a45dace2b..9a6d83140 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsAction.java @@ -20,12 +20,14 @@ package org.apache.maven.archiva.web.action.admin.repositories; */ import com.opensymphony.xwork2.Preparable; +import org.apache.archiva.admin.repository.RepositoryAdminException; +import org.apache.archiva.admin.repository.managed.ManagedRepository; import org.apache.archiva.audit.AuditEvent; +import org.apache.archiva.web.util.ContextUtils; import org.apache.commons.lang.StringUtils; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration; -import org.apache.archiva.web.util.ContextUtils; import org.apache.struts2.interceptor.ServletRequestAware; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; @@ -38,7 +40,6 @@ import java.util.regex.Pattern; /** * RepositoryGroupsAction - * */ @Controller( "repositoryGroupsAction" ) @Scope( "prototype" ) @@ -50,7 +51,7 @@ public class RepositoryGroupsAction private Map repositoryGroups; - private Map managedRepositories; + private Map managedRepositories; private Map> groupToRepositoryMap; @@ -71,12 +72,13 @@ public class RepositoryGroupsAction } public void prepare() + throws RepositoryAdminException { Configuration config = archivaConfiguration.getConfiguration(); repositoryGroup = new RepositoryGroupConfiguration(); repositoryGroups = config.getRepositoryGroupsAsMap(); - managedRepositories = config.getManagedRepositoriesAsMap(); + managedRepositories = getManagedRepositoryAdmin().getManagedRepositoriesAsMap(); groupToRepositoryMap = config.getGroupToRepositoryMap(); } @@ -233,7 +235,7 @@ public class RepositoryGroupsAction this.repositoryGroups = repositoryGroups; } - public Map getManagedRepositories() + public Map getManagedRepositories() { return managedRepositories; } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsActionTest.java index 8c5b9b66e..e29d52ee7 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/RepositoryGroupsActionTest.java @@ -22,6 +22,7 @@ package org.apache.maven.archiva.web.action.admin.repositories; import com.meterware.servletunit.ServletRunner; import com.meterware.servletunit.ServletUnitClient; import com.opensymphony.xwork2.Action; +import org.apache.archiva.admin.repository.RepositoryAdminException; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; @@ -36,20 +37,18 @@ import java.util.List; /** * RepositoryGroupsActionTest - * - * @version */ -public class RepositoryGroupsActionTest +public class RepositoryGroupsActionTest extends AbstractActionTestCase { private static final String REPO_GROUP_ID = "repo-group-ident"; - + private static final String REPO1_ID = "managed-repo-ident-1"; - + private static final String REPO2_ID = "managed-repo-ident-2"; - + private RepositoryGroupsAction action; - + private MockControl archivaConfigurationControl; private ArchivaConfiguration archivaConfiguration; @@ -58,22 +57,21 @@ public class RepositoryGroupsActionTest throws Exception { super.setUp(); - - //action = (RepositoryGroupsAction) lookup( Action.class.getName(), "repositoryGroupsAction" ); + action = (RepositoryGroupsAction) getActionProxy( "/admin/repositoryGroups.action" ).getAction(); - + archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class ); archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock(); action.setArchivaConfiguration( archivaConfiguration ); } public void testSecureActionBundle() - throws SecureActionException + throws SecureActionException, RepositoryAdminException { archivaConfiguration.getConfiguration(); archivaConfigurationControl.setReturnValue( new Configuration() ); archivaConfigurationControl.replay(); - + action.prepare(); SecureActionBundle bundle = action.getSecureActionBundle(); assertTrue( bundle.requiresAuthentication() ); @@ -86,41 +84,41 @@ public class RepositoryGroupsActionTest Configuration configuration = new Configuration(); archivaConfiguration.getConfiguration(); archivaConfigurationControl.setReturnValue( configuration, 2 ); - + archivaConfiguration.save( configuration ); archivaConfigurationControl.replay(); - + action.prepare(); RepositoryGroupConfiguration repositoryGroup = action.getRepositoryGroup(); repositoryGroup.setId( REPO_GROUP_ID ); - + String status = action.addRepositoryGroup(); assertEquals( Action.SUCCESS, status ); - + assertEquals( Collections.singletonList( repositoryGroup ), configuration.getRepositoryGroups() ); - + archivaConfigurationControl.verify(); } - + public void testAddEmptyRepositoryGroup() throws Exception { Configuration configuration = new Configuration(); archivaConfiguration.getConfiguration(); archivaConfigurationControl.setReturnValue( configuration, 2 ); - + archivaConfiguration.save( configuration ); - + archivaConfigurationControl.replay(); - + action.prepare(); - + String status = action.addRepositoryGroup(); assertEquals( Action.ERROR, status ); - + assertEquals( 0, configuration.getRepositoryGroups().size() ); } - + public void testAddDuplicateRepositoryGroup() throws Exception { @@ -129,21 +127,21 @@ public class RepositoryGroupsActionTest archivaConfigurationControl.setReturnValue( configuration, 3 ); archivaConfiguration.save( configuration ); - + archivaConfigurationControl.replay(); - + action.prepare(); RepositoryGroupConfiguration repositoryGroup = action.getRepositoryGroup(); repositoryGroup.setId( REPO_GROUP_ID ); - + String status = action.addRepositoryGroup(); assertEquals( Action.SUCCESS, status ); - + assertEquals( Collections.singletonList( repositoryGroup ), configuration.getRepositoryGroups() ); - + repositoryGroup.setId( REPO_GROUP_ID ); status = action.addRepositoryGroup(); - + assertEquals( Action.ERROR, status ); assertEquals( Collections.singletonList( repositoryGroup ), configuration.getRepositoryGroups() ); } @@ -155,79 +153,79 @@ public class RepositoryGroupsActionTest ServletUnitClient sc = sr.newClient(); Configuration configuration = createInitialConfiguration(); - + archivaConfiguration.getConfiguration(); archivaConfigurationControl.setReturnValue( configuration ); archivaConfigurationControl.replay(); - + action.setServletRequest( sc.newInvocation( "http://localhost/admin/repositoryGroups.action" ).getRequest() ); action.prepare(); String result = action.execute(); assertEquals( Action.SUCCESS, result ); - + assertEquals( "http://localhost:0/repository", action.getBaseUrl() ); - + assertNotNull( action.getRepositoryGroups() ); assertEquals( 1, action.getRepositoryGroups().size() ); assertEquals( 2, action.getManagedRepositories().size() ); - + RepositoryGroupConfiguration repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID ); - + assertEquals( 1, repoGroup.getRepositories().size() ); assertEquals( REPO1_ID, repoGroup.getRepositories().get( 0 ) ); assertNotNull( action.getGroupToRepositoryMap() ); assertEquals( 1, action.getGroupToRepositoryMap().size() ); - + List repos = action.getGroupToRepositoryMap().get( repoGroup.getId() ); assertEquals( 1, repos.size() ); assertEquals( REPO2_ID, repos.get( 0 ) ); } - + public void testAddRepositoryToGroup() throws Exception { Configuration configuration = createInitialConfiguration(); - + archivaConfiguration.getConfiguration(); archivaConfigurationControl.setReturnValue( configuration, 6 ); archivaConfiguration.save( configuration ); archivaConfigurationControl.replay(); - + action.prepare(); String result = action.execute(); assertEquals( Action.SUCCESS, result ); - + assertNotNull( action.getRepositoryGroups() ); assertEquals( 1, action.getRepositoryGroups().size() ); assertEquals( 2, action.getManagedRepositories().size() ); - + RepositoryGroupConfiguration repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID ); - assertEquals( 1 , repoGroup.getRepositories().size() ); + assertEquals( 1, repoGroup.getRepositories().size() ); assertEquals( REPO1_ID, repoGroup.getRepositories().get( 0 ) ); - + assertNotNull( action.getGroupToRepositoryMap() ); assertEquals( 1, action.getGroupToRepositoryMap().size() ); - + List repos = action.getGroupToRepositoryMap().get( repoGroup.getId() ); assertEquals( 1, repos.size() ); assertEquals( REPO2_ID, repos.get( 0 ) ); - + action.setRepoGroupId( REPO_GROUP_ID ); action.setRepoId( REPO2_ID ); - + result = action.addRepositoryToGroup(); assertEquals( Action.SUCCESS, result ); - + action.prepare(); result = action.execute(); assertEquals( Action.SUCCESS, result ); - + assertEquals( 1, action.getRepositoryGroups().size() ); repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID ); assertEquals( 2, repoGroup.getRepositories().size() ); assertEquals( REPO1_ID, repoGroup.getRepositories().get( 0 ) ); assertEquals( REPO2_ID, repoGroup.getRepositories().get( 1 ) ); - + assertEquals( 0, action.getGroupToRepositoryMap().size() ); assertNull( action.getGroupToRepositoryMap().get( repoGroup.getId() ) ); } @@ -236,47 +234,47 @@ public class RepositoryGroupsActionTest throws Exception { Configuration configuration = createInitialConfiguration(); - + archivaConfiguration.getConfiguration(); archivaConfigurationControl.setReturnValue( configuration, 6 ); archivaConfiguration.save( configuration ); archivaConfigurationControl.replay(); - + action.prepare(); String result = action.execute(); assertEquals( Action.SUCCESS, result ); - + assertNotNull( action.getRepositoryGroups() ); assertEquals( 1, action.getRepositoryGroups().size() ); assertEquals( 2, action.getManagedRepositories().size() ); - + RepositoryGroupConfiguration repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID ); - assertEquals( 1 , repoGroup.getRepositories().size() ); + assertEquals( 1, repoGroup.getRepositories().size() ); assertEquals( REPO1_ID, repoGroup.getRepositories().get( 0 ) ); - + assertNotNull( action.getGroupToRepositoryMap() ); assertEquals( 1, action.getGroupToRepositoryMap().size() ); - + List repos = action.getGroupToRepositoryMap().get( repoGroup.getId() ); assertEquals( 1, repos.size() ); assertEquals( REPO2_ID, repos.get( 0 ) ); - + action.setRepoGroupId( REPO_GROUP_ID ); action.setRepoId( REPO1_ID ); - + result = action.removeRepositoryFromGroup(); assertEquals( Action.SUCCESS, result ); - + action.prepare(); result = action.execute(); assertEquals( Action.SUCCESS, result ); - + repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID ); assertEquals( 0, repoGroup.getRepositories().size() ); - + assertNotNull( action.getGroupToRepositoryMap() ); assertEquals( 1, action.getGroupToRepositoryMap().size() ); - + repos = action.getGroupToRepositoryMap().get( repoGroup.getId() ); assertEquals( 2, repos.size() ); assertEquals( REPO1_ID, repos.get( 0 ) ); @@ -287,70 +285,70 @@ public class RepositoryGroupsActionTest throws Exception { Configuration configuration = createInitialConfiguration(); - + archivaConfiguration.getConfiguration(); archivaConfigurationControl.setReturnValue( configuration, 6 ); archivaConfiguration.save( configuration ); archivaConfigurationControl.replay(); - + action.prepare(); String result = action.execute(); assertEquals( Action.SUCCESS, result ); - + assertNotNull( action.getRepositoryGroups() ); assertEquals( 1, action.getRepositoryGroups().size() ); assertEquals( 2, action.getManagedRepositories().size() ); - + RepositoryGroupConfiguration repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID ); - assertEquals( 1 , repoGroup.getRepositories().size() ); + assertEquals( 1, repoGroup.getRepositories().size() ); assertEquals( REPO1_ID, repoGroup.getRepositories().get( 0 ) ); - + assertNotNull( action.getGroupToRepositoryMap() ); assertEquals( 1, action.getGroupToRepositoryMap().size() ); - + List repos = action.getGroupToRepositoryMap().get( repoGroup.getId() ); assertEquals( 1, repos.size() ); assertEquals( REPO2_ID, repos.get( 0 ) ); - + action.setRepoGroupId( REPO_GROUP_ID ); action.setRepoId( REPO1_ID ); - + result = action.addRepositoryToGroup(); assertEquals( Action.ERROR, result ); } - + public void testRemoveRepositoryNotInGroup() throws Exception { Configuration configuration = createInitialConfiguration(); - + archivaConfiguration.getConfiguration(); archivaConfigurationControl.setReturnValue( configuration, 6 ); archivaConfiguration.save( configuration ); archivaConfigurationControl.replay(); - + action.prepare(); String result = action.execute(); assertEquals( Action.SUCCESS, result ); - + assertNotNull( action.getRepositoryGroups() ); assertEquals( 1, action.getRepositoryGroups().size() ); assertEquals( 2, action.getManagedRepositories().size() ); - + RepositoryGroupConfiguration repoGroup = action.getRepositoryGroups().get( REPO_GROUP_ID ); - assertEquals( 1 , repoGroup.getRepositories().size() ); + assertEquals( 1, repoGroup.getRepositories().size() ); assertEquals( REPO1_ID, repoGroup.getRepositories().get( 0 ) ); - + assertNotNull( action.getGroupToRepositoryMap() ); assertEquals( 1, action.getGroupToRepositoryMap().size() ); - + List repos = action.getGroupToRepositoryMap().get( repoGroup.getId() ); assertEquals( 1, repos.size() ); assertEquals( REPO2_ID, repos.get( 0 ) ); - + action.setRepoGroupId( REPO_GROUP_ID ); action.setRepoId( REPO2_ID ); - + result = action.removeRepositoryFromGroup(); assertEquals( Action.ERROR, result ); } @@ -358,23 +356,23 @@ public class RepositoryGroupsActionTest private Configuration createInitialConfiguration() { Configuration config = new Configuration(); - + ManagedRepositoryConfiguration managedRepo1 = new ManagedRepositoryConfiguration(); managedRepo1.setId( REPO1_ID ); - + config.addManagedRepository( managedRepo1 ); - + ManagedRepositoryConfiguration managedRepo2 = new ManagedRepositoryConfiguration(); managedRepo2.setId( REPO2_ID ); - + config.addManagedRepository( managedRepo2 ); - + RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration(); repoGroup.setId( REPO_GROUP_ID ); repoGroup.addRepository( REPO1_ID ); - + config.addRepositoryGroup( repoGroup ); - + return config; } } diff --git a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditEvent.java b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditEvent.java index 6e6d3cf6c..779194927 100644 --- a/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditEvent.java +++ b/archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/AuditEvent.java @@ -89,6 +89,8 @@ public class AuditEvent public static final String DELETE_REPO_GROUP = "Deleted Repository Group"; + public static final String MODIFY_REPO_GROUP = "Modify Repository Group"; + public static final String ADD_REPO_TO_GROUP = "Added Repository to Group"; public static final String DELETE_REPO_FROM_GROUP = "Deleted Repository from Group";