1 package org.apache.maven.archiva.converter.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 org.apache.commons.io.FileUtils;
23 import org.codehaus.plexus.PlexusTestCase;
28 * @author Edwin Punzalan
30 public class CreateFileEventTest
31 extends PlexusTestCase
33 private File testDir = new File( PlexusTestCase.getBasedir(), "target/transaction-tests/create-file" );
35 public void testCreateCommitRollback()
38 File testFile = new File( testDir, "test-file.txt" );
40 CreateFileEvent event = new CreateFileEvent( "file contents", testFile );
42 assertFalse( "Test file is not yet created", testFile.exists() );
46 assertTrue( "Test file is not yet created", testFile.exists() );
50 assertFalse( "Test file is has been deleted after rollback", testFile.exists() );
51 assertFalse( "Test file parent directories has been rolledback too", testDir.exists() );
52 assertTrue( "target directory still exists", new File( PlexusTestCase.getBasedir(), "target" ).exists() );
55 public void testCreateCommitRollbackWithBackup()
58 File testFile = new File( testDir, "test-file.txt" );
60 testFile.getParentFile().mkdirs();
62 testFile.createNewFile();
64 FileUtils.writeStringToFile( testFile, "original contents", null );
66 CreateFileEvent event = new CreateFileEvent( "modified contents", testFile );
68 String contents = FileUtils.readFileToString( testFile, null );
70 assertEquals( "Test contents have not changed", "original contents", contents );
74 contents = FileUtils.readFileToString( testFile, null );
76 assertEquals( "Test contents have not changed", "modified contents", contents );
80 contents = FileUtils.readFileToString( testFile, null );
82 assertEquals( "Test contents have not changed", "original contents", contents );
85 public void testCreateRollbackCommit()
88 File testFile = new File( testDir, "test-file.txt" );
90 CreateFileEvent event = new CreateFileEvent( "file contents", testFile );
92 assertFalse( "Test file is not yet created", testFile.exists() );
96 assertFalse( "Test file is not yet created", testFile.exists() );
100 assertTrue( "Test file is not yet created", testFile.exists() );
103 protected void tearDown()
108 FileUtils.deleteDirectory( new File( PlexusTestCase.getBasedir(), "target/transaction-tests" ) );