View Javadoc
1   package org.codehaus.plexus.digest;
2   
3   /*
4    * Copyright 2001-2006 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 junit.framework.TestCase;
20  
21  public class DigestUtilsTest
22      extends TestCase
23  {
24      /**  SHA1 checksum from www.ibiblio.org/maven2, incuding file path */
25      private static final String SERVLETAPI_SHA1 = "bcc82975c0f9c681fcb01cc38504c992553e93ba";
26  
27      public void testCleanChecksum()
28          throws DigesterException
29      {
30          String expected = SERVLETAPI_SHA1
31              + "  /home/projects/maven/repository-staging/to-ibiblio/maven2/servletapi/servletapi/2.4/servletapi-2.4.pom";
32  
33          String s = DigestUtils.cleanChecksum( expected, "SHA1", "servletapi/servletapi/2.4/servletapi-2.4.pom" );
34          assertEquals( "Checksum doesn't match", SERVLETAPI_SHA1, s );
35  
36      }
37  
38      public void testCleanChecksumAltDash1()
39          throws DigesterException
40      {
41          String expected = SERVLETAPI_SHA1 + "  -";
42          String s = DigestUtils.cleanChecksum( expected, "SHA1", "servletapi/servletapi/2.4/servletapi-2.4.pom" );
43          assertEquals( "Checksum doesn't match", SERVLETAPI_SHA1, s );
44      }
45  
46      public void testCleanChecksumAltDash2()
47          throws DigesterException
48      {
49          String expected = "SHA1(-)=" + SERVLETAPI_SHA1;
50          String s = DigestUtils.cleanChecksum( expected, "SHA1", "servletapi/servletapi/2.4/servletapi-2.4.pom" );
51          assertEquals( "Checksum doesn't match", SERVLETAPI_SHA1, s );
52      }
53  }