--- /dev/null
+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();
+ }
+}
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;
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();
- }
- }
}
import java.io.File;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
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;
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() );
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()
Configuration configuration = prepDeletionTest( createRepository(), 4 );
+ MockControl control = mockAuditListeners();
+
+ MockControl metadataRepositoryControl = mockMetadataRepository();
+
String status = action.deleteContents();
assertEquals( Action.SUCCESS, status );
assertFalse( location.exists() );
repositoryStatisticsManagerControl.verify();
+ control.verify();
+ metadataRepositoryControl.verify();
}
public void testDeleteRepositoryAndAssociatedProxyConnectors()
assertEquals( 1, configuration.getProxyConnectors().size() );
+ MockControl control = mockAuditListeners();
+ MockControl metadataRepositoryControl = mockMetadataRepository();
String status = action.deleteContents();
assertEquals( Action.SUCCESS, status );
assertFalse( location.exists() );
repositoryStatisticsManagerControl.verify();
+ control.verify();
+ metadataRepositoryControl.verify();
}
public void testDeleteRepositoryCancelled()
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 )