View Javadoc

    1   /*
    2    * $Id: StrutsTestCaseHelper.java 502294 2007-02-01 17:28:00Z niallp $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
    10   * with the License.  You may obtain a copy of the License at
    11   *
    12   *  http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing,
    15   * software distributed under the License is distributed on an
    16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    17   * KIND, either express or implied.  See the License for the
    18   * specific language governing permissions and limitations
    19   * under the License.
    20   */
    21  package org.apache.struts2.util;
    22
    23  import java.util.HashMap;
    24  import java.util.Map;
    25
    26  import org.apache.struts2.dispatcher.Dispatcher;
    27  import org.springframework.mock.web.MockServletContext;
    28
    29  import com.opensymphony.xwork2.util.LocalizedTextUtil;
    30
    31  /***
    32   * Generic test setup methods to be used with any unit testing framework.
    33   */
    34  public class StrutsTestCaseHelper {
    35
    36      /***
    37       * Sets up the configuration settings, XWork configuration, and
    38       * message resources
    39       */
    40      public static void setUp() throws Exception {
    41          LocalizedTextUtil.clearDefaultResourceBundles();
    42      }
    43
    44      public static Dispatcher initDispatcher(Map<String,String> params) {
    45          if (params == null) {
    46              params = new HashMap<String,String>();
    47          }
    48          Dispatcher du = new Dispatcher(new MockServletContext(), params);
    49          du.init();
    50          Dispatcher.setInstance(du);
    51          return du;
    52      }
    53
    54      public static void tearDown() throws Exception {
    55          Dispatcher.setInstance(null);
    56      }
    57  }