1 package org.apache.maven.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.maven.archiva.transaction.CreateFileEvent;
25 import org.codehaus.plexus.PlexusTestCase;
26 import org.codehaus.plexus.util.FileUtils;
29 * @author Edwin Punzalan
31 public class CreateFileEventTest
32 extends AbstractFileEventTest
34 private File testDir = new File( PlexusTestCase.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( PlexusTestCase.getBasedir(), "target" ).exists() );
61 public void testCreateCommitRollbackWithBackup()
64 File testFile = new File( testDir, "test-file.txt" );
66 testFile.getParentFile().mkdirs();
68 testFile.createNewFile();
70 writeFile( testFile, "original contents" );
72 CreateFileEvent event = new CreateFileEvent( "modified contents", testFile, digesters );
74 String contents = readFile( testFile );
76 assertEquals( "Test contents have not changed", "original contents", contents );
80 contents = readFile( testFile );
82 assertEquals( "Test contents have not changed", "modified contents", contents );
84 assertChecksumCommit( testFile );
88 contents = readFile( testFile );
90 assertEquals( "Test contents have not changed", "original contents", contents );
92 assertChecksumRollback( testFile );
95 public void testCreateRollbackCommit()
98 File testFile = new File( testDir, "test-file.txt" );
100 CreateFileEvent event = new CreateFileEvent( "file contents", testFile, digesters );
102 assertFalse( "Test file is not yet created", testFile.exists() );
106 assertFalse( "Test file is not yet created", testFile.exists() );
110 assertTrue( "Test file is not yet created", testFile.exists() );
112 assertChecksumCommit( testFile );
115 protected void tearDown()
120 FileUtils.deleteDirectory( new File( PlexusTestCase.getBasedir(), "target/transaction-tests" ) );