Repository: camel Updated Branches: refs/heads/camel-2.15.x 2df8ed4e3 -> 1e7b0a1e5 refs/heads/camel-2.16.x bccbc9c76 -> ba901a9cd refs/heads/master 17e222db0 -> 1cab39f69
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/1cab39f6 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1cab39f6 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1cab39f6 Branch: refs/heads/master Commit: 1cab39f6998d65d6512b9bc6b47727c639856ad3 Parents: 17e222d Author: Sami Nurminen <[email protected]> Authored: Thu Nov 26 20:27:38 2015 +0200 Committer: Claus Ibsen <[email protected]> Committed: Sat Nov 28 09:02:45 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/1cab39f6/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 301fb0d..2451daf 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 @@ -290,7 +290,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/1cab39f6/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
