Search in sources :

Example 46 with DirtiesContext

use of org.springframework.test.annotation.DirtiesContext in project atlasmap by atlasmap.

the class AtlasMapComponentJsonTest method testMocksAreValid.

@Test
@DirtiesContext
public void testMocksAreValid() throws Exception {
    result.setExpectedCount(1);
    ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
    producerTemplate.sendBody("direct:start", Util.generateMockTwitterStatus());
    MockEndpoint.assertIsSatisfied(camelContext);
    Object body = result.getExchanges().get(0).getIn().getBody();
    assertEquals(String.class, body.getClass());
    ObjectMapper mapper = new ObjectMapper();
    JsonNode outJson = mapper.readTree((String) body);
    assertEquals("Bob", outJson.get("FirstName").asText());
    assertEquals("Vila", outJson.get("LastName").asText());
    assertEquals("bobvila1982", outJson.get("Title").asText());
    assertEquals("Let's build a house!", outJson.get("Description").asText());
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 47 with DirtiesContext

use of org.springframework.test.annotation.DirtiesContext in project atlasmap by atlasmap.

the class AtlasMapComponentTest method testMocksAreValid.

@Test
@DirtiesContext
public void testMocksAreValid() throws Exception {
    result.setExpectedCount(1);
    ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
    producerTemplate.sendBody("direct:start", Util.generateMockTwitterStatus());
    MockEndpoint.assertIsSatisfied(camelContext);
    Object body = result.getExchanges().get(0).getIn().getBody();
    assertEquals(String.class, body.getClass());
    ObjectMapper mapper = new ObjectMapper();
    JsonNode outJson = mapper.readTree((String) body);
    assertEquals("Bob", outJson.get("FirstName").asText());
    assertEquals("Vila", outJson.get("LastName").asText());
    assertEquals("bobvila1982", outJson.get("Title").asText());
    assertEquals("Let's build a house!", outJson.get("Description").asText());
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 48 with DirtiesContext

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

the class ExecScriptTest method testExecuteScript.

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

Example 49 with DirtiesContext

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

the class ExecOutFileTest method testOutFileConvertToInputStream.

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

Example 50 with DirtiesContext

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

the class ExecOutFileTest method testOutFileConvertToDocument.

@Test
@DirtiesContext
public void testOutFileConvertToDocument() throws Exception {
    Exchange e = sendWithMockedExecutor();
    Document body = e.getIn().getBody(Document.class);
    // do not parse it
    assertNotNull(body);
}
Also used : Exchange(org.apache.camel.Exchange) Document(org.w3c.dom.Document) 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