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.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;
28 import java.io.IOException;
29 import java.util.List;
35 public abstract class AbstractFileEventTest
36 extends PlexusInSpringTestCase
38 protected List digesters;
45 digesters = PlexusToSpringUtils.lookupList( PlexusToSpringUtils.buildSpringId( Digester.class.getName() ), getApplicationContext() );
48 protected void assertChecksumExists( File file, String algorithm )
50 assertChecksum( file, algorithm, true );
53 protected void assertChecksumDoesNotExist( File file, String algorithm )
55 assertChecksum( file, algorithm, false );
58 private void assertChecksum( File file, String algorithm, boolean exist )
60 String msg = exist ? "exists" : "does not exist";
61 File checksumFile = new File( file.getPath() + "." + algorithm );
62 assertEquals( "Test file " + algorithm + " checksum " + msg, exist, checksumFile.exists() );
65 protected void assertChecksumCommit( File file )
68 assertChecksumExists( file, "md5" );
69 assertChecksumExists( file, "sha1" );
72 protected void assertChecksumRollback( File file )
75 assertChecksumDoesNotExist( file, "md5" );
76 assertChecksumDoesNotExist( file, "sha1" );
79 protected String readFile( File file )
82 return FileUtils.readFileToString( file );
85 protected void writeFile( File file, String content )
88 FileUtils.writeStringToFile( file, content );