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
23 import org.junit.After;
24 import org.junit.Test;
26 import java.nio.file.Files;
27 import java.nio.file.Path;
28 import java.nio.file.Paths;
32 public class CreateFileEventTest
33 extends AbstractFileEventTest
35 private Path testDir = Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/transaction-tests/create-file" );
38 public void testCreateCommitRollback()
41 Path testFile = testDir.resolve("test-file.txt" );
43 CreateFileEvent event = new CreateFileEvent( "file contents", testFile, digesters );
45 assertFalse( "Test file is not yet created", Files.exists(testFile) );
49 assertTrue( "Test file has been created", Files.exists(testFile) );
51 assertChecksumCommit( testFile );
55 assertFalse( "Test file is has been deleted after rollback", Files.exists(testFile) );
57 assertChecksumRollback( testFile );
59 assertFalse( "Test file parent directories has been rolledback too", Files.exists(testDir) );
60 assertTrue( "target directory still exists", Files.exists(Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target" )) );
64 public void testCreateCommitRollbackWithBackup()
67 Path testFile = testDir.resolve( "test-file.txt" );
69 Files.createDirectories(testFile.getParent());
71 Files.createFile(testFile);
73 writeFile( testFile, "original contents" );
75 CreateFileEvent event = new CreateFileEvent( "modified contents", testFile, digesters );
77 String contents = readFile( testFile );
79 assertEquals( "Test contents have not changed", "original contents", contents );
83 contents = readFile( testFile );
85 assertEquals( "Test contents have not changed", "modified contents", contents );
87 assertChecksumCommit( testFile );
91 contents = readFile( testFile );
93 assertEquals( "Test contents have not changed", "original contents", contents );
95 assertChecksumRollback( testFile );
99 public void testCreateRollbackCommit()
102 Path testFile = testDir.resolve( "test-file.txt" );
104 CreateFileEvent event = new CreateFileEvent( "file contents", testFile, digesters );
106 assertFalse( "Test file is not yet created", Files.exists(testFile) );
110 assertFalse( "Test file is not yet created", Files.exists(testFile) );
114 assertTrue( "Test file is not yet created", Files.exists(testFile) );
116 assertChecksumCommit( testFile );
121 public void tearDown()
126 org.apache.archiva.common.utils.FileUtils.deleteDirectory( Paths.get( org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/transaction-tests" ) );