KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > error > TestExceptionPresenter


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// 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.error;
16
17 import org.apache.hivemind.ApplicationRuntimeException;
18 import org.apache.hivemind.test.HiveMindTestCase;
19 import org.apache.tapestry.IPage;
20 import org.apache.tapestry.IRequestCycle;
21 import org.apache.tapestry.error.ExceptionPresenterImpl;
22 import org.apache.tapestry.html.BasePage;
23 import org.apache.tapestry.services.ResponseRenderer;
24
25 /**
26  * Tests for {@link org.apache.tapestry.error.ExceptionPresenterImpl}.
27  *
28  * @author Howard M. Lewis Ship
29  * @since 4.0
30  */

31 public class TestExceptionPresenter extends BaseErrorTestCase
32 {
33     public abstract static class ExceptionFixture extends BasePage
34     {
35         public abstract void setException(Throwable JavaDoc exception);
36     }
37
38     public void testSuccess() throws Exception JavaDoc
39     {
40         Throwable JavaDoc cause = new IllegalArgumentException JavaDoc();
41         IPage page = newPage();
42
43         IRequestCycle cycle = newCycle("Exception", page);
44         ResponseRenderer renderer = newRenderer(cycle, null);
45
46         cycle.activate(page);
47
48         replayControls();
49
50         ExceptionPresenterImpl ep = new ExceptionPresenterImpl();
51         ep.setExceptionPageName("Exception");
52         ep.setResponseRenderer(renderer);
53
54         ep.presentException(cycle, cause);
55
56         verifyControls();
57
58         assertSame(cause, page.getProperty("exception"));
59     }
60
61     public void testFailure() throws Exception JavaDoc
62     {
63         Throwable JavaDoc cause = new IllegalArgumentException JavaDoc();
64         Throwable JavaDoc renderCause = new ApplicationRuntimeException("Some failure.");
65
66         IPage page = newPage();
67
68         IRequestCycle cycle = newCycle("Exception", page);
69         ResponseRenderer renderer = newRenderer(cycle, renderCause);
70         RequestExceptionReporter reporter = newReporter();
71
72         cycle.activate(page);
73
74         reporter.reportRequestException(ErrorMessages.unableToProcessClientRequest(cause), cause);
75         reporter.reportRequestException(
76                 ErrorMessages.unableToPresentExceptionPage(renderCause),
77                 renderCause);
78
79         replayControls();
80
81         ExceptionPresenterImpl ep = new ExceptionPresenterImpl();
82         ep.setExceptionPageName("Exception");
83         ep.setResponseRenderer(renderer);
84         ep.setRequestExceptionReporter(reporter);
85
86         try
87         {
88             ep.presentException(cycle, cause);
89             unreachable();
90         }
91         catch (ApplicationRuntimeException ex)
92         {
93             assertSame(renderCause, ex.getRootCause());
94         }
95
96         verifyControls();
97
98         assertSame(cause, page.getProperty("exception"));
99     }
100 }
Popular Tags