camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krass...@apache.org
Subject svn commit: r929929 [2/2] - in /camel/trunk/components/camel-exec: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/camel/ src/main/java/org/apache/camel/component/ src/main/java/org/apache/camel/co...
Date Thu, 01 Apr 2010 11:20:53 GMT
Added: 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=929929&view=auto
==============================================================================
--- camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java (added)
+++ camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java Thu Apr  1 11:20:51 2010
@@ -0,0 +1,236 @@
+/**
+ * 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 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.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_EXIT_VALUE;
+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.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_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 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 testResultConverterString() throws Exception {
+        String commandArgument = PRINT_IN_STDERR;
+        output.setExpectedMessageCount(1);
+        output.expectedHeaderReceived(EXEC_STDERR, commandArgument);
+        output.expectedHeaderReceived(EXEC_EXIT_VALUE, 1);
+
+        sendExchange(commandArgument, NO_TIMEOUT);
+        output.assertIsSatisfied();
+    }
+
+    /**
+     * Test print in stdout from threads.
+     * 
+     * @see ExecutableJavaProgram#THREADS
+     * @throws Exception
+     */
+    @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 if the process will be terminate in about a second
+     * 
+     * @see ExecutableJavaProgram#SLEEP_WITH_TIMEOUT
+     * @throws Exception
+     */
+    @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
+     * 
+     * @see ExecutableJavaProgram#READ_INPUT_LINES_AND_PRINT_THEM
+     * @throws Exception
+     */
+    @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);
+        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");
+    }
+
+    protected Exchange sendExchange(final Object commandArgument, final long timeout, final String body) {
+        final String classpath = "\"" + System.getProperty("java.class.path") + "\"";
+        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, "-cp" + classpath + " " + EXECUTABLE_PROGRAM_ARG + " " + commandArgument.toString());
+            }
+        });
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("direct:input").to("exec:java").to("mock:output");
+            }
+        };
+    }
+
+}

Added: 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=929929&view=auto
==============================================================================
--- camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecOutFileTest.java (added)
+++ camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecOutFileTest.java Thu Apr  1 11:20:51 2010
@@ -0,0 +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();
+    }
+}

Added: 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=929929&view=auto
==============================================================================
--- camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecProducerTest.java (added)
+++ camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecProducerTest.java Thu Apr  1 11:20:51 2010
@@ -0,0 +1,184 @@
+/**
+ * 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.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());
+    }
+
+    @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, args[0] + " " + args[1]);
+            }
+        });
+        List<String> commandArgs = execCommandExecutorMock.lastCommandResult.getCommand().getArgs();
+
+        assertEquals(args[0], commandArgs.get(0));
+        String secondArgEscaped = args[1].substring(1, args[1].length() - 1);
+        assertEquals(secondArgEscaped, 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 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);
+    }
+}

Added: 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=929929&view=auto
==============================================================================
--- camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecScriptTest.java (added)
+++ camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecScriptTest.java Thu Apr  1 11:20:51 2010
@@ -0,0 +1,132 @@
+/**
+ * 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.ExecBinding.EXEC_STDOUT;
+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().getHeader(EXEC_STDOUT);
+                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;
+    }
+}

Added: 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=929929&view=auto
==============================================================================
--- camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecTestUtils.java (added)
+++ camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecTestUtils.java Thu Apr  1 11:20:51 2010
@@ -0,0 +1,69 @@
+/**
+ * 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 org.apache.commons.exec.OS;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.Resource;
+
+public final class ExecTestUtils {
+
+    private static final Log LOG = LogFactory.getLog(ExecTestUtils.class);
+
+    private ExecTestUtils() {
+    }
+
+    /**
+     * Where on the file system is located the <code>classpathResource</code>?
+     * 
+     * @param classpathResource a resource in the classpath
+     * @return null if the resource does not exist in the classpath. If the file
+     *         is not null the resource is guaranteed to exist on the file
+     *         system
+     */
+    public static File getClasspathResourceFileOrNull(String classpathResource) {
+        if (classpathResource == null) {
+            return null;
+        }
+        try {
+            Resource resource = new ClassPathResource(classpathResource);
+            File resourceFile = resource.getFile();
+            return resourceFile;
+        } catch (IOException ioe) {
+            LOG.warn("The resource  " + classpathResource + " does not exist!", ioe);
+            return null;
+        }
+    }
+
+    /**
+     * @return the java executable in a system independent way.
+     */
+    public static String buildJavaExecutablePath() {
+        String javaHome = (String)System.getenv("JAVA_HOME");
+        if (javaHome == null) {
+            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");
+        return java.getAbsolutePath();
+    }
+
+}

Added: 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=929929&view=auto
==============================================================================
--- camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecutableJavaProgram.java (added)
+++ camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecutableJavaProgram.java Thu Apr  1 11:20:51 2010
@@ -0,0 +1,122 @@
+/**
+ * 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_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_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);
+            }
+        }
+    }
+}

Added: 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=929929&view=auto
==============================================================================
--- camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecCommandExecutorMock.java (added)
+++ camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecCommandExecutorMock.java Thu Apr  1 11:20:51 2010
@@ -0,0 +1,41 @@
+/**
+ * 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);
+        lastCommandResult.setStdout(new ByteArrayInputStream(STD_OUT_VALUE.getBytes()));
+        lastCommandResult.setExitValue(0);
+        return lastCommandResult;
+    }
+}

Added: camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecParseUtilsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecParseUtilsTest.java?rev=929929&view=auto
==============================================================================
--- camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecParseUtilsTest.java (added)
+++ camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecParseUtilsTest.java Thu Apr  1 11:20:51 2010
@@ -0,0 +1,138 @@
+/**
+ * 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.util.List;
+
+import org.junit.Test;
+
+import static org.apache.camel.component.exec.impl.ExecParseUtils.isDoubleQuoted;
+import static org.apache.camel.component.exec.impl.ExecParseUtils.isSingleQuoted;
+import static org.apache.camel.component.exec.impl.ExecParseUtils.splitToWhiteSpaceSeparatedTokens;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests for {@link ExecParseUtils}
+ */
+public class ExecParseUtilsTest {
+
+    @Test
+    public void testSingleQuoted() {
+        assertTrue(isSingleQuoted("\"c:\\program files\\test\""));
+    }
+
+    @Test
+    public void testSingleQuoted2() {
+        assertTrue(isSingleQuoted("\"with space\""));
+    }
+
+    @Test
+    public void testSingleQuotedNegative() {
+        assertFalse(isSingleQuoted("arg 0"));
+    }
+
+    @Test
+    public void testSingleQuotedNegative2() {
+        assertFalse(isSingleQuoted("\" \" space not allowed between quotes \""));
+    }
+
+    @Test
+    public void testSingleQuotedNegative3() {
+        assertFalse(isSingleQuoted("\"\"double quoted is not single quoted\"\""));
+    }
+
+    @Test
+    public void testEmptySingleQuotedNegative() {
+        assertFalse(isSingleQuoted("\"\""));
+    }
+
+    @Test
+    public void testEmptySingleQuotedNegative2() {
+        assertFalse(isSingleQuoted("\""));
+    }
+
+    @Test
+    public void testDoubleQuoted() {
+        assertTrue(isDoubleQuoted("\"\"c:\\program files\\test\\\"\""));
+    }
+
+    @Test
+    public void testEmptyDoubleQuotedNegative() {
+        assertFalse(isDoubleQuoted("\"\"\"\""));
+    }
+
+    @Test
+    public void testWhiteSpaceSeparatedArgs() {
+        List<String> args = splitToWhiteSpaceSeparatedTokens("arg0 arg1 arg2");
+        assertEquals("arg0", args.get(0));
+        assertEquals("arg1", args.get(1));
+        assertEquals("arg2", args.get(2));
+    }
+
+    @Test
+    public void testWhiteSpaceQuoted() {
+        List<String> args = splitToWhiteSpaceSeparatedTokens("\"arg 0\"");
+        assertEquals("arg 0", args.get(0));
+    }
+
+    @Test
+    public void testTwoQuotings() {
+        List<String> args = splitToWhiteSpaceSeparatedTokens("\"arg 0\" \"arg 1\"");
+        assertEquals("arg 0", args.get(0));
+        assertEquals("arg 1", args.get(1));
+    }
+
+    @Test
+    public void testWhitespaceSeparatedArgsWithSpaces() {
+        List<String> args = splitToWhiteSpaceSeparatedTokens("\"arg 0 \"   arg1 \"arg 2\"");
+        assertEquals("arg 0 ", args.get(0));
+        assertEquals("arg1", args.get(1));
+        assertEquals("arg 2", args.get(2));
+    }
+
+    @Test
+    public void testDoubleQuote() {
+        List<String> args = splitToWhiteSpaceSeparatedTokens("\"\"arg0\"\"");
+        assertEquals("\"arg0\"", args.get(0));
+    }
+
+    @Test
+    public void testDoubleQuoteAndSpace() {
+        List<String> args = splitToWhiteSpaceSeparatedTokens("\"\"arg0\"\" arg1");
+        assertEquals("\"arg0\"", args.get(0));
+        assertEquals("arg1", args.get(1));
+    }
+
+    @Test
+    public void testTwoDoubleQuotes() {
+        List<String> args = splitToWhiteSpaceSeparatedTokens("\"\"arg0\"\" \"\"arg1\"\"");
+        assertEquals("\"arg0\"", args.get(0));
+        assertEquals("\"arg1\"", args.get(1));
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testWhiteSpaceSeparatedArgsNotClosed() {
+        splitToWhiteSpaceSeparatedTokens("arg 0 \" arg1 \"arg 2\"");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testInvalidQuotes() {
+        splitToWhiteSpaceSeparatedTokens("\"\"arg 0 \" arg1 \"arg 2\"");
+    }
+}

Added: camel/trunk/components/camel-exec/src/test/resources/exec-test-script.bat
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-exec/src/test/resources/exec-test-script.bat?rev=929929&view=auto
==============================================================================
--- camel/trunk/components/camel-exec/src/test/resources/exec-test-script.bat (added)
+++ camel/trunk/components/camel-exec/src/test/resources/exec-test-script.bat Thu Apr  1 11:20:51 2010
@@ -0,0 +1,2 @@
+echo %JAVA_HOME%
+%JAVA_HOME%\bin\java.exe -cp %1 org.apache.camel.component.exec.ExecutableJavaProgram %2

Added: camel/trunk/components/camel-exec/src/test/resources/exec-test-script.sh
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-exec/src/test/resources/exec-test-script.sh?rev=929929&view=auto
==============================================================================
--- camel/trunk/components/camel-exec/src/test/resources/exec-test-script.sh (added)
+++ camel/trunk/components/camel-exec/src/test/resources/exec-test-script.sh Thu Apr  1 11:20:51 2010
@@ -0,0 +1,4 @@
+echo $1
+echo $JAVA_HOME
+
+$JAVA_HOME/bin/java -cp $1 org.apache.camel.component.exec.ExecutableJavaProgram $2

Added: 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=929929&view=auto
==============================================================================
--- camel/trunk/components/camel-exec/src/test/resources/log4j.properties (added)
+++ camel/trunk/components/camel-exec/src/test/resources/log4j.properties Thu Apr  1 11:20:51 2010
@@ -0,0 +1,34 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+#
+#
+# Write console logs only
+#
+log4j.rootLogger=INFO, out
+
+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
+
+# File appender
+log4j.appender.out=org.apache.log4j.FileAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.out.file=target/camel-exec-test.log
+log4j.appender.out.append=true
+

Added: camel/trunk/components/camel-exec/src/test/resources/org/apache/camel/component/exec/ExecEndpointTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-exec/src/test/resources/org/apache/camel/component/exec/ExecEndpointTest-context.xml?rev=929929&view=auto
==============================================================================
--- camel/trunk/components/camel-exec/src/test/resources/org/apache/camel/component/exec/ExecEndpointTest-context.xml (added)
+++ camel/trunk/components/camel-exec/src/test/resources/org/apache/camel/component/exec/ExecEndpointTest-context.xml Thu Apr  1 11:20:51 2010
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="
+  http://www.springframework.org/schema/beans 
+  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+  http://camel.apache.org/schema/spring 
+  http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+  <camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring"/>
+
+  <bean name="customBinding"
+    class="org.apache.camel.component.exec.impl.DefaultExecBinding"/>
+
+  <bean name="customExecutor"
+    class="org.apache.camel.component.exec.impl.ExecCommandExecutorMock"/>
+</beans>

Added: camel/trunk/components/camel-exec/src/test/resources/org/apache/camel/component/exec/ExecScriptTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-exec/src/test/resources/org/apache/camel/component/exec/ExecScriptTest-context.xml?rev=929929&view=auto
==============================================================================
--- camel/trunk/components/camel-exec/src/test/resources/org/apache/camel/component/exec/ExecScriptTest-context.xml (added)
+++ camel/trunk/components/camel-exec/src/test/resources/org/apache/camel/component/exec/ExecScriptTest-context.xml Thu Apr  1 11:20:51 2010
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+  <!--
+    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.
+  -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="
+  http://www.springframework.org/schema/beans 
+  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+  http://camel.apache.org/schema/spring 
+  http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+    <route>
+      <from uri="direct:input"/>
+      <to uri="exec:exec-test-script"/>
+    </route>
+  </camelContext>
+</beans>

Added: camel/trunk/components/camel-exec/src/test/resources/org/apache/camel/component/exec/exec-mock-executor-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-exec/src/test/resources/org/apache/camel/component/exec/exec-mock-executor-context.xml?rev=929929&view=auto
==============================================================================
--- camel/trunk/components/camel-exec/src/test/resources/org/apache/camel/component/exec/exec-mock-executor-context.xml (added)
+++ camel/trunk/components/camel-exec/src/test/resources/org/apache/camel/component/exec/exec-mock-executor-context.xml Thu Apr  1 11:20:51 2010
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+  <!--
+    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.
+  -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="
+  http://www.springframework.org/schema/beans 
+  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+  http://camel.apache.org/schema/spring 
+  http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+    <route>
+      <from uri="direct:input"/>
+      <to
+        uri="exec:mockedByCommandExecutorMock.exe?commandExecutor=#commandExecutorMock"/>
+    </route>
+  </camelContext>
+
+  <bean id="commandExecutorMock"
+    class="org.apache.camel.component.exec.impl.ExecCommandExecutorMock"/>
+</beans>



Mime
View raw message