    1   /***
    2    * @(#)EncodingFilterTest.java
    3    *
    4    * JFoxSOAF, Service-Oriented Application Framework
    5    *
    6    * Copyright(c) JFoxSOAF Team
    7    *
    8    * Licensed under the GNU LGPL, Version 2.1 (the "License");
    9    * you may not use this file except in compliance with the License.
    10   * You may obtain a copy of the License at
    11   *
    12   * http://www.gnu.org/copyleft/lesser.html
    13   *
    14   * Unless required by applicable law or agreed to in writing, software
    15   * distributed under the License is distributed on an "AS IS" BASIS,
    16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    17   * See the License for the specific language governing permissions and
    18   * limitations under the License.
    19   *
    20   * For more information, please visit:
    21   * http://www.jfox.cn/confluence/display/JFoxSOAF/Home
    22   * http://www.huihoo.org/jfox/jfoxsoaf
    23   */
    24
    25  package org.huihoo.jfox.soaf.util.filter;
    26
    27  import java.io.IOException;
    28
    29  import javax.servlet.FilterChain;
    30  import javax.servlet.FilterConfig;
    31  import javax.servlet.ServletException;
    32  import javax.servlet.ServletRequest;
    33  import javax.servlet.ServletResponse;
    34
    35  import junit.framework.TestCase;
    36
    37  /***
    38   * JUnit test case for the
    39   * {@link org.huihoo.jfox.soaf.util.filter.CharacterEncodingFilter).
    40   *
    41   * @author <a href="mailto:founder_chen@yahoo.com">Peter Cheng </a>
    42   * @version $Revision: 1.1 $ $Date: 2005/04/27 08:06:32 $
    43   * @version Revision: 1.0
    44   */
    45
    46  public class EncodingFilterTest extends TestCase {
    47
    48      /***
    49       * @see TestCase#setUp()
    50       */
    51      protected void setUp() throws Exception {
    52          super.setUp();
    53      }
    54
    55      /***
    56       * @see TestCase#tearDown()
    57       */
    58      protected void tearDown() throws Exception {
    59          super.tearDown();
    60      }
    61
    62      /***
    63       * Test for method:
    64       * doFilter(javax.servlet.ServletRequest,javax.servlet.ServletResponse,javax.servlet.FilterChain)
    65       *
    66       * @see EncodingFilter#doFilter(javax.servlet.ServletRequest,javax.servlet.ServletResponse,javax.servlet.FilterChain)
    67       */
    68      public void testDoFilter() {
    69          EncodingFilter encodingFilter = new EncodingFilter();
    70          try {
    71              encodingFilter.doFilter((ServletRequest) null,
    72                      (ServletResponse) null, (FilterChain) null);
    73              // NullPointerException thrown
    74          } catch (NullPointerException e) {
    75          } catch (IOException e) {
    76              e.printStackTrace();
    77          } catch (ServletException e) {
    78              e.printStackTrace();
    79          }
    80      }
    81
    82      /***
    83       * Test for method:
    84       * doFilter(javax.servlet.ServletRequest,javax.servlet.ServletResponse,javax.servlet.FilterChain)
    85       *
    86       * @see EncodingFilter#doFilter(javax.servlet.ServletRequest,javax.servlet.ServletResponse,javax.servlet.FilterChain)
    87       */
    88      public void testDoFilter1() {
    89          EncodingFilter encodingFilter = new EncodingFilter();
    90          MockHttpServletRequest mockServletRequest = new MockHttpServletRequest();
    91          MockHttpServletResponse mockServletResponse = new MockHttpServletResponse();
    92          MockFilterChain mockServletChain = new MockFilterChain();
    93          try {
    94              encodingFilter.doFilter(mockServletRequest, mockServletResponse,
    95                      mockServletChain);
    96          } catch (IOException e) {
    97              e.printStackTrace();
    98          } catch (ServletException e) {
    99              e.printStackTrace();
    100         }
    101     }
    102
    103     /***
    104      * Test for method: init(javax.servlet.FilterConfig)
    105      *
    106      * @see EncodingFilter#init(javax.servlet.FilterConfig)
    107      */
    108     public void testInit() throws Throwable {
    109         EncodingFilter encodingFilter = new EncodingFilter();
    110         try {
    111             encodingFilter.init((FilterConfig) null);
    112             // NullPointerException thrown
    113         } catch (NullPointerException e) {
    114         }
    115     }
    116 }