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;
29 public class CreateFileEventTest
30 extends AbstractFileEventTest
32 private File testDir = new File( FileUtil.getBasedir(), "target/transaction-tests/create-file" );
34 public void testCreateCommitRollback()
37 File testFile = new File( testDir, "test-file.txt" );
39 CreateFileEvent event = new CreateFileEvent( "file contents", testFile, digesters );
41 assertFalse( "Test file is not yet created", testFile.exists() );
45 assertTrue( "Test file has been created", testFile.exists() );
47 assertChecksumCommit( testFile );
51 assertFalse( "Test file is has been deleted after rollback", testFile.exists() );
53 assertChecksumRollback( testFile );
55 assertFalse( "Test file parent directories has been rolledback too", testDir.exists() );
56 assertTrue( "target directory still exists", new File( FileUtil.getBasedir(), "target" ).exists() );
59 public void testCreateCommitRollbackWithBackup()
62 File testFile = new File( testDir, "test-file.txt" );
64 testFile.getParentFile().mkdirs();
66 testFile.createNewFile();
68 writeFile( testFile, "original contents" );
70 CreateFileEvent event = new CreateFileEvent( "modified contents", testFile, digesters );
72 String contents = readFile( testFile );
74 assertEquals( "Test contents have not changed", "original contents", contents );
78 contents = readFile( testFile );
80 assertEquals( "Test contents have not changed", "modified contents", contents );
82 assertChecksumCommit( testFile );
86 contents = readFile( testFile );
88 assertEquals( "Test contents have not changed", "original contents", contents );
90 assertChecksumRollback( testFile );
93 public void testCreateRollbackCommit()
96 File testFile = new File( testDir, "test-file.txt" );
98 CreateFileEvent event = new CreateFileEvent( "file contents", testFile, digesters );
100 assertFalse( "Test file is not yet created", testFile.exists() );
104 assertFalse( "Test file is not yet created", testFile.exists() );
108 assertTrue( "Test file is not yet created", testFile.exists() );
110 assertChecksumCommit( testFile );
113 protected void tearDown()
118 FileUtils.deleteDirectory( new File( FileUtil.getBasedir(), "target/transaction-tests" ) );