You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/11/28 09:05:36 UTC

[3/3] camel git commit: CAMEL-9340: Using working dir as default parent file for fileStore file when fileStore file has no parent file given.

CAMEL-9340: Using working dir as default parent file for fileStore file when fileStore file has no parent file given.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1e7b0a1e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1e7b0a1e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1e7b0a1e

Branch: refs/heads/camel-2.15.x
Commit: 1e7b0a1e59885f76fdf24b2acfeed7b8db300088
Parents: 2df8ed4
Author: Sami Nurminen <sn...@gmail.com>
Authored: Thu Nov 26 20:27:38 2015 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Nov 28 09:05:24 2015 +0100

----------------------------------------------------------------------
 .../idempotent/FileIdempotentRepository.java    |  4 +++-
 .../FileIdempotentConsumerCreateRepoTest.java   | 24 ++++++++++++++++++--
 2 files changed, 25 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/1e7b0a1e/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java b/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java
index 59c6853..3216424 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/idempotent/FileIdempotentRepository.java
@@ -283,7 +283,9 @@ public class FileIdempotentRepository extends ServiceSupport implements Idempote
         if (!fileStore.exists()) {
             LOG.debug("Creating filestore: {}", fileStore);
             File parent = fileStore.getParentFile();
-            parent.mkdirs();
+            if (parent != null) {
+                parent.mkdirs();
+            }
             boolean created = FileUtil.createNewFile(fileStore);
             if (!created) {
                 throw new IOException("Cannot create filestore: " + fileStore);

http://git-wip-us.apache.org/repos/asf/camel/blob/1e7b0a1e/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentConsumerCreateRepoTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentConsumerCreateRepoTest.java b/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentConsumerCreateRepoTest.java
index 9198b95..698f8b0 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentConsumerCreateRepoTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/FileIdempotentConsumerCreateRepoTest.java
@@ -21,6 +21,8 @@ import java.io.File;
 import static java.util.UUID.randomUUID;
 
 import org.apache.camel.spi.IdempotentRepository;
+import org.apache.camel.util.FileUtil;
+import org.junit.After;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -28,11 +30,25 @@ import static org.apache.camel.processor.idempotent.FileIdempotentRepository.fil
 
 public class FileIdempotentConsumerCreateRepoTest extends Assert {
 
+    File store;
+
     @Test
     public void shouldCreateParentOfRepositoryFileStore() throws Exception {
-        // Given
         File parentDirectory = new File("target/repositoryParent_" + randomUUID());
-        File store = new File(parentDirectory, "store");
+        store = new File(parentDirectory, "store");
+        assertStoreExists(store);
+    }
+
+    @Test
+    public void shouldUseCurrentDirIfHasNoParentFile() throws Exception {
+        String storeFileName = "store" + randomUUID();
+        store = new File(storeFileName);
+        assertStoreExists(store);
+    }
+
+
+    private void assertStoreExists(File store) throws Exception {
+        // Given
         IdempotentRepository<String> repo = fileIdempotentRepository(store);
 
         // must start repo
@@ -47,4 +63,8 @@ public class FileIdempotentConsumerCreateRepoTest extends Assert {
         repo.stop();
     }
 
+    @After
+    public void after() {
+        FileUtil.deleteFile(this.store);
+    }
 }
\ No newline at end of file