Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import akka.actor.ActorIdentity;
- import akka.actor.ActorRef;
- import akka.actor.ActorSystem;
- import akka.event.Logging;
- import akka.testkit.JavaTestKit;
- import akka.testkit.TestProbe;
- import com.typesafe.training.coffeehouse.CoffeeHouse;
- import org.junit.AfterClass;
- import org.junit.BeforeClass;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.junit.runners.JUnit4;
- import scala.concurrent.duration.Duration;
- import static org.junit.Assert.*;
- @RunWith(JUnit4.class)
- public class CoffeeHouseTest {
- static ActorSystem system;
- @BeforeClass
- public static void setup() {
- system = ActorSystem.create();
- }
- @AfterClass
- public static void teardown() {
- JavaTestKit.shutdownActorSystem(system);
- system = null;
- }
- @Test
- public void creatingCoffeeHouseDebug() {
- new JavaTestKit(system) {{
- new EventFilter<Void>(Logging.Debug.class) {
- protected Void run() {
- system.actorOf(CoffeeHouse.props());
- return null;
- }
- }.matches(".*[Oo]pen.*").occurrences(1).exec();
- }};
- }
- @Test
- public void creatingNewGuestActors() {
- new JavaTestKit(system) {{
- ActorRef coffeeHouse = system.actorOf(CoffeeHouse.props(), "create-guest");
- final String guestPath = "/user/create-guest/$*";
- coffeeHouse.tell(CoffeeHouse.CreateGuest.Instance, null);
- new AwaitAssert(duration("1 minute"), duration("200 millis")) {
- @Override
- protected void check() {
- system.actorSelection(guestPath)
- .tell(new akka.actor.Identify(101), getRef());
- ActorIdentity i =
- expectMsgClass(duration("100 millis"), ActorIdentity.class);
- assertEquals(i.correlationId(), 101);
- assertNotNull(i.getRef());
- }
- };
- }};
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement