FileDocCategorySizeDatePackage
DispatcherTest.javaAPI DocExample5110Mon Jul 23 13:26:12 BST 2007org.apache.struts2.dispatcher

DispatcherTest

public class DispatcherTest extends org.apache.struts2.StrutsTestCase
Test case for Dispatcher.

Fields Summary
Constructors Summary
Methods Summary
public voidtestConfigurationManager()

    	Dispatcher du = null;
    	InternalConfigurationManager configurationManager = new InternalConfigurationManager();
    	try {
    		du = new Dispatcher(new MockServletContext(), new HashMap<String, String>());
    		du.setConfigurationManager(configurationManager);
    		
    		du.init();
    		
            Dispatcher.setInstance(du);
            
            assertFalse(configurationManager.destroyConfiguration);
            
            du.cleanup();
            
            assertTrue(configurationManager.destroyConfiguration);
            
    	}
    	finally {
    		du.setInstance(null);
    	}
    
public voidtestDefaultResurceBundlePropertyLoaded()

        Locale.setDefault(Locale.US); // force to US locale as we also have _de and _da properties

        // some i18n messages from xwork-messages.properties
        assertEquals(
                LocalizedTextUtil.findDefaultText("xwork.error.action.execution", Locale.US),
                "Error during Action invocation");

        // some i18n messages from struts-messages.properties
        assertEquals(
                LocalizedTextUtil.findDefaultText("struts.messages.error.uploading", Locale.US,
                        new Object[] { "some error messages" }),
                "Error uploading: some error messages");
    
public voidtestDispatcherListener()

    	
    	final DispatcherListenerState state = new DispatcherListenerState();
    	
    	Dispatcher.addDispatcherListener(new DispatcherListener() {
			public void dispatcherDestroyed(Dispatcher du) {
				state.isDestroyed = true;
			}
			public void dispatcherInitialized(Dispatcher du) {
				state.isInitialized = true;
			}
    	});
    	
    	
    	assertFalse(state.isDestroyed);
    	assertFalse(state.isInitialized);
    	
        Dispatcher du = initDispatcher(new HashMap<String, String>() );
    	
    	assertTrue(state.isInitialized);
    	
    	du.cleanup();
    	
    	assertTrue(state.isDestroyed);
    
public voidtestPrepareSetEncodingProperly()

        HttpServletRequest req = new MockHttpServletRequest();
        HttpServletResponse res = new MockHttpServletResponse();

        Dispatcher du = initDispatcher(new HashMap() {{
            put(StrutsConstants.STRUTS_I18N_ENCODING, "utf-8");
        }});
        du.prepare(req, res);

        assertEquals(req.getCharacterEncoding(), "utf-8");
    
public voidtestPrepareSetEncodingPropertyWithMultipartRequest()

        MockHttpServletRequest req = new MockHttpServletRequest();
        MockHttpServletResponse res = new MockHttpServletResponse();

        req.setContentType("multipart/form-data");
        Dispatcher du = initDispatcher(new HashMap() {{
            put(StrutsConstants.STRUTS_I18N_ENCODING, "utf-8");
        }});
        du.prepare(req, res);

        assertEquals("utf-8", req.getCharacterEncoding());