From: Brett Porter Date: Tue, 19 Jan 2010 07:29:54 +0000 (+0000) Subject: [MRM-1282] ensure repository metadata is deleted when repository is X-Git-Tag: archiva-1.4-M1~1017^2~41 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0e588344064c6ea4248950f563c4e3797b1f45e2;p=archiva.git [MRM-1282] ensure repository metadata is deleted when repository is git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@900685 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AuditEventArgumentsMatcher.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AuditEventArgumentsMatcher.java new file mode 100644 index 000000000..81bed6f71 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/AuditEventArgumentsMatcher.java @@ -0,0 +1,49 @@ +package org.apache.maven.archiva.web.action; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.Arrays; + +import org.apache.maven.archiva.repository.audit.AuditEvent; +import org.easymock.ArgumentsMatcher; + +public class AuditEventArgumentsMatcher + implements ArgumentsMatcher +{ + public boolean matches( Object[] objects, Object[] objects1 ) + { + if ( objects.length != 1 || objects1.length != 1 ) + { + return false; + } + else + { + AuditEvent o1 = (AuditEvent) objects[0]; + AuditEvent o2 = (AuditEvent) objects1[0]; + o2.setTimestamp( o1.getTimestamp() ); // effectively ignore the timestamp + return o1.equals( o2 ); + } + } + + public String toString( Object[] objects ) + { + return Arrays.asList( objects ).toString(); + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/UploadActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/UploadActionTest.java index 2ac78407b..7f25503b7 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/UploadActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/UploadActionTest.java @@ -47,7 +47,6 @@ import org.apache.maven.archiva.repository.audit.AuditListener; import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent; import org.apache.maven.archiva.repository.metadata.MetadataTools; import org.codehaus.plexus.spring.PlexusInSpringTestCase; -import org.easymock.ArgumentsMatcher; import org.easymock.MockControl; import org.easymock.classextension.MockClassControl; @@ -681,27 +680,4 @@ public class UploadActionTest verifyChecksums( repoLocation ); } - private static class AuditEventArgumentsMatcher - implements ArgumentsMatcher - { - public boolean matches( Object[] objects, Object[] objects1 ) - { - if ( objects.length != 1 || objects1.length != 1 ) - { - return false; - } - else - { - AuditEvent o1 = (AuditEvent) objects[0]; - AuditEvent o2 = (AuditEvent) objects1[0]; - o2.setTimestamp( o1.getTimestamp() ); // effectively ignore the timestamp - return o1.equals( o2 ); - } - } - - public String toString( Object[] objects ) - { - return Arrays.asList( objects ).toString(); - } - } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java index a7bf0b97e..94f7b674e 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java @@ -21,6 +21,7 @@ package org.apache.maven.archiva.web.action.admin.repositories; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -34,7 +35,10 @@ import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration; import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration; +import org.apache.maven.archiva.repository.audit.AuditEvent; +import org.apache.maven.archiva.repository.audit.AuditListener; import org.apache.maven.archiva.security.ArchivaRoleConstants; +import org.apache.maven.archiva.web.action.AuditEventArgumentsMatcher; import org.codehaus.plexus.redback.role.RoleManager; import org.codehaus.plexus.redback.role.RoleManagerException; import org.codehaus.plexus.registry.RegistryException; @@ -145,10 +149,14 @@ public class DeleteManagedRepositoryActionTest prepareRoleManagerMock(); - Configuration configuration = prepDeletionTest( createRepository(), 4 ); - + Configuration configuration = prepDeletionTest( createRepository(), 4 ); + + MockControl control = mockAuditListeners(); + + MockControl metadataRepositoryControl = mockMetadataRepository(); + String status = action.deleteEntry(); - + assertEquals( Action.SUCCESS, status ); assertTrue( configuration.getManagedRepositories().isEmpty() ); @@ -156,6 +164,29 @@ public class DeleteManagedRepositoryActionTest assertTrue( location.exists() ); repositoryStatisticsManagerControl.verify(); + control.verify(); + metadataRepositoryControl.verify(); + } + + private MockControl mockMetadataRepository() + { + MockControl metadataRepositoryControl = MockControl.createControl( MetadataRepository.class ); + MetadataRepository metadataRepository = (MetadataRepository) metadataRepositoryControl.getMock(); + metadataRepository.deleteRepository( REPO_ID ); + metadataRepositoryControl.replay(); + action.setMetadataRepository( metadataRepository ); + return metadataRepositoryControl; + } + + private MockControl mockAuditListeners() + { + MockControl control = MockControl.createControl( AuditListener.class ); + AuditListener listener = (AuditListener) control.getMock(); + listener.auditEvent( new AuditEvent( REPO_ID, "guest", null, AuditEvent.DELETE_MANAGED_REPO ) ); + control.setMatcher( new AuditEventArgumentsMatcher() ); + control.replay(); + action.setAuditListeners( Arrays.asList( listener ) ); + return control; } public void testDeleteRepositoryDeleteContent() @@ -168,6 +199,10 @@ public class DeleteManagedRepositoryActionTest Configuration configuration = prepDeletionTest( createRepository(), 4 ); + MockControl control = mockAuditListeners(); + + MockControl metadataRepositoryControl = mockMetadataRepository(); + String status = action.deleteContents(); assertEquals( Action.SUCCESS, status ); @@ -177,6 +212,8 @@ public class DeleteManagedRepositoryActionTest assertFalse( location.exists() ); repositoryStatisticsManagerControl.verify(); + control.verify(); + metadataRepositoryControl.verify(); } public void testDeleteRepositoryAndAssociatedProxyConnectors() @@ -194,6 +231,8 @@ public class DeleteManagedRepositoryActionTest assertEquals( 1, configuration.getProxyConnectors().size() ); + MockControl control = mockAuditListeners(); + MockControl metadataRepositoryControl = mockMetadataRepository(); String status = action.deleteContents(); assertEquals( Action.SUCCESS, status ); @@ -204,6 +243,8 @@ public class DeleteManagedRepositoryActionTest assertFalse( location.exists() ); repositoryStatisticsManagerControl.verify(); + control.verify(); + metadataRepositoryControl.verify(); } public void testDeleteRepositoryCancelled() @@ -241,15 +282,19 @@ public class DeleteManagedRepositoryActionTest assertEquals( 1, configuration.getRepositoryGroups().size() ); + MockControl control = mockAuditListeners(); + MockControl metadataRepositoryControl = mockMetadataRepository(); String status = action.deleteContents(); assertEquals( Action.SUCCESS, status ); assertTrue( configuration.getManagedRepositories().isEmpty() ); - assertEquals( 0, ( ( RepositoryGroupConfiguration ) configuration.getRepositoryGroups().get( 0 ) ).getRepositories().size() ); + assertEquals( 0, configuration.getRepositoryGroups().get( 0 ).getRepositories().size() ); assertFalse( location.exists() ); repositoryStatisticsManagerControl.verify(); + control.verify(); + metadataRepositoryControl.verify(); } private Configuration prepDeletionTest( ManagedRepositoryConfiguration originalRepository, int expectCountGetConfig ) diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java index aa5882007..437972390 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/metadata/repository/MetadataRepository.java @@ -69,5 +69,9 @@ public interface MetadataRepository void deleteArtifact( String repositoryId, String namespace, String project, String version, String id ); + /** + * Delete a repository's metadata. This includes all associated metadata facets. + * @param repoId the repository to delete + */ void deleteRepository( String repoId ); }