Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

Some tests in uPortal 3 that use classes from javax.servlet.* in their runtime environment need to be running within a servlet container.
Package org.jasig.portal.servlet in tests directory contains the following basic classes extending JUnit test functionality:

Test Servlet

This servlet performs HTTP tests using Reflection API and sends reports to the HTTP test runner which is a standalone Java application.
It uses the Spring config file to register HTTP test beans. uPortal 3 registers this servlet and its mappings in the web.xml.

     <servlet>
        <servlet-name>TestServlet</servlet-name>
        <display-name>Test servlet</display-name>
        <servlet-class>org.jasig.portal.servlet.TestServlet</servlet-class>
        <init-param>
            <param-name>contextFileName</param-name>
            <param-value>test_servlet_beans.xml</param-value>
        </init-param>
     </servlet>
     ...
     <!-- uPortal test services -->
     <servlet-mapping>
        <servlet-name>TestServlet</servlet-name>
        <url-pattern>/TestServlet/*</url-pattern>
     </servlet-mapping>

Where contextFileName is the URI to the beans Spring configuration file.
In the example above test beans are defined in the file test_servlet_beans.xml located in the same package:

<beans default-lazy-init="true">
         
    <bean id="containerTest" class="org.jasig.portal.portlet.container.HttpContainerTestBean" singleton="true">
    </bean>
	
    <bean id="portletUrlTest" class="org.jasig.portal.portlet.url.PortletUrlTest" singleton="true">
    </bean>
	
    <bean id="wsrpContainerTest" class="org.jasig.portal.wsrp.WsrpPortletContainerHttpTestBean" singleton="true">
    </bean>
	
</beans>

HTTP Test Runner

It works as a standalone socket server accepting TCP/IP connections from the test servlet and shows results of tests running by that servlet.
Connects to the test servlet to execute HTTP tests specified by the parameters:

  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.
    # 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.
  • No labels