Search in sources :

Example 6 with DirtiesContext

use of org.springframework.test.annotation.DirtiesContext in project camel by apache.

the class ExecOutFileTest method testOutFileConvertToByteArray.

@Test
@DirtiesContext
public void testOutFileConvertToByteArray() throws Exception {
    Exchange e = sendWithMockedExecutor();
    byte[] body = e.getIn().getBody(byte[].class);
    assertEquals(FILE_CONTENT, new String(body));
}
Also used : Exchange(org.apache.camel.Exchange) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 7 with DirtiesContext

use of org.springframework.test.annotation.DirtiesContext 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 8 with DirtiesContext

use of org.springframework.test.annotation.DirtiesContext 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 9 with DirtiesContext

use of org.springframework.test.annotation.DirtiesContext 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 10 with DirtiesContext

use of org.springframework.test.annotation.DirtiesContext 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)

Aggregations

DirtiesContext (org.springframework.test.annotation.DirtiesContext)86 Test (org.junit.Test)83 Exchange (org.apache.camel.Exchange)21 Event (org.opennms.netmgt.xml.event.Event)19 Processor (org.apache.camel.Processor)11 DroolsCorrelationEngine (org.opennms.netmgt.correlation.drools.DroolsCorrelationEngine)10 IOException (java.io.IOException)9 NCSComponent (org.opennms.netmgt.model.ncs.NCSComponent)9 ProducerTemplate (org.apache.camel.ProducerTemplate)7 Ignore (org.junit.Ignore)7 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 LinkedHashMap (java.util.LinkedHashMap)5 CommonBindyTest (org.apache.camel.dataformat.bindy.CommonBindyTest)5 FactHandle (org.kie.api.runtime.rule.FactHandle)5 SnmpValueFactory (org.opennms.netmgt.snmp.SnmpValueFactory)5 Message (org.apache.camel.Message)4 BigDecimal (java.math.BigDecimal)3 Registration (org.opennms.core.soa.Registration)3