Search in sources :

Example 81 with DirtiesContext

use of org.springframework.test.annotation.DirtiesContext in project java-design-patterns by iluwatar.

the class WireTapRouteTest method testWireTap.

/**
 * Test if both endpoints receive exactly one message containing the same, unchanged body.
 * @throws Exception in case of en exception during the test
 */
@Test
@DirtiesContext
public void testWireTap() throws Exception {
    entry.sendBody("TEST");
    endpoint.expectedMessageCount(1);
    wireTapEndpoint.expectedMessageCount(1);
    endpoint.assertIsSatisfied();
    wireTapEndpoint.assertIsSatisfied();
    Message endpointIn = endpoint.getExchanges().get(0).getIn();
    Message wireTapEndpointIn = wireTapEndpoint.getExchanges().get(0).getIn();
    assertEquals("TEST", endpointIn.getBody());
    assertEquals("TEST", wireTapEndpointIn.getBody());
}
Also used : Message(org.apache.camel.Message) Test(org.junit.jupiter.api.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 82 with DirtiesContext

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

the class AtlasMapComponentJavaToJsonTest 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);
    Message msg = result.getExchanges().get(0).getIn();
    assertEquals("application/json", msg.getHeader(Exchange.CONTENT_TYPE));
    Object body = msg.getBody();
    assertEquals(String.class, body.getClass());
    ObjectMapper mapper = new ObjectMapper();
    JsonNode sfJson = mapper.readTree((String) body);
    assertNotNull(sfJson.get("TwitterScreenName__c"));
    assertEquals("bobvila1982", sfJson.get("TwitterScreenName__c").asText());
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) Message(org.apache.camel.Message) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 83 with DirtiesContext

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

the class AtlasMapComponentJsonToJavaTest method testMocksAreValid.

@Test
@DirtiesContext
public void testMocksAreValid() throws Exception {
    result.setExpectedCount(1);
    final ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
    producerTemplate.sendBody("direct:start", new ByteArrayInputStream("{\"field1\":\"value1\"}".getBytes()));
    MockEndpoint.assertIsSatisfied(camelContext);
    final Object body = result.getExchanges().get(0).getIn().getBody();
    assertEquals(Pojo.class, body.getClass());
    assertEquals("value1", ((Pojo) body).getField1());
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 84 with DirtiesContext

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

the class AtlasMapComponentTest method testSeparateNotSucceed.

@Test
@DirtiesContext
public void testSeparateNotSucceed() throws Exception {
    result.setExpectedCount(1);
    ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
    Status s = Util.generateMockTwitterStatus();
    when(s.getUser().getName()).thenReturn("BobVila");
    producerTemplate.sendBody("direct:start", s);
    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("BobVila", outJson.get("FirstName").asText());
    assertNull(outJson.get("LastName"));
    assertEquals("bobvila1982", outJson.get("Title").asText());
    assertEquals("Let's build a house!", outJson.get("Description").asText());
}
Also used : Status(twitter4j.Status) 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 85 with DirtiesContext

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

the class AtlasMapMultiDocsTest method test.

@Test
@DirtiesContext
public void test() throws Exception {
    result.setExpectedCount(1);
    Map<String, Message> sourceMap = new HashMap<>();
    SourceContact javaSource = new SourceContact();
    javaSource.setFirstName("JavaFirstName");
    javaSource.setLastName("JavaLastName");
    javaSource.setPhoneNumber("JavaPhoneNumber");
    javaSource.setZipCode("JavaZipCode");
    Message msg = new DefaultMessage(camelContext);
    msg.setBody(javaSource);
    sourceMap.put("DOCID:JAVA:CONTACT:S", msg);
    msg = new DefaultMessage(camelContext);
    msg.setBody(JSON_SOURCE);
    sourceMap.put("DOCID:JSON:CONTACT:S", msg);
    msg = new DefaultMessage(camelContext);
    msg.setBody(XML_SOURCE);
    sourceMap.put("DOCID:XML:CONTACT:S", msg);
    ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
    producerTemplate.sendBodyAndProperty("direct:start", null, "CAPTURED_OUT_MESSAGES_MAP", sourceMap);
    MockEndpoint.assertIsSatisfied(camelContext);
    Exchange exchange = result.getExchanges().get(0);
    Map<?, ?> targetMap = exchange.getProperty(AtlasConstants.ATLAS_TARGET_MAP, Map.class);
    TargetContact javaTarget = (TargetContact) targetMap.get("DOCID:JAVA:CONTACT:T");
    assertEquals("JavaFirstName", javaTarget.getFirstName());
    assertEquals("XmlLastName", javaTarget.getLastName());
    assertEquals("JsonPhoneNumber", javaTarget.getPhoneNumber());
    String jsonTarget = (String) targetMap.get("DOCID:JSON:CONTACT:T");
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonTargetNode = mapper.readTree(jsonTarget);
    assertEquals("JsonFirstName", jsonTargetNode.get("firstName").asText());
    assertEquals("JavaLastName", jsonTargetNode.get("lastName").asText());
    assertEquals("XmlPhoneNumber", jsonTargetNode.get("phoneNumber").asText());
    String xmlTarget = (String) targetMap.get("DOCID:XML:CONTACT:T");
    JAXBElement<XmlContactAttribute> xmlTargetJaxb = AtlasXmlTestHelper.unmarshal(xmlTarget, XmlContactAttribute.class);
    XmlContactAttribute xmlTargetObj = xmlTargetJaxb.getValue();
    assertEquals("XmlFirstName", xmlTargetObj.getFirstName());
    assertEquals("JsonLastName", xmlTargetObj.getLastName());
    assertEquals("JavaPhoneNumber", xmlTargetObj.getPhoneNumber());
}
Also used : DefaultMessage(org.apache.camel.impl.DefaultMessage) ProducerTemplate(org.apache.camel.ProducerTemplate) Message(org.apache.camel.Message) DefaultMessage(org.apache.camel.impl.DefaultMessage) HashMap(java.util.HashMap) XmlContactAttribute(io.atlasmap.xml.test.v2.XmlContactAttribute) TargetContact(io.atlasmap.java.test.TargetContact) JsonNode(com.fasterxml.jackson.databind.JsonNode) Exchange(org.apache.camel.Exchange) SourceContact(io.atlasmap.java.test.SourceContact) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) 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