Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

  1. bean - defines the name of the test bean
  2. method - defines the name of the test method to be executed
  3. connect - if true the test servlet will send the report to the HTTP test runner
    The httptestrunner.properties sets the port number of the socket server and the test servlet URL.
    No Format
    # The test runner properties
    # Server socket port for communication with the test servlet
    server_socket_port = 10999
    # Tomcat port
    web_app_port = 8080
    # Test servlet URL, must start with "/"
    servletUrl = /uP3/TestServlet
    
    The test runner reads the list of test beans from the same Spring configuration file which URL is provided by the test servlet.

    HttpTestCase class

    It is an extension of JUnit's TestCase with its own initTest() method to initialize a test bean with ServletConfig, HttpServletRequest and HttpServletResponse. Accepts all assertions supported by JUnit. Subclasses need to be registered within the Spring config file of the test servlet. PortletUrlTest is an example of the HTTP test bean:
    Code Block
    borderStylesolid
    titlePortletUrlTest.java
    borderStylesolid
    /* Copyright 2004 The JA-SIG Collaborative.  All rights reserved.
     * See license distributed with this file and
     * available online at http://www.uportal.org/license.html
     */
    
    package org.jasig.portal.portlet.url;
    
    ...
    
    import org.jasig.portal.servlet.HttpTestCase;
    
    
    /**
     * Tests for the IPortletUrl impls
     *
     * @author Michael Ivanov: mivanov at unicon.net
     *
     */
    public class PortletUrlTest extends HttpTestCase {
    
        ...
        
        /**
         * @see TestCase#setUp()
         */
        protected void setUp() throws Exception {
            
        }
        
        private IPortletWindow getTestPortletWindow() {
        	return new PortletWindowImpl(new PortletEntityImpl(),PortletIdFactory.createPortletWindowId("1")); 
        }
    
        public void testUrlProcessor() {
        	
        	String param1 = "param1";
        	String param2 = "param2";
        	String value11 = "value11";
        	String value21 = "value21";
        	String value22 = "value22";
        	
        	IPortletWindow window  = getTestPortletWindow();
        	
        	PortletRequestParameterProcessor processor = new PortletRequestParameterProcessor();
        	IPortletWindowManager windowManager = new MockPortletWindowManager();
        	IPortletParameterSyntaxProvider syntaxProvider = new PortletParameterSyntaxProviderImpl();
        	
        	processor.setWindowManager(windowManager);
        	processor.setParameterSyntaxProvider(syntaxProvider);
        	
            // Writing parameters into request
        	WritableHttpServletRequestImpl writer = new WritableHttpServletRequestImpl(getRequest());
        	writer.setParameterValues(syntaxProvider.getRequestParameterName(param1,window.getObjectId()),new String[] { value11 });
        	writer.setParameterValues(syntaxProvider.getRequestParameterName(param2,window.getObjectId()),new String[] { value21, value22 });
        	writer.setParameterValues(syntaxProvider.getWindowStateCommandName(window.getObjectId()),new String[] { WindowState.MAXIMIZED.toString() });
        	writer.setParameterValues(syntaxProvider.getPortletModeCommandName(window.getObjectId()),new String[] { PortletMode.HELP.toString() });
        	writer.setParameterValues(syntaxProvider.getActionTargetCommandName(),new String[] { window.getObjectId().toString() });
        	
        	// Checking the syntax provider
        	assertTrue(syntaxProvider.isPortletModeCommand(syntaxProvider.getPortletModeCommandName(window.getObjectId())));
        	assertTrue(syntaxProvider.isWindowStateCommand(syntaxProvider.getWindowStateCommandName(window.getObjectId())));
        	assertTrue(syntaxProvider.isPortletParameter(syntaxProvider.getRequestParameterName(param1,window.getObjectId())));
        	assertTrue(syntaxProvider.isPortletParameter(syntaxProvider.getRequestParameterName(param2,window.getObjectId())));
        	
        	// Parameter processing
        	processor.processParameters(writer,getResponse());
        	
        	assertEquals(windowManager.getPortletMode(window.getObjectId(),getRequest()),PortletMode.HELP);
        	assertEquals(windowManager.getWindowState(window.getObjectId(),getRequest()),WindowState.MAXIMIZED);
        	assertEquals(syntaxProvider.getRealParameterName(syntaxProvider.getRequestParameterName(param1,window.getObjectId())),param1);
        	assertEquals(syntaxProvider.getRequestParameterName(param2,window.getObjectId()),
            syntaxProvider.getRequestParameterName(syntaxProvider.getRealParameterName(syntaxProvider.getRequestParameterName(param2,window.getObjectId())),window.getObjectId()));
        	
        	
        }
    
        // Some other test methods
        ...
        
    }