View Javadoc

1   package org.apache.struts2.portlet.servlet;
2   
3   import org.apache.struts2.ServletActionContext;
4   import org.apache.struts2.StrutsTestCase;
5   import org.apache.struts2.dispatcher.mapper.ActionMapping;
6   import org.apache.struts2.portlet.PortletActionConstants;
7   import org.apache.struts2.portlet.context.PortletActionContext;
8   import org.springframework.mock.web.portlet.MockPortletContext;
9   import org.springframework.mock.web.portlet.MockPortletRequest;
10  
11  import com.opensymphony.xwork2.ActionContext;
12  
13  public class PortletServletRequestTest extends StrutsTestCase {
14  	
15  	private MockPortletRequest portletRequest;
16  	private MockPortletContext portletContext;
17  	private PortletServletRequest request;
18  	
19  	protected void setUp() throws Exception {
20  		super.setUp();
21  		portletRequest = new MockPortletRequest();
22  		portletContext = new MockPortletContext();
23  		request = new PortletServletRequest(portletRequest, portletContext);
24  	}
25  	
26  	public void testGetServletPathShouldHandleDefaultActionExtension() throws Exception {
27  		portletRequest.setParameter(PortletActionConstants.ACTION_PARAM, "actionName");
28  		request.setExtension("action");
29  		assertEquals("actionName.action", request.getServletPath());
30  	}
31  	
32  	public void testGetServletPathShouldHandleCustomActionExtension() throws Exception {
33  		portletRequest.setParameter(PortletActionConstants.ACTION_PARAM, "actionName");
34  		request.setExtension("custom");
35  		assertEquals("actionName.custom", request.getServletPath());
36  	}
37  	
38  	public void testGetServletPathShouldHandleNoExtension() throws Exception {
39  		portletRequest.setParameter(PortletActionConstants.ACTION_PARAM, "actionName");
40  		request.setExtension("");
41  		assertEquals("actionName", request.getServletPath());
42  	}
43  	
44  	public void testGetServletPathShouldHandleMultipleExtensionsByUsingTheFirst() throws Exception {
45  		portletRequest.setParameter(PortletActionConstants.ACTION_PARAM, "actionName");
46  		request.setExtension("action,,");
47  		assertEquals("actionName.action", request.getServletPath());
48  	}
49  }