Package net.sourceforge.stripes

Source Code of net.sourceforge.stripes.StripesTestFixture

package net.sourceforge.stripes;

import net.sourceforge.stripes.mock.MockServletContext;
import net.sourceforge.stripes.controller.StripesFilter;
import net.sourceforge.stripes.controller.DispatcherServlet;

import java.util.Map;
import java.util.HashMap;

/**
* Test fixture that sets up a MockServletContext in a way that it can then be
* used be any test in Stripes.
*
* @author Tim Fennell
*/
public class StripesTestFixture {
    private static MockServletContext context;

    /**
     * Gets a reference to the test MockServletContext. If the context is not already
     * instantiated and setup, it will be built lazily.
     *
     * @return an instance of MockServletContext for testing wiith
     */
    public static synchronized MockServletContext getServletContext() {
        if (context == null) {
            context = new MockServletContext("test");

            // Add the Stripes Filter
            Map<String,String> filterParams = new HashMap<String,String>();
            filterParams.put("ActionResolver.Packages", "net.sourceforge.stripes");
            filterParams.put("LocalePicker.Class", "net.sourceforge.stripes.localization.MockLocalePicker");
            context.addFilter(StripesFilter.class, "StripesFilter", filterParams);

            // Add the Stripes Dispatcher
            context.setServlet(DispatcherServlet.class, "StripesDispatcher", null);
        }

        return context;
    }
}
TOP

Related Classes of net.sourceforge.stripes.StripesTestFixture

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.