1   /**
2    *  Copyright 2003-2007 Greg Luck
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  
17  package net.sf.ehcache.constructs.web.filter;
18  
19  import com.meterware.httpunit.HttpInternalErrorException;
20  import net.sf.ehcache.constructs.web.AbstractWebTest;
21  
22  import java.io.IOException;
23  
24  import org.xml.sax.SAXException;
25  
26  /**
27   * {@link Filter#doFilter} captures all exceptions passed up to it from subclasses.
28   *
29   * In a web application, because of the vaguaries of HTTP and networking, there are often errors
30   * that happen near continously. We want to filter these out.
31   *
32   *
33   * @author <a href="mailto:gluck@thoughtworks.com">Greg Luck</a>
34   * @version $Id: FilterTest.java 512 2007-07-10 09:18:45Z gregluck $
35   */
36  public class FilterTest extends AbstractWebTest {
37  
38      /**
39       * The GzipFilter filter definition is set up to do special logging for NullPointerException
40       * Check that debug level logging is used. This needs to be done manually at present
41       */
42      public void testHandlingOfNullPointerException() throws Exception {
43          try {
44              getResponseFromAcceptGzipRequest("/errors/NullPointerException.jsp");
45              fail();
46          } catch (HttpInternalErrorException e) {
47              //expected
48          }
49      }
50  
51      /**
52       * The GzipFilter's init-params are not set up for IllegalArgumentException.
53       * Check that the default behaviour applies. This needs to be done manually at present.
54       */
55      public void testHandlingOfIllegalArgumentException() throws Exception {
56          try {
57              getResponseFromAcceptGzipRequest("/errors/IllegalArgumentException.jsp");
58              fail();
59          } catch (HttpInternalErrorException e) {
60              //expected
61          }
62      }
63  
64      /**
65       * The GzipFilter's init-params are not set up for IllegalArgumentException.
66       * Check that the default behaviour applies. This needs to be done manually at present.
67       */
68      public void testHandlingOfIOException() throws IOException, SAXException {
69          try {
70              getResponseFromAcceptGzipRequest("/errors/IOException.jsp");
71              fail();
72          } catch (HttpInternalErrorException e) {
73              //expected
74          }
75      }
76  
77  }