pekko/akka-camel/src/test/java/akka/camel/ConsumerJavaTestBase.java

60 lines
1.9 KiB
Java
Raw Normal View History

/**
* Copyright (C) 2009-2012 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.camel;
import static org.junit.Assert.assertEquals;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.Test;
import scala.concurrent.Await;
import scala.concurrent.ExecutionContext;
import scala.concurrent.util.Duration;
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;
import akka.testkit.JavaTestKit;
/**
* @author Martin Krasser
*/
public class ConsumerJavaTestBase {
2012-08-14 08:04:24 +02:00
static ActorSystem system = ActorSystem.create("test", AkkaSpec.testConf());
@AfterClass
public static void tearDownAfterClass() {
system.shutdown();
}
@Test
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() {
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);
}};
}
}