1 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 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 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 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 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 |