1 package org.apache.maven.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 org.codehaus.plexus.PlexusTestCase;
23 import org.codehaus.plexus.digest.Digester;
24 import org.codehaus.plexus.util.IOUtil;
27 import java.io.FileInputStream;
28 import java.io.FileOutputStream;
29 import java.io.IOException;
30 import java.util.List;
34 * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
37 public abstract class AbstractFileEventTest
38 extends PlexusTestCase
40 protected List digesters;
47 digesters = getContainer().lookupList( Digester.class.getName() );
50 protected void assertChecksumExists( File file, String algorithm )
52 assertChecksum( file, algorithm, true );
55 protected void assertChecksumDoesNotExist( File file, String algorithm )
57 assertChecksum( file, algorithm, false );
60 private void assertChecksum( File file, String algorithm, boolean exist )
62 String msg = exist ? "exists" : "does not exist";
63 File checksumFile = new File( file.getPath() + "." + algorithm );
64 assertEquals( "Test file " + algorithm + " checksum " + msg, exist, checksumFile.exists() );
67 protected void assertChecksumCommit( File file )
70 assertChecksumExists( file, "md5" );
71 assertChecksumExists( file, "sha1" );
74 protected void assertChecksumRollback( File file )
77 assertChecksumDoesNotExist( file, "md5" );
78 assertChecksumDoesNotExist( file, "sha1" );
81 protected String readFile( File file )
84 FileInputStream in = null;
87 in = new FileInputStream( file );
88 return IOUtil.toString( in );
96 protected void writeFile( File file, String content )
99 FileOutputStream out = null;
102 out = new FileOutputStream( file );
103 IOUtil.copy( content, out );