KickJava   Java API By Example, From Geeks To Geeks.

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


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.tapestry.IPage;
19 import org.apache.tapestry.IRequestCycle;
20 import org.apache.tapestry.StaleSessionException;
21 import org.apache.tapestry.services.ResponseRenderer;
22
23 /**
24  * Tests for {@link org.apache.tapestry.error.StaleSessionExceptionPresenterImpl}.
25  *
26  * @author Howard M. Lewis Ship
27  * @since 4.0
28  */

29 public class TestStaleSessionExceptionPresenter extends BaseErrorTestCase
30 {
31     public void testSuccess() throws Exception JavaDoc
32     {
33         IPage page = newPage();
34         IRequestCycle cycle = newCycle("StaleSession", page);
35         ResponseRenderer renderer = newRenderer(cycle, null);
36
37         cycle.activate(page);
38
39         replayControls();
40
41         StaleSessionExceptionPresenterImpl presenter = new StaleSessionExceptionPresenterImpl();
42
43         presenter.setPageName("StaleSession");
44         presenter.setResponseRenderer(renderer);
45
46         presenter.presentStaleSessionException(cycle, new StaleSessionException());
47
48         verifyControls();
49     }
50
51     public void testFailure() throws Exception JavaDoc
52     {
53         StaleSessionException cause = new StaleSessionException();
54         Throwable JavaDoc renderCause = new ApplicationRuntimeException("Some failure.");
55
56         IPage page = newPage();
57
58         IRequestCycle cycle = newCycle("StaleSession", page);
59         ResponseRenderer renderer = newRenderer(cycle, renderCause);
60         RequestExceptionReporter reporter = newReporter();
61
62         cycle.activate(page);
63
64         reporter.reportRequestException(ErrorMessages.unableToProcessClientRequest(cause), cause);
65         reporter.reportRequestException(
66                 ErrorMessages.unableToPresentExceptionPage(renderCause),
67                 renderCause);
68
69         replayControls();
70
71         StaleSessionExceptionPresenterImpl presenter = new StaleSessionExceptionPresenterImpl();
72         presenter.setPageName("StaleSession");
73         presenter.setResponseRenderer(renderer);
74         presenter.setRequestExceptionReporter(reporter);
75
76         try
77         {
78             presenter.presentStaleSessionException(cycle, cause);
79             unreachable();
80         }
81         catch (ApplicationRuntimeException ex)
82         {
83             assertSame(renderCause, ex.getRootCause());
84         }
85
86         verifyControls();
87     }
88 }
89
Popular Tags