2012-01-19 14:38:44 +00:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
2011-05-23 11:37:56 -04:00
|
|
|
|
2012-01-19 14:38:44 +00:00
|
|
|
package akka.camel;
|
2011-05-23 11:37:56 -04:00
|
|
|
|
2012-01-19 14:38:44 +00:00
|
|
|
import akka.actor.ActorRef;
|
|
|
|
|
import akka.actor.ActorSystem;
|
|
|
|
|
import akka.actor.Props;
|
2012-07-25 20:11:18 +02:00
|
|
|
import scala.concurrent.Await;
|
|
|
|
|
import scala.concurrent.util.Duration;
|
2011-05-23 11:37:56 -04:00
|
|
|
import org.junit.AfterClass;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
2012-07-25 20:11:18 +02:00
|
|
|
import java.util.concurrent.Future;
|
2012-01-19 14:38:44 +00:00
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
2011-05-23 11:37:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Martin Krasser
|
|
|
|
|
*/
|
|
|
|
|
public class ConsumerJavaTestBase {
|
|
|
|
|
|
2012-01-19 14:38:44 +00:00
|
|
|
static ActorSystem system = ActorSystem.create("test");
|
2012-07-25 20:11:18 +02:00
|
|
|
static Camel camel = CamelExtension.get(system);
|
2012-01-19 14:38:44 +00:00
|
|
|
|
2011-05-23 11:37:56 -04:00
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
|
public static void tearDownAfterClass() {
|
2012-01-19 14:38:44 +00:00
|
|
|
system.shutdown();
|
2011-05-23 11:37:56 -04:00
|
|
|
}
|
|
|
|
|
|
2012-01-19 14:38:44 +00:00
|
|
|
@Test
|
2012-07-25 20:11:18 +02:00
|
|
|
public void shouldHandleExceptionThrownByActorAndGenerateCustomResponse() throws Exception {
|
|
|
|
|
Duration timeout = Duration.create(1, TimeUnit.SECONDS);
|
|
|
|
|
ActorRef ref = Await.result(
|
|
|
|
|
camel.activationFutureFor(system.actorOf(new Props(SampleErrorHandlingConsumer.class)), timeout),
|
|
|
|
|
timeout);
|
2012-01-19 14:38:44 +00:00
|
|
|
|
|
|
|
|
String result = camel.template().requestBody("direct:error-handler-test-java", "hello", String.class);
|
2011-05-23 11:37:56 -04:00
|
|
|
assertEquals("error: hello", result);
|
|
|
|
|
}
|
|
|
|
|
}
|