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-09-14 10:08:40 +02:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import org.junit.AfterClass;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
2012-07-25 20:11:18 +02:00
|
|
|
import scala.concurrent.Await;
|
2012-08-14 13:16:43 +02:00
|
|
|
import scala.concurrent.ExecutionContext;
|
2012-07-25 20:11:18 +02:00
|
|
|
import scala.concurrent.util.Duration;
|
2012-09-14 10:08:40 +02:00
|
|
|
import scala.concurrent.util.FiniteDuration;
|
|
|
|
|
import akka.actor.ActorRef;
|
|
|
|
|
import akka.actor.ActorSystem;
|
|
|
|
|
import akka.actor.Props;
|
2012-08-14 08:04:24 +02:00
|
|
|
import akka.testkit.AkkaSpec;
|
2012-09-14 10:08:40 +02:00
|
|
|
import akka.testkit.JavaTestKit;
|
2011-05-23 11:37:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Martin Krasser
|
|
|
|
|
*/
|
|
|
|
|
public class ConsumerJavaTestBase {
|
|
|
|
|
|
2012-08-14 08:04:24 +02:00
|
|
|
static ActorSystem system = ActorSystem.create("test", AkkaSpec.testConf());
|
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 {
|
2012-08-14 08:04:24 +02:00
|
|
|
new JavaTestKit(system) {{
|
|
|
|
|
String result = new EventFilter<String>(Exception.class) {
|
|
|
|
|
protected String run() {
|
2012-09-14 10:08:40 +02:00
|
|
|
FiniteDuration timeout = Duration.create(1, TimeUnit.SECONDS);
|
2012-08-14 16:29:38 +02:00
|
|
|
Camel camel = CamelExtension.get(system);
|
|
|
|
|
ExecutionContext executionContext = system.dispatcher();
|
2012-08-14 08:04:24 +02:00
|
|
|
try {
|
|
|
|
|
ActorRef ref = Await.result(
|
2012-08-14 16:29:38 +02:00
|
|
|
camel.activationFutureFor(system.actorOf(new Props(SampleErrorHandlingConsumer.class)), timeout, executionContext),
|
2012-08-14 08:04:24 +02:00
|
|
|
timeout);
|
|
|
|
|
return camel.template().requestBody("direct:error-handler-test-java", "hello", String.class);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
return e.getMessage();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}.occurrences(1).exec();
|
|
|
|
|
assertEquals("error: hello", result);
|
|
|
|
|
}};
|
2011-05-23 11:37:56 -04:00
|
|
|
}
|
|
|
|
|
}
|