01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.services;
16:
17: import org.apache.tapestry.internal.test.InternalBaseTestCase;
18: import org.apache.tapestry.services.Heartbeat;
19: import org.testng.annotations.Test;
20:
21: public class HeartbeatImplTest extends InternalBaseTestCase {
22: @Test
23: public void single_heartbeat() {
24: Runnable r1 = mockRunnable();
25: Runnable r2 = mockRunnable();
26:
27: replay();
28:
29: Heartbeat hb = new HeartbeatImpl();
30:
31: hb.begin();
32:
33: hb.defer(r1);
34: hb.defer(r2);
35:
36: verify();
37:
38: r1.run();
39: r2.run();
40:
41: replay();
42:
43: hb.end();
44:
45: verify();
46: }
47:
48: @Test
49: public void nested_heartbeats() {
50: Runnable r1 = mockRunnable();
51: Runnable r2 = mockRunnable();
52: Runnable r3 = mockRunnable();
53:
54: replay();
55:
56: Heartbeat hb = new HeartbeatImpl();
57:
58: hb.begin();
59:
60: hb.defer(r1);
61: hb.defer(r2);
62:
63: hb.begin();
64:
65: hb.defer(r3);
66:
67: verify();
68:
69: r3.run();
70:
71: replay();
72:
73: hb.end();
74:
75: verify();
76:
77: r1.run();
78: r2.run();
79:
80: replay();
81:
82: hb.end();
83:
84: verify();
85: }
86: }
|