Example usage for org.springframework.mock.web MockHttpServletRequest addParameter

List of usage examples for org.springframework.mock.web MockHttpServletRequest addParameter

Introduction

In this page you can find the example usage for org.springframework.mock.web MockHttpServletRequest addParameter.

Prototype

public void addParameter(String name, String... values) 

Source Link

Document

Add an array of values for the specified HTTP parameter.

Usage

From source file:org.hdiv.dataComposer.DataComposerFactoryTest.java

public void testNewInstanceAjax() {

    MockHttpServletRequest request = (MockHttpServletRequest) HDIVUtil.getHttpServletRequest();

    IDataComposer dataComposer = this.dataComposerFactory.newInstance(request);

    dataComposer.beginRequest("GET", "/ajax");
    String stateId = dataComposer.endRequest();
    dataComposer.endPage();//from  w ww. jav a 2s  .c o m

    // Create other instance
    request.addParameter("_HDIV_STATE_", stateId);
    request.addHeader("x-requested-with", "XMLHttpRequest");
    this.getConfig().setReuseExistingPageInAjaxRequest(true);

    dataComposer = this.dataComposerFactory.newInstance(request);

    dataComposer.beginRequest("GET", "/ajax");
    String stateId2 = dataComposer.endRequest();
    dataComposer.endPage();

    assertEquals(getPageId(stateId), getPageId(stateId2));
}

From source file:org.hdiv.dataComposer.DataComposerFactoryTest.java

public void testNewInstancePjax() {

    MockHttpServletRequest request = (MockHttpServletRequest) HDIVUtil.getHttpServletRequest();

    IDataComposer dataComposer = this.dataComposerFactory.newInstance(request);

    dataComposer.beginRequest("GET", "/ajax");
    String stateId = dataComposer.endRequest();
    dataComposer.endPage();//from w  w w. j  a v a 2 s.c  o m

    // Create other instance
    request.addParameter("_HDIV_STATE_", stateId);
    request.addHeader("x-requested-with", "XMLHttpRequest");
    request.addHeader("X-PJAX", "");
    this.getConfig().setReuseExistingPageInAjaxRequest(true);

    dataComposer = this.dataComposerFactory.newInstance(request);

    dataComposer.beginRequest("GET", "/ajax");
    String stateId2 = dataComposer.endRequest();
    dataComposer.endPage();

    // Next page id is expected
    assertEquals(getPageId(stateId), Integer.parseInt(getPageId(stateId2)) - 1 + "");
}

From source file:org.jasig.cas.web.flow.AuthenticationViaFormActionTests.java

@Test
public void testSuccessfulAuthenticationWithNoServiceAndWarn() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockRequestContext context = new MockRequestContext();

    request.addParameter("username", "test");
    request.addParameter("password", "test");
    request.addParameter("warn", "true");

    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    context.getRequestScope().put("credentials", TestUtils.getCredentialsWithSameUsernameAndPassword());
    //      this.action.bind(context);
    //     assertEquals("success", this.action.submit(context).getId());
    //        assertNotNull(response.getCookie(this.warnCookieGenerator
    //            .getCookieName()));
}

From source file:org.jasig.cas.web.flow.AuthenticationViaFormActionTests.java

@Test
public void testSuccessfulAuthenticationWithServiceAndWarn() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockRequestContext context = new MockRequestContext();

    request.addParameter("username", "test");
    request.addParameter("password", "test");
    request.addParameter("warn", "true");
    request.addParameter("service", "test");

    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    context.getRequestScope().put("credentials", TestUtils.getCredentialsWithSameUsernameAndPassword());
    //       this.action.bind(context);
    //       assertEquals("success", this.action.submit(context).getId());
    //        assertNotNull(response.getCookie(this.warnCookieGenerator
    //            .getCookieName()));
}

From source file:org.pentaho.platform.dataaccess.datasource.wizard.csv.FileUploadServiceTest.java

@Test
public void testUpload() throws Exception {

    PentahoSystemHelper.init();/*from www . j a v a 2  s  .  co  m*/
    StandaloneSession pSession = new StandaloneSession("12345678901234567890");
    PentahoSessionHolder.setSession(pSession);

    UUID uuid = UUIDUtil.getUUID();
    String fileName = uuid.toString();
    MockHttpSession session = new MockHttpSession(null, "12345678901234567890"); //$NON-NLS-1$
    MockHttpServletRequest request = new MockHttpServletRequest("POST", ""); //$NON-NLS-1$ //$NON-NLS-2$
    request.setSession(session);
    request.addParameter("file_name", fileName); //$NON-NLS-1$
    request.addParameter("mark_temporary", "true"); //$NON-NLS-1$ //$NON-NLS-2$
    request.setContentType("multipart/form-data; boundary=boundary"); //$NON-NLS-1$
    StringBuffer content = new StringBuffer();
    content.append("--boundary\r\n"); //$NON-NLS-1$
    content.append(
            "Content-Disposition: form-data; name=uploadFormElement; filename=test_file.csv\r\nContent-Type: multipart/form-data\r\n\r\n"); //$NON-NLS-1$ 

    content.append("REGIONC,NWEIGHT,HD65,xdate,Location,charlen,xfactor,Flag\r\n"); //$NON-NLS-1$
    content.append("3,25677.96525,1231,1/1/10,Afghanistan,11,111.9090909,0\r\n"); //$NON-NLS-1$
    content.append("4,24261.81026,1663,1/2/10,Albania,7,237.5714286,0\r\n"); //$NON-NLS-1$
    content.append("2,31806.29502,5221,1/3/10,Algeria,7,745.8571429,1\r\n");//$NON-NLS-1$
    content.append("4,22345.39749,5261,1/4/10,American Samoa,14,375.7857143,1\r\n");//$NON-NLS-1$
    content.append("4,22345.39749,5261,1/4/10,American Samoa,14,375.7857143,1\r\n");//$NON-NLS-1$
    content.append("3,25677.96525,1231,1/1/10,Afghanistan,11,111.9090909,0\r\n");//$NON-NLS-1$
    content.append("4,24261.81026,1663,1/2/10,Albania,7,237.5714286,0\r\n");//$NON-NLS-1$
    content.append("2,31806.29502,5221,1/3/10,Algeria,7,745.8571429,1\r\n");//$NON-NLS-1$
    content.append("4,22345.39749,5261,1/4/10,American Samoa,14,375.7857143,1\r\n");//$NON-NLS-1$

    content.append("--boundary--\r\n"); //$NON-NLS-1$
    request.setContent(content.toString().getBytes());
    UploadFileDebugServlet uploadServlet = new UploadFileDebugServlet();
    MockHttpServletResponse response = new MockHttpServletResponse();
    uploadServlet.service(request, response);

    response.getWriter().flush();
    response.getWriter().close();
    fileName = response.getContentAsString();
    String path = PentahoSystem.getApplicationContext().getSolutionPath(TMP_FILE_PATH);

    String filenameWithPath = path + File.separatorChar + fileName;
    File file = new File(filenameWithPath);
    assertTrue(file.exists());
    if (file.exists()) {
        file.delete();
    }
}

From source file:org.jasig.cas.web.flow.AuthenticationViaFormActionTests.java

@Test
public void testRenewWithServiceAndSameCredentials() throws Exception {
    final String ticketGrantingTicket = getCentralAuthenticationService()
            .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword());
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockRequestContext context = new MockRequestContext();

    context.getFlowScope().put("ticketGrantingTicketId", ticketGrantingTicket);
    request.addParameter("renew", "true");
    request.addParameter("service", "test");
    request.addParameter("username", "test");
    request.addParameter("password", "test");

    context.setExternalContext(//from  w  ww .j  a v  a2s  .c o m
            new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    context.getFlowScope().put("service", TestUtils.getService("test"));
    //    this.action.bind(context);
    //   assertEquals("warn", this.action.submit(context).getId());
}

From source file:org.jasig.cas.web.flow.AuthenticationViaFormActionTests.java

@Test
public void testRenewWithServiceAndDifferentCredentials() throws Exception {
    final String ticketGrantingTicket = getCentralAuthenticationService()
            .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword());
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockRequestContext context = new MockRequestContext();

    context.getFlowScope().put("ticketGrantingTicketId", ticketGrantingTicket);
    request.addParameter("renew", "true");
    request.addParameter("service", "test");
    request.addParameter("username", "test2");
    request.addParameter("password", "test2");

    context.setExternalContext(/*ww w .  java2s  . c om*/
            new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    //    this.action.bind(context);

    //    assertEquals("success", this.action.submit(context).getId());
}

From source file:org.jasig.cas.web.flow.AuthenticationViaFormActionTests.java

@Test
public void testRenewWithServiceAndBadCredentials() throws Exception {
    final String ticketGrantingTicket = getCentralAuthenticationService()
            .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword());
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockRequestContext context = new MockRequestContext();

    context.getFlowScope().put("ticketGrantingTicketId", ticketGrantingTicket);
    request.addParameter("renew", "true");
    request.addParameter("service", "test");

    context.setExternalContext(//from  w ww  .ja v  a  2s.  c om
            new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    context.getRequestScope().put("credentials", TestUtils.getCredentialsWithDifferentUsernameAndPassword());
    context.getRequestScope().put("org.springframework.validation.BindException.credentials",
            new BindException(TestUtils.getCredentialsWithDifferentUsernameAndPassword(), "credentials"));
    //     this.action.bind(context);
    //     assertEquals("error", this.action.submit(context).getId());
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.ConceptControllerTest.java

@Test
public void shouldReturnTheAuditInfoForTheFullRepresentation() throws Exception {
    MockHttpServletRequest httpReq = new MockHttpServletRequest();
    httpReq.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL);
    Object result = controller.retrieve("0dde1358-7fcf-4341-a330-f119241a46e8", httpReq);
    Assert.assertNotNull(result);/* ww w  .j a v  a  2s .  c o  m*/
    Assert.assertNotNull(PropertyUtils.getProperty(result, "auditInfo"));
}