[jboss-svn-commits] JBL Code SVN: r25248 - in labs/jbossesb/trunk/product/rosetta: tests/src/org/jboss/soa/esb/listeners/gateway and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Feb 13 00:17:21 EST 2009


Author: beve
Date: 2009-02-13 00:17:21 -0500 (Fri, 13 Feb 2009)
New Revision: 25248

Modified:
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/FileUtil.java
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java
Log:
Work for https://jira.jboss.org/jira/browse/JBESB-2401 "FileGatewayListener: Does not support overwriting of processed files."


Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/FileUtil.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/FileUtil.java	2009-02-13 00:39:18 UTC (rev 25247)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/util/FileUtil.java	2009-02-13 05:17:21 UTC (rev 25248)
@@ -59,8 +59,8 @@
         }
 
         if(to.exists()) {
-            LOGGER.debug("Unable to rename file '" + from.getAbsolutePath() + "' to '" + to.getAbsolutePath() + "'.  '" + to.getAbsolutePath() + "' already exist.");
-            return false;
+            // copy the file contents from the inprocess file to the destination file.
+            return copyFile(from, to);
         }
 
         if (!from.renameTo(to))

Modified: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java	2009-02-13 00:39:18 UTC (rev 25247)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/listeners/gateway/FileGatewayListenerUnitTest.java	2009-02-13 05:17:21 UTC (rev 25248)
@@ -25,6 +25,7 @@
 import java.io.File;
 import java.io.FileFilter;
 import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.net.MalformedURLException;
 
@@ -33,6 +34,7 @@
 import org.jboss.internal.soa.esb.services.registry.MockRegistry;
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.util.FileUtil;
 import org.jboss.soa.esb.util.Util;
 import org.jboss.soa.esb.common.tests.BaseTest;
 import org.jboss.soa.esb.helpers.ConfigTree;
@@ -248,21 +250,28 @@
         assertNull(gateway.setFileWorking(file1));
     }
 
-    public void test_rename_to_file_exists() throws GatewayException, IOException, RegistryException, ConfigurationException {
-        ConfigTree tree = createTestListenerConfig();
-
-        FileGatewayListener gateway = new FileGatewayListener(tree) {
-            protected File getWorkFileName(File fileIn, String suffix) {
-                return file2;
-            }
-        };
-
-        file2.createNewFile();
-        assertTrue(!file1.exists());
-        assertTrue(file2.exists());
-
-        assertNull(gateway.setFileWorking(file1));
+    public void test_rename_with_pre_existing_file_verify_content() throws GatewayException, IOException, RegistryException, ConfigurationException {
+        final File processedFile = new File(dir1, "file.processed");
+        processedFile.createNewFile();
+        writeToFile("firstPayload", processedFile);
+        
+        final File inProcessFile = new File(dir1, "file.inprocess");
+        final String inProcessPayload = "secondPayload";
+        inProcessFile.createNewFile();
+        writeToFile(inProcessPayload, inProcessFile);
+        
+        final FileGatewayListener gateway = new FileGatewayListener(createTestListenerConfig());
+        gateway.renameFile(inProcessFile, processedFile);
+        
+        assertEquals(inProcessPayload,  FileUtil.readTextFile(processedFile));
     }
+    
+    private void writeToFile(final String content, final File to) throws IOException
+    {
+        FileWriter writer = new FileWriter(to);
+        writer.write(content);
+        writer.close();
+    }
 
     private ConfigTree createTestListenerConfig() throws MalformedURLException, ConfigurationException, RegistryException, GatewayException {
         ConfigTree tree = new ConfigTree("test");




More information about the jboss-svn-commits mailing list