Author: davsclaus
Date: Wed Dec  8 08:51:32 2010
New Revision: 1043337

URL: http://svn.apache.org/viewvc?rev=1043337&view=rev
Log:
Added exec test using quoted arguments.

Modified:
    
camel/trunk/components/camel-exec/src/main/java/org/apache/camel/component/exec/impl/DefaultExecBinding.java
    
camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java
    
camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecTestUtils.java
    
camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecutableJavaProgram.java
    camel/trunk/components/camel-exec/src/test/resources/log4j.properties

Modified: 
camel/trunk/components/camel-exec/src/main/java/org/apache/camel/component/exec/impl/DefaultExecBinding.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-exec/src/main/java/org/apache/camel/component/exec/impl/DefaultExecBinding.java?rev=1043337&r1=1043336&r2=1043337&view=diff
==============================================================================
--- 
camel/trunk/components/camel-exec/src/main/java/org/apache/camel/component/exec/impl/DefaultExecBinding.java
 (original)
+++ 
camel/trunk/components/camel-exec/src/main/java/org/apache/camel/component/exec/impl/DefaultExecBinding.java
 Wed Dec  8 08:51:32 2010
@@ -27,6 +27,8 @@ import org.apache.camel.component.exec.E
 import org.apache.camel.component.exec.ExecEndpoint;
 import org.apache.camel.component.exec.ExecResult;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import static 
org.apache.camel.component.exec.impl.ExecParseUtils.splitToWhiteSpaceSeparatedTokens;
 
@@ -37,6 +39,8 @@ import static org.apache.camel.component
  */
 public class DefaultExecBinding implements ExecBinding {
 
+    private static final Log LOG = LogFactory.getLog(DefaultExecBinding.class);
+
     @SuppressWarnings("unchecked")
     public ExecCommand readInput(Exchange exchange, ExecEndpoint endpoint) {
         ObjectHelper.notNull(exchange, "exchange");
@@ -60,6 +64,9 @@ public class DefaultExecBinding implemen
                 // use args from header instead from endpoint
                 s = 
exchange.getContext().getTypeConverter().convertTo(String.class, exchange, 
args);
             }
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Parsing argument String to a List: " + s);
+            }
             argsList = splitToWhiteSpaceSeparatedTokens(s);
         }
 

Modified: 
camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java?rev=1043337&r1=1043336&r2=1043337&view=diff
==============================================================================
--- 
camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java
 (original)
+++ 
camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java
 Wed Dec  8 08:51:32 2010
@@ -44,6 +44,7 @@ import static org.apache.camel.component
 import static 
org.apache.camel.component.exec.ExecutableJavaProgram.EXIT_WITH_VALUE_0;
 import static 
org.apache.camel.component.exec.ExecutableJavaProgram.EXIT_WITH_VALUE_1;
 import static 
org.apache.camel.component.exec.ExecutableJavaProgram.PRINT_IN_STDERR;
+import static 
org.apache.camel.component.exec.ExecutableJavaProgram.PRINT_ARGS_STDOUT;
 import static 
org.apache.camel.component.exec.ExecutableJavaProgram.PRINT_IN_STDOUT;
 import static 
org.apache.camel.component.exec.ExecutableJavaProgram.READ_INPUT_LINES_AND_PRINT_THEM;
 import static 
org.apache.camel.component.exec.ExecutableJavaProgram.SLEEP_WITH_TIMEOUT;
@@ -203,9 +204,6 @@ public class ExecJavaProcessTest extends
 
     /**
      * Test print in stdout from threads.
-     * 
-     * @see ExecutableJavaProgram#THREADS
-     * @throws Exception
      */
     @Test
     public void testExecJavaProcessThreads() throws Exception {
@@ -224,9 +222,6 @@ public class ExecJavaProcessTest extends
 
     /**
      * Test print in stdout using string as args
-     *
-     * @see ExecutableJavaProgram#THREADS
-     * @throws Exception
      */
     @Test
     public void testExecJavaArgsAsString() throws Exception {
@@ -257,10 +252,69 @@ public class ExecJavaProcessTest extends
     }
 
     /**
+     * Test print in stdout using string as args with quotes
+     */
+    @Test
+    public void testExecJavaArgsAsStringWithQuote() throws Exception {
+        output.setExpectedMessageCount(1);
+
+        Exchange exchange = producerTemplate.send("direct:input", new 
Processor() {
+            public void process(Exchange exchange) throws Exception {
+                final String javaAbsolutePath = buildJavaExecutablePath();
+
+                // use string for args
+                String classpath = System.getProperty("java.class.path");
+                String args = "-cp \"" + classpath + "\" " + 
EXECUTABLE_PROGRAM_ARG + " " + PRINT_ARGS_STDOUT + " \"Hello World\"";
+
+                exchange.getIn().setBody("hello");
+                exchange.getIn().setHeader(EXEC_COMMAND_EXECUTABLE, 
javaAbsolutePath);
+                exchange.getIn().setHeader(EXEC_COMMAND_ARGS, args);
+                exchange.getIn().setHeader(EXEC_USE_STDERR_ON_EMPTY_STDOUT, 
true);
+            }
+        });
+
+        output.assertIsSatisfied();
+
+        ExecResult result = exchange.getIn().getBody(ExecResult.class);
+        assertNotNull(result);
+
+        String out = IOConverter.toString(result.getStdout(), exchange);
+        assertEquals(PRINT_ARGS_STDOUT + "\nHello World\n", out);
+    }
+
+    /**
+     * Test print in stdout using string as args with quotes
+     */
+    @Test
+    public void testExecJavaArgsAsStringWithoutQuote() throws Exception {
+        output.setExpectedMessageCount(1);
+
+        Exchange exchange = producerTemplate.send("direct:input", new 
Processor() {
+            public void process(Exchange exchange) throws Exception {
+                final String javaAbsolutePath = buildJavaExecutablePath();
+
+                // use string for args
+                String classpath = System.getProperty("java.class.path");
+                String args = "-cp \"" + classpath + "\" " + 
EXECUTABLE_PROGRAM_ARG + " " + PRINT_ARGS_STDOUT + " Hello World";
+
+                exchange.getIn().setBody("hello");
+                exchange.getIn().setHeader(EXEC_COMMAND_EXECUTABLE, 
javaAbsolutePath);
+                exchange.getIn().setHeader(EXEC_COMMAND_ARGS, args);
+                exchange.getIn().setHeader(EXEC_USE_STDERR_ON_EMPTY_STDOUT, 
true);
+            }
+        });
+
+        output.assertIsSatisfied();
+
+        ExecResult result = exchange.getIn().getBody(ExecResult.class);
+        assertNotNull(result);
+
+        String out = IOConverter.toString(result.getStdout(), exchange);
+        assertEquals(PRINT_ARGS_STDOUT + "\nHello\nWorld\n", out);
+    }
+
+    /**
      * Test if the process will be terminate in about a second
-     * 
-     * @see ExecutableJavaProgram#SLEEP_WITH_TIMEOUT
-     * @throws Exception
      */
     @Test
     public void testExecJavaProcessTimeout() throws Exception {
@@ -277,9 +331,6 @@ public class ExecJavaProcessTest extends
 
     /**
      * Test reading of input lines from the executable's stdin
-     * 
-     * @see ExecutableJavaProgram#READ_INPUT_LINES_AND_PRINT_THEM
-     * @throws Exception
      */
     @Test
     public void testExecJavaProcessInputLines() throws Exception {

Modified: 
camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecTestUtils.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecTestUtils.java?rev=1043337&r1=1043336&r2=1043337&view=diff
==============================================================================
--- 
camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecTestUtils.java
 (original)
+++ 
camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecTestUtils.java
 Wed Dec  8 08:51:32 2010
@@ -57,8 +57,9 @@ public final class ExecTestUtils {
      * @return the java executable in a system independent way.
      */
     public static String buildJavaExecutablePath() {
-        String javaHome = (String)System.getenv("JAVA_HOME");
+        String javaHome = System.getenv("JAVA_HOME");
         if (javaHome == null) {
+            System.out.println("The Exec component tests will fail, because 
the environment variable JAVA_HOME is not set!");
             throw new IllegalStateException("The Exec component tests will 
fail, because the environment variable JAVA_HOME is not set!");
         }
         File java = new File(javaHome + File.separator + "bin" + 
File.separator + "java");

Modified: 
camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecutableJavaProgram.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecutableJavaProgram.java?rev=1043337&r1=1043336&r2=1043337&view=diff
==============================================================================
--- 
camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecutableJavaProgram.java
 (original)
+++ 
camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecutableJavaProgram.java
 Wed Dec  8 08:51:32 2010
@@ -37,6 +37,8 @@ public class ExecutableJavaProgram {
 
     public static final String PRINT_IN_STDOUT = "print.in.stdout";
 
+    public static final String PRINT_ARGS_STDOUT = "print.args.stdout";
+
     public static final String PRINT_IN_STDERR = "print.in.stderr";
 
     public static final String READ_INPUT_LINES_AND_PRINT_THEM = 
"read.input.lines.and.print.them";
@@ -59,6 +61,11 @@ public class ExecutableJavaProgram {
         if (args[0].equals(PRINT_IN_STDOUT)) {
             System.out.print(PRINT_IN_STDOUT);
             System.exit(0);
+        } else if (args[0].equals(PRINT_ARGS_STDOUT)) {
+            for (String arg : args) {
+                System.out.println(arg);
+            }
+            System.exit(0);
         } else if (args[0].equals(PRINT_IN_STDERR)) {
             System.err.print(PRINT_IN_STDERR);
             System.exit(1);

Modified: camel/trunk/components/camel-exec/src/test/resources/log4j.properties
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-exec/src/test/resources/log4j.properties?rev=1043337&r1=1043336&r2=1043337&view=diff
==============================================================================
--- camel/trunk/components/camel-exec/src/test/resources/log4j.properties 
(original)
+++ camel/trunk/components/camel-exec/src/test/resources/log4j.properties Wed 
Dec  8 08:51:32 2010
@@ -21,6 +21,8 @@
 #
 log4j.rootLogger=INFO, out
 
+#log4j.logger.org.apache.camel.component.exec=DEBUG
+
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
 log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} 
- %m%n


Reply via email to