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 2008/11/29 12:57:08 UTC
svn commit: r721666 - in /activemq/camel/trunk/camel-core/src:
main/java/org/apache/camel/component/file/FileProducer.java
test/java/org/apache/camel/component/file/FileProduceTempPrefixTest.java
Author: davsclaus
Date: Sat Nov 29 03:57:08 2008
New Revision: 721666
URL: http://svn.apache.org/viewvc?rev=721666&view=rev
Log:
CAMEL-1072: Aligned unit test in file producer to be as ftp producer to unit test the temp filename.
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempPrefixTest.java
Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java?rev=721666&r1=721665&r2=721666&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java Sat Nov 29 03:57:08 2008
@@ -61,8 +61,7 @@
boolean writeAsTempAndRename = ObjectHelper.isNotNullAndNonEmpty(endpoint.getTempPrefix());
File tempTarget = null;
if (writeAsTempAndRename) {
- // compute temporary name with the temp prefix
- tempTarget = new File(target.getParent(), endpoint.getTempPrefix() + target.getName());
+ tempTarget = createTempFileName(target);
}
// write the file
@@ -222,6 +221,12 @@
return answer;
}
+ protected File createTempFileName(File target) {
+ File tempTarget;
+ tempTarget = new File(target.getParent(), endpoint.getTempPrefix() + target.getName());
+ return tempTarget;
+ }
+
private static void buildDirectory(File file) {
String dirName = file.getAbsolutePath();
int index = dirName.lastIndexOf(File.separatorChar);
Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempPrefixTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempPrefixTest.java?rev=721666&r1=721665&r2=721666&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempPrefixTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileProduceTempPrefixTest.java Sat Nov 29 03:57:08 2008
@@ -19,6 +19,7 @@
import java.io.File;
import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
import org.apache.camel.builder.RouteBuilder;
/**
@@ -26,6 +27,26 @@
*/
public class FileProduceTempPrefixTest extends ContextTestSupport {
+ private String fileUrl = "file://target/tempandrename/?tempPrefix=inprogress.";
+
+ public void testCreateTempFileName() throws Exception {
+ Endpoint endpoint = context.getEndpoint(fileUrl);
+ FileProducer producer = (FileProducer) endpoint.createProducer();
+
+ File fileName = new File("target/tempandrename/claus.txt");
+ File tempFileName = producer.createTempFileName(fileName);
+ assertEquals("target" + File.separatorChar + "tempandrename" + File.separatorChar + "inprogress.claus.txt", tempFileName.getPath());
+ }
+
+ public void testNoPathCreateTempFileName() throws Exception {
+ Endpoint endpoint = context.getEndpoint(fileUrl);
+ FileProducer producer = (FileProducer) endpoint.createProducer();
+
+ File fileName = new File("claus.txt");
+ File tempFileName = producer.createTempFileName(fileName);
+ assertEquals("inprogress.claus.txt", tempFileName.getPath());
+ }
+
public void testTempPrefix() throws Exception {
deleteDirectory("target/tempandrename");
@@ -42,7 +63,7 @@
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
- from("direct:a").to("file://target/tempandrename/?tempPrefix=inprogress.");
+ from("direct:a").to(fileUrl);
}
};
}