[jboss-svn-commits] JBL Code SVN: r24234 - in labs/jbossesb/workspace/skeagh: examples/file-routing/src/test/resources and 4 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Dec 4 05:48:56 EST 2008


Author: beve
Date: 2008-12-04 05:48:56 -0500 (Thu, 04 Dec 2008)
New Revision: 24234

Added:
   labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/FileRoutingConstants.java
   labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/lifecycle/FileInfo.java
Modified:
   labs/jbossesb/workspace/skeagh/examples/file-routing/src/main/java/org/jboss/esb/examples/filerouter/MyTestService.java
   labs/jbossesb/workspace/skeagh/examples/file-routing/src/test/resources/sample.txt
   labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/AbstractFileInboundRouter.java
   labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/FileInboundRouter.java
   labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/eval/PatternEvaluatorImpl.java
   labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/lifecycle/DefaultFileLifecycle.java
   labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/lifecycle/FileLifecycle.java
   labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/FileInboundRouterTest.java
   labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/FileOutboundRouterTest.java
Log:
Work for https://jira.jboss.org/jira/browse/JBESB-2214 "FileInboundRouter: add file information as invocation parameters to the invocation context"


Modified: labs/jbossesb/workspace/skeagh/examples/file-routing/src/main/java/org/jboss/esb/examples/filerouter/MyTestService.java
===================================================================
--- labs/jbossesb/workspace/skeagh/examples/file-routing/src/main/java/org/jboss/esb/examples/filerouter/MyTestService.java	2008-12-04 10:40:12 UTC (rev 24233)
+++ labs/jbossesb/workspace/skeagh/examples/file-routing/src/main/java/org/jboss/esb/examples/filerouter/MyTestService.java	2008-12-04 10:48:56 UTC (rev 24234)
@@ -19,6 +19,9 @@
  */
 package org.jboss.esb.examples.filerouter;
 
+import java.util.Map;
+
+import org.jboss.esb.api.context.InvocationContext;
 import org.jboss.esb.api.message.Message;
 import org.jboss.esb.api.service.Service;
 import org.jboss.esb.api.service.ServiceException;
@@ -33,14 +36,19 @@
     /**
      * Processes the message.
      *
-     * @param msg - the esb message object instance.
+     * @param messsage - the esb message object instance.
      * @return Messsage - the esb message object instance.
      * @throws ServiceException - if an exception occurs during processing.
      */
-    public Message process(final Message msg) throws ServiceException
+    public Message process(final Message messsage) throws ServiceException
     {
-        System.out.println("MyTestService message payload : " + msg.getPayload());
-        return msg;
+        final InvocationContext invocationContext = InvocationContext.getContext();
+        final Map<String, String> invocationParameters = invocationContext.getInvocationParameters();
+        System.out.println("##################### MyTestService ########################");
+        System.out.println("Message payload '" + messsage.getPayload() + "'");
+        System.out.println("InvocationParameters '" + invocationParameters + "'");
+        System.out.println("############################################################");
+        return messsage;
     }
 
 }

Modified: labs/jbossesb/workspace/skeagh/examples/file-routing/src/test/resources/sample.txt
===================================================================
--- labs/jbossesb/workspace/skeagh/examples/file-routing/src/test/resources/sample.txt	2008-12-04 10:40:12 UTC (rev 24233)
+++ labs/jbossesb/workspace/skeagh/examples/file-routing/src/test/resources/sample.txt	2008-12-04 10:48:56 UTC (rev 24234)
@@ -1,2 +1 @@
-File Router Example:
-This is an example file used with the file-router exemple
+This is an example file used with the file-routine example

Modified: labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/AbstractFileInboundRouter.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/AbstractFileInboundRouter.java	2008-12-04 10:40:12 UTC (rev 24233)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/AbstractFileInboundRouter.java	2008-12-04 10:48:56 UTC (rev 24234)
@@ -1,5 +1,5 @@
 /*
- * JBoss, Home of Professional Open Source
+ null* JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and others contributors as indicated
  * by the @authors tag. All rights reserved.
  * See the copyright.txt in the distribution for a
@@ -20,6 +20,7 @@
 package org.jboss.esb.file;
 
 import java.io.File;
+import java.util.Map;
 import java.util.Properties;
 
 import org.apache.log4j.Logger;
@@ -101,31 +102,6 @@
     public static final String STREAM_TYPE = "STREAM";
 
     /**
-     * Key used in the InvocationContext for the FileLifecycle.
-     */
-    public static final String PROP_FILE_LIFECYCLE = "in-file-lifecycle";
-
-    /**
-     * Key used in the InvocationContext for the File object.
-     */
-    public static final String PROP_FILE_OBJ = "in-file-obj";
-
-    /**
-     * Key used in the InvocationContext for the absolute path to the File.
-     */
-    public static final String PROP_FILE_PATH = "in-file-path";
-
-    /**
-     * Key used in the InvocationContext for the file lenght.
-     */
-    public static final String PROP_FILE_LENGTH = "in-file-length";
-
-    /**
-     * Key used in the InvocationContext for the files last modified date.
-     */
-    public static final String PROP_FILE_LASTMOD = "in-file-lastmod";
-
-    /**
      * The file selector pattern use.
      */
     @Property(use = Use.OPTIONAL, name = "fileSelectorPattern", defaultVal = "*")
@@ -251,22 +227,22 @@
     @Override
     public final void onSchedule() throws SchedulingException
     {
-        logger.info("Schedule triggered for '" + objectName + "'");
-
         if (shuttingDown)
         {
             return;
         }
 
-        // TODO: add invocation parameters to the invocation context.
-        final InvocationContext invocationContext = new InvocationContext();
-
-        final FileLifecycle fileLifecycle = selectFile(invocationContext);
+        final FileLifecycle fileLifecycle = selectFile();
         if (fileLifecycle != null)
         {
+            final Map<String, String> invocationParamters = createInvocationParameters(fileLifecycle);
+            final InvocationContext invocationContext = new InvocationContext(invocationParamters);
+
+            // Store the file lifecycle in the invocation context.
+            invocationContext.setContextObject(FileLifecycle.class.getName(), fileLifecycle);
+
             final Message message = createEsbMessage(fileLifecycle, invocationContext);
             // the call below will be removed in the near future. See comments on method.
-            setFileMetadata(fileLifecycle, invocationContext);
             try
             {
                 dispatcher.dispatch(message, invocationContext);
@@ -285,17 +261,13 @@
     }
 
     /**
-     * Selects a file from the input directory and creates a
-     * {@link FileLifecycle} using the picked up file.
+     * Selects a file from the input directory and creates a {@link FileLifecycle}
+     * using the picked up file.
      *
-     * @param invocationContext
-     *            The invocation context.
      * @return FileLifecycle {@link FileLifecycle} associated with the file.
-     *
-     * @throws SchedulingException
-     *             If en exception occurs while trying to compose the message.
+     * @throws SchedulingException If en exception occurs while trying to compose the message.
      */
-    private FileLifecycle selectFile(final InvocationContext invocationContext) throws SchedulingException
+    private FileLifecycle selectFile() throws SchedulingException
     {
         final File[] files = fileSelector.select(inputDir);
 
@@ -304,9 +276,7 @@
             return null;
         }
 
-        // Store the FileLifecycle in the invocation context.
         final FileLifecycle fileLifecycle = fileLifecycleFactory.newInstance();
-        invocationContext.setContextObject(FileLifecycle.class.getName(), fileLifecycle);
 
         for (int i = 0; i < files.length; i++)
         {
@@ -345,6 +315,15 @@
     abstract Message createEsbMessage(final FileLifecycle fileLifecycle, final InvocationContext invocationContext) throws SchedulingException;
 
     /**
+     * Creates a Map that will be used as invocation parameters.
+     *
+     * @param fileLifecycle The {@link FileLifecycle}.
+     * @return Map The invocation paramters map.
+     *
+     */
+    abstract Map<String, String> createInvocationParameters(final FileLifecycle fileLifecycle);
+
+    /**
      * Optional method that will be called after the message has be dispatched to the ESB.
      *
      * @param message The ESB Message object.
@@ -386,6 +365,9 @@
         sb.append("', fileSelectorPattern='").append(fileSelectorPattern);
         sb.append("', fileSelector='").append(fileSelector.getClass().getName());
         sb.append("', payloadType='").append(payloadType);
+        sb.append("', workingRenamePattern='").append(workingRenamePattern);
+        sb.append("', processedRenamePattern='").append(processedRenamePattern);
+        sb.append("', errorRenamePattern='").append(errorRenamePattern);
         sb.append("', fileLifecycleFactory : '" + fileLifecycleFactory.getClass().getName());
         sb.append("']");
         return sb.toString();
@@ -402,6 +384,16 @@
     }
 
     /**
+     * Get the input directory.
+     *
+     * @return File The input directory.
+     */
+    public final File getInputDir()
+    {
+        return inputDir.getAbsoluteFile();
+    }
+
+    /**
      * Gets the configured file selector pattern.
      *
      * @return String The configured file selector pattern.
@@ -460,32 +452,4 @@
     {
         return properties;
     }
-
-    /**
-     * Sets metadata information into the InvocationContext. The following
-     * properties are currently set: <lu> <li>{@link #PROP_FILE_LIFECYCLE} - The
-     * {@link FileLifecycle}</li> <li>{@link #PROP_FILE_OBJ} - The File object
-     * itself</li> <li>{@link #PROP_FILE_PATH} - The absolute path to the file</li>
-     * <li>{@link #PROP_FILE_LENGTH} - The lenght of the file</li> <li>
-     * {@link #PROP_FILE_LASTMOD} - The last modified date for the file</li>
-     * </lu> Subclasses can override this method to add additional properties.
-     *
-     * @param fromFileLifecycle The {@link FileLifecycle}.
-     * @param toContext The {@link InvocationContext}.
-     *
-     * @TODO: These properties should be set as invocation parameters when the
-     *        InvocationContext is created. There is a separate
-     *        jira(https://jira.jboss.org/jira/browse/JBESB-2214) for this issue
-     *        which is why I'm leaving this for now./Daniel 2008-12-03.
-     */
-    protected final void setFileMetadata(final FileLifecycle fromFileLifecycle, final InvocationContext toContext)
-    {
-        // Add some metadata about the file to the InvocationContext.
-        final File currentFile = fromFileLifecycle.getFile();
-        toContext.setContextObject(PROP_FILE_LIFECYCLE, fromFileLifecycle);
-        toContext.setContextObject(PROP_FILE_OBJ, currentFile);
-        toContext.setContextObject(PROP_FILE_PATH, currentFile.getAbsolutePath());
-        toContext.setContextObject(PROP_FILE_LENGTH, currentFile.length());
-        toContext.setContextObject(PROP_FILE_LASTMOD, currentFile.lastModified());
-    }
 }

Modified: labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/FileInboundRouter.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/FileInboundRouter.java	2008-12-04 10:40:12 UTC (rev 24233)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/FileInboundRouter.java	2008-12-04 10:48:56 UTC (rev 24234)
@@ -19,12 +19,21 @@
  */
 package org.jboss.esb.file;
 
+import static org.jboss.esb.file.FileRoutingConstants.IN_FILE_LASTMOD;
+import static org.jboss.esb.file.FileRoutingConstants.IN_FILE_LENGTH;
+import static org.jboss.esb.file.FileRoutingConstants.IN_FILE_NAME;
+import static org.jboss.esb.file.FileRoutingConstants.IN_FILE_PATH;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 import org.jboss.esb.api.context.InvocationContext;
 import org.jboss.esb.api.message.Message;
+import org.jboss.esb.file.lifecycle.FileInfo;
 import org.jboss.esb.file.lifecycle.FileLifecycle;
 import org.jboss.esb.schedule.SchedulingException;
 import org.jboss.esb.util.FileUtil;
@@ -84,6 +93,36 @@
     }
 
     /**
+     * Creates a Map that will be used as invocation parameters.
+     *
+     * This method add the following:
+     * <lu>
+     *  <li>{@link #IN_FILE_PATH} - The absolute path to the file</li>
+     *  <li>{@link #IN_FILE_NAME} - The absolute path to the file</li>
+     *  <li>{@link #IN_FILE_LENGTH} - The lenght of the file</li>
+     *  <li>{@link #IN_FILE_LASTMOD} - The last modified date for the file</li>
+     * </lu>
+     *
+     * @param fileLifecycle The {@link FileLifecycle}.
+     * @return Map The invocation paramters map.
+     *
+     */
+    @Override
+    protected final Map<String, String> createInvocationParameters(final FileLifecycle fileLifecycle)
+    {
+        final List<FileInfo> fileHistory = fileLifecycle.getFileHistory();
+        final FileInfo fileInfo = fileHistory.get(0);
+        final File orgFile = fileInfo.getFile();
+
+        final HashMap<String, String> invParams = new HashMap<String, String>();
+        invParams.put(IN_FILE_PATH, orgFile.getAbsolutePath());
+        invParams.put(IN_FILE_NAME, orgFile.getName());
+        invParams.put(IN_FILE_LENGTH, Long.toString(fileInfo.getLength()));
+        invParams.put(IN_FILE_LASTMOD, Long.toString(fileInfo.getLastModified()));
+        return invParams;
+    }
+
+    /**
      * Optional method that will be called after the message has be dispatched to the ESB.
      *
      * @param message       The ESB Message object.

Added: labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/FileRoutingConstants.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/FileRoutingConstants.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/FileRoutingConstants.java	2008-12-04 10:48:56 UTC (rev 24234)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors by the @authors tag. See the copyright.txt
+ * in the distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.esb.file;
+
+/**
+ * Constants used for both in and outbound routers.
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ * @since 5.0
+ */
+public final class FileRoutingConstants
+{
+    /**
+     * Private constructor.
+     */
+    private FileRoutingConstants()
+    {
+    }
+
+    /**
+     * Key used in the InvocationContext for the absolute path to the File.
+     */
+    public static final String IN_FILE_PATH = "in-file-path";
+
+    /**
+     * Key used in the InvocationContext for the name of inbound File.
+     */
+    public static final String IN_FILE_NAME = "in-file-name";
+
+    /**
+     * Key used in the InvocationContext for the file lenght.
+     */
+    public static final String IN_FILE_LENGTH = "in-file-length";
+
+    /**
+     * Key used in the InvocationContext for the files last modified date.
+     */
+    public static final String IN_FILE_LASTMOD = "in-file-lastmod";
+
+
+}

Modified: labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/eval/PatternEvaluatorImpl.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/eval/PatternEvaluatorImpl.java	2008-12-04 10:40:12 UTC (rev 24233)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/eval/PatternEvaluatorImpl.java	2008-12-04 10:48:56 UTC (rev 24234)
@@ -20,10 +20,10 @@
  */
 package org.jboss.esb.file.eval;
 
-import java.io.File;
+import static org.jboss.esb.file.FileRoutingConstants.IN_FILE_NAME;
 
+import java.util.Map;
 import org.jboss.esb.api.context.InvocationContext;
-import org.jboss.esb.file.AbstractFileInboundRouter;
 import org.jboss.esb.util.FileUtil;
 
 /**
@@ -44,10 +44,11 @@
     {
         String newName = FileUtil.removePath(filePattern);
 
-        File file = (File) invocationContext.getContextObject(AbstractFileInboundRouter.PROP_FILE_OBJ);
-        if (file != null)
+        final Map<String, String> invocationParameters = invocationContext.getInvocationParameters();
+        final String fileName = invocationParameters.get(IN_FILE_NAME);
+        if (fileName != null)
         {
-            newName = newName.replace(FILE_NAME, file.getName());
+            newName = newName.replace(FILE_NAME, fileName);
         }
 
         newName = newName.replace(TIMESTAMP_TOKEN, String.valueOf(System.currentTimeMillis()));

Modified: labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/lifecycle/DefaultFileLifecycle.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/lifecycle/DefaultFileLifecycle.java	2008-12-04 10:40:12 UTC (rev 24233)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/lifecycle/DefaultFileLifecycle.java	2008-12-04 10:48:56 UTC (rev 24234)
@@ -24,7 +24,6 @@
 import java.util.List;
 import java.util.UUID;
 
-import org.apache.log4j.Logger;
 import org.jboss.esb.util.AssertArgument;
 import org.jboss.esb.util.FileUtil;
 
@@ -45,11 +44,6 @@
     private static final long serialVersionUID = 1L;
 
     /**
-     * Logger.
-     */
-    private Logger log = Logger.getLogger(DefaultFileLifecycle.class);
-
-    /**
      * The name of the file currently being processed.
      */
     private String fileName;
@@ -70,9 +64,10 @@
     private FileLifecycleConfig config;
 
     /**
-     * Holds the file currently being processed.
+     * Holds the file that have been processed.
+     * For example will contain the file set by a call to setFile.
      */
-    private List<File> fileHistory = new ArrayList<File>();
+    private List<FileInfo> fileHistory = new ArrayList<FileInfo>();
 
     /**
      * Id for this lifecycle.
@@ -99,7 +94,7 @@
         }
 
         fileHistory.clear();
-        fileHistory.add(file);
+        fileHistory.add(new FileInfo(file));
     }
 
     /**
@@ -138,7 +133,7 @@
         }
         else
         {
-            fileHistory.get(fileHistory.size() - 1).delete();
+            fileHistory.get(fileHistory.size() - 1).getFile().delete();
             return null;
         }
     }
@@ -149,14 +144,14 @@
      */
     public final File getFile()
     {
-        return fileHistory.get(fileHistory.size() - 1);
+        return fileHistory.get(fileHistory.size() - 1).getFile();
     }
 
     /**
      * Get the file history list.
      * @return List List of Files.
      */
-    public final List<File> getFileHistory()
+    public final List<FileInfo> getFileHistory()
     {
         return fileHistory;
     }
@@ -241,7 +236,7 @@
             throw new IllegalStateException("Was not able to rename file '" + getFile() + "' to '" + toFile + "'");
         }
 
-        fileHistory.add(toFile);
+        fileHistory.add(new FileInfo(toFile));
         return toFile;
     }
 

Added: labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/lifecycle/FileInfo.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/lifecycle/FileInfo.java	                        (rev 0)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/lifecycle/FileInfo.java	2008-12-04 10:48:56 UTC (rev 24234)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors by the @authors tag. See the copyright.txt
+ * in the distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this software; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF
+ * site: http://www.fsf.org.
+ */
+package org.jboss.esb.file.lifecycle;
+
+import java.io.File;
+
+import org.jboss.esb.util.AssertArgument;
+
+/**
+ * FileInfo is just a wrapper around a File object that also saves information
+ * that will be lost once the file is removed/renamed.
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ *
+ */
+public class FileInfo
+{
+    /**
+     * The wrapped file.
+     */
+    private final File file;
+
+    /**
+     * Last modified value.
+     */
+    private long lastModified;
+
+    /**
+     * Lenght of file.
+     */
+    private long length;
+
+    /**
+     * Sole constructor.
+     *
+     * @param file The file to wrap.
+     */
+    public FileInfo(final File file)
+    {
+        AssertArgument.isNotNull(file, "file");
+        this.file = file;
+        lastModified = file.lastModified();
+        length = file.length();
+    }
+
+    /**
+     * Gets the file object.
+     *
+     * @return File The file object.
+     */
+    public final File getFile()
+    {
+        return file;
+    }
+
+    /**
+     * Get the last modified value at the time this object was created.
+     *
+     * @return long The stored last modified value.
+     */
+    public final long getLastModified()
+    {
+        return lastModified;
+    }
+
+    /**
+     * Gets the lenght of the file at the time this object was created.
+     *
+     * @return long The lenght of the file at the time this object was created.
+     */
+    public final long getLength()
+    {
+        return length;
+    }
+}

Modified: labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/lifecycle/FileLifecycle.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/lifecycle/FileLifecycle.java	2008-12-04 10:40:12 UTC (rev 24233)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/lifecycle/FileLifecycle.java	2008-12-04 10:48:56 UTC (rev 24234)
@@ -111,7 +111,7 @@
     /**
      * @return List File history list.
      */
-    List<File> getFileHistory();
+    List<FileInfo> getFileHistory();
 
 
     /**

Modified: labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/FileInboundRouterTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/FileInboundRouterTest.java	2008-12-04 10:40:12 UTC (rev 24233)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/FileInboundRouterTest.java	2008-12-04 10:48:56 UTC (rev 24234)
@@ -20,6 +20,10 @@
  */
 package org.jboss.esb.file;
 
+import static org.jboss.esb.file.FileRoutingConstants.IN_FILE_LASTMOD;
+import static org.jboss.esb.file.FileRoutingConstants.IN_FILE_LENGTH;
+import static org.jboss.esb.file.FileRoutingConstants.IN_FILE_NAME;
+import static org.jboss.esb.file.FileRoutingConstants.IN_FILE_PATH;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
@@ -29,6 +33,7 @@
 import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Map;
 
 import org.jboss.esb.api.context.InvocationContext;
 import org.jboss.esb.api.exception.ConfigurationException;
@@ -41,6 +46,7 @@
 import org.jboss.esb.schedule.SchedulingException;
 import org.jboss.esb.util.FileUtil;
 import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -93,18 +99,25 @@
     }
 
     @Test
-    public void verifyThatFileMetaDataHasBeenSetOnInvocationContext() throws SchedulingException, ConfigurationException
+    public void verifyThatInvocationParametersHaveBeenSet() throws SchedulingException, ConfigurationException
     {
         triggerOnSchedule("stringType");
 
         InvocationContext context = dispatcher.getInvocationContext();
+        Map<String, String> invParams = context.getInvocationParameters();
 
-        assertNotNull(context.getContextObject(AbstractFileInboundRouter.PROP_FILE_LASTMOD));
-        assertNotNull(context.getContextObject(AbstractFileInboundRouter.PROP_FILE_PATH));
-        assertNotNull(context.getContextObject(AbstractFileInboundRouter.PROP_FILE_LIFECYCLE));
-        assertNotNull(context.getContextObject(AbstractFileInboundRouter.PROP_FILE_OBJ));
-        assertNotNull(context.getContextObject(AbstractFileInboundRouter.PROP_FILE_LENGTH));
+        assertTrue(invParams.containsKey(IN_FILE_LASTMOD));
+        assertNotNull(invParams.get(IN_FILE_LASTMOD));
 
+        assertTrue(invParams.containsKey(IN_FILE_PATH));
+        assertNotNull(invParams.get(IN_FILE_PATH));
+
+        assertTrue(invParams.containsKey(IN_FILE_NAME));
+        assertNotNull(invParams.get(IN_FILE_NAME));
+
+        assertTrue(invParams.containsKey(IN_FILE_LENGTH));
+        assertNotNull(invParams.get(IN_FILE_LENGTH));
+
         final String[] list = getFilesFromDir(inputFile.getParentFile(), "-processed");
         processedFile = new File(inputFile.getParentFile(), list[0]);
     }
@@ -147,6 +160,19 @@
         assertNotNull("There should have been an router named 'stringType' in the config", inboundRouterConfig);
     }
 
+    @AfterClass
+    public static void classTearDown()
+    {
+        FileInboundRouter router = (FileInboundRouter) inboundRouterConfig.getRouter();
+        File inputDir = router.getInputDir();
+        final String[] list = getFilesFromDir(inputDir,  "-processed");
+        for (String string : list)
+        {
+            File file = new File(inputDir, string);
+            file.delete();
+        }
+    }
+
     private void triggerOnSchedule(final String routerNameInConfig) throws ConfigurationException, SchedulingException
     {
         final InboundRouterConfig routerConfig = DeploymentUtil.getInboundRouter(routerNameInConfig, runtime);
@@ -209,7 +235,7 @@
 
     }
 
-    private String[] getFilesFromDir(final File dir, final String suffix)
+    private static String[] getFilesFromDir(final File dir, final String suffix)
     {
         String[] files = dir.list( new FilenameFilter()
         {

Modified: labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/FileOutboundRouterTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/FileOutboundRouterTest.java	2008-12-04 10:40:12 UTC (rev 24233)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/FileOutboundRouterTest.java	2008-12-04 10:48:56 UTC (rev 24234)
@@ -20,10 +20,14 @@
  */
 package org.jboss.esb.file;
 
+import static org.jboss.esb.file.FileRoutingConstants.IN_FILE_NAME;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+
 import java.io.File;
 import java.io.IOException;
+import java.util.HashMap;
+
 import org.jboss.esb.api.context.InvocationContext;
 import org.jboss.esb.api.exception.ConfigurationException;
 import org.jboss.esb.api.exception.DeploymentException;
@@ -70,7 +74,7 @@
         final FileOutboundRouter router = (FileOutboundRouter) outboundRouterConfig.getRouter();
         router.initialize();
 
-        setFileNameInInvocationContext("file1");
+        setFileNameAsInvocationParameter("file1");
 
         final String payload = "Text payload string";
         final Message message = new Message();
@@ -83,10 +87,11 @@
         assertEquals(payload, new String(fileContent));
     }
 
-    private void setFileNameInInvocationContext(final String fileName)
+    private void setFileNameAsInvocationParameter(final String fileName)
     {
-        InvocationContext invocationContext = new InvocationContext();
-        invocationContext.setContextObject(AbstractFileInboundRouter.PROP_FILE_OBJ, new File(fileName));
+        HashMap<String, String> invocationParameters = new HashMap<String, String>();
+        invocationParameters.put(IN_FILE_NAME, new File(fileName).getName());
+        InvocationContext invocationContext = new InvocationContext(invocationParameters);
         InvocationContext.setContext(invocationContext);
     }
 




More information about the jboss-svn-commits mailing list