1 package org.apache.maven.archiva.transaction;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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 }