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.commons.logging.Log;
18: import org.apache.tapestry.MarkupWriter;
19: import org.apache.tapestry.internal.test.InternalBaseTestCase;
20: import org.apache.tapestry.runtime.RenderCommand;
21: import org.apache.tapestry.runtime.RenderQueue;
22: import org.testng.annotations.Test;
23:
24: public class RenderQueueImplTest extends InternalBaseTestCase {
25: @Test
26: public void run_commands() {
27: final RenderCommand command2 = newMock(RenderCommand.class);
28: RenderCommand command1 = new RenderCommand() {
29: public void render(MarkupWriter writer, RenderQueue queue) {
30: queue.push(command2);
31: }
32: };
33:
34: Log log = mockLog();
35: MarkupWriter writer = mockMarkupWriter();
36: RenderQueueImpl queue = new RenderQueueImpl(log);
37:
38: expect(log.isDebugEnabled()).andReturn(false).atLeastOnce();
39:
40: command2.render(writer, queue);
41:
42: replay();
43:
44: queue.push(command1);
45: queue.run(writer);
46:
47: verify();
48: }
49:
50: @Test
51: public void command_failed() {
52: final RuntimeException t = new RuntimeException("Oops.");
53:
54: RenderCommand rc = new RenderCommand() {
55:
56: public void render(MarkupWriter writer, RenderQueue queue) {
57: throw t;
58: }
59:
60: @Override
61: public String toString() {
62: return "FailedCommand";
63: }
64: };
65:
66: Log log = mockLog();
67: MarkupWriter writer = mockMarkupWriter();
68:
69: expect(log.isDebugEnabled()).andReturn(false).atLeastOnce();
70:
71: log.error("Render queue error in FailedCommand: Oops.", t);
72:
73: replay();
74:
75: RenderQueueImpl queue = new RenderQueueImpl(log);
76:
77: queue.push(rc);
78:
79: try {
80: queue.run(writer);
81: unreachable();
82: } catch (RuntimeException ex) {
83: assertSame(ex, t);
84: }
85:
86: verify();
87: }
88:
89: }
|