1 package org.apache.archiva.transaction;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import junit.framework.TestCase;
23 import org.apache.commons.io.FileUtils;
24 import org.codehaus.plexus.digest.Digester;
25 import org.codehaus.plexus.digest.Md5Digester;
26 import org.codehaus.plexus.digest.Sha1Digester;
29 import java.io.IOException;
30 import java.util.Arrays;
31 import java.util.List;
32 import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
33 import org.junit.Before;
34 import org.junit.runner.RunWith;
39 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
40 public abstract class AbstractFileEventTest
43 protected List<Digester> digesters;
45 @SuppressWarnings( "unchecked" )
53 digesters = Arrays.asList( (Digester) new Md5Digester(), (Digester) new Sha1Digester() );
56 protected void assertChecksumExists( File file, String algorithm )
58 assertChecksum( file, algorithm, true );
61 protected void assertChecksumDoesNotExist( File file, String algorithm )
63 assertChecksum( file, algorithm, false );
66 private void assertChecksum( File file, String algorithm, boolean exist )
68 String msg = exist ? "exists" : "does not exist";
69 File checksumFile = new File( file.getPath() + "." + algorithm );
70 assertEquals( "Test file " + algorithm + " checksum " + msg, exist, checksumFile.exists() );
73 protected void assertChecksumCommit( File file )
76 assertChecksumExists( file, "md5" );
77 assertChecksumExists( file, "sha1" );
80 protected void assertChecksumRollback( File file )
83 assertChecksumDoesNotExist( file, "md5" );
84 assertChecksumDoesNotExist( file, "sha1" );
87 protected String readFile( File file )
90 return FileUtils.readFileToString( file );
93 protected void writeFile( File file, String content )
96 FileUtils.writeStringToFile( file, content );