001 // Copyright 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.services.impl; 016 017 import static org.easymock.EasyMock.expectLastCall; 018 019 import org.apache.hivemind.ApplicationRuntimeException; 020 import org.apache.hivemind.ErrorLog; 021 import org.apache.hivemind.Location; 022 import org.apache.tapestry.BaseComponentTestCase; 023 import org.apache.tapestry.services.ResetEventHub; 024 import org.apache.tapestry.services.WebRequestServicer; 025 import org.apache.tapestry.web.WebRequest; 026 import org.apache.tapestry.web.WebResponse; 027 import org.testng.annotations.Test; 028 029 /** 030 * Tests for {@link org.apache.tapestry.services.impl.DisableCachingFilter}. 031 * 032 * @author Howard M. Lewis Ship 033 * @since 4.0 034 */ 035 @Test(sequential=true) 036 public class TestDisableCachingFilter extends BaseComponentTestCase 037 { 038 private WebResponse newResponse() 039 { 040 return newMock(WebResponse.class); 041 } 042 043 private WebRequestServicer newServicer() 044 { 045 return newMock(WebRequestServicer.class); 046 } 047 048 private ResetEventHub newREC() 049 { 050 return newMock(ResetEventHub.class); 051 } 052 053 public void test_Normal() throws Exception 054 { 055 WebRequest request = newRequest(); 056 WebResponse response = newResponse(); 057 WebRequestServicer servicer = newServicer(); 058 ResetEventHub rec = newREC(); 059 060 servicer.service(request, response); 061 rec.fireResetEvent(); 062 063 replay(); 064 065 DisableCachingFilter f = new DisableCachingFilter(); 066 f.setResetEventHub(rec); 067 068 f.service(request, response, servicer); 069 070 verify(); 071 } 072 073 public void test_Reset_Failure() throws Exception 074 { 075 WebRequest request = newRequest(); 076 WebResponse response = newResponse(); 077 WebRequestServicer servicer = newServicer(); 078 079 ResetEventHub rec = newMock(ResetEventHub.class); 080 ErrorLog log = newMock(ErrorLog.class); 081 082 Location l = fabricateLocation(99); 083 084 Throwable t = new ApplicationRuntimeException("Mock failure.", l, null); 085 086 servicer.service(request, response); 087 088 rec.fireResetEvent(); 089 expectLastCall().andThrow(t); 090 091 log.error(ImplMessages.errorResetting(t), l, t); 092 093 replay(); 094 095 DisableCachingFilter f = new DisableCachingFilter(); 096 f.setResetEventHub(rec); 097 f.setErrorLog(log); 098 099 f.service(request, response, servicer); 100 101 verify(); 102 } 103 }