View Javadoc

1   package org.apache.maven.archiva.transaction;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.commons.io.FileUtils;
23  import org.codehaus.plexus.spring.PlexusInSpringTestCase;
24  import org.codehaus.plexus.spring.PlexusToSpringUtils;
25  import org.codehaus.plexus.digest.Digester;
26  
27  import java.io.File;
28  import java.io.IOException;
29  import java.util.List;
30  
31  /**
32   * 
33   * @version $Id: AbstractFileEventTest.java 755305 2009-03-17 16:24:16Z brett $
34   */
35  public abstract class AbstractFileEventTest
36      extends PlexusInSpringTestCase
37  {
38      protected List<Digester> digesters;
39  
40      @SuppressWarnings("unchecked")
41      public void setUp()
42          throws Exception
43      {
44          super.setUp();
45  
46          digesters = PlexusToSpringUtils.lookupList( PlexusToSpringUtils.buildSpringId( Digester.class.getName() ), getApplicationContext() );
47      }
48  
49      protected void assertChecksumExists( File file, String algorithm )
50      {
51          assertChecksum( file, algorithm, true );
52      }
53  
54      protected void assertChecksumDoesNotExist( File file, String algorithm )
55      {
56          assertChecksum( file, algorithm, false );
57      }
58  
59      private void assertChecksum( File file, String algorithm, boolean exist )
60      {
61          String msg = exist ? "exists" : "does not exist";
62          File checksumFile = new File( file.getPath() + "." + algorithm );
63          assertEquals( "Test file " + algorithm + " checksum " + msg, exist, checksumFile.exists() );
64      }
65  
66      protected void assertChecksumCommit( File file )
67          throws IOException
68      {
69          assertChecksumExists( file, "md5" );
70          assertChecksumExists( file, "sha1" );
71      }
72  
73      protected void assertChecksumRollback( File file )
74          throws IOException
75      {
76          assertChecksumDoesNotExist( file, "md5" );
77          assertChecksumDoesNotExist( file, "sha1" );
78      }
79  
80      protected String readFile( File file )
81          throws IOException
82      {
83          return FileUtils.readFileToString( file );
84      }
85  
86      protected void writeFile( File file, String content )
87          throws IOException
88      {
89          FileUtils.writeStringToFile( file, content );
90      }
91  }