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
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() );
}
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() );
}
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
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 );
}
}
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;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
+import org.junit.After;
+import org.junit.Assert;
/**
* ChecksummedFileTest
private static final Charset FILE_ENCODING = Charset.forName( "UTF-8" );
- @Before
+ @After
public void cleanTestDir()
{
try
catch ( IOException ex )
{
LoggerFactory.getLogger( ChecksummedFileTest.class ).warn( ex.getMessage(), ex );
- }
+ }
}
-
+
private Path createTestableJar( String filename )
throws IOException
{
ChecksummedFile checksummedFile = new ChecksummedFile( testfile );
String expectedChecksum = "f42047fe2e177ac04d0df7aa44d408be";
String actualChecksum = checksummedFile.calculateChecksum( ChecksumAlgorithm.MD5 );
- assertEquals( expectedChecksum, actualChecksum );
+ Assert.assertEquals( expectedChecksum, actualChecksum );
}
@Test
ChecksummedFile checksummedFile = new ChecksummedFile( testfile );
String expectedChecksum = "2bb14b388973351b0a4dfe11d171965f59cc61a1";
String actualChecksum = checksummedFile.calculateChecksum( ChecksumAlgorithm.SHA1 );
- assertEquals( expectedChecksum, actualChecksum );
+ Assert.assertEquals( expectedChecksum, actualChecksum );
}
@Test
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
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 ) );
}
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
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
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 ) );
}
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 ) ) );
}
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 ) ) );
}
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 ) ) );
}
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 );
}
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
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
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." );
}
}
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." );
}
}
}