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
24 import org.apache.commons.io.FileUtils;
25 import org.apache.archiva.common.utils.FileUtil;
26 import org.junit.After;
27 import org.junit.Test;
31 public class CreateFileEventTest
32 extends AbstractFileEventTest
34 private File testDir = new File( FileUtil.getBasedir(), "target/transaction-tests/create-file" );
37 public void testCreateCommitRollback()
40 File testFile = new File( testDir, "test-file.txt" );
42 CreateFileEvent event = new CreateFileEvent( "file contents", testFile, digesters );
44 assertFalse( "Test file is not yet created", testFile.exists() );
48 assertTrue( "Test file has been created", testFile.exists() );
50 assertChecksumCommit( testFile );
54 assertFalse( "Test file is has been deleted after rollback", testFile.exists() );
56 assertChecksumRollback( testFile );
58 assertFalse( "Test file parent directories has been rolledback too", testDir.exists() );
59 assertTrue( "target directory still exists", new File( FileUtil.getBasedir(), "target" ).exists() );
63 public void testCreateCommitRollbackWithBackup()
66 File testFile = new File( testDir, "test-file.txt" );
68 testFile.getParentFile().mkdirs();
70 testFile.createNewFile();
72 writeFile( testFile, "original contents" );
74 CreateFileEvent event = new CreateFileEvent( "modified contents", testFile, digesters );
76 String contents = readFile( testFile );
78 assertEquals( "Test contents have not changed", "original contents", contents );
82 contents = readFile( testFile );
84 assertEquals( "Test contents have not changed", "modified contents", contents );
86 assertChecksumCommit( testFile );
90 contents = readFile( testFile );
92 assertEquals( "Test contents have not changed", "original contents", contents );
94 assertChecksumRollback( testFile );
98 public void testCreateRollbackCommit()
101 File testFile = new File( testDir, "test-file.txt" );
103 CreateFileEvent event = new CreateFileEvent( "file contents", testFile, digesters );
105 assertFalse( "Test file is not yet created", testFile.exists() );
109 assertFalse( "Test file is not yet created", testFile.exists() );
113 assertTrue( "Test file is not yet created", testFile.exists() );
115 assertChecksumCommit( testFile );
120 public void tearDown()
125 FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "target/transaction-tests" ) );