[jboss-svn-commits] JBL Code SVN: r23678 - in labs/jbossesb/workspace/skeagh: examples/file-router/src/main/resources and 5 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Nov 3 09:55:18 EST 2008
Author: beve
Date: 2008-11-03 09:55:17 -0500 (Mon, 03 Nov 2008)
New Revision: 23678
Added:
labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/lifecycle/FileLifecycleConfigTest.java
labs/jbossesb/workspace/skeagh/routing/file/src/test/resources/log4j.xml
Modified:
labs/jbossesb/workspace/skeagh/examples/file-router/README.TXT
labs/jbossesb/workspace/skeagh/examples/file-router/pom.xml
labs/jbossesb/workspace/skeagh/examples/file-router/src/main/resources/jboss-esb.xml
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/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/main/java/org/jboss/esb/file/lifecycle/FileLifecycleConfig.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/file-inbound-router_01.xml
labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/lifecycle/DefaultFileLifecycleTest.java
Log:
Added support for different working, processed and error directories.
Modified: labs/jbossesb/workspace/skeagh/examples/file-router/README.TXT
===================================================================
--- labs/jbossesb/workspace/skeagh/examples/file-router/README.TXT 2008-11-03 13:51:28 UTC (rev 23677)
+++ labs/jbossesb/workspace/skeagh/examples/file-router/README.TXT 2008-11-03 14:55:17 UTC (rev 23678)
@@ -2,7 +2,6 @@
===================
This example illustrates a simple JBossESB 5.0 File Router example.
-
How to Run?
===========
Requirements:
@@ -15,6 +14,8 @@
3. Run "mvn clean install pax:provision". This starts the OSGi container (Felix) and deploys the ESB.
4. Open a new console window ("Window 3")
5. Copy src/text/resources/sample.txt to target/input. This file will be picked up by the the ESB.
+ Switch back to "Window 2) and see the output from the Service.
+ The processed file will now have moved to the specified 'processedDir'(target/output by default).
Things to try
=============
Modified: labs/jbossesb/workspace/skeagh/examples/file-router/pom.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/examples/file-router/pom.xml 2008-11-03 13:51:28 UTC (rev 23677)
+++ labs/jbossesb/workspace/skeagh/examples/file-router/pom.xml 2008-11-03 14:55:17 UTC (rev 23678)
@@ -125,6 +125,7 @@
<tasks>
<property name="runtime-classpath" refid="maven.runtime.classpath"/>
<mkdir dir="${basedir}/target/input"/>
+ <mkdir dir="${basedir}/target/working"/>
<mkdir dir="${basedir}/target/output"/>
<mkdir dir="${basedir}/target/error"/>
</tasks>
Modified: labs/jbossesb/workspace/skeagh/examples/file-router/src/main/resources/jboss-esb.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/examples/file-router/src/main/resources/jboss-esb.xml 2008-11-03 13:51:28 UTC (rev 23677)
+++ labs/jbossesb/workspace/skeagh/examples/file-router/src/main/resources/jboss-esb.xml 2008-11-03 14:55:17 UTC (rev 23678)
@@ -9,14 +9,20 @@
<services>
<service serviceCategory="examples" serviceName="InboundRouter-File" serviceDescription="First Example" class="org.jboss.esb.examples.filerouter.MyTestService">
<inRouter name="fileRouter" class="org.jboss.esb.file.FileInboundRouter">
+ <!-- Mandatory properties -->
<property name="scheduleResourceId">schedule1</property>
<property name="inputDir">../target/input</property>
+
+ <!-- Optional properties -->
<property name="fileSelectorPattern">*.txt</property>
+ <property name="fileSelector">org.jboss.esb.file.filtering.WildcardFileSelector</property>
+ <property name="fileEncoding">UTF-8</property>
+ <property name="workingDir">../target/working</property>
<property name="workingRenamePattern">${name}-${timestamp}.working</property>
+ <property name="processedDir">../target/output</property>
<property name="processedRenamePattern">${name}-${timestamp}.done</property>
+ <property name="errorDir">../target/error</property>
<property name="errrorRenamePattern">${name}-${timestamp}.error</property>
- <property name="fileEncoding">UTF-8</property>
- <property name="fileSelector">org.jboss.esb.file.filtering.WildcardFileSelector</property>
<property name="messageComposer">org.jboss.esb.file.composers.FileStringMessageComposer</property>
<property name="fileLifecycleFactory">org.jboss.esb.file.lifecycle.DefaultFileLifecycleFactory</property>
</inRouter>
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-11-03 13:51:28 UTC (rev 23677)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/FileInboundRouter.java 2008-11-03 14:55:17 UTC (rev 23678)
@@ -71,9 +71,12 @@
* <li>fileSelectorPattern - the file matching pattern used to filter files to pick up from the inputDir. Default: '*'</li>
* <li>fileSelector - the concrete {@link FileSelector} implementation to use. Default: org.jboss.esb.file.filtering.WildcardFileSelector </li>
* <li>fileEncoding - the file encoding to use when reading the file. Default: UTF-8.</li>
+ * <li>workingDir - the directory from where files will be places during processing.</li>
* <li>workingRenamePattern - the pattern used for naming files that the esb is processing. Default: ${name}.working</li>
+ * <li>processedDir - the directory where files will be placed after successful processing.</li>
+ * <li>processedRenamePattern - the pattern used for naming files that have be processed successfully. Default: ${name}.processed}</li>
+ * <li>errorDir - the directory where files will be placed when a processing error occurs.</li>
* <li>errorRenamePattern - the pattern used for naming files when a processing error occurs. Default: ${name}.error</li>
- * <li>processedRenamePattern - the pattern used for naming files that have be processed successfully. Default: ${name}.processed}</li>
* <li>messageComposer - the concrete {@link MessageComposer} implementation to use. Default: org.jboss.esb.file.composers.FileStringMessageComposer</li>
* <li>fileLifecycleFactory - the concrete {@link FileLifecycleFactory} implementation to use. Default: org.jboss.esb.file.lifecycle.DefaultFileLifecycleFactory</li>
* </lu>
@@ -119,18 +122,36 @@
private String workingRenamePattern;
/**
+ * The directory where files that are being processed are placed.
+ */
+ @Property(use = Use.OPTIONAL, name = "workingDir")
+ private String workingDir;
+
+ /**
* The rename pattern for a file when an error occurs.
*/
@Property(use = Use.OPTIONAL, name = "errorRenamePattern", defaultVal = "${name}.error")
private String errorRenamePattern;
/**
+ * The directory where files will be places if an error occurs while processing.
+ */
+ @Property(use = Use.OPTIONAL, name = "errorDir")
+ private String errorDir;
+
+ /**
* The processed rename pattern for a successfully processed file.
*/
@Property(use = Use.OPTIONAL, name = "processedRenamePattern", defaultVal = "${name}.processed")
private String processedRenamePattern;
/**
+ * The directory where files that have been successfully processed are placed.
+ */
+ @Property(use = Use.OPTIONAL, name = "processedDir")
+ private String processedDir;
+
+ /**
* The message composer to use.
*/
@Property(use = Use.OPTIONAL, name = "messageComposer", defaultVal = "org.jboss.esb.file.composers.FileBytesMessageComposer")
@@ -145,8 +166,8 @@
/**
* Additional properties.
* Any properties specified in the configuration that are not matched to fields of
- * this class. These will be passed along to the message composer, file selector,
- * and the lifecycle factory.
+ * this class.
+ * These will be passed along to the message composer, file selector, and the lifecycle factory.
*/
@org.jboss.esb.api.annotations.Properties
private Properties properties = new Properties();
@@ -182,7 +203,7 @@
private Object objectName;
/**
- * Flag used to detarmine if shutdown in in progress.
+ * Flag used to determine if shutdown is in progress.
*/
private volatile boolean shuttingDown;
@@ -202,9 +223,12 @@
fileSelector = FileSelector.Factory.newInstance(fileSelectorImpl, properties);
// Config the file lifecycle factory...
+ properties.setProperty(FileLifecycle.WORKING_DIRECTORY, workingDir != null ? workingDir : inputDirName);
properties.setProperty(FileLifecycle.WORKING_RENAME_PATTERN, workingRenamePattern);
+ properties.setProperty(FileLifecycle.ERROR_DIRECTORY, errorDir != null ? errorDir : inputDirName);
properties.setProperty(FileLifecycle.ERROR_RENAME_PATTERN, errorRenamePattern);
properties.setProperty(FileLifecycle.PROCESSED_RENAME_PATTERN, processedRenamePattern);
+ properties.setProperty(FileLifecycle.PROCESSED_DIRECTORY, processedDir != null ? processedDir : inputDirName);
fileLifecycleFactory = FileLifecycleFactory.Factory.newInstance(fileLifecycleFactoryName, properties);
// Config the message composer...
@@ -239,7 +263,7 @@
return;
}
- logger.info(" schedule triggered...");
+ logger.info(" Schedule triggered for '" + objectName + "'");
final InvocationContext invocationContext = new InvocationContext();
final Message message = createEsbMessage(invocationContext);
@@ -257,9 +281,9 @@
fileLifecycle.toError();
throw new SchedulingException(e.getMessage(), e);
}
+
+ onProcessingComplete(message, fileLifecycle);
}
-
- //onProcessingComplete(message, fileLifecycle);
}
/**
@@ -391,7 +415,6 @@
* @return Message The ESB Message object.
* @throws SchedulingException If an exception occurs while decomposing.
*/
- @SuppressWarnings("unused")
private Message onProcessingComplete(final Message message, final FileLifecycle fileLifecycle) throws SchedulingException
{
try
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-11-03 13:51:28 UTC (rev 23677)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/lifecycle/DefaultFileLifecycle.java 2008-11-03 14:55:17 UTC (rev 23678)
@@ -106,7 +106,7 @@
*/
public final File toWorking()
{
- return renameFile(config.getWorkingRenamePattern());
+ return renameFile(config.getWorkingDir(), config.getWorkingRenamePattern());
}
/**
@@ -117,7 +117,7 @@
*/
public final File toError()
{
- return renameFile(config.getErrorRenamePattern());
+ return renameFile(config.getErrorDir(), config.getErrorRenamePattern());
}
/**
@@ -130,7 +130,7 @@
{
if (config.getProcessedRenamePattern() != null)
{
- return renameFile(config.getProcessedRenamePattern());
+ return renameFile(config.getProcessedDir(), config.getProcessedRenamePattern());
}
else
{
@@ -216,19 +216,23 @@
}
/**
- * Renames the file(getFile()) using the passed in rename expression.
+ * Renames the file(getFile()) using the passed in rename expression,
+ * and specifies the output directory.
*
+ * @param toDir The target directory for this rename operation. If null then the current files directory is used as the output directory.
* @param renameExpression The name expression for the destination file.
* @return File File object to the renamed file, or null if the current file does not have a parent directory.
*/
- private File renameFile(final String renameExpression)
+ private File renameFile(final File toDir, final String renameExpression)
{
final File currentRevision = getFile();
final String newName = evalNameExpression(renameExpression);
- final File dir = currentRevision.getParentFile();
+ final File dir = toDir == null ? currentRevision.getParentFile() : toDir;
+
if (dir != null)
{
+
final File toFile = new File(dir, newName);
if (!toFile.exists())
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-11-03 13:51:28 UTC (rev 23677)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/lifecycle/FileLifecycle.java 2008-11-03 14:55:17 UTC (rev 23678)
@@ -41,14 +41,29 @@
/**
* Key used in properties map.
*/
+ String WORKING_DIRECTORY = "workingDirectory";
+
+ /**
+ * Key used in properties map.
+ */
String ERROR_RENAME_PATTERN = "errorRenamePattern";
/**
* Key used in properties map.
*/
+ String ERROR_DIRECTORY = "errorDirectory";
+
+ /**
+ * Key used in properties map.
+ */
String PROCESSED_RENAME_PATTERN = "processedRenamePattern";
/**
+ * Key used in properties map.
+ */
+ String PROCESSED_DIRECTORY = "processedDirectory";
+
+ /**
* String used as a replacement key.
*/
String FILE_NAME = "${name}";
Modified: labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/lifecycle/FileLifecycleConfig.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/lifecycle/FileLifecycleConfig.java 2008-11-03 13:51:28 UTC (rev 23677)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/main/java/org/jboss/esb/file/lifecycle/FileLifecycleConfig.java 2008-11-03 14:55:17 UTC (rev 23678)
@@ -19,8 +19,11 @@
*/
package org.jboss.esb.file.lifecycle;
+import java.io.File;
import java.util.Properties;
+import org.jboss.esb.api.exception.ConfigurationException;
+
/**
* File Lifecycle Configuration.
*
@@ -44,15 +47,35 @@
private String processedRenamePattern;
/**
+ * The directory where files that are in process(working) are placed.
+ */
+ private File workingDir;
+
+ /**
+ * The directory where processed file will be places.
+ */
+ private File processedDir;
+
+ /**
+ * The directory where error files will be placed.
+ */
+ private File errorDir;
+
+ /**
* Configures this instance.
*
* @param properties The properties used in initialize this instance.
+ * @throws ConfigurationException If one of the specified directories does not exist.
*/
- public final void setConfiguration(final Properties properties)
+ public final void setConfiguration(final Properties properties) throws ConfigurationException
{
workingRenamePattern = properties.getProperty(FileLifecycle.WORKING_RENAME_PATTERN, FileLifecycle.PREFIX_TOKEN + "." + FileLifecycle.SUFFIX_TOKEN + ".working");
errorRenamePattern = properties.getProperty(FileLifecycle.ERROR_RENAME_PATTERN, FileLifecycle.PREFIX_TOKEN + "." + FileLifecycle.SUFFIX_TOKEN + ".error");
- processedRenamePattern = properties.getProperty(FileLifecycle.PROCESSED_RENAME_PATTERN);
+ processedRenamePattern = properties.getProperty(FileLifecycle.PROCESSED_RENAME_PATTERN, FileLifecycle.PREFIX_TOKEN + "." + FileLifecycle.SUFFIX_TOKEN + ".processed");
+
+ workingDir = getFileRefToDir(FileLifecycle.WORKING_DIRECTORY, properties);
+ processedDir = getFileRefToDir(FileLifecycle.PROCESSED_DIRECTORY, properties);
+ errorDir = getFileRefToDir(FileLifecycle.ERROR_DIRECTORY, properties);
}
/**
@@ -78,4 +101,59 @@
{
return processedRenamePattern;
}
+
+ /**
+ * Gets the name of the directory in-process(working) files files
+ * will be stored.
+ *
+ * @return File File object to the directory working files are stored.
+ */
+ public final File getWorkingDir()
+ {
+ return workingDir;
+ }
+
+ /**
+ * Gets the name of the directory where processed files
+ * will be stored.
+ *
+ * @return File File object to the directory where processed files are stored.
+ */
+ public final File getProcessedDir()
+ {
+ return processedDir;
+ }
+
+ /**
+ * Gets the name of the directory where error files
+ * will be stored.
+ *
+ * @return File File object to the directory where error files are stored.
+ */
+ public final File getErrorDir()
+ {
+ return errorDir;
+ }
+
+ /**
+ *
+ * @param propertyName The name of the property to extract.
+ * @param properties The properties.
+ * @return File File object to directory, or null if the propertyName did not exist in the properties object.
+ * @throws ConfigurationException If the directory was specified in the properties but does not exist in the file system.
+ */
+ private File getFileRefToDir(final String propertyName, final Properties properties) throws ConfigurationException
+ {
+ final String dirName = properties.getProperty(propertyName);
+ if (dirName != null)
+ {
+ final File directory = new File(dirName);
+ if (!directory.exists())
+ {
+ throw new ConfigurationException("The directory '" + directory.getAbsolutePath() + "' specified for '" + propertyName + "' does not exist.");
+ }
+ return directory;
+ }
+ return null;
+ }
}
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-11-03 13:51:28 UTC (rev 23677)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/FileInboundRouterTest.java 2008-11-03 14:55:17 UTC (rev 23678)
@@ -40,9 +40,9 @@
import org.jboss.esb.file.composers.AbstractFileMessageComposer;
import org.jboss.esb.schedule.SchedulingException;
import org.jboss.esb.util.FileUtil;
+import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Test;
@@ -57,39 +57,33 @@
private static DeploymentRuntime runtime;
private static InboundRouterConfig inboundRouterConfig;
- private File testFile;
+ private File inputFile;
+ private File processedFile;
private String testPayload = "Some payload text..";
+ final MockDispatcher dispatcher = new MockDispatcher();
@Test
public void onSchedule() throws IOException, SchedulingException, ConfigurationException
{
- FileInboundRouter fileRouter = (FileInboundRouter) inboundRouterConfig.getRouter();
-
- MockDispatcher dispatcher = new MockDispatcher();
+ final FileInboundRouter fileRouter = (FileInboundRouter) inboundRouterConfig.getRouter();
fileRouter.setDispatcher(dispatcher);
fileRouter.initialize();
fileRouter.onSchedule();
- File parentFile = testFile.getParentFile();
- System.out.println(parentFile.getAbsolutePath());
- String[] list = parentFile.list(new FilenameFilter() {
- public boolean accept(File dir, String name)
- {
- return name.endsWith("-processed");
- }
- });
- assertTrue(list.length > 0);
- assertEquals(testPayload, new String(FileUtil.readTextFile(new File(parentFile, list[0]))));
+ String[] list = files(inputFile.getParentFile(), "-processed");
+ assertTrue("One file should have been created", list.length == 1);
+ processedFile = new File(inputFile.getParentFile(), list[0]);
+
+ assertEquals(testPayload, new String(FileUtil.readTextFile(processedFile)));
}
@Test
- @Ignore
public void verifyThatFileMetaDataHasBeenSetOnInvocationContext() throws SchedulingException, ConfigurationException
{
- FileInboundRouter fileRouter = (FileInboundRouter) inboundRouterConfig.getRouter();
- MockDispatcher dispatcher = new MockDispatcher();
+ final FileInboundRouter fileRouter = (FileInboundRouter) inboundRouterConfig.getRouter();
fileRouter.setDispatcher(dispatcher);
+
fileRouter.initialize();
fileRouter.onSchedule();
@@ -99,27 +93,46 @@
assertNotNull(context.getContextObject(AbstractFileMessageComposer.PROP_FILE_LIFECYCLE));
assertNotNull(context.getContextObject(AbstractFileMessageComposer.PROP_FILE_OBJ));
assertNotNull(context.getContextObject(AbstractFileMessageComposer.PROP_FILE_LENGTH));
+
+ final String[] list = files(inputFile.getParentFile(), "-processed");
+ processedFile = new File(inputFile.getParentFile(), list[0]);
}
@Test
- @Ignore
public void onScheduleWithDifferentOutputDirectory() throws IOException, ConfigurationException, SchedulingException, DeploymentException
{
- DeploymentRuntime runtime = DeploymentUtil.createRuntime(FileInboundRouterTest.class.getResourceAsStream("file-inbound-router_02.xml"));
- InboundRouterConfig inboundRouterConfig = DeploymentUtil.getInboundRouter("fileRouter", runtime);
- FileInboundRouter fileRouter = (FileInboundRouter) inboundRouterConfig.getRouter();
- MockDispatcher dispatcher = new MockDispatcher();
+ final InboundRouterConfig inboundRouterConfig = DeploymentUtil.getInboundRouter("fileRouter2", runtime);
+ final FileInboundRouter fileRouter = (FileInboundRouter) inboundRouterConfig.getRouter();
fileRouter.setDispatcher(dispatcher);
+
+ final File processedDir = new File(inputFile.getParentFile() + File.separator + "processedDir");
+ processedDir.mkdir();
+
fileRouter.initialize();
fileRouter.onSchedule();
+
+ final String[] list = files(processedDir, ".processed");
+ assertNotNull(list);
+ assertTrue(list.length > 0);
+ processedFile = new File(processedDir, list[0]);
+ assertEquals(testPayload, new String(FileUtil.readTextFile(processedFile)));
}
@Before
public void createFile() throws IOException
{
- testFile = createFile((FileInboundRouter) inboundRouterConfig.getRouter(), testPayload);
+ inputFile = createFile((FileInboundRouter) inboundRouterConfig.getRouter(), testPayload);
}
+ @After
+ public void deleteProcessedFile()
+ {
+ if (processedFile != null && processedFile.exists())
+ {
+ processedFile.delete();
+ }
+ }
+
@BeforeClass
public static void classSetup() throws DeploymentException, IOException
{
@@ -172,4 +185,15 @@
}
}
+
+ private String[] files(final File dir, final String suffix)
+ {
+ String[] list = dir.list(new FilenameFilter() {
+ public boolean accept(File dir, String name)
+ {
+ return name.endsWith(suffix);
+ }
+ });
+ return list;
+ }
}
Modified: labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/file-inbound-router_01.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/file-inbound-router_01.xml 2008-11-03 13:51:28 UTC (rev 23677)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/file-inbound-router_01.xml 2008-11-03 14:55:17 UTC (rev 23678)
@@ -17,6 +17,17 @@
<property name="processedRenamePattern">${name}-${timestamp}-processed</property>
</inRouter>
</service>
+
+ <service serviceCategory="service-cat" serviceName="service-b" serviceDescription="TestService" class="org.jboss.esb.file.MyTestService">
+ <inRouter name="fileRouter2" class="org.jboss.esb.file.FileInboundRouter">
+ <property name="scheduleResourceId">schedule1</property>
+ <property name="inputDir">target/test-classes/</property>
+ <property name="fileSelectorPattern">*.txt</property>
+ <property name="workingRenamePattern">${name}-${timestamp}.${suffix}</property>
+ <property name="processedDir">target/test-classes/processedDir</property>
+ <property name="processedRenamePattern">${name}.processed</property>
+ </inRouter>
+ </service>
</services>
</jbossesb>
\ No newline at end of file
Modified: labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/lifecycle/DefaultFileLifecycleTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/lifecycle/DefaultFileLifecycleTest.java 2008-11-03 13:51:28 UTC (rev 23677)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/lifecycle/DefaultFileLifecycleTest.java 2008-11-03 14:55:17 UTC (rev 23678)
@@ -25,7 +25,9 @@
import java.io.File;
import java.io.IOException;
import java.util.List;
+import java.util.Properties;
+import org.jboss.esb.api.exception.ConfigurationException;
import org.junit.Test;
/**
@@ -39,16 +41,116 @@
@Test
public void setFile() throws IOException
{
- DefaultFileLifecycle fileLifecycle = new DefaultFileLifecycle();
+ final DefaultFileLifecycle fileLifecycle = new DefaultFileLifecycle();
File file = File.createTempFile("junit", ".test");
+ file.deleteOnExit();
fileLifecycle.setFile(file);
List<File> fileHistory = fileLifecycle.getFileHistory();
assertEquals(1, fileHistory.size());
- file = File.createTempFile("junit2", ".test");
- fileLifecycle.setFile(file);
+ final File file2 = File.createTempFile("junit2", ".test");
+ file2.deleteOnExit();
+ fileLifecycle.setFile(file2);
assertEquals(1, fileHistory.size());
}
+ @Test
+ public void toWorking() throws ConfigurationException, IOException
+ {
+ final DefaultFileLifecycle fileLifecycle = new DefaultFileLifecycle();
+ final FileLifecycleConfig fileLifecycleConfig = new FileLifecycleConfig();
+ final Properties properties = new Properties();
+ final File workingDir = new File("workingDir");
+ final File testFile = File.createTempFile("fileLifecycleTest-toWorking", ".unit");
+ testFile.deleteOnExit();
+
+ try
+ {
+ workingDir.mkdir();
+ properties.setProperty(FileLifecycle.WORKING_DIRECTORY, workingDir.getAbsolutePath());
+ fileLifecycleConfig.setConfiguration(properties);
+ fileLifecycle.setConfiguration(fileLifecycleConfig);
+
+ fileLifecycle.setFile(testFile);
+ fileLifecycle.toWorking();
+
+ File workingFile = new File(workingDir, testFile.getName() + ".working");
+ assertTrue("File should have been moved to the working directory", workingFile.exists());
+ workingFile.delete();
+ }
+ finally
+ {
+ if (workingDir != null && workingDir.exists())
+ {
+ workingDir.delete();
+ }
+ }
+ }
+
+ @Test
+ public void toError() throws ConfigurationException, IOException
+ {
+ final DefaultFileLifecycle fileLifecycle = new DefaultFileLifecycle();
+ final FileLifecycleConfig fileLifecycleConfig = new FileLifecycleConfig();
+ final Properties properties = new Properties();
+ final File errorDir = new File("errorDir");
+ final File testFile = File.createTempFile("fileLifecycleTest-toError", ".unit");
+ testFile.deleteOnExit();
+
+ try
+ {
+ errorDir.mkdir();
+ properties.setProperty(FileLifecycle.ERROR_DIRECTORY, errorDir.getAbsolutePath());
+ fileLifecycleConfig.setConfiguration(properties);
+ fileLifecycle.setConfiguration(fileLifecycleConfig);
+
+ fileLifecycle.setFile(testFile);
+ fileLifecycle.toError();
+
+ File errorFile = new File(errorDir, testFile.getName() + ".error");
+ assertTrue("File should have been moved to the error directory", errorFile.exists());
+ errorFile.delete();
+ }
+ finally
+ {
+ if (errorDir != null && errorDir.exists())
+ {
+ errorDir.delete();
+ }
+ }
+ }
+
+ @Test
+ public void toProcessed() throws ConfigurationException, IOException
+ {
+ final DefaultFileLifecycle fileLifecycle = new DefaultFileLifecycle();
+ final FileLifecycleConfig fileLifecycleConfig = new FileLifecycleConfig();
+ final Properties properties = new Properties();
+ final File processedDir = new File("processedDir");
+ final File testFile = File.createTempFile("fileLifecycleTest-toProcessed", ".unit");
+ testFile.deleteOnExit();
+
+ try
+ {
+ processedDir.mkdir();
+ properties.setProperty(FileLifecycle.PROCESSED_DIRECTORY, processedDir.getAbsolutePath());
+ fileLifecycleConfig.setConfiguration(properties);
+ fileLifecycle.setConfiguration(fileLifecycleConfig);
+
+ fileLifecycle.setFile(testFile);
+ fileLifecycle.toProcessed();
+
+ File processedFile = new File(processedDir, testFile.getName() + ".processed");
+ assertTrue("File should have been moved to the processed directory", processedFile.exists());
+ processedFile.delete();
+ }
+ finally
+ {
+ if (processedDir != null && processedDir.exists())
+ {
+ processedDir.delete();
+ }
+ }
+ }
}
Added: labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/lifecycle/FileLifecycleConfigTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/lifecycle/FileLifecycleConfigTest.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/test/java/org/jboss/esb/file/lifecycle/FileLifecycleConfigTest.java 2008-11-03 14:55:17 UTC (rev 23678)
@@ -0,0 +1,190 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.Properties;
+
+import org.jboss.esb.api.exception.ConfigurationException;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Test for {@link FileLifecycleConfig}.
+ *
+ * @author <a href="mailto:dbevenius at jboss.com">Daniel Bevenius</a>
+ *
+ */
+public class FileLifecycleConfigTest
+{
+ private FileLifecycleConfig fileLifecycleConfig;
+ private Properties configProperties;
+ private String defaultRenamePrefix = FileLifecycle.PREFIX_TOKEN + "." + FileLifecycle.SUFFIX_TOKEN;
+
+ @Test
+ public void setConfigurationDefaultWorkingRenamePattern() throws ConfigurationException
+ {
+ fileLifecycleConfig.setConfiguration(configProperties);
+ assertEquals(defaultRenamePrefix + ".working", fileLifecycleConfig.getWorkingRenamePattern());
+ }
+
+ @Test
+ public void setConfigurationWorkingRenamePattern() throws ConfigurationException
+ {
+ final String pattern = "${name}-working";
+ configProperties.setProperty(FileLifecycle.WORKING_RENAME_PATTERN, pattern);
+ fileLifecycleConfig.setConfiguration(configProperties);
+
+ assertEquals(pattern, fileLifecycleConfig.getWorkingRenamePattern());
+ }
+
+ @Test
+ public void setConfigurationDefaultErrorRenamePattern() throws ConfigurationException
+ {
+ fileLifecycleConfig.setConfiguration(configProperties);
+ assertEquals(defaultRenamePrefix + ".error", fileLifecycleConfig.getErrorRenamePattern());
+ }
+
+ @Test
+ public void setConfigurationErrorRenamePattern() throws ConfigurationException
+ {
+ final String pattern = "${name}-error";
+ configProperties.setProperty(FileLifecycle.ERROR_RENAME_PATTERN, pattern);
+ fileLifecycleConfig.setConfiguration(configProperties);
+
+ assertEquals(pattern, fileLifecycleConfig.getErrorRenamePattern());
+ }
+
+ @Test
+ public void setConfigurationDefaultProcessedRenamePattern() throws ConfigurationException
+ {
+ fileLifecycleConfig.setConfiguration(configProperties);
+ assertEquals(defaultRenamePrefix + ".processed", fileLifecycleConfig.getProcessedRenamePattern());
+ }
+
+ @Test
+ public void setConfigurationProcessedRenamePattern() throws ConfigurationException
+ {
+ final String pattern = "${name}-processed";
+ configProperties.setProperty(FileLifecycle.PROCESSED_RENAME_PATTERN, pattern);
+ fileLifecycleConfig.setConfiguration(configProperties);
+
+ assertEquals(pattern, fileLifecycleConfig.getProcessedRenamePattern());
+ }
+
+ @Test ( expected = ConfigurationException.class )
+ public void shouldThrowIfProcessDirDoesNotExist() throws ConfigurationException
+ {
+ final File processedDir = new File("processedDir");
+ configProperties.setProperty(FileLifecycle.PROCESSED_DIRECTORY, processedDir.getAbsolutePath());
+ fileLifecycleConfig.setConfiguration(configProperties);
+ }
+
+ @Test
+ public void setConfigurationProcessedDir() throws ConfigurationException
+ {
+ final File processedDir = new File("processedDir");
+ try
+ {
+ processedDir.mkdir();
+ configProperties.setProperty(FileLifecycle.PROCESSED_DIRECTORY, processedDir.getAbsolutePath());
+ fileLifecycleConfig.setConfiguration(configProperties);
+ assertTrue(fileLifecycleConfig.getProcessedDir().exists());
+ }
+ finally
+ {
+ if (processedDir != null && processedDir.exists())
+ {
+ processedDir.delete();
+ }
+ }
+ }
+
+ @Test ( expected = ConfigurationException.class )
+ public void shouldThrowIfErrorDirDoesNotExist() throws ConfigurationException
+ {
+ final File errorDir = new File("errorDir");
+ configProperties.setProperty(FileLifecycle.ERROR_DIRECTORY, errorDir.getAbsolutePath());
+ fileLifecycleConfig.setConfiguration(configProperties);
+ }
+
+ @Test
+ public void setConfigurationErrorDir() throws ConfigurationException
+ {
+ final File errorDir = new File("errorDir");
+ try
+ {
+ errorDir.mkdir();
+ configProperties.setProperty(FileLifecycle.ERROR_DIRECTORY, errorDir.getAbsolutePath());
+ fileLifecycleConfig.setConfiguration(configProperties);
+
+ assertTrue(fileLifecycleConfig.getErrorDir().exists());
+ }
+ finally
+ {
+ if (errorDir != null && errorDir.exists())
+ {
+ errorDir.delete();
+ }
+ }
+ }
+
+ @Test ( expected = ConfigurationException.class )
+ public void shouldThrowIfWorkingDirDoesNotExist() throws ConfigurationException
+ {
+ final File workingDir = new File("workingDir");
+ configProperties.setProperty(FileLifecycle.WORKING_DIRECTORY, workingDir.getAbsolutePath());
+ fileLifecycleConfig.setConfiguration(configProperties);
+ }
+
+ @Test
+ public void setConfigurationWorkingDir() throws ConfigurationException
+ {
+ final File workingDir = new File("workingDir");
+ try
+ {
+ workingDir.mkdir();
+ configProperties.setProperty(FileLifecycle.WORKING_DIRECTORY, workingDir.getAbsolutePath());
+ fileLifecycleConfig.setConfiguration(configProperties);
+ assertTrue(fileLifecycleConfig.getWorkingDir().exists());
+ }
+ finally
+ {
+ if (workingDir != null && workingDir.exists())
+ {
+ workingDir.delete();
+ }
+ }
+ }
+
+
+ @Before
+ public void setup()
+ {
+ fileLifecycleConfig = new FileLifecycleConfig();
+ configProperties = new Properties();
+ }
+
+}
Added: labs/jbossesb/workspace/skeagh/routing/file/src/test/resources/log4j.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/routing/file/src/test/resources/log4j.xml (rev 0)
+++ labs/jbossesb/workspace/skeagh/routing/file/src/test/resources/log4j.xml 2008-11-03 14:55:17 UTC (rev 23678)
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- ===================================================================== -->
+<!-- -->
+<!-- Log4j Configuration -->
+<!-- -->
+<!-- ===================================================================== -->
+
+<!--
+ | For more configuration infromation and examples see the Jakarta Log4j
+ | owebsite: http://jakarta.apache.org/log4j
+ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+ <!-- ============================== -->
+ <!-- Append messages to the console -->
+ <!-- ============================== -->
+
+ <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+ <param name="Target" value="System.out"/>
+
+ <layout class="org.apache.log4j.PatternLayout">
+ <!-- The default pattern: Date Priority [Category] Message\n -->
+ <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%t][%c{1}] %m%n"/>
+ </layout>
+ </appender>
+
+ <!-- ================ -->
+ <!-- Limit categories -->
+
+ <category name="org.milyn">
+ <priority value="error"/>
+ </category>
+
+ <category name="org.quartz">
+ <priority value="error"/>
+ </category>
+
+ <category name="org.jboss">
+ <priority value="error"/>
+ </category>
+
+ <category name="org.jboss.esb.file">
+ <priority value="info"/>
+ </category>
+
+ <category name="org.apache.activemq">
+ <priority value="ERROR"/>
+ </category>
+
+ <!-- ======================= -->
+ <!-- Setup the Root category -->
+ <!-- ======================= -->
+
+ <root>
+ <appender-ref ref="CONSOLE"/>
+ </root>
+
+</log4j:configuration>
+
More information about the jboss-svn-commits
mailing list