use of org.junit.Test in project camel by apache.
the class AdvisedMockEndpointProducerTest method startCamelContext.
@Test
@InSequence(1)
public void startCamelContext(CamelContext context) throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() {
interceptSendToEndpoint("mock:outbound").skipSendToOriginalEndpoint().log("Intercepting message [${body}] from mock endpoint").to("mock:intercepted");
from("direct:inbound").to("mock:outbound");
}
});
context.startAllRoutes();
}
use of org.junit.Test in project camel by apache.
the class EventEndpointTest method sendMessagesToProducers.
@Test
public void sendMessagesToProducers() {
produceObject.sendBody("string");
EventPayload foo = new EventPayloadString("foo");
produceStringPayload.sendBody(foo);
produceObject.sendBody(1234);
produceString.sendBody("test");
EventPayload<Integer> bar = new EventPayloadInteger(2);
produceIntegerPayload.sendBody(bar);
EventPayload<Integer> baz = new EventPayloadInteger(12);
produceIntegerPayload.sendBody(baz);
produceFooQualifier.sendBody(456L);
produceBarQualifier.sendBody(495L);
produceObject.sendBody(777L);
assertThat(observer.getObjectEvents(), contains("string", foo, 1234, "test", bar, baz, 456L, 495L, 777L));
// assertThat(observer.getStringEvents(), contains("string", "test"));
assertThat(observer.getStringPayloadEvents(), contains(foo));
assertThat(observer.getIntegerPayloadEvents(), contains(bar, baz));
assertThat(observer.getDefaultQualifierEvents(), contains("string", foo, 1234, "test", bar, baz, 777L));
assertThat(observer.getFooQualifierEvents(), contains(456L));
assertThat(observer.getBarQualifierEvents(), contains(495L));
}
use of org.junit.Test in project camel by apache.
the class ObjectCacheProducerTest method testAddingMultipleDataInCacheAndGettingBack.
/**
* Test storing 3 elements into object cache then retrieving them back.
* We allow cache to store maximum of 2 values to check that overflow to disk not happened (it is not
* allowed in ehcache object cache (not serializable cache)).
*
* @throws Exception
* @see net.sf.ehcache.Element for information about object cache operations in ehcache
*/
@Test
public void testAddingMultipleDataInCacheAndGettingBack() throws Exception {
context.addRoutes(new RouteBuilder() {
public void configure() {
onException(Exception.class).handled(true).to("log:LOGGER").to("mock:ObjectCacheProducerTest.cacheException");
from("direct:a").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")).to("cache://TestCache1?objectCache=true&overflowToDisk=false&diskPersistent=false&maxElementsInMemory=2");
from("direct:aGet").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_GET)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson")).to("cache://TestCache1?objectCache=true&overflowToDisk=false&diskPersistent=false&maxElementsInMemory=2").choice().when(header(CacheConstants.CACHE_ELEMENT_WAS_FOUND).isNotNull()).to("mock:ObjectCacheProducerTest.result").end();
from("direct:b").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson_2")).to("cache://TestCache1?objectCache=true&overflowToDisk=false&diskPersistent=false&maxElementsInMemory=2");
from("direct:bGet").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_GET)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson_2")).to("cache://TestCache1?objectCache=true&overflowToDisk=false&diskPersistent=false&maxElementsInMemory=2").choice().when(header(CacheConstants.CACHE_ELEMENT_WAS_FOUND).isNotNull()).to("mock:ObjectCacheProducerTest.result").end();
from("direct:c").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson_3")).to("cache://TestCache1?objectCache=true&overflowToDisk=false&diskPersistent=false&maxElementsInMemory=2");
from("direct:cGet").setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_GET)).setHeader(CacheConstants.CACHE_KEY, constant("Ralph_Waldo_Emerson_3")).to("cache://TestCache1?objectCache=true&overflowToDisk=false&diskPersistent=false&maxElementsInMemory=2").choice().when(header(CacheConstants.CACHE_ELEMENT_WAS_FOUND).isNotNull()).to("mock:ObjectCacheProducerTest.result").end();
}
});
context.setTracing(true);
context.start();
resultEndpoint.expectedMessageCount(2);
cacheExceptionEndpoint.expectedMessageCount(0);
log.debug("------------Beginning CacheProducer Add and Get Test---------------");
log.debug("Putting data into cache");
sendNonSerializedData("direct:a", newPoetry("Ralph Waldo Emerson", "Brahma"));
sendNonSerializedData("direct:b", newPoetry("Ralph Waldo Emerson", "The Rhodora"));
sendNonSerializedData("direct:c", newPoetry("Ralph Waldo Emerson", "Concord Hymn"));
log.debug("Retrieving data from cache");
sendEmptyBody("direct:aGet");
sendEmptyBody("direct:bGet");
sendEmptyBody("direct:cGet");
cacheExceptionEndpoint.assertIsSatisfied();
resultEndpoint.assertIsSatisfied();
}
use of org.junit.Test in project camel by apache.
the class CacheBasedTokenReplacerTest method testCacheBasedTokenReplacer.
@Test
public void testCacheBasedTokenReplacer() throws Exception {
log.debug("Beginning Test ---> testCacheBasedTokenReplacer()");
resultEndpoint.expectedMessageCount(1);
List<String> keys = new ArrayList<String>();
keys.add("novel");
keys.add("author");
keys.add("number");
keys.add("quote");
for (final String key : keys) {
producerTemplate.send(new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
Message in = exchange.getIn();
in.setHeader(CacheConstants.CACHE_OPERATION, CacheConstants.CACHE_OPERATION_ADD);
in.setHeader(CacheConstants.CACHE_KEY, key);
if (key.equalsIgnoreCase("novel")) {
in.setBody("Rubaiyat");
} else if (key.equalsIgnoreCase("author")) {
in.setBody("Omar Khayyam");
} else if (key.equalsIgnoreCase("number")) {
in.setBody("one");
} else {
in.setBody(quote);
}
}
});
}
resultEndpoint.assertIsSatisfied();
log.debug("Completed Test ---> testCacheBasedTokenReplacer()");
}
use of org.junit.Test in project camel by apache.
the class CacheBasedXPathElementReplacerTest method testCacheBasedXPathElementReplacer.
@Test
public void testCacheBasedXPathElementReplacer() throws Exception {
log.debug("Beginning Test ---> testCacheBasedXPathElementReplacer()");
resultEndpoint.expectedMessageCount(1);
List<String> keys = new ArrayList<String>();
keys.add("book1");
keys.add("book2");
keys.add("XML_FRAGMENT");
for (final String key : keys) {
producerTemplate.send(new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
Message in = exchange.getIn();
in.setHeader(CacheConstants.CACHE_OPERATION, CacheConstants.CACHE_OPERATION_ADD);
in.setHeader(CacheConstants.CACHE_KEY, key);
if (key.equalsIgnoreCase("book1")) {
in.setBody(book1);
} else if (key.equalsIgnoreCase("book2")) {
in.setBody(book2);
} else {
in.setBody(xmlFragment);
}
}
});
}
resultEndpoint.assertIsSatisfied();
log.debug("Completed Test ---> testCacheBasedXPathElementReplacer()");
}
Aggregations