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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations