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.junit.After;
26 import org.junit.Test;
30 public class CreateFileEventTest
31 extends AbstractFileEventTest
33 private File testDir = new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/transaction-tests/create-file" );
36 public void testCreateCommitRollback()
39 File testFile = new File( testDir, "test-file.txt" );
41 CreateFileEvent event = new CreateFileEvent( "file contents", testFile, digesters );
43 assertFalse( "Test file is not yet created", testFile.exists() );
47 assertTrue( "Test file has been created", testFile.exists() );
49 assertChecksumCommit( testFile );
53 assertFalse( "Test file is has been deleted after rollback", testFile.exists() );
55 assertChecksumRollback( testFile );
57 assertFalse( "Test file parent directories has been rolledback too", testDir.exists() );
58 assertTrue( "target directory still exists", new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target" ).exists() );
62 public void testCreateCommitRollbackWithBackup()
65 File testFile = new File( testDir, "test-file.txt" );
67 testFile.getParentFile().mkdirs();
69 testFile.createNewFile();
71 writeFile( testFile, "original contents" );
73 CreateFileEvent event = new CreateFileEvent( "modified contents", testFile, digesters );
75 String contents = readFile( testFile );
77 assertEquals( "Test contents have not changed", "original contents", contents );
81 contents = readFile( testFile );
83 assertEquals( "Test contents have not changed", "modified contents", contents );
85 assertChecksumCommit( testFile );
89 contents = readFile( testFile );
91 assertEquals( "Test contents have not changed", "original contents", contents );
93 assertChecksumRollback( testFile );
97 public void testCreateRollbackCommit()
100 File testFile = new File( testDir, "test-file.txt" );
102 CreateFileEvent event = new CreateFileEvent( "file contents", testFile, digesters );
104 assertFalse( "Test file is not yet created", testFile.exists() );
108 assertFalse( "Test file is not yet created", testFile.exists() );
112 assertTrue( "Test file is not yet created", testFile.exists() );
114 assertChecksumCommit( testFile );
119 public void tearDown()
124 FileUtils.deleteDirectory( new File( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/transaction-tests" ) );