You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dk...@apache.org on 2011/12/02 18:03:50 UTC

svn commit: r1209585 [10/22] - in /camel/trunk: ./ apache-camel/ buildingtools/ camel-core/ camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/api/management/ camel-core/src/main/java/org/apache/camel/builder/ camel-co...

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=1209585&r1=1209584&r2=1209585&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 Fri Dec  2 17:03:07 2011
@@ -1,391 +1,391 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.exec;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.camel.EndpointInject;
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.Produce;
-import org.apache.camel.ProducerTemplate;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.converter.IOConverter;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-
-import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_ARGS;
-import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_EXECUTABLE;
-import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_TIMEOUT;
-import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_WORKING_DIR;
-import static org.apache.camel.component.exec.ExecBinding.EXEC_EXIT_VALUE;
-import static org.apache.camel.component.exec.ExecBinding.EXEC_STDERR;
-import static org.apache.camel.component.exec.ExecBinding.EXEC_USE_STDERR_ON_EMPTY_STDOUT;
-import static org.apache.camel.component.exec.ExecEndpoint.NO_TIMEOUT;
-import static org.apache.camel.component.exec.ExecTestUtils.buildJavaExecutablePath;
-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_ARGS_STDOUT;
-import static org.apache.camel.component.exec.ExecutableJavaProgram.PRINT_IN_STDERR;
-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;
-import static org.apache.camel.component.exec.ExecutableJavaProgram.THREADS;
-import static org.apache.commons.io.IOUtils.LINE_SEPARATOR;
-
-/**
- * Tests the functionality of the {@link ExecComponent}, executing<br>
- * <i>java org.apache.camel.component.exec.ExecutableJavaProgram</i> <br>
- * command. <b>Note, that the tests assume, that the JAVA_HOME system variable
- * is set.</b> This is a more credible assumption, than assuming that java is in
- * the path, because the Maven scripts build the path to java with the JAVA_HOME
- * environment variable.
- * 
- * @see {@link ExecutableJavaProgram}
- */
-public class ExecJavaProcessTest extends CamelTestSupport {
-
-    private static final String EXECUTABLE_PROGRAM_ARG = ExecutableJavaProgram.class.getName();
-
-    @Produce(uri = "direct:input")
-    private ProducerTemplate producerTemplate;
-
-    @EndpointInject(uri = "mock:output")
-    private MockEndpoint output;
-
-    @Test
-    public void testExecJavaProcessExitCode0() throws Exception {
-        output.setExpectedMessageCount(1);
-        output.expectedHeaderReceived(EXEC_EXIT_VALUE, 0);
-
-        sendExchange(EXIT_WITH_VALUE_0, NO_TIMEOUT);
-        output.assertIsSatisfied();
-    }
-
-    @Test
-    public void testExecJavaProcessExitCode1() throws Exception {
-        output.setExpectedMessageCount(1);
-        output.expectedHeaderReceived(EXEC_EXIT_VALUE, 1);
-
-        sendExchange(EXIT_WITH_VALUE_1, NO_TIMEOUT);
-        output.assertIsSatisfied();
-    }
-
-    @Test
-    public void testExecJavaProcessStdout() throws Exception {
-        String commandArgument = PRINT_IN_STDOUT;
-        output.setExpectedMessageCount(1);
-        output.expectedHeaderReceived(EXEC_EXIT_VALUE, 0);
-
-        Exchange e = sendExchange(commandArgument, NO_TIMEOUT);
-        ExecResult inBody = e.getIn().getBody(ExecResult.class);
-
-        output.assertIsSatisfied();
-        assertEquals(PRINT_IN_STDOUT, IOUtils.toString(inBody.getStdout()));
-    }
-
-    @Test
-    public void testConvertResultToString() throws Exception {
-        String commandArgument = PRINT_IN_STDOUT;
-        output.setExpectedMessageCount(1);
-
-        Exchange e = sendExchange(commandArgument, NO_TIMEOUT);
-        output.assertIsSatisfied();
-        String out = e.getIn().getBody(String.class);
-        assertEquals(PRINT_IN_STDOUT, out);
-    }
-
-    @Test
-    public void testByteArrayInputStreamIsResetInConverter() throws Exception {
-        String commandArgument = PRINT_IN_STDOUT;
-        output.setExpectedMessageCount(1);
-
-        Exchange e = sendExchange(commandArgument, NO_TIMEOUT);
-        String out1 = e.getIn().getBody(String.class);
-        // the second conversion should not need a reset, this is handled
-        // in the type converter.
-        String out2 = e.getIn().getBody(String.class);
-        
-        output.assertIsSatisfied();
-        assertEquals(PRINT_IN_STDOUT, out1);
-        assertEquals(out1, out2);
-    }
-
-    @Test
-    public void testIfStdoutIsNullStderrIsReturnedInConverter() throws Exception {
-        // this will be printed
-        String commandArgument = PRINT_IN_STDERR;
-        output.setExpectedMessageCount(1);
-
-        Exchange e = sendExchange(commandArgument, NO_TIMEOUT, null, true);
-        ExecResult body = e.getIn().getBody(ExecResult.class);
-
-        output.assertIsSatisfied();
-        assertNull("the test executable must not print anything in stdout", body.getStdout());
-        assertNotNull("the test executable must print in stderr", body.getStderr());
-        // the converter must fall back to the stderr, because stdout is null
-        String stderr = e.getIn().getBody(String.class);
-        assertEquals(PRINT_IN_STDERR, stderr);
-    }
-
-    @Test
-    public void testStdoutIsNull() throws Exception {
-        // this will be printed
-        String commandArgument = PRINT_IN_STDERR;
-        output.setExpectedMessageCount(1);
-
-        Exchange e = sendExchange(commandArgument, NO_TIMEOUT, null, false);
-        ExecResult body = e.getIn().getBody(ExecResult.class);
-
-        output.assertIsSatisfied();
-        assertNull("the test executable must not print anything in stdout", body.getStdout());
-        assertNotNull("the test executable must print in stderr", body.getStderr());
-        // the converter must fall back to the stderr, because stdout is null
-        String out = e.getIn().getBody(String.class);
-        assertNull("Should be null", out);
-    }
-
-    @Test
-    public void testConvertResultToInputStream() throws Exception {
-        String commandArgument = PRINT_IN_STDOUT;
-        output.setExpectedMessageCount(1);
-
-        Exchange e = sendExchange(commandArgument, NO_TIMEOUT);
-        output.assertIsSatisfied();
-        InputStream out = e.getIn().getBody(InputStream.class);
-        assertEquals(PRINT_IN_STDOUT, IOUtils.toString(out));
-    }
-
-    @Test
-    public void testConvertResultToByteArray() throws Exception {
-        String commandArgument = PRINT_IN_STDOUT;
-        output.setExpectedMessageCount(1);
-
-        Exchange e = sendExchange(commandArgument, NO_TIMEOUT);
-        output.assertIsSatisfied();
-        byte[] out = e.getIn().getBody(byte[].class);
-        assertNotNull(out);
-        assertEquals(PRINT_IN_STDOUT, new String(out));
-    }
-
-    @Test
-    public void testInvalidWorkingDir() throws Exception {
-        String commandArgument = PRINT_IN_STDOUT;
-        final List<String> args = buildArgs(commandArgument);
-        final String javaAbsolutePath = buildJavaExecutablePath();
-
-        Exchange e = producerTemplate.send(new Processor() {
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(EXEC_COMMAND_EXECUTABLE, javaAbsolutePath);
-                exchange.getIn().setHeader(EXEC_COMMAND_WORKING_DIR, "\\cdd:///invalidWWorkginDir");
-                exchange.getIn().setHeader(EXEC_COMMAND_ARGS, args);
-            }
-        });
-        assertEquals(ExecException.class, e.getException().getClass());
-    }
-
-    /**
-     * Test print in stdout from threads.
-     */
-    @Test
-    public void testExecJavaProcessThreads() throws Exception {
-        output.setExpectedMessageCount(1);
-        Exchange exchange = sendExchange(THREADS, NO_TIMEOUT);
-
-        String err = IOUtils.toString(exchange.getIn().getHeader(EXEC_STDERR, InputStream.class));
-        ExecResult result = exchange.getIn().getBody(ExecResult.class);
-        String[] outs = IOUtils.toString(result.getStdout()).split(LINE_SEPARATOR);
-        String[] errs = err.split(LINE_SEPARATOR);
-
-        output.assertIsSatisfied();
-        assertEquals(ExecutableJavaProgram.LINES_TO_PRINT_FROM_EACH_THREAD, outs.length);
-        assertEquals(ExecutableJavaProgram.LINES_TO_PRINT_FROM_EACH_THREAD, errs.length);
-    }
-
-    /**
-     * Test print in stdout using string as args
-     */
-    @Test
-    public void testExecJavaArgsAsString() 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_IN_STDOUT;
-
-                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_IN_STDOUT, out);
-    }
-
-    /**
-     * 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);
-        assertTrue(out, out.contains("1Hello World"));
-    }
-
-    /**
-     * 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);
-        assertTrue(out, out.contains("1Hello"));
-        assertTrue(out, out.contains("2World"));
-    }
-
-    /**
-     * Test if the process will be terminate in about a second
-     */
-    @Test
-    public void testExecJavaProcessTimeout() throws Exception {
-        int killAfterMillis = 1000;
-        output.setExpectedMessageCount(1);
-        // add some tolerance
-        output.setMinimumResultWaitTime(800);
-        // max (the test program sleeps 60 000)
-        output.setResultWaitTime(30000);
-
-        sendExchange(SLEEP_WITH_TIMEOUT, killAfterMillis);
-        output.assertIsSatisfied();
-    }
-
-    /**
-     * Test reading of input lines from the executable's stdin
-     */
-    @Test
-    public void testExecJavaProcessInputLines() throws Exception {
-        final StringBuilder builder = new StringBuilder();
-        int lines = 10;
-        for (int t = 1; t < lines; t++) {
-            builder.append("Line" + t + LINE_SEPARATOR);
-        }
-        String whiteSpaceSeparatedLines = builder.toString();
-        String expected = builder.toString();
-
-        Exchange e = sendExchange(READ_INPUT_LINES_AND_PRINT_THEM, 20000, whiteSpaceSeparatedLines, false);
-        ExecResult inBody = e.getIn().getBody(ExecResult.class);
-        assertEquals(expected, IOUtils.toString(inBody.getStdout()));
-    }
-
-    protected Exchange sendExchange(final Object commandArgument, final long timeout) {
-        return sendExchange(commandArgument, timeout, "testBody", false);
-    }
-
-    protected Exchange sendExchange(final Object commandArgument, final long timeout, final String body, final boolean useStderrOnEmptyStdout) {
-        final List<String> args = buildArgs(commandArgument);
-        final String javaAbsolutePath = buildJavaExecutablePath();
-
-        return producerTemplate.send(new Processor() {
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setBody(body);
-                exchange.getIn().setHeader(EXEC_COMMAND_EXECUTABLE, javaAbsolutePath);
-                exchange.getIn().setHeader(EXEC_COMMAND_TIMEOUT, timeout);
-                exchange.getIn().setHeader(EXEC_COMMAND_ARGS, args);
-                if (useStderrOnEmptyStdout) {
-                    exchange.getIn().setHeader(EXEC_USE_STDERR_ON_EMPTY_STDOUT, true);
-                }
-            }
-        });
-    }
-
-    private List<String> buildArgs(Object commandArgument) {
-        String classpath = System.getProperty("java.class.path");
-        List<String> args = new ArrayList<String>();
-        args.add("-cp");
-        args.add(classpath);
-        args.add(EXECUTABLE_PROGRAM_ARG);
-        args.add(commandArgument.toString());
-        return args;
-    }
-
-    @Override
-    protected RouteBuilder createRouteBuilder() {
-        return new RouteBuilder() {
-            public void configure() {
-                from("direct:input").to("exec:java").to("mock:output");
-            }
-        };
-    }
-
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.exec;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.converter.IOConverter;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+
+import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_ARGS;
+import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_EXECUTABLE;
+import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_TIMEOUT;
+import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_WORKING_DIR;
+import static org.apache.camel.component.exec.ExecBinding.EXEC_EXIT_VALUE;
+import static org.apache.camel.component.exec.ExecBinding.EXEC_STDERR;
+import static org.apache.camel.component.exec.ExecBinding.EXEC_USE_STDERR_ON_EMPTY_STDOUT;
+import static org.apache.camel.component.exec.ExecEndpoint.NO_TIMEOUT;
+import static org.apache.camel.component.exec.ExecTestUtils.buildJavaExecutablePath;
+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_ARGS_STDOUT;
+import static org.apache.camel.component.exec.ExecutableJavaProgram.PRINT_IN_STDERR;
+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;
+import static org.apache.camel.component.exec.ExecutableJavaProgram.THREADS;
+import static org.apache.commons.io.IOUtils.LINE_SEPARATOR;
+
+/**
+ * Tests the functionality of the {@link ExecComponent}, executing<br>
+ * <i>java org.apache.camel.component.exec.ExecutableJavaProgram</i> <br>
+ * command. <b>Note, that the tests assume, that the JAVA_HOME system variable
+ * is set.</b> This is a more credible assumption, than assuming that java is in
+ * the path, because the Maven scripts build the path to java with the JAVA_HOME
+ * environment variable.
+ * 
+ * @see {@link ExecutableJavaProgram}
+ */
+public class ExecJavaProcessTest extends CamelTestSupport {
+
+    private static final String EXECUTABLE_PROGRAM_ARG = ExecutableJavaProgram.class.getName();
+
+    @Produce(uri = "direct:input")
+    private ProducerTemplate producerTemplate;
+
+    @EndpointInject(uri = "mock:output")
+    private MockEndpoint output;
+
+    @Test
+    public void testExecJavaProcessExitCode0() throws Exception {
+        output.setExpectedMessageCount(1);
+        output.expectedHeaderReceived(EXEC_EXIT_VALUE, 0);
+
+        sendExchange(EXIT_WITH_VALUE_0, NO_TIMEOUT);
+        output.assertIsSatisfied();
+    }
+
+    @Test
+    public void testExecJavaProcessExitCode1() throws Exception {
+        output.setExpectedMessageCount(1);
+        output.expectedHeaderReceived(EXEC_EXIT_VALUE, 1);
+
+        sendExchange(EXIT_WITH_VALUE_1, NO_TIMEOUT);
+        output.assertIsSatisfied();
+    }
+
+    @Test
+    public void testExecJavaProcessStdout() throws Exception {
+        String commandArgument = PRINT_IN_STDOUT;
+        output.setExpectedMessageCount(1);
+        output.expectedHeaderReceived(EXEC_EXIT_VALUE, 0);
+
+        Exchange e = sendExchange(commandArgument, NO_TIMEOUT);
+        ExecResult inBody = e.getIn().getBody(ExecResult.class);
+
+        output.assertIsSatisfied();
+        assertEquals(PRINT_IN_STDOUT, IOUtils.toString(inBody.getStdout()));
+    }
+
+    @Test
+    public void testConvertResultToString() throws Exception {
+        String commandArgument = PRINT_IN_STDOUT;
+        output.setExpectedMessageCount(1);
+
+        Exchange e = sendExchange(commandArgument, NO_TIMEOUT);
+        output.assertIsSatisfied();
+        String out = e.getIn().getBody(String.class);
+        assertEquals(PRINT_IN_STDOUT, out);
+    }
+
+    @Test
+    public void testByteArrayInputStreamIsResetInConverter() throws Exception {
+        String commandArgument = PRINT_IN_STDOUT;
+        output.setExpectedMessageCount(1);
+
+        Exchange e = sendExchange(commandArgument, NO_TIMEOUT);
+        String out1 = e.getIn().getBody(String.class);
+        // the second conversion should not need a reset, this is handled
+        // in the type converter.
+        String out2 = e.getIn().getBody(String.class);
+        
+        output.assertIsSatisfied();
+        assertEquals(PRINT_IN_STDOUT, out1);
+        assertEquals(out1, out2);
+    }
+
+    @Test
+    public void testIfStdoutIsNullStderrIsReturnedInConverter() throws Exception {
+        // this will be printed
+        String commandArgument = PRINT_IN_STDERR;
+        output.setExpectedMessageCount(1);
+
+        Exchange e = sendExchange(commandArgument, NO_TIMEOUT, null, true);
+        ExecResult body = e.getIn().getBody(ExecResult.class);
+
+        output.assertIsSatisfied();
+        assertNull("the test executable must not print anything in stdout", body.getStdout());
+        assertNotNull("the test executable must print in stderr", body.getStderr());
+        // the converter must fall back to the stderr, because stdout is null
+        String stderr = e.getIn().getBody(String.class);
+        assertEquals(PRINT_IN_STDERR, stderr);
+    }
+
+    @Test
+    public void testStdoutIsNull() throws Exception {
+        // this will be printed
+        String commandArgument = PRINT_IN_STDERR;
+        output.setExpectedMessageCount(1);
+
+        Exchange e = sendExchange(commandArgument, NO_TIMEOUT, null, false);
+        ExecResult body = e.getIn().getBody(ExecResult.class);
+
+        output.assertIsSatisfied();
+        assertNull("the test executable must not print anything in stdout", body.getStdout());
+        assertNotNull("the test executable must print in stderr", body.getStderr());
+        // the converter must fall back to the stderr, because stdout is null
+        String out = e.getIn().getBody(String.class);
+        assertNull("Should be null", out);
+    }
+
+    @Test
+    public void testConvertResultToInputStream() throws Exception {
+        String commandArgument = PRINT_IN_STDOUT;
+        output.setExpectedMessageCount(1);
+
+        Exchange e = sendExchange(commandArgument, NO_TIMEOUT);
+        output.assertIsSatisfied();
+        InputStream out = e.getIn().getBody(InputStream.class);
+        assertEquals(PRINT_IN_STDOUT, IOUtils.toString(out));
+    }
+
+    @Test
+    public void testConvertResultToByteArray() throws Exception {
+        String commandArgument = PRINT_IN_STDOUT;
+        output.setExpectedMessageCount(1);
+
+        Exchange e = sendExchange(commandArgument, NO_TIMEOUT);
+        output.assertIsSatisfied();
+        byte[] out = e.getIn().getBody(byte[].class);
+        assertNotNull(out);
+        assertEquals(PRINT_IN_STDOUT, new String(out));
+    }
+
+    @Test
+    public void testInvalidWorkingDir() throws Exception {
+        String commandArgument = PRINT_IN_STDOUT;
+        final List<String> args = buildArgs(commandArgument);
+        final String javaAbsolutePath = buildJavaExecutablePath();
+
+        Exchange e = producerTemplate.send(new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(EXEC_COMMAND_EXECUTABLE, javaAbsolutePath);
+                exchange.getIn().setHeader(EXEC_COMMAND_WORKING_DIR, "\\cdd:///invalidWWorkginDir");
+                exchange.getIn().setHeader(EXEC_COMMAND_ARGS, args);
+            }
+        });
+        assertEquals(ExecException.class, e.getException().getClass());
+    }
+
+    /**
+     * Test print in stdout from threads.
+     */
+    @Test
+    public void testExecJavaProcessThreads() throws Exception {
+        output.setExpectedMessageCount(1);
+        Exchange exchange = sendExchange(THREADS, NO_TIMEOUT);
+
+        String err = IOUtils.toString(exchange.getIn().getHeader(EXEC_STDERR, InputStream.class));
+        ExecResult result = exchange.getIn().getBody(ExecResult.class);
+        String[] outs = IOUtils.toString(result.getStdout()).split(LINE_SEPARATOR);
+        String[] errs = err.split(LINE_SEPARATOR);
+
+        output.assertIsSatisfied();
+        assertEquals(ExecutableJavaProgram.LINES_TO_PRINT_FROM_EACH_THREAD, outs.length);
+        assertEquals(ExecutableJavaProgram.LINES_TO_PRINT_FROM_EACH_THREAD, errs.length);
+    }
+
+    /**
+     * Test print in stdout using string as args
+     */
+    @Test
+    public void testExecJavaArgsAsString() 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_IN_STDOUT;
+
+                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_IN_STDOUT, out);
+    }
+
+    /**
+     * 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);
+        assertTrue(out, out.contains("1Hello World"));
+    }
+
+    /**
+     * 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);
+        assertTrue(out, out.contains("1Hello"));
+        assertTrue(out, out.contains("2World"));
+    }
+
+    /**
+     * Test if the process will be terminate in about a second
+     */
+    @Test
+    public void testExecJavaProcessTimeout() throws Exception {
+        int killAfterMillis = 1000;
+        output.setExpectedMessageCount(1);
+        // add some tolerance
+        output.setMinimumResultWaitTime(800);
+        // max (the test program sleeps 60 000)
+        output.setResultWaitTime(30000);
+
+        sendExchange(SLEEP_WITH_TIMEOUT, killAfterMillis);
+        output.assertIsSatisfied();
+    }
+
+    /**
+     * Test reading of input lines from the executable's stdin
+     */
+    @Test
+    public void testExecJavaProcessInputLines() throws Exception {
+        final StringBuilder builder = new StringBuilder();
+        int lines = 10;
+        for (int t = 1; t < lines; t++) {
+            builder.append("Line" + t + LINE_SEPARATOR);
+        }
+        String whiteSpaceSeparatedLines = builder.toString();
+        String expected = builder.toString();
+
+        Exchange e = sendExchange(READ_INPUT_LINES_AND_PRINT_THEM, 20000, whiteSpaceSeparatedLines, false);
+        ExecResult inBody = e.getIn().getBody(ExecResult.class);
+        assertEquals(expected, IOUtils.toString(inBody.getStdout()));
+    }
+
+    protected Exchange sendExchange(final Object commandArgument, final long timeout) {
+        return sendExchange(commandArgument, timeout, "testBody", false);
+    }
+
+    protected Exchange sendExchange(final Object commandArgument, final long timeout, final String body, final boolean useStderrOnEmptyStdout) {
+        final List<String> args = buildArgs(commandArgument);
+        final String javaAbsolutePath = buildJavaExecutablePath();
+
+        return producerTemplate.send(new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody(body);
+                exchange.getIn().setHeader(EXEC_COMMAND_EXECUTABLE, javaAbsolutePath);
+                exchange.getIn().setHeader(EXEC_COMMAND_TIMEOUT, timeout);
+                exchange.getIn().setHeader(EXEC_COMMAND_ARGS, args);
+                if (useStderrOnEmptyStdout) {
+                    exchange.getIn().setHeader(EXEC_USE_STDERR_ON_EMPTY_STDOUT, true);
+                }
+            }
+        });
+    }
+
+    private List<String> buildArgs(Object commandArgument) {
+        String classpath = System.getProperty("java.class.path");
+        List<String> args = new ArrayList<String>();
+        args.add("-cp");
+        args.add(classpath);
+        args.add(EXECUTABLE_PROGRAM_ARG);
+        args.add(commandArgument.toString());
+        return args;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:input").to("exec:java").to("mock:output");
+            }
+        };
+    }
+
+}

Propchange: camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecOutFileTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecOutFileTest.java?rev=1209585&r1=1209584&r2=1209585&view=diff
==============================================================================
--- camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecOutFileTest.java (original)
+++ camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecOutFileTest.java Fri Dec  2 17:03:07 2011
@@ -1,129 +1,129 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.exec;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.w3c.dom.Document;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.Produce;
-import org.apache.camel.ProducerTemplate;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
-
-import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_OUT_FILE;
-import static org.apache.commons.io.IOUtils.LINE_SEPARATOR;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-@ContextConfiguration(locations = {"exec-mock-executor-context.xml"})
-public class ExecOutFileTest extends AbstractJUnit4SpringContextTests {
-
-    private static final String FILE_CONTENT = buildFileContent();
-
-    private static final File FILE = new File("target/outfiletest.xml");
-
-    @Produce(uri = "direct:input")
-    private ProducerTemplate producerTemplate;
-
-    @Before
-    public void setUp() throws IOException {
-        FILE.createNewFile();
-        FileUtils.writeStringToFile(FILE, FILE_CONTENT);
-    }
-
-    @After
-    public void tearDown() {
-        FileUtils.deleteQuietly(FILE);
-    }
-
-    @Test
-    @DirtiesContext
-    public void testOutFile() throws Exception {
-        Exchange e = sendWithMockedExecutor();
-        ExecResult result = e.getIn().getBody(ExecResult.class);
-        assertNotNull(result);
-        File outFile = result.getCommand().getOutFile();
-        assertNotNull(outFile);
-        assertEquals(FILE_CONTENT, FileUtils.readFileToString(outFile));
-    }
-
-    @Test
-    @DirtiesContext
-    public void testOutFileConvertToInputStream() throws Exception {
-        Exchange e = sendWithMockedExecutor();
-        InputStream body = e.getIn().getBody(InputStream.class);
-        assertNotNull(body);
-        assertEquals(FILE_CONTENT, IOUtils.toString(body));
-    }
-
-    @Test
-    @DirtiesContext
-    public void testOutFileConvertToDocument() throws Exception {
-        Exchange e = sendWithMockedExecutor();
-        Document body = e.getIn().getBody(Document.class);
-        assertNotNull(body); // do not parse it
-    }
-
-    @Test
-    @DirtiesContext
-    public void testOutFileConvertToString() throws Exception {
-        Exchange e = sendWithMockedExecutor();
-        assertEquals(FILE_CONTENT, e.getIn().getBody(String.class));
-    }
-
-    @Test
-    @DirtiesContext
-    public void testOutFileConvertToByteArray() throws Exception {
-        Exchange e = sendWithMockedExecutor();
-        byte[] body = e.getIn().getBody(byte[].class);
-        assertEquals(FILE_CONTENT, new String(body));
-    }
-
-    private Exchange sendWithMockedExecutor() {
-        Exchange e = producerTemplate.send(new Processor() {
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setHeader(EXEC_COMMAND_OUT_FILE, FILE.getPath());
-                exchange.getIn().setBody(FILE_CONTENT);
-            }
-        });
-        return e;
-    }
-
-    private static String buildFileContent() {
-        StringBuilder builder = new StringBuilder();
-        builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append(LINE_SEPARATOR);
-        builder.append("<data>").append(LINE_SEPARATOR);
-        builder.append("<element>data1</element>").append(LINE_SEPARATOR);
-        builder.append("<element>data2</element>").append(LINE_SEPARATOR);
-        builder.append("</data>").append(LINE_SEPARATOR);
-        builder.append(LINE_SEPARATOR);
-        return builder.toString();
-    }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.exec;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.w3c.dom.Document;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_OUT_FILE;
+import static org.apache.commons.io.IOUtils.LINE_SEPARATOR;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@ContextConfiguration(locations = {"exec-mock-executor-context.xml"})
+public class ExecOutFileTest extends AbstractJUnit4SpringContextTests {
+
+    private static final String FILE_CONTENT = buildFileContent();
+
+    private static final File FILE = new File("target/outfiletest.xml");
+
+    @Produce(uri = "direct:input")
+    private ProducerTemplate producerTemplate;
+
+    @Before
+    public void setUp() throws IOException {
+        FILE.createNewFile();
+        FileUtils.writeStringToFile(FILE, FILE_CONTENT);
+    }
+
+    @After
+    public void tearDown() {
+        FileUtils.deleteQuietly(FILE);
+    }
+
+    @Test
+    @DirtiesContext
+    public void testOutFile() throws Exception {
+        Exchange e = sendWithMockedExecutor();
+        ExecResult result = e.getIn().getBody(ExecResult.class);
+        assertNotNull(result);
+        File outFile = result.getCommand().getOutFile();
+        assertNotNull(outFile);
+        assertEquals(FILE_CONTENT, FileUtils.readFileToString(outFile));
+    }
+
+    @Test
+    @DirtiesContext
+    public void testOutFileConvertToInputStream() throws Exception {
+        Exchange e = sendWithMockedExecutor();
+        InputStream body = e.getIn().getBody(InputStream.class);
+        assertNotNull(body);
+        assertEquals(FILE_CONTENT, IOUtils.toString(body));
+    }
+
+    @Test
+    @DirtiesContext
+    public void testOutFileConvertToDocument() throws Exception {
+        Exchange e = sendWithMockedExecutor();
+        Document body = e.getIn().getBody(Document.class);
+        assertNotNull(body); // do not parse it
+    }
+
+    @Test
+    @DirtiesContext
+    public void testOutFileConvertToString() throws Exception {
+        Exchange e = sendWithMockedExecutor();
+        assertEquals(FILE_CONTENT, e.getIn().getBody(String.class));
+    }
+
+    @Test
+    @DirtiesContext
+    public void testOutFileConvertToByteArray() throws Exception {
+        Exchange e = sendWithMockedExecutor();
+        byte[] body = e.getIn().getBody(byte[].class);
+        assertEquals(FILE_CONTENT, new String(body));
+    }
+
+    private Exchange sendWithMockedExecutor() {
+        Exchange e = producerTemplate.send(new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(EXEC_COMMAND_OUT_FILE, FILE.getPath());
+                exchange.getIn().setBody(FILE_CONTENT);
+            }
+        });
+        return e;
+    }
+
+    private static String buildFileContent() {
+        StringBuilder builder = new StringBuilder();
+        builder.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append(LINE_SEPARATOR);
+        builder.append("<data>").append(LINE_SEPARATOR);
+        builder.append("<element>data1</element>").append(LINE_SEPARATOR);
+        builder.append("<element>data2</element>").append(LINE_SEPARATOR);
+        builder.append("</data>").append(LINE_SEPARATOR);
+        builder.append(LINE_SEPARATOR);
+        return builder.toString();
+    }
+}

Propchange: camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecOutFileTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecProducerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecProducerTest.java?rev=1209585&r1=1209584&r2=1209585&view=diff
==============================================================================
--- camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecProducerTest.java (original)
+++ camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecProducerTest.java Fri Dec  2 17:03:07 2011
@@ -1,202 +1,202 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.exec;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.ExchangePattern;
-import org.apache.camel.Processor;
-import org.apache.camel.Produce;
-import org.apache.camel.ProducerTemplate;
-import org.apache.camel.component.exec.impl.ExecCommandExecutorMock;
-import org.apache.commons.io.IOUtils;
-
-import org.junit.Test;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
-
-import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_ARGS;
-import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_EXECUTABLE;
-import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_TIMEOUT;
-import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_WORKING_DIR;
-import static org.apache.commons.io.IOUtils.LINE_SEPARATOR;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-/**
- * Test the functionality of {@link ExecProducer}
- */
-@ContextConfiguration(locations = {"exec-mock-executor-context.xml"})
-public class ExecProducerTest extends AbstractJUnit4SpringContextTests {
-
-    @Produce(uri = "direct:input")
-    private ProducerTemplate producerTemplate;
-
-    @Autowired
-    private ExecCommandExecutorMock execCommandExecutorMock;
-
-    @Test
-    @DirtiesContext
-    public void testWithContextConfiguration() {
-        producerTemplate.sendBody("direct:input", "test");
-        // the expected string is defined in the route configuration
-        assertEquals("mockedByCommandExecutorMock.exe", execCommandExecutorMock.lastCommandResult.getCommand().getExecutable());
-    }
-
-    @Test
-    @DirtiesContext
-    public void testOverrideExecutable() {
-        final String command = "java";
-
-        producerTemplate.send(new Processor() {
-
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setBody("noinput");
-                exchange.getIn().setHeader(EXEC_COMMAND_EXECUTABLE, command);
-            }
-        });
-
-        assertEquals(command, execCommandExecutorMock.lastCommandResult.getCommand().getExecutable());
-    }
-
-    /**
-     * Tests that the args are set literally.
-     */
-    @Test
-    @DirtiesContext
-    public void testOverrideArgs() {
-        final String[] args = {"-version", "classpath:c:/program files/test/"};
-        producerTemplate.send(new Processor() {
-
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setBody("noinput");
-                exchange.getIn().setHeader(EXEC_COMMAND_ARGS, Arrays.asList(args));
-            }
-        });
-        List<String> commandArgs = execCommandExecutorMock.lastCommandResult.getCommand().getArgs();
-
-        assertEquals(args[0], commandArgs.get(0));
-        assertEquals(args[1], commandArgs.get(1));
-    }
-
-    @Test
-    @DirtiesContext
-    public void testOverrideTimeout() {
-        producerTemplate.send(new Processor() {
-
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setBody("noinput");
-                exchange.getIn().setHeader(EXEC_COMMAND_TIMEOUT, "1000");
-            }
-        });
-        assertEquals(1000, execCommandExecutorMock.lastCommandResult.getCommand().getTimeout());
-    }
-
-    @Test
-    @DirtiesContext
-    public void testInputLines() throws IOException {
-        // String must be convertible to InputStream
-        final String input = "line1" + LINE_SEPARATOR + "line2";
-        producerTemplate.send(new Processor() {
-
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setBody(input);
-            }
-        });
-        assertEquals(input, IOUtils.toString(execCommandExecutorMock.lastCommandResult.getCommand().getInput()));
-    }
-
-    @Test
-    @DirtiesContext
-    public void testInputLinesNotConvertibleToInputStream() throws IOException {
-        // String must be convertible to InputStream
-        final Integer notConvertibleToInputStreamBody = new Integer(1);
-        Exchange e = producerTemplate.send(new Processor() {
-
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setBody(notConvertibleToInputStreamBody);
-            }
-        });
-        ExecResult result = e.getIn().getBody(ExecResult.class);
-        assertNotNull(result);
-        assertNull(result.getCommand().getInput());
-    }
-    
-    @Test
-    @DirtiesContext
-    public void testNullInBody() throws IOException {
-        // Null body must also be supported
-        Exchange e = producerTemplate.send(new Processor() {
-
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setBody(null);
-            }
-        });
-        ExecResult result = e.getIn().getBody(ExecResult.class);
-        assertNotNull(result);
-        assertNull(result.getCommand().getInput());
-    }
-
-    @Test
-    @DirtiesContext
-    public void testOverrideWorkingDir() {
-        final String workingDir = "c:/program files/test";
-
-        producerTemplate.send(new Processor() {
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setBody("");
-                exchange.getIn().setHeader(EXEC_COMMAND_WORKING_DIR, workingDir);
-            }
-        });
-        assertEquals(workingDir, execCommandExecutorMock.lastCommandResult.getCommand().getWorkingDir());
-    }
-
-    @Test
-    @DirtiesContext
-    public void testInInOnlyExchange() throws Exception {
-        Exchange exchange = producerTemplate.send(new Processor() {
-            public void process(Exchange exchange) throws Exception {
-                exchange.setPattern(ExchangePattern.InOnly);
-                exchange.getIn().setBody("inonly");
-            }
-        });
-        // test the conversion
-        ExecResult result = exchange.getIn().getBody(ExecResult.class);
-        assertNotNull(result);
-    }
-
-    @Test
-    @DirtiesContext
-    public void testOutCapableExchange() throws Exception {
-        Exchange exchange = producerTemplate.send(new Processor() {
-            public void process(Exchange exchange) throws Exception {
-                exchange.setPattern(ExchangePattern.InOut);
-                exchange.getIn().setBody("inout");
-            }
-        });
-        // test the conversion
-        ExecResult result = exchange.getOut().getBody(ExecResult.class);
-        assertNotNull(result);
-    }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.exec;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.exec.impl.ExecCommandExecutorMock;
+import org.apache.commons.io.IOUtils;
+
+import org.junit.Test;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_ARGS;
+import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_EXECUTABLE;
+import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_TIMEOUT;
+import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_WORKING_DIR;
+import static org.apache.commons.io.IOUtils.LINE_SEPARATOR;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+/**
+ * Test the functionality of {@link ExecProducer}
+ */
+@ContextConfiguration(locations = {"exec-mock-executor-context.xml"})
+public class ExecProducerTest extends AbstractJUnit4SpringContextTests {
+
+    @Produce(uri = "direct:input")
+    private ProducerTemplate producerTemplate;
+
+    @Autowired
+    private ExecCommandExecutorMock execCommandExecutorMock;
+
+    @Test
+    @DirtiesContext
+    public void testWithContextConfiguration() {
+        producerTemplate.sendBody("direct:input", "test");
+        // the expected string is defined in the route configuration
+        assertEquals("mockedByCommandExecutorMock.exe", execCommandExecutorMock.lastCommandResult.getCommand().getExecutable());
+    }
+
+    @Test
+    @DirtiesContext
+    public void testOverrideExecutable() {
+        final String command = "java";
+
+        producerTemplate.send(new Processor() {
+
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody("noinput");
+                exchange.getIn().setHeader(EXEC_COMMAND_EXECUTABLE, command);
+            }
+        });
+
+        assertEquals(command, execCommandExecutorMock.lastCommandResult.getCommand().getExecutable());
+    }
+
+    /**
+     * Tests that the args are set literally.
+     */
+    @Test
+    @DirtiesContext
+    public void testOverrideArgs() {
+        final String[] args = {"-version", "classpath:c:/program files/test/"};
+        producerTemplate.send(new Processor() {
+
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody("noinput");
+                exchange.getIn().setHeader(EXEC_COMMAND_ARGS, Arrays.asList(args));
+            }
+        });
+        List<String> commandArgs = execCommandExecutorMock.lastCommandResult.getCommand().getArgs();
+
+        assertEquals(args[0], commandArgs.get(0));
+        assertEquals(args[1], commandArgs.get(1));
+    }
+
+    @Test
+    @DirtiesContext
+    public void testOverrideTimeout() {
+        producerTemplate.send(new Processor() {
+
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody("noinput");
+                exchange.getIn().setHeader(EXEC_COMMAND_TIMEOUT, "1000");
+            }
+        });
+        assertEquals(1000, execCommandExecutorMock.lastCommandResult.getCommand().getTimeout());
+    }
+
+    @Test
+    @DirtiesContext
+    public void testInputLines() throws IOException {
+        // String must be convertible to InputStream
+        final String input = "line1" + LINE_SEPARATOR + "line2";
+        producerTemplate.send(new Processor() {
+
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody(input);
+            }
+        });
+        assertEquals(input, IOUtils.toString(execCommandExecutorMock.lastCommandResult.getCommand().getInput()));
+    }
+
+    @Test
+    @DirtiesContext
+    public void testInputLinesNotConvertibleToInputStream() throws IOException {
+        // String must be convertible to InputStream
+        final Integer notConvertibleToInputStreamBody = new Integer(1);
+        Exchange e = producerTemplate.send(new Processor() {
+
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody(notConvertibleToInputStreamBody);
+            }
+        });
+        ExecResult result = e.getIn().getBody(ExecResult.class);
+        assertNotNull(result);
+        assertNull(result.getCommand().getInput());
+    }
+    
+    @Test
+    @DirtiesContext
+    public void testNullInBody() throws IOException {
+        // Null body must also be supported
+        Exchange e = producerTemplate.send(new Processor() {
+
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody(null);
+            }
+        });
+        ExecResult result = e.getIn().getBody(ExecResult.class);
+        assertNotNull(result);
+        assertNull(result.getCommand().getInput());
+    }
+
+    @Test
+    @DirtiesContext
+    public void testOverrideWorkingDir() {
+        final String workingDir = "c:/program files/test";
+
+        producerTemplate.send(new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody("");
+                exchange.getIn().setHeader(EXEC_COMMAND_WORKING_DIR, workingDir);
+            }
+        });
+        assertEquals(workingDir, execCommandExecutorMock.lastCommandResult.getCommand().getWorkingDir());
+    }
+
+    @Test
+    @DirtiesContext
+    public void testInInOnlyExchange() throws Exception {
+        Exchange exchange = producerTemplate.send(new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.setPattern(ExchangePattern.InOnly);
+                exchange.getIn().setBody("inonly");
+            }
+        });
+        // test the conversion
+        ExecResult result = exchange.getIn().getBody(ExecResult.class);
+        assertNotNull(result);
+    }
+
+    @Test
+    @DirtiesContext
+    public void testOutCapableExchange() throws Exception {
+        Exchange exchange = producerTemplate.send(new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.setPattern(ExchangePattern.InOut);
+                exchange.getIn().setBody("inout");
+            }
+        });
+        // test the conversion
+        ExecResult result = exchange.getOut().getBody(ExecResult.class);
+        assertNotNull(result);
+    }
+}

Propchange: camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecProducerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecScriptTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecScriptTest.java?rev=1209585&r1=1209584&r2=1209585&view=diff
==============================================================================
--- camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecScriptTest.java (original)
+++ camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecScriptTest.java Fri Dec  2 17:03:07 2011
@@ -1,131 +1,131 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.exec;
-
-import java.io.File;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.Produce;
-import org.apache.camel.ProducerTemplate;
-import org.apache.commons.exec.OS;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
-
-import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_ARGS;
-import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_EXECUTABLE;
-import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_TIMEOUT;
-import static org.apache.camel.component.exec.ExecBinding.EXEC_STDERR;
-import static org.apache.camel.component.exec.ExecEndpoint.NO_TIMEOUT;
-import static org.apache.camel.component.exec.ExecTestUtils.getClasspathResourceFileOrNull;
-import static org.apache.camel.component.exec.ExecutableJavaProgram.PRINT_IN_STDOUT;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Test executing a OS script. Use only manually, see the TODO
- */
-@ContextConfiguration
-public class ExecScriptTest extends AbstractJUnit4SpringContextTests {
-
-    @Produce(uri = "direct:input")
-    private ProducerTemplate producerTemplate;
-
-    /**
-     * TODO <b>the test is ignored for now to prevent accidental build
-     * failures.</b> Java 1.5 does not offer a method to check if a file is
-     * executable there is only a canRead method, which is not enough to
-     * guarantee that the script can be executed. <br>
-     * 
-     * @throws Exception
-     */
-    @Test
-    @DirtiesContext
-    @Ignore
-    public void testExecuteScript() throws Exception {
-        File scriptFile = getExecScriptFileOrNull("exec-test-script");
-        if (scriptFile != null) {
-            String classpathArg = getClasspathArg();
-            Exchange exchange = executeScript(scriptFile, NO_TIMEOUT, classpathArg, PRINT_IN_STDOUT);
-            if (exchange != null) {
-                String out = (String)exchange.getIn().getBody(String.class);
-                String err = (String)exchange.getIn().getHeader(EXEC_STDERR);
-
-                assertNotNull(out);
-                assertTrue(out.contains(PRINT_IN_STDOUT));
-                assertNull(err);
-            }
-        } else {
-            String os = System.getProperty("os.name");
-            logger.warn("Executing batch scripts is not tested on " + os);
-        }
-    }
-
-    private Exchange executeScript(final File scriptFile, long timeout, String... args) {
-        StringBuilder argsBuilder = new StringBuilder();
-        for (String arg : args) {
-            argsBuilder.append(arg + " ");
-        }
-        final String whiteSpaceSeparatedArgs = argsBuilder.toString().trim();
-
-        return producerTemplate.send(new Processor() {
-            public void process(Exchange exchange) throws Exception {
-                exchange.getIn().setBody(PRINT_IN_STDOUT);
-                exchange.getIn().setHeader(EXEC_COMMAND_TIMEOUT, NO_TIMEOUT);
-                exchange.getIn().setHeader(EXEC_COMMAND_EXECUTABLE, scriptFile.getAbsolutePath());
-                exchange.getIn().setHeader(EXEC_COMMAND_ARGS, whiteSpaceSeparatedArgs);
-            }
-        });
-    }
-
-    private String getClasspathArg() {
-        String classpath = System.getProperty("java.class.path");
-        if (OS.isFamilyWindows()) {
-            // On windows the ";" character is replaced by a space by the
-            // command interpreter. Thus the classpath is split with the
-            // ;-token. Therefore the classpath should be quoted with double
-            // quotes
-            classpath = "\"\"" + classpath + "\"\"";
-        } else {
-            // quote only once
-            classpath = "\"" + classpath + "\"";
-        }
-        return classpath;
-
-    }
-
-    private File getExecScriptFileOrNull(String scriptNameBase) {
-        String resource = null;
-        if (OS.isFamilyWindows()) {
-            resource = scriptNameBase + ".bat";
-        } else if (OS.isFamilyUnix()) {
-            resource = scriptNameBase + ".sh";
-        }
-        File resourceFile = getClasspathResourceFileOrNull(resource);
-        // TODO use canExecute here (available since java 1.6)
-        if (resourceFile != null && !resourceFile.canRead()) {
-            logger.warn("The resource  " + resourceFile.getAbsolutePath() + " is not readable!");
-            // it is not readable, do not try to execute it
-            return null;
-        }
-        return resourceFile;
-    }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.exec;
+
+import java.io.File;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.commons.exec.OS;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_ARGS;
+import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_EXECUTABLE;
+import static org.apache.camel.component.exec.ExecBinding.EXEC_COMMAND_TIMEOUT;
+import static org.apache.camel.component.exec.ExecBinding.EXEC_STDERR;
+import static org.apache.camel.component.exec.ExecEndpoint.NO_TIMEOUT;
+import static org.apache.camel.component.exec.ExecTestUtils.getClasspathResourceFileOrNull;
+import static org.apache.camel.component.exec.ExecutableJavaProgram.PRINT_IN_STDOUT;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Test executing a OS script. Use only manually, see the TODO
+ */
+@ContextConfiguration
+public class ExecScriptTest extends AbstractJUnit4SpringContextTests {
+
+    @Produce(uri = "direct:input")
+    private ProducerTemplate producerTemplate;
+
+    /**
+     * TODO <b>the test is ignored for now to prevent accidental build
+     * failures.</b> Java 1.5 does not offer a method to check if a file is
+     * executable there is only a canRead method, which is not enough to
+     * guarantee that the script can be executed. <br>
+     * 
+     * @throws Exception
+     */
+    @Test
+    @DirtiesContext
+    @Ignore
+    public void testExecuteScript() throws Exception {
+        File scriptFile = getExecScriptFileOrNull("exec-test-script");
+        if (scriptFile != null) {
+            String classpathArg = getClasspathArg();
+            Exchange exchange = executeScript(scriptFile, NO_TIMEOUT, classpathArg, PRINT_IN_STDOUT);
+            if (exchange != null) {
+                String out = (String)exchange.getIn().getBody(String.class);
+                String err = (String)exchange.getIn().getHeader(EXEC_STDERR);
+
+                assertNotNull(out);
+                assertTrue(out.contains(PRINT_IN_STDOUT));
+                assertNull(err);
+            }
+        } else {
+            String os = System.getProperty("os.name");
+            logger.warn("Executing batch scripts is not tested on " + os);
+        }
+    }
+
+    private Exchange executeScript(final File scriptFile, long timeout, String... args) {
+        StringBuilder argsBuilder = new StringBuilder();
+        for (String arg : args) {
+            argsBuilder.append(arg + " ");
+        }
+        final String whiteSpaceSeparatedArgs = argsBuilder.toString().trim();
+
+        return producerTemplate.send(new Processor() {
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setBody(PRINT_IN_STDOUT);
+                exchange.getIn().setHeader(EXEC_COMMAND_TIMEOUT, NO_TIMEOUT);
+                exchange.getIn().setHeader(EXEC_COMMAND_EXECUTABLE, scriptFile.getAbsolutePath());
+                exchange.getIn().setHeader(EXEC_COMMAND_ARGS, whiteSpaceSeparatedArgs);
+            }
+        });
+    }
+
+    private String getClasspathArg() {
+        String classpath = System.getProperty("java.class.path");
+        if (OS.isFamilyWindows()) {
+            // On windows the ";" character is replaced by a space by the
+            // command interpreter. Thus the classpath is split with the
+            // ;-token. Therefore the classpath should be quoted with double
+            // quotes
+            classpath = "\"\"" + classpath + "\"\"";
+        } else {
+            // quote only once
+            classpath = "\"" + classpath + "\"";
+        }
+        return classpath;
+
+    }
+
+    private File getExecScriptFileOrNull(String scriptNameBase) {
+        String resource = null;
+        if (OS.isFamilyWindows()) {
+            resource = scriptNameBase + ".bat";
+        } else if (OS.isFamilyUnix()) {
+            resource = scriptNameBase + ".sh";
+        }
+        File resourceFile = getClasspathResourceFileOrNull(resource);
+        // TODO use canExecute here (available since java 1.6)
+        if (resourceFile != null && !resourceFile.canRead()) {
+            logger.warn("The resource  " + resourceFile.getAbsolutePath() + " is not readable!");
+            // it is not readable, do not try to execute it
+            return null;
+        }
+        return resourceFile;
+    }
+}

Propchange: camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecScriptTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecTestUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=1209585&r1=1209584&r2=1209585&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 Fri Dec  2 17:03:07 2011
@@ -1,130 +1,130 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.exec;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.io.LineIterator;
-
-/**
- * A test Java main class to be executed. The behavior of the program is
- * controlled by the arguments that the {@link #main(String[])} receives. Valid
- * arguments are the public static fields of the class.
- */
-public class ExecutableJavaProgram {
-    /**
-     * Start 2 threads that print text in the stdout and stderr, each printing
-     * {@link #LINES_TO_PRINT_FROM_EACH_THREAD} lines.
-     */
-    public static final String THREADS = "threads";
-
-    public static final String SLEEP_WITH_TIMEOUT = "timeout";
-
-    public static final int SLEEP_TIME = 60 * 1000;
-
-    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";
-
-    public static final int EXIT_WITH_VALUE_0 = 0;
-
-    public static final int EXIT_WITH_VALUE_1 = 1;
-
-    public static final int LINES_TO_PRINT_FROM_EACH_THREAD = 50;
-
-    protected ExecutableJavaProgram() {
-
-    }
-
-    public static void main(String[] args) throws Exception {
-        if (args == null || args.length == 0) {
-            throw new IllegalArgumentException("Empty args are not allowed.");
-        }
-
-        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 (int i = 0; i < args.length; i++) {
-                String arg = args[i];
-                System.out.println(i + arg);
-            }
-            System.exit(0);
-        } else if (args[0].equals(PRINT_IN_STDERR)) {
-            System.err.print(PRINT_IN_STDERR);
-            System.exit(1);
-        } else if (args[0].equals(String.valueOf(EXIT_WITH_VALUE_0))) {
-            System.exit(0);
-        } else if (args[0].equals(String.valueOf(EXIT_WITH_VALUE_1))) {
-            System.exit(1);
-        } else if (args[0].equals(THREADS)) {
-            Thread stderrPrinterThread = new Thread(new ErrPrinter());
-            Thread stdoutPrinterThread = new Thread(new OutPrinter());
-
-            stderrPrinterThread.start();
-            stdoutPrinterThread.start();
-            stderrPrinterThread.join();
-            stdoutPrinterThread.join();
-
-        } else if (args[0].equals(SLEEP_WITH_TIMEOUT)) {
-            doSleep();
-            System.exit(0);
-        } else if (READ_INPUT_LINES_AND_PRINT_THEM.equals(args[0])) {
-            LineIterator iterator = IOUtils.lineIterator(System.in, "UTF-8");
-            while (iterator.hasNext()) {
-                String line = iterator.nextLine();
-                System.out.println(line);
-
-            }
-        } else {
-            System.out.println(args[0]);
-        }
-
-    }
-
-    private static void doSleep() throws InterruptedException {
-        int sleepInterval = 50;
-        // Note, that sleeping in the main thread prevents the process from
-        // being destroyed for that time. The process is killed namely when
-        // sleep returns(observed on Windows XP)
-        int t = 0;
-        System.out.println("Sleeping every " + String.valueOf(sleepInterval) + " ms");
-        for (; t < SLEEP_TIME % sleepInterval; t += sleepInterval) {
-            Thread.sleep(sleepInterval);
-        }
-
-    }
-
-    private static class ErrPrinter implements Runnable {
-        public void run() {
-            for (int t = 0; t < LINES_TO_PRINT_FROM_EACH_THREAD; t++) {
-                System.err.println(PRINT_IN_STDERR);
-            }
-        }
-    }
-
-    private static class OutPrinter implements Runnable {
-        public void run() {
-            for (int t = 0; t < LINES_TO_PRINT_FROM_EACH_THREAD; t++) {
-                System.out.println(PRINT_IN_STDOUT);
-            }
-        }
-    }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.exec;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.LineIterator;
+
+/**
+ * A test Java main class to be executed. The behavior of the program is
+ * controlled by the arguments that the {@link #main(String[])} receives. Valid
+ * arguments are the public static fields of the class.
+ */
+public class ExecutableJavaProgram {
+    /**
+     * Start 2 threads that print text in the stdout and stderr, each printing
+     * {@link #LINES_TO_PRINT_FROM_EACH_THREAD} lines.
+     */
+    public static final String THREADS = "threads";
+
+    public static final String SLEEP_WITH_TIMEOUT = "timeout";
+
+    public static final int SLEEP_TIME = 60 * 1000;
+
+    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";
+
+    public static final int EXIT_WITH_VALUE_0 = 0;
+
+    public static final int EXIT_WITH_VALUE_1 = 1;
+
+    public static final int LINES_TO_PRINT_FROM_EACH_THREAD = 50;
+
+    protected ExecutableJavaProgram() {
+
+    }
+
+    public static void main(String[] args) throws Exception {
+        if (args == null || args.length == 0) {
+            throw new IllegalArgumentException("Empty args are not allowed.");
+        }
+
+        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 (int i = 0; i < args.length; i++) {
+                String arg = args[i];
+                System.out.println(i + arg);
+            }
+            System.exit(0);
+        } else if (args[0].equals(PRINT_IN_STDERR)) {
+            System.err.print(PRINT_IN_STDERR);
+            System.exit(1);
+        } else if (args[0].equals(String.valueOf(EXIT_WITH_VALUE_0))) {
+            System.exit(0);
+        } else if (args[0].equals(String.valueOf(EXIT_WITH_VALUE_1))) {
+            System.exit(1);
+        } else if (args[0].equals(THREADS)) {
+            Thread stderrPrinterThread = new Thread(new ErrPrinter());
+            Thread stdoutPrinterThread = new Thread(new OutPrinter());
+
+            stderrPrinterThread.start();
+            stdoutPrinterThread.start();
+            stderrPrinterThread.join();
+            stdoutPrinterThread.join();
+
+        } else if (args[0].equals(SLEEP_WITH_TIMEOUT)) {
+            doSleep();
+            System.exit(0);
+        } else if (READ_INPUT_LINES_AND_PRINT_THEM.equals(args[0])) {
+            LineIterator iterator = IOUtils.lineIterator(System.in, "UTF-8");
+            while (iterator.hasNext()) {
+                String line = iterator.nextLine();
+                System.out.println(line);
+
+            }
+        } else {
+            System.out.println(args[0]);
+        }
+
+    }
+
+    private static void doSleep() throws InterruptedException {
+        int sleepInterval = 50;
+        // Note, that sleeping in the main thread prevents the process from
+        // being destroyed for that time. The process is killed namely when
+        // sleep returns(observed on Windows XP)
+        int t = 0;
+        System.out.println("Sleeping every " + String.valueOf(sleepInterval) + " ms");
+        for (; t < SLEEP_TIME % sleepInterval; t += sleepInterval) {
+            Thread.sleep(sleepInterval);
+        }
+
+    }
+
+    private static class ErrPrinter implements Runnable {
+        public void run() {
+            for (int t = 0; t < LINES_TO_PRINT_FROM_EACH_THREAD; t++) {
+                System.err.println(PRINT_IN_STDERR);
+            }
+        }
+    }
+
+    private static class OutPrinter implements Runnable {
+        public void run() {
+            for (int t = 0; t < LINES_TO_PRINT_FROM_EACH_THREAD; t++) {
+                System.out.println(PRINT_IN_STDOUT);
+            }
+        }
+    }
+}

Propchange: camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecutableJavaProgram.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecCommandExecutorMock.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecCommandExecutorMock.java?rev=1209585&r1=1209584&r2=1209585&view=diff
==============================================================================
--- camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecCommandExecutorMock.java (original)
+++ camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecCommandExecutorMock.java Fri Dec  2 17:03:07 2011
@@ -1,39 +1,39 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.exec.impl;
-
-import java.io.ByteArrayInputStream;
-
-import org.apache.camel.component.exec.ExecCommand;
-import org.apache.camel.component.exec.ExecCommandExecutor;
-import org.apache.camel.component.exec.ExecResult;
-
-/**
- * Simple mock of {@link ExecCommandExecutor}
- */
-public class ExecCommandExecutorMock implements ExecCommandExecutor {
-
-    public static final String STD_OUT_VALUE = "stdout";
-
-    public ExecResult lastCommandResult;
-
-    public ExecResult execute(ExecCommand command) {
-
-        lastCommandResult = new ExecResult(command, new ByteArrayInputStream(STD_OUT_VALUE.getBytes()), null, 0);
-        return lastCommandResult;
-    }
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.exec.impl;
+
+import java.io.ByteArrayInputStream;
+
+import org.apache.camel.component.exec.ExecCommand;
+import org.apache.camel.component.exec.ExecCommandExecutor;
+import org.apache.camel.component.exec.ExecResult;
+
+/**
+ * Simple mock of {@link ExecCommandExecutor}
+ */
+public class ExecCommandExecutorMock implements ExecCommandExecutor {
+
+    public static final String STD_OUT_VALUE = "stdout";
+
+    public ExecResult lastCommandResult;
+
+    public ExecResult execute(ExecCommand command) {
+
+        lastCommandResult = new ExecResult(command, new ByteArrayInputStream(STD_OUT_VALUE.getBytes()), null, 0);
+        return lastCommandResult;
+    }
+}

Propchange: camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecCommandExecutorMock.java
------------------------------------------------------------------------------
    svn:eol-style = native