View Javadoc
1   package org.codehaus.plexus.digest;
2   
3   /*
4    * Copyright 2001-2007 The Codehaus.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import org.codehaus.plexus.PlexusTestCase;
20  
21  import java.io.File;
22  
23  /**
24   * ChecksumFileTest 
25   *
26   * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
27   * @version $Id$
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  }