1 package org.codehaus.plexus.digest;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import org.codehaus.plexus.PlexusTestCase;
20
21 import java.io.File;
22
23
24
25
26
27
28
29 public class ChecksumFileTest extends PlexusTestCase
30 {
31 private ChecksumFile checksum;
32
33 protected void setUp()
34 throws Exception
35 {
36 super.setUp();
37
38 checksum = (ChecksumFile) lookup( ChecksumFile.class.getName() );
39 }
40
41 public void testIsValidChecksum()
42 throws Exception
43 {
44 File exampleDir = new File( getBasedir(), "src/test/examples" );
45
46 assertTrue( checksum.isValidChecksum( new File( exampleDir, "redback-authz-open.jar.md5" ) ) );
47 assertTrue( checksum.isValidChecksum( new File( exampleDir, "redback-authz-open.jar.sha1" ) ) );
48
49 assertTrue( checksum.isValidChecksum( new File( exampleDir, "plain.jar.md5" ) ) );
50 assertTrue( checksum.isValidChecksum( new File( exampleDir, "plain.jar.sha1" ) ) );
51
52 assertTrue( checksum.isValidChecksum( new File( exampleDir, "single-space.jar.md5" ) ) );
53 assertTrue( checksum.isValidChecksum( new File( exampleDir, "single-space.jar.sha1" ) ) );
54
55 assertTrue( checksum.isValidChecksum( new File( exampleDir, "space-asterisk.jar.md5" ) ) );
56 assertTrue( checksum.isValidChecksum( new File( exampleDir, "space-asterisk.jar.sha1" ) ) );
57
58 assertTrue( checksum.isValidChecksum( new File( exampleDir, "openssl.jar.md5" ) ) );
59 assertTrue( checksum.isValidChecksum( new File( exampleDir, "openssl.jar.sha1" ) ) );
60 }
61
62 public void testCreateChecksum()
63 throws Exception
64 {
65 File dataFile = File.createTempFile( "plexus-digest-test", null );
66 dataFile.deleteOnExit();
67
68 File md5File = checksum.createChecksum( dataFile, new Md5Digester() );
69 md5File.deleteOnExit();
70 assertNotNull( md5File );
71 assertTrue( md5File.isFile() );
72 assertTrue( checksum.isValidChecksum( md5File ) );
73
74 File sha1File = checksum.createChecksum( dataFile, new Sha1Digester() );
75 sha1File.deleteOnExit();
76 assertNotNull( sha1File );
77 assertTrue( sha1File.isFile() );
78 assertTrue( checksum.isValidChecksum( sha1File ) );
79 }
80
81 }