Search in sources :

Example 51 with Processor

use of org.apache.camel.Processor in project camel by apache.

the class ExecProducerTest method testOverrideArgs.

/**
     * 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));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) IOException(java.io.IOException) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 52 with Processor

use of org.apache.camel.Processor in project camel by apache.

the class ExecProducerTest method testInputLines.

@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()));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) IOException(java.io.IOException) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 53 with Processor

use of org.apache.camel.Processor in project camel by apache.

the class ExecProducerTest method testNullInBody.

@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());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) IOException(java.io.IOException) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 54 with Processor

use of org.apache.camel.Processor in project camel by apache.

the class ExecProducerTest method testInputLinesNotConvertibleToInputStream.

@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());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) IOException(java.io.IOException) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 55 with Processor

use of org.apache.camel.Processor in project camel by apache.

the class ExecProducerTest method testOverrideWorkingDir.

@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());
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) IOException(java.io.IOException) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Aggregations

Processor (org.apache.camel.Processor)1467 Exchange (org.apache.camel.Exchange)1368 Test (org.junit.Test)634 RouteBuilder (org.apache.camel.builder.RouteBuilder)543 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)164 Message (org.apache.camel.Message)119 ArrayList (java.util.ArrayList)65 HashMap (java.util.HashMap)64 IOException (java.io.IOException)55 CamelExecutionException (org.apache.camel.CamelExecutionException)52 Endpoint (org.apache.camel.Endpoint)46 Map (java.util.Map)45 File (java.io.File)38 List (java.util.List)34 Producer (org.apache.camel.Producer)33 DefaultExchange (org.apache.camel.impl.DefaultExchange)29 SendProcessor (org.apache.camel.processor.SendProcessor)26 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)26 CountDownLatch (java.util.concurrent.CountDownLatch)24 Expression (org.apache.camel.Expression)24