Search in sources :

Example 1 with Test

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();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Test(org.junit.Test) InSequence(org.jboss.arquillian.junit.InSequence)

Example 2 with Test

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));
}
Also used : EventPayloadInteger(org.apache.camel.cdi.pojo.EventPayloadInteger) EventPayloadInteger(org.apache.camel.cdi.pojo.EventPayloadInteger) EventPayloadString(org.apache.camel.cdi.pojo.EventPayloadString) EventPayload(org.apache.camel.cdi.pojo.EventPayload) Test(org.junit.Test)

Example 3 with Test

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();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) Test(org.junit.Test)

Example 4 with Test

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()");
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Message(org.apache.camel.Message) ArrayList(java.util.ArrayList) Test(org.junit.Test) BaseCacheTest(org.apache.camel.component.BaseCacheTest)

Example 5 with Test

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()");
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Message(org.apache.camel.Message) ArrayList(java.util.ArrayList) Test(org.junit.Test) BaseCacheTest(org.apache.camel.component.BaseCacheTest)

Aggregations

Test (org.junit.Test)198823 ArrayList (java.util.ArrayList)9546 File (java.io.File)9168 HashMap (java.util.HashMap)5749 IOException (java.io.IOException)5434 List (java.util.List)4309 QuickTest (com.hazelcast.test.annotation.QuickTest)4024 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3265 Configuration (org.apache.hadoop.conf.Configuration)3260 Properties (java.util.Properties)3016 Date (java.util.Date)2950 Path (org.apache.hadoop.fs.Path)2924 Map (java.util.Map)2907 Response (javax.ws.rs.core.Response)2884 InputStream (java.io.InputStream)2876 ByteArrayInputStream (java.io.ByteArrayInputStream)2777 CountDownLatch (java.util.concurrent.CountDownLatch)2681 Connection (java.sql.Connection)2478 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2462 Session (org.hibernate.Session)2419