1 package org.apache.maven.archiva.converter.transaction;
4 * Copyright 2005-2006 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.codehaus.plexus.PlexusTestCase;
20 import org.apache.commons.io.FileUtils;
25 * @author Edwin Punzalan
27 public class CreateFileEventTest
28 extends PlexusTestCase
30 private File testDir = new File( PlexusTestCase.getBasedir(), "target/transaction-tests/create-file" );
32 public void testCreateCommitRollback()
35 File testFile = new File( testDir, "test-file.txt" );
37 CreateFileEvent event = new CreateFileEvent( "file contents", testFile );
39 assertFalse( "Test file is not yet created", testFile.exists() );
43 assertTrue( "Test file is not yet created", testFile.exists() );
47 assertFalse( "Test file is has been deleted after rollback", testFile.exists() );
48 assertFalse( "Test file parent directories has been rolledback too", testDir.exists() );
49 assertTrue( "target directory still exists", new File( PlexusTestCase.getBasedir(), "target" ).exists() );
52 public void testCreateCommitRollbackWithBackup()
55 File testFile = new File( testDir, "test-file.txt" );
57 testFile.getParentFile().mkdirs();
59 testFile.createNewFile();
61 FileUtils.writeStringToFile( testFile, "original contents", null );
63 CreateFileEvent event = new CreateFileEvent( "modified contents", testFile );
65 String contents = FileUtils.readFileToString( testFile, null );
67 assertEquals( "Test contents have not changed", "original contents", contents );
71 contents = FileUtils.readFileToString( testFile, null );
73 assertEquals( "Test contents have not changed", "modified contents", contents );
77 contents = FileUtils.readFileToString( testFile, null );
79 assertEquals( "Test contents have not changed", "original contents", contents );
82 public void testCreateRollbackCommit()
85 File testFile = new File( testDir, "test-file.txt" );
87 CreateFileEvent event = new CreateFileEvent( "file contents", testFile );
89 assertFalse( "Test file is not yet created", testFile.exists() );
93 assertFalse( "Test file is not yet created", testFile.exists() );
97 assertTrue( "Test file is not yet created", testFile.exists() );
100 protected void tearDown()
105 FileUtils.deleteDirectory( new File( PlexusTestCase.getBasedir(), "target/transaction-tests" ) );