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.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
24 import org.apache.commons.io.FileUtils;
25 import org.codehaus.plexus.digest.Digester;
26 import org.codehaus.plexus.digest.Md5Digester;
27 import org.codehaus.plexus.digest.Sha1Digester;
28 import org.junit.Before;
29 import org.junit.runner.RunWith;
31 import java.io.IOException;
32 import java.nio.charset.Charset;
33 import java.nio.file.Files;
34 import java.nio.file.Path;
35 import java.nio.file.Paths;
36 import java.util.Arrays;
37 import java.util.List;
42 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
43 public abstract class AbstractFileEventTest
46 protected List<Digester> digesters;
48 @SuppressWarnings( "unchecked" )
56 digesters = Arrays.asList( (Digester) new Md5Digester(), (Digester) new Sha1Digester() );
59 protected void assertChecksumExists(Path file, String algorithm )
62 assertChecksum( file, algorithm, true );
65 protected void assertChecksumDoesNotExist( Path file, String algorithm )
67 assertChecksum( file, algorithm, false );
70 private void assertChecksum( Path file, String algorithm, boolean exist )
72 String msg = exist ? "exists" : "does not exist";
73 Path checksumFile = Paths.get( file.toAbsolutePath() + "." + algorithm );
74 assertEquals( "Test file " + algorithm + " checksum " + msg, exist, Files.exists(checksumFile) );
77 protected void assertChecksumCommit( Path file )
80 assertChecksumExists( file, "md5" );
81 assertChecksumExists( file, "sha1" );
84 protected void assertChecksumRollback( Path file )
87 assertChecksumDoesNotExist( file, "md5" );
88 assertChecksumDoesNotExist( file, "sha1" );
91 protected String readFile( Path file )
94 return FileUtils.readFileToString( file.toFile() );
97 protected void writeFile( Path file, String content )
100 org.apache.archiva.common.utils.FileUtils.writeStringToFile( file, Charset.defaultCharset(), content );