Search in sources :

Example 31 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class NettyHttpStreamCacheFileResponseTest method testStreamCacheToFileShouldBeDeletedInCaseOfResponse.

@Test
public void testStreamCacheToFileShouldBeDeletedInCaseOfResponse() throws Exception {
    NotifyBuilder builder = new NotifyBuilder(context).whenDone(1).create();
    String out = template.requestBody("http://localhost:{{port}}/myserver", body, String.class);
    assertEquals(body2, out);
    assertTrue(builder.matches(5, TimeUnit.SECONDS));
    // the temporary files should have been deleted
    File file = new File("target/cachedir");
    String[] files = file.list();
    assertEquals("There should be no files", 0, files.length);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) File(java.io.File) Test(org.junit.Test)

Example 32 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class NettyHttpStreamCacheFileResponseTest method testStreamCacheToFileShouldBeDeletedInCaseOfResponse.

@Test
public void testStreamCacheToFileShouldBeDeletedInCaseOfResponse() throws Exception {
    NotifyBuilder builder = new NotifyBuilder(context).whenDone(1).create();
    String out = template.requestBody("http://localhost:{{port}}/myserver", body, String.class);
    assertEquals(body2, out);
    assertTrue(builder.matches(5, TimeUnit.SECONDS));
    // the temporary files should have been deleted
    File file = new File("target/cachedir");
    String[] files = file.list();
    assertEquals("There should be no files", 0, files.length);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) File(java.io.File) Test(org.junit.Test)

Example 33 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class JmsErrorHandlerLogStackTraceTest method testErrorHandlerLogStackTrace.

@Test
public void testErrorHandlerLogStackTrace() throws Exception {
    JmsComponent jms = context.getComponent("jms", JmsComponent.class);
    assertFalse(jms.getConfiguration().isErrorHandlerLogStackTrace());
    // should fail
    NotifyBuilder notify = new NotifyBuilder(context).whenFailed(1).create();
    template.sendBody("jms:queue:foo", "Hello World");
    assertTrue(notify.matchesMockWaitTime());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Test(org.junit.Test)

Example 34 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class JmsRequestReplyCorrelationTest method testRequestReplyCorrelationWithDuplicateId.

/**
     * As the correlationID should be unique when receiving the reply message, 
     * now we just expect to get an exception here.
     */
@Test
public void testRequestReplyCorrelationWithDuplicateId() throws Exception {
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(1);
    NotifyBuilder notify = new NotifyBuilder(context).whenReceived(1).create();
    // just send out the request to fill the correlation id first
    template.asyncSend("jms:queue:helloDelay", new Processor() {

        public void process(Exchange exchange) throws Exception {
            exchange.setPattern(ExchangePattern.InOut);
            Message in = exchange.getIn();
            in.setBody("Hello World");
            in.setHeader("JMSCorrelationID", "b");
        }
    });
    // Added use the notify to make sure the message is processed, so we get the exception later
    notify.matches(1, TimeUnit.SECONDS);
    Exchange out = template.send("jms:queue:helloDelay", ExchangePattern.InOut, new Processor() {

        public void process(Exchange exchange) throws Exception {
            Message in = exchange.getIn();
            in.setBody("Hello World");
            in.setHeader("JMSCorrelationID", "b");
        }
    });
    result.assertIsSatisfied();
    assertNotNull("We are expecting the exception here!", out.getException());
    assertTrue("Get a wrong exception", out.getException() instanceof IllegalArgumentException);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Message(org.apache.camel.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 35 with NotifyBuilder

use of org.apache.camel.builder.NotifyBuilder in project camel by apache.

the class QueueToQueueTransactionWithoutDefineTransactionManagerTest method testNoTransactionRollbackUsingXmlQueueToQueue.

@Test
public void testNoTransactionRollbackUsingXmlQueueToQueue() throws Exception {
    // configure routes and add to camel context
    context.addRoutes(new SpringRouteBuilder() {

        @Override
        public void configure() throws Exception {
            errorHandler(noErrorHandler());
            from("activemq:queue:foo?transacted=false").process(new ConditionalExceptionProcessor()).to("activemq:queue:bar?transacted=false");
        }
    });
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();
    template.sendBody("activemq:queue:foo", "blah");
    notify.matchesMockWaitTime();
    assertTrue("Expected only 1 calls to process() (1 failure) but encountered " + getConditionalExceptionProcessor().getCount() + ".", getConditionalExceptionProcessor().getCount() == 1);
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) SpringRouteBuilder(org.apache.camel.spring.SpringRouteBuilder) Test(org.junit.Test)

Aggregations

NotifyBuilder (org.apache.camel.builder.NotifyBuilder)109 Test (org.junit.Test)72 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)30 File (java.io.File)24 Exchange (org.apache.camel.Exchange)10 RouteBuilder (org.apache.camel.builder.RouteBuilder)9 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 HashSet (java.util.HashSet)4 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 Processor (org.apache.camel.Processor)4 StopWatch (org.apache.camel.util.StopWatch)4 ConnectException (java.net.ConnectException)3 ExecutorService (java.util.concurrent.ExecutorService)3 Ignore (org.junit.Ignore)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Future (java.util.concurrent.Future)2 ZipFile (java.util.zip.ZipFile)2