SHOW:
|
|
- or go back to the newest paste.
1 | - | import akka.actor.ActorIdentity; |
1 | + | import akka.actor.ActorIdentity; |
2 | - | import akka.actor.ActorRef; |
2 | + | import akka.actor.ActorRef; |
3 | - | import akka.actor.ActorSystem; |
3 | + | import akka.actor.ActorSystem; |
4 | - | import akka.event.Logging; |
4 | + | import akka.event.Logging; |
5 | - | import akka.testkit.JavaTestKit; |
5 | + | import akka.testkit.JavaTestKit; |
6 | - | import akka.testkit.TestProbe; |
6 | + | import akka.testkit.TestProbe; |
7 | - | import com.typesafe.training.coffeehouse.CoffeeHouse; |
7 | + | import com.typesafe.training.coffeehouse.CoffeeHouse; |
8 | - | import org.junit.AfterClass; |
8 | + | import org.junit.AfterClass; |
9 | - | import org.junit.BeforeClass; |
9 | + | import org.junit.BeforeClass; |
10 | - | import org.junit.Test; |
10 | + | import org.junit.Test; |
11 | - | import org.junit.runner.RunWith; |
11 | + | import org.junit.runner.RunWith; |
12 | - | import org.junit.runners.JUnit4; |
12 | + | import org.junit.runners.JUnit4; |
13 | - | import scala.concurrent.duration.Duration; |
13 | + | import scala.concurrent.duration.Duration; |
14 | - | import static org.junit.Assert.*; |
14 | + | import static org.junit.Assert.*; |
15 | - | |
15 | + | |
16 | - | @RunWith(JUnit4.class) |
16 | + | @RunWith(JUnit4.class) |
17 | - | public class CoffeeHouseTest { |
17 | + | public class CoffeeHouseTest { |
18 | - | |
18 | + | |
19 | - | static ActorSystem system; |
19 | + | static ActorSystem system; |
20 | - | |
20 | + | |
21 | - | @BeforeClass |
21 | + | @BeforeClass |
22 | - | public static void setup() { |
22 | + | public static void setup() { |
23 | - | system = ActorSystem.create(); |
23 | + | system = ActorSystem.create(); |
24 | - | } |
24 | + | } |
25 | - | |
25 | + | |
26 | - | @AfterClass |
26 | + | @AfterClass |
27 | - | public static void teardown() { |
27 | + | public static void teardown() { |
28 | - | JavaTestKit.shutdownActorSystem(system); |
28 | + | JavaTestKit.shutdownActorSystem(system); |
29 | - | system = null; |
29 | + | system = null; |
30 | - | } |
30 | + | } |
31 | - | |
31 | + | |
32 | - | @Test |
32 | + | @Test |
33 | - | public void creatingCoffeeHouseDebug() { |
33 | + | public void creatingCoffeeHouseDebug() { |
34 | - | new JavaTestKit(system) {{ |
34 | + | new JavaTestKit(system) {{ |
35 | - | new EventFilter<Void>(Logging.Debug.class) { |
35 | + | new EventFilter<Void>(Logging.Debug.class) { |
36 | - | protected Void run() { |
36 | + | protected Void run() { |
37 | - | system.actorOf(CoffeeHouse.props()); |
37 | + | system.actorOf(CoffeeHouse.props()); |
38 | - | return null; |
38 | + | return null; |
39 | - | } |
39 | + | } |
40 | - | }.matches(".*[Oo]pen.*").occurrences(1).exec(); |
40 | + | }.matches(".*[Oo]pen.*").occurrences(1).exec(); |
41 | - | }}; |
41 | + | }}; |
42 | - | } |
42 | + | } |
43 | - | |
43 | + | |
44 | - | @Test |
44 | + | @Test |
45 | - | public void creatingNewGuestActors() { |
45 | + | public void creatingNewGuestActors() { |
46 | - | new JavaTestKit(system) {{ |
46 | + | new JavaTestKit(system) {{ |
47 | - | ActorRef coffeeHouse = system.actorOf(CoffeeHouse.props(), "create-guest"); |
47 | + | ActorRef coffeeHouse = system.actorOf(CoffeeHouse.props(), "create-guest"); |
48 | - | final String guestPath = "/user/create-guest/$*"; |
48 | + | final String guestPath = "/user/create-guest/$*"; |
49 | - | coffeeHouse.tell(CoffeeHouse.CreateGuest.Instance, null); |
49 | + | coffeeHouse.tell(CoffeeHouse.CreateGuest.Instance, null); |
50 | - | new AwaitAssert(duration("1 minute"), duration("200 millis")) { |
50 | + | new AwaitAssert(duration("1 minute"), duration("200 millis")) { |
51 | - | @Override |
51 | + | @Override |
52 | - | protected void check() { |
52 | + | protected void check() { |
53 | - | system.actorSelection(guestPath) |
53 | + | system.actorSelection(guestPath) |
54 | - | .tell(new akka.actor.Identify(101), getRef()); |
54 | + | .tell(new akka.actor.Identify(101), getRef()); |
55 | - | ActorIdentity i = |
55 | + | ActorIdentity i = |
56 | - | expectMsgClass(duration("100 millis"), ActorIdentity.class); |
56 | + | expectMsgClass(duration("100 millis"), ActorIdentity.class); |
57 | - | assertEquals(i.correlationId(), 101); |
57 | + | assertEquals(i.correlationId(), 101); |
58 | - | assertNotNull(i.getRef()); |
58 | + | assertNotNull(i.getRef()); |
59 | - | |
59 | + | |
60 | - | } |
60 | + | } |
61 | - | }; |
61 | + | }; |
62 | - | }}; |
62 | + | }}; |
63 | - | } |
63 | + | } |
64 | - | |
64 | + | |
65 | } |