ManagedRepositoryContent content = new ManagedDefaultRepositoryContent();
content.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null );
archivaConfigControl.replay();
repoFactoryControl.replay();
auditLogsDaoControl.replay();
String returnString = uploadAction.doUpload();
assertEquals( Action.SUCCESS, returnString );
archivaConfigControl.verify();
repoFactoryControl.verify();
auditLogsDaoControl.verify();
String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation();
String[] artifactsList = new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/" ).list();
Arrays.sort( artifactsList );
assertEquals( 9, artifactsList.length );
assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/"
+ MetadataTools.MAVEN_METADATA ).exists() );
assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/"
+ MetadataTools.MAVEN_METADATA + ".sha1" ).exists() );
assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/"
+ MetadataTools.MAVEN_METADATA + ".md5" ).exists() );
int startIndex = "artifact-upload-1.0-".length();
String timestamp = getTimestamp( artifactsList, startIndex, 0 );
assertAllArtifactsIncludingSupportArtifactsArePresent( repoLocation, "artifact-upload-1.0-" + timestamp,
"1.0-SNAPSHOT" );
verifyArtifactChecksums( repoLocation, "artifact-upload-1.0-" + timestamp, "1.0-SNAPSHOT" );
verifyPomChecksums( repoLocation, "artifact-upload-1.0-" + timestamp, "1.0-SNAPSHOT" );
verifyProjectMetadataChecksums( repoLocation );
verifyVersionMetadataChecksums( repoLocation, "1.0-SNAPSHOT" );
// verify build number
File metadataFile =
new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/" + MetadataTools.MAVEN_METADATA );
ArchivaRepositoryMetadata artifactMetadata = RepositoryMetadataReader.read( metadataFile );
SnapshotVersion snapshotVersion = artifactMetadata.getSnapshotVersion();
assertEquals( "Incorrect build number set in artifact metadata.", 1, snapshotVersion.getBuildNumber() );
String timestampPart = StringUtils.substringBeforeLast( timestamp, "-" );
assertEquals( "Incorrect timestamp set in artifact metadata.", timestampPart, snapshotVersion.getTimestamp() );
String buildnumber = StringUtils.substringAfterLast( timestamp, "-" );
assertEquals( "Incorrect build number in filename.", "1", buildnumber );
archivaConfigControl.reset();
repoFactoryControl.reset();
auditLogsDaoControl.reset();
auditLogsDaoControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
// MRM-1353
// upload snapshot artifact again and check if build number was incremented
setUploadParameters( "1.0-SNAPSHOT", null,
new File( getBasedir(),
"target/test-classes/upload-artifact-test/artifact-to-be-uploaded.jar" ), null,
true );
archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
repoFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( REPOSITORY_ID ), content );
auditLogsDaoControl.expectAndReturn( auditLogsDao.saveAuditLogs( new ArchivaAuditLogs() ), null );
archivaConfigControl.replay();
repoFactoryControl.replay();
auditLogsDaoControl.replay();