import java.io.File;
import java.io.IOException;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
import com.opensymphony.xwork2.Action;
import org.apache.archiva.checksum.ChecksumAlgorithm;
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.RepositoryContentFactory;
import org.apache.maven.archiva.repository.RepositoryNotFoundException;
+import org.apache.maven.archiva.repository.audit.AuditEvent;
+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;
private RepositoryContentFactory repoFactory;
private MockControl repoFactoryControl;
-
+
private static final String REPOSITORY_ID = "test-repo";
- private Configuration config;
+ private Configuration config;
public void setUp()
throws Exception
repoFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class );
repoFactory = (RepositoryContentFactory) repoFactoryControl.getMock();
-
+
uploadAction = new UploadAction();
uploadAction.setScheduler( scheduler );
uploadAction.setConfiguration( archivaConfig );
File testRepo = new File( getBasedir(), "target/test-classes/test-repo" );
testRepo.mkdirs();
-
+
assertTrue( testRepo.exists() );
-
+
config = new Configuration();
ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
repoConfig.setId( REPOSITORY_ID );
repoConfig.setName( REPOSITORY_ID );
repoConfig.setBlockRedeployments( true );
config.addManagedRepository( repoConfig );
-
+
RepositoryScanningConfiguration repoScanning = new RepositoryScanningConfiguration();
repoScanning.setKnownContentConsumers( new ArrayList<String>() );
config.setRepositoryScanning( repoScanning );
private void assertAllArtifactsIncludingSupportArtifactsArePresent( String repoLocation )
{
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ).exists() );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.sha1" ).exists() );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.md5" ).exists() );
-
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ).exists() );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ).exists() );
-
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
+ assertTrue(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ).exists() );
+ assertTrue(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.sha1" ).exists() );
+ assertTrue(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.md5" ).exists() );
+
+ assertTrue(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
+ assertTrue(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ).exists() );
+ assertTrue(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ).exists() );
+
+ assertTrue(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
".sha1" ).exists() );
assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
throws IOException
{
// verify checksums of jar file
- ChecksummedFile checksum =
- new ChecksummedFile( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ) );
+ ChecksummedFile checksum = new ChecksummedFile(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ) );
String sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
String md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
- String contents =
- FileUtils.readFileToString( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.sha1" ) );
+ String contents = FileUtils.readFileToString(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.sha1" ) );
assertTrue( StringUtils.contains( contents, sha1 ) );
- contents =
- FileUtils.readFileToString( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.md5" ) );
+ contents = FileUtils.readFileToString(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.md5" ) );
assertTrue( StringUtils.contains( contents, md5 ) );
// verify checksums of pom file
- checksum =
- new ChecksummedFile( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
+ checksum = new ChecksummedFile(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
- contents =
- FileUtils.readFileToString( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ) );
+ contents = FileUtils.readFileToString(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ) );
assertTrue( StringUtils.contains( contents, sha1 ) );
- contents =
- FileUtils.readFileToString( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ) );
+ contents = FileUtils.readFileToString(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ) );
assertTrue( StringUtils.contains( contents, md5 ) );
// verify checksums of metadata file
- checksum =
- new ChecksummedFile( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
- MetadataTools.MAVEN_METADATA ) );
+ checksum = new ChecksummedFile(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ) );
sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
- contents =
- FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
- MetadataTools.MAVEN_METADATA + ".sha1" ) );
+ contents = FileUtils.readFileToString(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA + ".sha1" ) );
assertTrue( StringUtils.contains( contents, sha1 ) );
- contents =
- FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
- MetadataTools.MAVEN_METADATA + ".md5" ) );
+ contents = FileUtils.readFileToString(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA + ".md5" ) );
assertTrue( StringUtils.contains( contents, md5 ) );
}
public void testArtifactUploadWithPomSuccessful()
throws Exception
{
- setUploadParameters( "1.0", null,
- new File( getBasedir(),
- "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
+ setUploadParameters( "1.0", null, new File( getBasedir(),
+ "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
new File( getBasedir(), "target/test-classes/upload-artifact-test/pom.xml" ), false );
ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
archivaConfigControl.replay();
repoFactoryControl.replay();
+ MockControl control = mockAuditLogs(
+ Arrays.asList( "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar",
+ "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
+
String returnString = uploadAction.doUpload();
assertEquals( Action.SUCCESS, returnString );
archivaConfigControl.verify();
repoFactoryControl.verify();
+ control.verify();
String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
verifyChecksums( repoLocation );
}
+ private MockControl mockAuditLogs( List<String> resources )
+ {
+ return mockAuditLogs( AuditEvent.UPLOAD_FILE, resources );
+ }
+
+ private MockControl mockAuditLogs( String action, List<String> resources )
+ {
+ MockControl control = MockControl.createControl( AuditListener.class );
+ AuditListener listener = (AuditListener) control.getMock();
+ boolean matcherSet = false;
+ for ( String resource : resources )
+ {
+ listener.auditEvent( new AuditEvent( REPOSITORY_ID, "guest", resource, action ) );
+ if ( !matcherSet )
+ {
+ control.setMatcher( new AuditEventArgumentsMatcher() );
+ matcherSet = true;
+ }
+ }
+ control.replay();
+
+ uploadAction.setAuditListeners( Collections.singletonList( listener ) );
+ return control;
+ }
+
public void testArtifactUploadWithClassifier()
throws Exception
{
- setUploadParameters( "1.0", "tests",
- new File( getBasedir(),
- "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
- false );
+ setUploadParameters( "1.0", "tests", new File( getBasedir(),
+ "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
+ new File( getBasedir(), "target/test-classes/upload-artifact-test/pom.xml" ), false );
ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
archivaConfigControl.replay();
repoFactoryControl.replay();
+ MockControl control = mockAuditLogs(
+ Arrays.asList( "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar",
+ "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
+
String returnString = uploadAction.doUpload();
assertEquals( Action.SUCCESS, returnString );
archivaConfigControl.verify();
repoFactoryControl.verify();
+ control.verify();
String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar" ).exists() );
+ assertTrue( new File( repoLocation,
+ "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar" ).exists() );
assertTrue( new File( repoLocation,
"/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.sha1" ).exists() );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.md5" ).exists() );
+ assertTrue( new File( repoLocation,
+ "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.md5" ).exists() );
- assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
- assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ).exists() );
- assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ).exists() );
+ assertTrue(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
+ assertTrue(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ).exists() );
+ assertTrue(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ).exists() );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
+ assertTrue(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
".sha1" ).exists() );
assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
".md5" ).exists() );
// verify checksums of jar file
- ChecksummedFile checksum =
- new ChecksummedFile( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar" ) );
+ ChecksummedFile checksum = new ChecksummedFile(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar" ) );
String sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
String md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
- String contents =
- FileUtils.readFileToString( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.sha1" ) );
+ String contents = FileUtils.readFileToString(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.sha1" ) );
assertTrue( StringUtils.contains( contents, sha1 ) );
- contents =
- FileUtils.readFileToString( new File( repoLocation,
- "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.md5" ) );
+ contents = FileUtils.readFileToString(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0-tests.jar.md5" ) );
+ assertTrue( StringUtils.contains( contents, md5 ) );
+
+ // verify checksums of jar file
+ checksum = new ChecksummedFile(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
+ sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
+ md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
+
+ contents = FileUtils.readFileToString(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ) );
+ assertTrue( StringUtils.contains( contents, sha1 ) );
+
+ contents = FileUtils.readFileToString(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ) );
assertTrue( StringUtils.contains( contents, md5 ) );
// verify checksums of metadata file
- checksum =
- new ChecksummedFile( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
- MetadataTools.MAVEN_METADATA ) );
+ checksum = new ChecksummedFile(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ) );
sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
- contents =
- FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
- MetadataTools.MAVEN_METADATA + ".sha1" ) );
+ contents = FileUtils.readFileToString(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA + ".sha1" ) );
assertTrue( StringUtils.contains( contents, sha1 ) );
- contents =
- FileUtils.readFileToString( new File( repoLocation, "/org/apache/archiva/artifact-upload/" +
- MetadataTools.MAVEN_METADATA + ".md5" ) );
+ contents = FileUtils.readFileToString(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA + ".md5" ) );
assertTrue( StringUtils.contains( contents, md5 ) );
}
public void testArtifactUploadGeneratePomSuccessful()
throws Exception
{
- setUploadParameters( "1.0", null,
- new File( getBasedir(),
- "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
- true );
+ setUploadParameters( "1.0", null, new File( getBasedir(),
+ "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
+ null, true );
ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
archivaConfigControl.replay();
repoFactoryControl.replay();
+ MockControl control = mockAuditLogs(
+ Arrays.asList( "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar",
+ "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
+
String returnString = uploadAction.doUpload();
assertEquals( Action.SUCCESS, returnString );
archivaConfigControl.verify();
repoFactoryControl.verify();
+ control.verify();
String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
verifyChecksums( repoLocation );
}
+ public void testArtifactUploadNoPomSuccessful()
+ throws Exception
+ {
+ setUploadParameters( "1.0", null, new File( getBasedir(),
+ "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
+ null, false );
+
+ ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
+ content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
+
+ archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+ repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
+
+ archivaConfigControl.replay();
+ repoFactoryControl.replay();
+
+ MockControl control =
+ mockAuditLogs( Arrays.asList( "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ) );
+
+ String returnString = uploadAction.doUpload();
+ assertEquals( Action.SUCCESS, returnString );
+
+ archivaConfigControl.verify();
+ repoFactoryControl.verify();
+ control.verify();
+
+ String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
+ assertTrue(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ).exists() );
+ assertTrue(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.sha1" ).exists() );
+ assertTrue(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.md5" ).exists() );
+
+ assertFalse(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
+ assertFalse(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.sha1" ).exists() );
+ assertFalse(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom.md5" ).exists() );
+
+ assertTrue(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
+ ".sha1" ).exists() );
+ assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
+ ".md5" ).exists() );
+
+ // verify checksums of jar file
+ ChecksummedFile checksum = new ChecksummedFile(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ) );
+ String sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
+ String md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
+
+ String contents = FileUtils.readFileToString(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.sha1" ) );
+ assertTrue( StringUtils.contains( contents, sha1 ) );
+
+ contents = FileUtils.readFileToString(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar.md5" ) );
+ assertTrue( StringUtils.contains( contents, md5 ) );
+
+ // verify checksums of metadata file
+ checksum = new ChecksummedFile(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ) );
+ sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 );
+ md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 );
+
+ contents = FileUtils.readFileToString(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA + ".sha1" ) );
+ assertTrue( StringUtils.contains( contents, sha1 ) );
+
+ contents = FileUtils.readFileToString(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA + ".md5" ) );
+ assertTrue( StringUtils.contains( contents, md5 ) );
+ }
+
public void testArtifactUploadFailedRepositoryNotFound()
throws Exception
- {
- setUploadParameters( "1.0", null,
- new File( getBasedir(),
- "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
- false );
+ {
+ setUploadParameters( "1.0", null, new File( getBasedir(),
+ "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
+ null, false );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
repoFactoryControl.expectAndThrow( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ),
repoFactoryControl.verify();
String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
- assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ).exists() );
+ assertFalse(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar" ).exists() );
- assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
+ assertFalse(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ).exists() );
- assertFalse( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
+ assertFalse(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
}
public void testArtifactUploadSnapshots()
throws Exception
{
- setUploadParameters( "1.0-SNAPSHOT", null,
- new File( getBasedir(),
- "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
- true );
+ setUploadParameters( "1.0-SNAPSHOT", null, new File( getBasedir(),
+ "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
+ null, true );
ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
archivaConfigControl.replay();
repoFactoryControl.replay();
+ SimpleDateFormat fmt = new SimpleDateFormat( "yyyyMMdd.HHmmss" );
+ fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
+ String timestamp = fmt.format( new Date() );
+ MockControl control = mockAuditLogs( Arrays.asList(
+ "org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + "-1.jar",
+ "org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + timestamp + "-1.pom" ) );
+
String returnString = uploadAction.doUpload();
assertEquals( Action.SUCCESS, returnString );
archivaConfigControl.verify();
repoFactoryControl.verify();
+ control.verify();
String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
assertEquals( 6, new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/" ).list().length );
- assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
+ assertTrue(
+ new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() );
assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
".sha1" ).exists() );
assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA +
public void testChecksumIsCorrectWhenArtifactIsReUploaded()
throws Exception
{
- setUploadParameters( "1.0", null,
- new File( getBasedir(),
- "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
- true );
+ setUploadParameters( "1.0", null, new File( getBasedir(),
+ "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
+ null, true );
ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById( REPOSITORY_ID );
- repoConfig.setBlockRedeployments( false );
- content.setRepository( repoConfig );
-
+ repoConfig.setBlockRedeployments( false );
+ content.setRepository( repoConfig );
+
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
verifyChecksums( repoLocation );
// RE-upload artifact
- setUploadParameters( "1.0", null,
- new File( getBasedir(),
- "target/test-classes/upload-artifact-test/artifact-to-be-reuploaded.jar" ),
+ setUploadParameters( "1.0", null, new File( getBasedir(),
+ "target/test-classes/upload-artifact-test/artifact-to-be-reuploaded.jar" ),
null, true );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
archivaConfigControl.replay();
repoFactoryControl.replay();
+ // TODO: track modifications?
+// MockControl control = mockAuditLogs( AuditEvent.MODIFY_FILE, Arrays.asList(
+ MockControl control = mockAuditLogs(
+ Arrays.asList( "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar",
+ "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
+
returnString = uploadAction.doUpload();
assertEquals( Action.SUCCESS, returnString );
archivaConfigControl.verify();
repoFactoryControl.verify();
+ control.verify();
repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
verifyChecksums( repoLocation );
}
-
+
public void testUploadArtifactAlreadyExistingRedeploymentsBlocked()
throws Exception
- {
- setUploadParameters( "1.0", null,
- new File( getBasedir(),
- "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
- true );
+ {
+ setUploadParameters( "1.0", null, new File( getBasedir(),
+ "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
+ null, true );
ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
String returnString = uploadAction.doUpload();
assertEquals( Action.SUCCESS, returnString );
-
- setUploadParameters( "1.0", null,
- new File( getBasedir(),
- "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
- true );
-
+
+ setUploadParameters( "1.0", null, new File( getBasedir(),
+ "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
+ null, true );
+
+ MockControl control = mockAuditLogs( Collections.<String>emptyList() );
+
returnString = uploadAction.doUpload();
assertEquals( Action.ERROR, returnString );
archivaConfigControl.verify();
repoFactoryControl.verify();
+ control.verify();
String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
verifyChecksums( repoLocation );
}
-
+
public void testUploadArtifactAlreadyExistingRedeploymentsAllowed()
throws Exception
- {
- setUploadParameters( "1.0", null,
- new File( getBasedir(),
- "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
- true );
-
+ {
+ setUploadParameters( "1.0", null, new File( getBasedir(),
+ "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
+ null, true );
+
ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById( REPOSITORY_ID );
- repoConfig.setBlockRedeployments( false );
- content.setRepository( repoConfig );
-
+ repoConfig.setBlockRedeployments( false );
+ content.setRepository( repoConfig );
+
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config, 2 );
repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content, 2 );
String returnString = uploadAction.doUpload();
assertEquals( Action.SUCCESS, returnString );
-
- setUploadParameters( "1.0", null,
- new File( getBasedir(),
- "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
- true );
-
+
+ setUploadParameters( "1.0", null, new File( getBasedir(),
+ "target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ),
+ null, true );
+
+ // TODO: track modifications?
+// MockControl control = mockAuditLogs( AuditEvent.MODIFY_FILE, Arrays.asList(
+ MockControl control = mockAuditLogs(
+ Arrays.asList( "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.jar",
+ "org/apache/archiva/artifact-upload/1.0/artifact-upload-1.0.pom" ) );
+
returnString = uploadAction.doUpload();
assertEquals( Action.SUCCESS, returnString );
-
+
archivaConfigControl.verify();
repoFactoryControl.verify();
-
+ control.verify();
+
String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation );
-
+
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();
+ }
+ }
}