KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > services > impl > TestDisableCachingFilter


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.services.impl;
16
17 import org.apache.hivemind.ApplicationRuntimeException;
18 import org.apache.hivemind.ErrorLog;
19 import org.apache.hivemind.Location;
20 import org.apache.hivemind.test.HiveMindTestCase;
21 import org.apache.tapestry.services.ResetEventCoordinator;
22 import org.apache.tapestry.services.WebRequestServicer;
23 import org.apache.tapestry.web.WebRequest;
24 import org.apache.tapestry.web.WebResponse;
25 import org.easymock.MockControl;
26
27 /**
28  * Tests for {@link org.apache.tapestry.services.impl.DisableCachingFilter}.
29  *
30  * @author Howard M. Lewis Ship
31  * @since 4.0
32  */

33 public class TestDisableCachingFilter extends HiveMindTestCase
34 {
35     private WebRequest newRequest()
36     {
37         return (WebRequest) newMock(WebRequest.class);
38     }
39
40     private WebResponse newResponse()
41     {
42         return (WebResponse) newMock(WebResponse.class);
43     }
44
45     private WebRequestServicer newServicer()
46     {
47         return (WebRequestServicer) newMock(WebRequestServicer.class);
48     }
49
50     private ResetEventCoordinator newREC()
51     {
52         return (ResetEventCoordinator) newMock(ResetEventCoordinator.class);
53     }
54
55     public void testNormal() throws Exception JavaDoc
56     {
57         WebRequest request = newRequest();
58         WebResponse response = newResponse();
59         WebRequestServicer servicer = newServicer();
60         ResetEventCoordinator rec = newREC();
61
62         servicer.service(request, response);
63         rec.fireResetEvent();
64
65         replayControls();
66
67         DisableCachingFilter f = new DisableCachingFilter();
68         f.setResetEventCoordinator(rec);
69
70         f.service(request, response, servicer);
71
72         verifyControls();
73     }
74
75     public void testResetFailure() throws Exception JavaDoc
76     {
77         WebRequest request = newRequest();
78         WebResponse response = newResponse();
79         WebRequestServicer servicer = newServicer();
80         MockControl control = newControl(ResetEventCoordinator.class);
81         ResetEventCoordinator rec = (ResetEventCoordinator) control.getMock();
82         ErrorLog log = (ErrorLog) newMock(ErrorLog.class);
83
84         Location l = fabricateLocation(99);
85
86         Throwable JavaDoc t = new ApplicationRuntimeException("Mock failure.", l, null);
87
88         servicer.service(request, response);
89
90         rec.fireResetEvent();
91         control.setThrowable(t);
92
93         log.error(ImplMessages.errorResetting(t), l, t);
94
95         replayControls();
96
97         DisableCachingFilter f = new DisableCachingFilter();
98         f.setResetEventCoordinator(rec);
99         f.setErrorLog(log);
100
101         f.service(request, response, servicer);
102
103         verifyControls();
104     }
105
106 }
Popular Tags