Search in sources :

Example 1 with MockServletConfig

use of org.apache.struts.mock.MockServletConfig in project sonarqube by SonarSource.

the class TestAuthorizeAction method setUp.

/* setUp method for test case */
protected void setUp() throws Exception {
    this.request = new MockHttpServletRequest();
    this.principal = new MockPrincipal("Mr. Macri", new String[] { "administrator" });
    this.request.setUserPrincipal(principal);
    MockServletConfig servletConfig = new MockServletConfig();
    MockServletContext servletContext = new MockServletContext();
    MockActionServlet servlet = new MockActionServlet(servletContext, servletConfig);
    servlet.initInternal();
    this.saContext = new ServletActionContext(servletContext, request, new MockHttpServletResponse());
    this.saContext.setActionServlet(servlet);
    this.command = new AuthorizeAction();
}
Also used : MockActionServlet(org.apache.struts.mock.MockActionServlet) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) MockPrincipal(org.apache.struts.mock.MockPrincipal) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) MockServletConfig(org.apache.struts.mock.MockServletConfig) MockServletContext(org.apache.struts.mock.MockServletContext) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse)

Example 2 with MockServletConfig

use of org.apache.struts.mock.MockServletConfig in project sonarqube by SonarSource.

the class TestPerformForward method setUp.

/* setUp method for test case */
protected void setUp() throws Exception {
    this.request = new MockHttpServletRequest();
    this.principal = new MockPrincipal("Mr. Macri", new String[] { "administrator" });
    this.request.setUserPrincipal(principal);
    MockServletConfig servletConfig = new MockServletConfig();
    MockServletContext servletContext = new MockServletContext();
    MockActionServlet servlet = new MockActionServlet(servletContext, servletConfig);
    servlet.initInternal();
    this.saContext = new ServletActionContext(servletContext, request, new MockHttpServletResponse());
    this.saContext.setActionServlet(servlet);
    this.command = new PerformForward();
}
Also used : MockActionServlet(org.apache.struts.mock.MockActionServlet) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) MockPrincipal(org.apache.struts.mock.MockPrincipal) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) MockServletConfig(org.apache.struts.mock.MockServletConfig) MockServletContext(org.apache.struts.mock.MockServletContext) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse)

Example 3 with MockServletConfig

use of org.apache.struts.mock.MockServletConfig in project sonarqube by SonarSource.

the class TestSetOriginalURI method testSetOriginalURI.

public void testSetOriginalURI() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("foo/", "bar.do", null, null);
    MockServletConfig servletConfig = new MockServletConfig();
    MockServletContext servletContext = new MockServletContext();
    MockActionServlet servlet = new MockActionServlet(servletContext, servletConfig);
    servlet.initInternal();
    ServletActionContext saContext = new ServletActionContext(servletContext, request, new MockHttpServletResponse());
    saContext.setActionServlet(servlet);
    boolean result = command.execute(saContext);
    assertTrue(!result);
    String uri = (String) request.getAttribute(Globals.ORIGINAL_URI_KEY);
    assertTrue("Original uri not correct: " + uri, "bar.do".equals(uri));
    request.setPathElements("foo/", "bar2.do", null, null);
    uri = (String) request.getAttribute(Globals.ORIGINAL_URI_KEY);
    assertTrue("Original uri not correct: " + uri, "bar.do".equals(uri));
}
Also used : MockActionServlet(org.apache.struts.mock.MockActionServlet) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) MockServletConfig(org.apache.struts.mock.MockServletConfig) MockServletContext(org.apache.struts.mock.MockServletContext) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse)

Example 4 with MockServletConfig

use of org.apache.struts.mock.MockServletConfig in project sonarqube by SonarSource.

the class TagTestBase method setUp.

/**
     * Helper method that creates/configures a basic configuration of Mock
     * Objects.
     *
     *
     * PageContext ServletConfig ServletContext HttpServletRequest HttpSession
     * HttpServletResponse
     *
     * "/myapp", "/foo", null, null,
     */
public void setUp() {
    // -- default Module
    this.moduleConfig = new ModuleConfigImpl("");
    this.moduleConfig.addForwardConfig(new ForwardConfig("foo", "/bar.jsp", false));
    this.moduleConfig.addForwardConfig(new ForwardConfig("relative1", "relative.jsp", false));
    this.moduleConfig.addForwardConfig(new ForwardConfig("relative2", "relative.jsp", false));
    this.moduleConfig.addForwardConfig(new ForwardConfig("external", "http://struts.apache.org/", false));
    // -- module "/2"
    this.moduleConfig2 = new ModuleConfigImpl("/2");
    this.moduleConfig2.addForwardConfig(new ForwardConfig("foo", "/baz.jsp", false));
    this.moduleConfig2.addForwardConfig(new ForwardConfig("relative1", "relative.jsp", false));
    this.moduleConfig2.addForwardConfig(new ForwardConfig("relative2", "relative.jsp", false));
    this.moduleConfig2.addForwardConfig(new ForwardConfig("external", "http://struts.apache.org/", false));
    // -- module "/3"
    this.moduleConfig3 = new ModuleConfigImpl("/3");
    // -- configure the ServletContext
    this.servletContext = new MockServletContext();
    this.servletContext.setAttribute(Globals.MODULE_KEY, moduleConfig);
    this.servletContext.setAttribute(Globals.MODULE_KEY + "/2", moduleConfig2);
    this.servletContext.setAttribute(Globals.MODULE_KEY + "/3", moduleConfig3);
    // -- configure the ServletConfig
    this.servletConfig = new MockServletConfig();
    this.servletConfig.setServletContext(servletContext);
    // -- configure the request
    this.request = new MockHttpServletRequest(new MockHttpSession());
    pageContext = new MockPageContext(servletConfig, request, new MockHttpServletResponse());
}
Also used : MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) MockServletConfig(org.apache.struts.mock.MockServletConfig) MockHttpSession(org.apache.struts.mock.MockHttpSession) MockPageContext(org.apache.struts.mock.MockPageContext) ForwardConfig(org.apache.struts.config.ForwardConfig) ModuleConfigImpl(org.apache.struts.config.impl.ModuleConfigImpl) MockServletContext(org.apache.struts.mock.MockServletContext) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse)

Example 5 with MockServletConfig

use of org.apache.struts.mock.MockServletConfig in project sonarqube by SonarSource.

the class TestHtmlTag method setUp.

/**
     * Set up mock objects.
     */
public void setUp() {
    config = new MockServletConfig();
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    pageContext = new MockPageContext(config, request, response);
    htmlTag = new HtmlTag();
    htmlTag.setPageContext(pageContext);
}
Also used : MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) MockServletConfig(org.apache.struts.mock.MockServletConfig) MockPageContext(org.apache.struts.mock.MockPageContext) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse)

Aggregations

MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)6 MockHttpServletResponse (org.apache.struts.mock.MockHttpServletResponse)6 MockServletConfig (org.apache.struts.mock.MockServletConfig)6 MockServletContext (org.apache.struts.mock.MockServletContext)5 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)3 MockActionServlet (org.apache.struts.mock.MockActionServlet)3 MockPageContext (org.apache.struts.mock.MockPageContext)3 ModuleConfigImpl (org.apache.struts.config.impl.ModuleConfigImpl)2 MockPrincipal (org.apache.struts.mock.MockPrincipal)2 ForwardConfig (org.apache.struts.config.ForwardConfig)1 ModuleConfig (org.apache.struts.config.ModuleConfig)1 MockHttpSession (org.apache.struts.mock.MockHttpSession)1