]> source.dussan.org Git - archiva.git/commitdiff
Test fix to make test specific path, minor fix, import fix 57/head
authorEric Barboni <skygo@apache.org>
Tue, 11 Feb 2020 19:38:48 +0000 (20:38 +0100)
committerEric Barboni <skygo@apache.org>
Tue, 11 Feb 2020 19:38:48 +0000 (20:38 +0100)
archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/Checksum.java
archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksumAlgorithm.java
archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksumUtil.java
archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksummedFile.java
archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/AbstractChecksumTestCase.java
archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksumAlgorithmTest.java
archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksumTest.java
archiva-modules/archiva-base/archiva-checksum/src/test/java/org/apache/archiva/checksum/ChecksummedFileTest.java

index 2a198877eff79848b33927764c094e73176bd352..d32e5fb5e2e2018e42aa56dc0da23c05f2e0af54 100644 (file)
@@ -19,12 +19,7 @@ package org.apache.archiva.checksum;
  * under the License.
  */
 
-import java.io.IOException;
 import java.nio.ByteBuffer;
-import java.nio.MappedByteBuffer;
-import java.nio.channels.FileChannel;
-import java.nio.file.Path;
-import java.nio.file.StandardOpenOption;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 
@@ -108,13 +103,13 @@ public class Checksum
         if (this.result == null || this.result.length==0) {
             finish();
         }
-        return md.isEqual( this.result, cmp );
+        return MessageDigest.isEqual( this.result, cmp );
     }
 
     public boolean compare(String hexString) {
         if (this.result == null || this.result.length==0) {
             finish();
         }
-        return md.isEqual(this.result, Hex.decode( hexString ));
+        return MessageDigest.isEqual(this.result, Hex.decode( hexString ));
     }
 }
index bf6252decabed9796c0121c0239e86b535ed7de3..99c710004a7fee7709d66dabab5693fc8f240b7b 100644 (file)
@@ -23,11 +23,8 @@ package org.apache.archiva.checksum;
 import org.apache.commons.io.FilenameUtils;
 
 import java.nio.file.Path;
-import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
index bb6a710ae26865765e2821a614cb421177da8f9d..0770ad8dd841226f606e219cbcecfe6db6394ede 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.archiva.checksum;
  * under the License.
  */
 
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.nio.MappedByteBuffer;
 import java.nio.channels.FileChannel;
index 1279bdcd5976a2bdc90b4c7f8576ac0d29952090..0bf0a467d5fb4bd53479413abb1407e6e1ba809b 100644 (file)
@@ -133,7 +133,7 @@ public class ChecksummedFile
     {
         for ( String ext : checksumAlgorithm.getExt( ) )
         {
-            Path file = referenceFile.resolveSibling( referenceFile.getFileName( ) + "." + checksumAlgorithm.getExt( ) );
+            Path file = referenceFile.resolveSibling( referenceFile.getFileName( ) + "." + ext );
             if ( Files.exists( file ) )
             {
                 return file;
@@ -340,7 +340,7 @@ public class ChecksummedFile
 
     private void writeChecksumFile( Path checksumFile, Charset encoding, String checksumHex )
     {
-        FileUtils.writeStringToFile( checksumFile, FILE_ENCODING, checksumHex + "  " + referenceFile.getFileName( ).toString( ) );
+        FileUtils.writeStringToFile( checksumFile, encoding, checksumHex + "  " + referenceFile.getFileName( ).toString( ) );
     }
 
     private boolean isValidChecksumPattern( String filename, String path )
index f1caab9b1007850ce6d74109b3d287257fae45d8..ada972f140953a0d6a1bbc40da273bcd38f9a2df 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.archiva.checksum;
  * under the License.
  */
 
-import junit.framework.TestCase;
 import org.apache.archiva.common.utils.FileUtils;
 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
 import org.junit.runner.RunWith;
@@ -28,6 +27,9 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.rules.TestName;
 
 /**
  * AbstractChecksumTestCase
@@ -36,11 +38,12 @@ import java.nio.file.Paths;
  */
 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
 public abstract class AbstractChecksumTestCase
-    extends TestCase
 {
+    @Rule public TestName name = new TestName();
+
     public Path getTestOutputDir()
     {
-        Path dir = Paths.get( FileUtils.getBasedir(), "target/test-output/" + getName() );
+        Path dir = Paths.get( FileUtils.getBasedir(), "target/test-output/" + name.getMethodName() );
         if ( !Files.exists(dir))
         {
             try
@@ -49,7 +52,7 @@ public abstract class AbstractChecksumTestCase
             }
             catch ( IOException e )
             {
-                fail( "Unable to create test output directory: " + dir.toAbsolutePath() );
+                Assert.fail( "Unable to create test output directory: " + dir.toAbsolutePath() );
             }
         }
         return dir;
@@ -61,7 +64,7 @@ public abstract class AbstractChecksumTestCase
         Path file = dir.resolve(filename );
         if ( !Files.exists(file))
         {
-            fail( "Test Resource does not exist: " + file.toAbsolutePath() );
+            Assert.fail( "Test Resource does not exist: " + file.toAbsolutePath() );
         }
         return file;
     }
index 56fc5ad492a1315744c6fed32415523f3bd365cf..579b24369aeba258b8ede5d977617fdebfd9945d 100644 (file)
@@ -19,12 +19,11 @@ package org.apache.archiva.checksum;
  * under the License.
  */
 
-import junit.framework.TestCase;
 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-
 import java.nio.file.Paths;
+import org.junit.Assert;
 
 /**
  * ChecksumAlgorithmTest
@@ -33,20 +32,19 @@ import java.nio.file.Paths;
  */
 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
 public class ChecksumAlgorithmTest
-    extends TestCase
 {
     @Test
     public void testGetHashByExtensionSha1()
     {
-        assertEquals( ChecksumAlgorithm.SHA1, ChecksumAlgorithm.getByExtension( Paths.get( "something.jar.sha1" ) ) );
-        assertEquals( ChecksumAlgorithm.SHA1, ChecksumAlgorithm.getByExtension( Paths.get( "OTHER.JAR.SHA1" ) ) );
+        Assert.assertEquals( ChecksumAlgorithm.SHA1, ChecksumAlgorithm.getByExtension( Paths.get( "something.jar.sha1" ) ) );
+        Assert.assertEquals( ChecksumAlgorithm.SHA1, ChecksumAlgorithm.getByExtension( Paths.get( "OTHER.JAR.SHA1" ) ) );
     }
     
     @Test
     public void testGetHashByExtensionMd5()
     {
-        assertEquals( ChecksumAlgorithm.MD5, ChecksumAlgorithm.getByExtension( Paths.get( "something.jar.md5" ) ) );
-        assertEquals( ChecksumAlgorithm.MD5, ChecksumAlgorithm.getByExtension( Paths.get( "OTHER.JAR.MD5" ) ) );
+        Assert.assertEquals( ChecksumAlgorithm.MD5, ChecksumAlgorithm.getByExtension( Paths.get( "something.jar.md5" ) ) );
+        Assert.assertEquals( ChecksumAlgorithm.MD5, ChecksumAlgorithm.getByExtension( Paths.get( "OTHER.JAR.MD5" ) ) );
     }
 
     @Test
@@ -55,7 +53,7 @@ public class ChecksumAlgorithmTest
         try
         {
             ChecksumAlgorithm.getByExtension( Paths.get( "something.jar" ) );
-            fail( "Expected " + IllegalArgumentException.class.getName() );
+            Assert.fail( "Expected " + IllegalArgumentException.class.getName() );
         }
         catch ( IllegalArgumentException e )
         {
index ca3dab891308724e7d73c34775242e10ebde9180..79767459ca452bc930df3d86867e284defb3a0d2 100644 (file)
@@ -23,12 +23,12 @@ import org.apache.archiva.common.utils.FileUtils;
 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-
 import java.io.IOException;
 import java.nio.charset.Charset;
 import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.List;
+import org.junit.Assert;
 
 /**
  * ChecksumTest
@@ -46,7 +46,7 @@ public class ChecksumTest
     public void testConstructSha1()
     {
         Checksum checksum = new Checksum( ChecksumAlgorithm.SHA1 );
-        assertEquals( "Checksum.algorithm", checksum.getAlgorithm().getAlgorithm(), ChecksumAlgorithm.SHA1
+        Assert.assertEquals( "Checksum.algorithm", checksum.getAlgorithm().getAlgorithm(), ChecksumAlgorithm.SHA1
             .getAlgorithm() );
     }
 
@@ -54,7 +54,7 @@ public class ChecksumTest
     public void testConstructMd5()
     {
         Checksum checksum = new Checksum( ChecksumAlgorithm.MD5 );
-        assertEquals( "Checksum.algorithm", checksum.getAlgorithm().getAlgorithm(), ChecksumAlgorithm.MD5
+        Assert.assertEquals( "Checksum.algorithm", checksum.getAlgorithm().getAlgorithm(), ChecksumAlgorithm.MD5
             .getAlgorithm() );
     }
 
@@ -65,7 +65,7 @@ public class ChecksumTest
         byte buf[] = ( "You know, I'm sick of following my dreams, man. "
             + "I'm just going to ask where they're going and hook up with 'em later. - Mitch Hedberg" ).getBytes();
         checksum.update( buf, 0, buf.length );
-        assertEquals( "Checksum", "e396119ae0542e85a74759602fd2f81e5d36d762", checksum.getChecksum() );
+        Assert.assertEquals( "Checksum", "e396119ae0542e85a74759602fd2f81e5d36d762", checksum.getChecksum() );
     }
 
     @Test
@@ -84,32 +84,32 @@ public class ChecksumTest
 
         ChecksumUtil.update( checksums, checkFile );
 
-        assertEquals( "Checksum SHA1", "e396119ae0542e85a74759602fd2f81e5d36d762", checksumSha1.getChecksum() );
-        assertEquals( "Checksum MD5", "21c2c5ca87ec018adacb2e2fb3432219", checksumMd5.getChecksum() );
+        Assert.assertEquals( "Checksum SHA1", "e396119ae0542e85a74759602fd2f81e5d36d762", checksumSha1.getChecksum() );
+        Assert.assertEquals( "Checksum MD5", "21c2c5ca87ec018adacb2e2fb3432219", checksumMd5.getChecksum() );
     }
 
     @Test
     public void testUpdateWholeUpdatePartial()
     {
         Checksum checksum = new Checksum( ChecksumAlgorithm.SHA1 );
-        assertEquals( "Checksum unset", UNSET_SHA1, checksum.getChecksum() );
+        Assert.assertEquals( "Checksum unset", UNSET_SHA1, checksum.getChecksum() );
 
         String expected = "066c2cbbc8cdaecb8ff97dcb84502462d6f575f3";
         byte reesepieces[] = "eatagramovabits".getBytes();
         checksum.update( reesepieces, 0, reesepieces.length );
         String actual = checksum.getChecksum();
 
-        assertEquals( "Expected", expected, actual );
+        Assert.assertEquals( "Expected", expected, actual );
 
         // Reset the checksum.
         checksum.reset();
-        assertEquals( "Checksum unset", UNSET_SHA1, checksum.getChecksum() );
+        Assert.assertEquals( "Checksum unset", UNSET_SHA1, checksum.getChecksum() );
 
         // Now parse it again in 3 pieces.
         checksum.update( reesepieces, 0, 5 );
         checksum.update( reesepieces, 5, 5 );
         checksum.update( reesepieces, 10, reesepieces.length - 10 );
 
-        assertEquals( "Expected", expected, actual );
+        Assert.assertEquals( "Expected", expected, actual );
     }
 }
index fb1ddd3b3bf2bcf2baadb5c2af8b500b6fc5de91..e9f2e433f2cd9e1279b10a1dd355e5bfe8a81df1 100644 (file)
@@ -24,7 +24,6 @@ import org.apache.commons.lang3.StringUtils;
 import org.junit.Before;
 import org.junit.Test;
 import org.slf4j.LoggerFactory;
-
 import java.io.IOException;
 import java.nio.charset.Charset;
 import java.nio.file.Files;
@@ -32,6 +31,8 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.StandardCopyOption;
 import java.util.Arrays;
+import org.junit.After;
+import org.junit.Assert;
 
 /**
  * ChecksummedFileTest
@@ -54,7 +55,7 @@ public class ChecksummedFileTest
     private static final Charset FILE_ENCODING = Charset.forName( "UTF-8" );
 
 
-    @Before
+    @After
     public void cleanTestDir()
     {
         try
@@ -64,9 +65,9 @@ public class ChecksummedFileTest
         catch ( IOException ex )
         {
             LoggerFactory.getLogger( ChecksummedFileTest.class ).warn( ex.getMessage(), ex );
-        }
+        }        
     }
-
+    
     private Path createTestableJar( String filename )
         throws IOException
     {
@@ -110,7 +111,7 @@ public class ChecksummedFileTest
         ChecksummedFile checksummedFile = new ChecksummedFile( testfile );
         String expectedChecksum = "f42047fe2e177ac04d0df7aa44d408be";
         String actualChecksum = checksummedFile.calculateChecksum( ChecksumAlgorithm.MD5 );
-        assertEquals( expectedChecksum, actualChecksum );
+        Assert.assertEquals( expectedChecksum, actualChecksum );
     }
 
     @Test
@@ -121,7 +122,7 @@ public class ChecksummedFileTest
         ChecksummedFile checksummedFile = new ChecksummedFile( testfile );
         String expectedChecksum = "2bb14b388973351b0a4dfe11d171965f59cc61a1";
         String actualChecksum = checksummedFile.calculateChecksum( ChecksumAlgorithm.SHA1 );
-        assertEquals( expectedChecksum, actualChecksum );
+        Assert.assertEquals( expectedChecksum, actualChecksum );
     }
 
     @Test
@@ -132,10 +133,10 @@ public class ChecksummedFileTest
         ChecksummedFile checksummedFile = new ChecksummedFile( testableJar );
         checksummedFile.writeFile( ChecksumAlgorithm.SHA1 );
         Path hashFile = checksummedFile.getChecksumFile( ChecksumAlgorithm.SHA1 );
-        assertTrue( "ChecksumAlgorithm file should exist.", Files.exists(hashFile) );
+        Assert.assertTrue( "ChecksumAlgorithm file should exist.", Files.exists(hashFile) );
         String hashContents = org.apache.commons.io.FileUtils.readFileToString( hashFile.toFile(), "UTF-8" );
         hashContents = StringUtils.trim( hashContents );
-        assertEquals( "2bb14b388973351b0a4dfe11d171965f59cc61a1  redback-authz-open.jar", hashContents );
+        Assert.assertEquals( "2bb14b388973351b0a4dfe11d171965f59cc61a1  redback-authz-open.jar", hashContents );
     }
 
     @Test
@@ -149,15 +150,15 @@ public class ChecksummedFileTest
         org.apache.commons.io.FileUtils.writeStringToFile( sha1File.toFile(), "sha1sum: redback-authz-open.jar: No such file or directory", "UTF-8" );
 
         ChecksummedFile checksummedFile = new ChecksummedFile( jarFile );
-        assertFalse( "ChecksummedFile.isValid(SHA1) == false",
+        Assert.assertFalse( "ChecksummedFile.isValid(SHA1) == false",
                      checksummedFile.isValidChecksum( ChecksumAlgorithm.SHA1 ) );
 
         UpdateStatusList fixed = checksummedFile.fixChecksums( Arrays.asList( ChecksumAlgorithm.SHA1 ) );
-        assertEquals(1, fixed.getStatusList().size());
-        assertFalse(fixed.getTotalStatus()==UpdateStatus.ERROR);
-        assertTrue( "ChecksummedFile.fixChecksums() == true", fixed.getStatusList().get(0).getValue()==UpdateStatus.UPDATED );
+        Assert.assertEquals(1, fixed.getStatusList().size());
+        Assert.assertFalse(fixed.getTotalStatus()==UpdateStatus.ERROR);
+        Assert.assertTrue( "ChecksummedFile.fixChecksums() == true", fixed.getStatusList().get(0).getValue()==UpdateStatus.UPDATED );
 
-        assertTrue( "ChecksummedFile.isValid(SHA1) == true",
+        Assert.assertTrue( "ChecksummedFile.isValid(SHA1) == true",
                     checksummedFile.isValidChecksum( ChecksumAlgorithm.SHA1 ) );
     }
 
@@ -165,7 +166,7 @@ public class ChecksummedFileTest
     public void testGetChecksumFile()
     {
         ChecksummedFile checksummedFile = new ChecksummedFile( Paths.get( "test.jar" ) );
-        assertEquals( "test.jar.sha1", checksummedFile.getChecksumFile( ChecksumAlgorithm.SHA1 ).getFileName().toString() );
+        Assert.assertEquals( "test.jar.sha1", checksummedFile.getChecksumFile( ChecksumAlgorithm.SHA1 ).getFileName().toString() );
     }
 
     @Test
@@ -175,7 +176,7 @@ public class ChecksummedFileTest
         Path jarFile = createTestableJar( "examples/redback-authz-open.jar", true, false );
 
         ChecksummedFile checksummedFile = new ChecksummedFile( jarFile );
-        assertTrue( "ChecksummedFile.isValid(SHA1)", checksummedFile.isValidChecksum( ChecksumAlgorithm.SHA1 ) );
+        Assert.assertTrue( "ChecksummedFile.isValid(SHA1)", checksummedFile.isValidChecksum( ChecksumAlgorithm.SHA1 ) );
     }
 
     @Test
@@ -189,7 +190,7 @@ public class ChecksummedFileTest
         FileUtils.writeStringToFile( sha1File, FILE_ENCODING, "sha1sum: redback-authz-open.jar: No such file or directory" );
 
         ChecksummedFile checksummedFile = new ChecksummedFile( jarFile );
-        assertFalse( "ChecksummedFile.isValid(SHA1)", checksummedFile.isValidChecksum( ChecksumAlgorithm.SHA1 ) );
+        Assert.assertFalse( "ChecksummedFile.isValid(SHA1)", checksummedFile.isValidChecksum( ChecksumAlgorithm.SHA1 ) );
 
     }
 
@@ -200,7 +201,7 @@ public class ChecksummedFileTest
         Path jarFile = createTestableJar( "examples/redback-authz-open.jar", false, false );
 
         ChecksummedFile checksummedFile = new ChecksummedFile( jarFile );
-        assertFalse( "ChecksummedFile.isValid(SHA1,MD5)", checksummedFile.isValidChecksums(
+        Assert.assertFalse( "ChecksummedFile.isValid(SHA1,MD5)", checksummedFile.isValidChecksums(
             Arrays.asList(ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 ) ) );
 
     }
@@ -212,7 +213,7 @@ public class ChecksummedFileTest
         Path jarFile = createTestableJar( "examples/redback-authz-open.jar", true, true );
 
         ChecksummedFile checksummedFile = new ChecksummedFile( jarFile );
-        assertTrue( "ChecksummedFile.isValid(SHA1,MD5)", checksummedFile.isValidChecksums(
+        Assert.assertTrue( "ChecksummedFile.isValid(SHA1,MD5)", checksummedFile.isValidChecksums(
             Arrays.asList(ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 ) ) );
     }
 
@@ -223,7 +224,7 @@ public class ChecksummedFileTest
         Path jarFile = createTestableJar( "examples/redback-authz-open.jar", true, false );
 
         ChecksummedFile checksummedFile = new ChecksummedFile( jarFile );
-        assertTrue( "ChecksummedFile.isValid(SHA1)", checksummedFile.isValidChecksums(
+        Assert.assertTrue( "ChecksummedFile.isValid(SHA1)", checksummedFile.isValidChecksums(
             Arrays.asList(ChecksumAlgorithm.SHA1, ChecksumAlgorithm.MD5 ) ) );
 
     }
@@ -240,7 +241,7 @@ public class ChecksummedFileTest
         ChecksummedFile checksummedFile = new ChecksummedFile( testfile );
         String s = checksummedFile.parseChecksum( expectedFile, ChecksumAlgorithm.SHA1,
                                                   "servletapi/servletapi/2.4/servletapi-2.4.pom", FILE_ENCODING);
-        assertEquals( "Checksum doesn't match", SERVLETAPI_SHA1, s );
+        Assert.assertEquals( "Checksum doesn't match", SERVLETAPI_SHA1, s );
 
     }
 
@@ -254,7 +255,7 @@ public class ChecksummedFileTest
         ChecksummedFile checksummedFile = new ChecksummedFile( testfile );
         String s = checksummedFile.parseChecksum( expectedFile, ChecksumAlgorithm.SHA1,
                                                   "servletapi/servletapi/2.4/servletapi-2.4.pom", FILE_ENCODING );
-        assertEquals( "Checksum doesn't match", SERVLETAPI_SHA1, s );
+        Assert.assertEquals( "Checksum doesn't match", SERVLETAPI_SHA1, s );
     }
 
     @Test
@@ -267,7 +268,7 @@ public class ChecksummedFileTest
         ChecksummedFile checksummedFile = new ChecksummedFile( testfile );
         String s = checksummedFile.parseChecksum( expectedFile, ChecksumAlgorithm.SHA1,
                                                   "servletapi/servletapi/2.4/servletapi-2.4.pom" , FILE_ENCODING);
-        assertEquals( "Checksum doesn't match", SERVLETAPI_SHA1, s );
+        Assert.assertEquals( "Checksum doesn't match", SERVLETAPI_SHA1, s );
     }
 
     @Test
@@ -282,12 +283,12 @@ public class ChecksummedFileTest
         try
         {
             String s = checksummedFile.parseChecksum( expectedFile, ChecksumAlgorithm.SHA1, "maven-metadata-remote.xml", FILE_ENCODING );
-            assertEquals( "Checksum doesn't match", REMOTE_METADATA_SHA1, s );
+            Assert.assertEquals( "Checksum doesn't match", REMOTE_METADATA_SHA1, s );
         }
         catch ( ChecksumValidationException e )
         {
             e.printStackTrace();
-            fail( "IOException should not occur." );
+            Assert.fail( "IOException should not occur." );
         }
     }
 
@@ -303,12 +304,12 @@ public class ChecksummedFileTest
         try
         {
             String s = checksummedFile.parseChecksum( expectedFile, ChecksumAlgorithm.MD5, "maven-metadata-remote.xml", FILE_ENCODING );
-            assertEquals( "Checksum doesn't match", REMOTE_METADATA_MD5, s );
+            Assert.assertEquals( "Checksum doesn't match", REMOTE_METADATA_MD5, s );
         }
         catch ( ChecksumValidationException e )
         {
             e.printStackTrace();
-            fail( "IOException should not occur." );
+            Assert.fail( "IOException should not occur." );
         }
     }
 }