From 4cb99823a0cf9e843f1767cbbbd9045eb057e4a7 Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Thu, 25 Feb 2010 10:14:17 +0000 Subject: [PATCH] [MRM-1312] mda5 and sha are not generated for snapshot jars merge from 1.3.x branch -r916197 with a few tweaks in variable name in UploadArtifactTest to resolve conflict git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@916217 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva/web/action/UploadAction.java | 2 +- .../archiva/web/action/UploadActionTest.java | 77 ++++++++++++++++++- 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java index 4d5db60d4..1106d9426 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/UploadAction.java @@ -359,7 +359,7 @@ public class UploadAction { copyFile( artifactFile, targetPath, filename, fixChecksums ); triggerAuditEvent( repository.getId(), path + "/" + filename, AuditEvent.UPLOAD_FILE ); - queueRepositoryTask( repository.getId(), repository.toFile( artifactReference ) ); + queueRepositoryTask( repository.getId(), targetFile ); } } catch ( IOException ie ) 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 7f25503b7..7f052b6be 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 @@ -526,7 +526,9 @@ public class UploadActionTest control.verify(); String repoLocation = config.findManagedRepositoryById( REPOSITORY_ID ).getLocation(); - assertEquals( 6, new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/" ).list().length ); + String[] artifactsList = new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/" ).list(); + + assertEquals( 6, artifactsList.length ); assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA ).exists() ); @@ -534,6 +536,79 @@ public class UploadActionTest ".sha1" ).exists() ); assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/" + MetadataTools.MAVEN_METADATA + ".md5" ).exists() ); + + int startIndex = "artifact-upload-1.0-".length(); + int endIndex = -1; + + if ( artifactsList[0].contains( "jar" ) ) + { + endIndex = artifactsList[0].indexOf( ".jar" ); + } + else + { + endIndex = artifactsList[0].indexOf( ".pom" ); + } + + String actualTimestamp = artifactsList[0].substring( startIndex, endIndex ); + + assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".jar" ).exists() ); + assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".jar.md5" ).exists() ); + assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".jar.sha1" ).exists() ); + assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".pom" ).exists() ); + assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".pom.md5" ).exists() ); + assertTrue( new File( repoLocation, "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".pom.sha1" ).exists() ); + + // verify checksums of jar file + ChecksummedFile checksum = + new ChecksummedFile( new File( repoLocation, + "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".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-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".jar.sha1" ) ); + assertTrue( StringUtils.contains( contents, sha1 ) ); + + contents = + FileUtils.readFileToString( new File( repoLocation, + "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".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-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".pom" ) ); + sha1 = checksum.calculateChecksum( ChecksumAlgorithm.SHA1 ); + md5 = checksum.calculateChecksum( ChecksumAlgorithm.MD5 ); + + contents = + FileUtils.readFileToString( new File( repoLocation, + "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".pom.sha1" ) ); + assertTrue( StringUtils.contains( contents, sha1 ) ); + + contents = + FileUtils.readFileToString( new File( repoLocation, + "/org/apache/archiva/artifact-upload/1.0-SNAPSHOT/artifact-upload-1.0-" + actualTimestamp + ".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 ) ); + 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 testChecksumIsCorrectWhenArtifactIsReUploaded() -- 2.39.5