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

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

Introduction

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

Prototype

@Override
public Locale getLocale() 

Source Link

Document

Return the first preferred Locale locale configured in this mock request.

Usage

From source file:org.springframework.test.web.servlet.htmlunit.HtmlUnitRequestBuilderTests.java

@Test
public void buildRequestLocaleFr() {
    webRequest.setAdditionalHeader("Accept-Language", "fr");

    MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);

    assertThat(actualRequest.getLocale(), equalTo(Locale.FRENCH));
}

From source file:alpha.portal.webapp.controller.CaseFormControllerTest.java

/**
 * Test delete./*www.j a va 2s .  c om*/
 * 
 * @throws Exception
 *             the exception
 */
@Test
public void testDelete() throws Exception {
    MockHttpServletRequest request = this.newGet("/caseform");
    request.setParameter("caseId", CaseFormControllerTest.caseId);
    request.setRemoteUser("admin");
    final ModelAndView mv = this.form.showForm(this.filters, request, new MockHttpServletResponse());
    final AlphaCase myCase = (AlphaCase) mv.getModel().get("case");

    request = this.newPost("/caseform");
    request.setRemoteUser("admin");
    request.addParameter("delete", "");

    final BindingResult errors = new DataBinder(myCase).getBindingResult();
    final String view = this.form.deleteCase(myCase, errors, request);
    Assert.assertEquals(this.form.getCancelView(), view);
    Assert.assertNotNull(request.getSession().getAttribute("successMessages"));

    final Locale locale = request.getLocale();
    final ArrayList<Object> msgs = (ArrayList<Object>) request.getSession().getAttribute("successMessages");
    Assert.assertTrue(msgs.contains(this.form.getText("case.deleted", locale)));

    Assert.assertFalse(this.caseManager.exists(CaseFormControllerTest.caseId));
}

From source file:alpha.portal.webapp.controller.CaseFormControllerTest.java

/**
 * Test add.//from   w ww.  j  av a 2 s  .  c o  m
 * 
 * @throws Exception
 *             the exception
 */
@Test
public void testAdd() throws Exception {
    MockHttpServletRequest request = this.newGet("/caseform");
    request.setRemoteUser("admin");
    final ModelAndView mv = this.form.showForm(this.filters, request, new MockHttpServletResponse());

    request = this.newPost("/caseform");
    request.setRemoteUser("admin");
    final AlphaCase aCase = (AlphaCase) mv.getModel().get("case");
    aCase.setName("test case which does not exist yet");
    final BindingResult errors = new DataBinder(aCase).getBindingResult();
    final String view = this.form.addCase(aCase, errors, request, new MockHttpServletResponse());

    final List<AlphaCase> dbCases = this.caseManager.findByName(aCase.getName());
    Assert.assertNotNull(dbCases);
    Assert.assertTrue(dbCases.size() >= 1);
    final AlphaCase dbCase = dbCases.get(0);
    Assert.assertNotNull(dbCase);
    Assert.assertEquals("redirect:/caseform?caseId=" + dbCase.getCaseId(), view);
    Assert.assertFalse(errors.hasErrors());
    Assert.assertNotNull(request.getSession().getAttribute("successMessages"));

    final Locale locale = request.getLocale();
    final ArrayList<Object> msgs = (ArrayList<Object>) request.getSession().getAttribute("successMessages");
    Assert.assertTrue(msgs.contains(this.form.getText("case.added", locale)));
}

From source file:alpha.portal.webapp.controller.CaseFormControllerTest.java

/**
 * Test edit./*from  w w  w.j av  a  2  s . c  o  m*/
 * 
 * @throws Exception
 *             the exception
 */
@Test
public void testEdit() throws Exception {
    MockHttpServletRequest request = this.newGet("/caseform");
    request.setParameter("caseId", CaseFormControllerTest.caseId);
    request.setRemoteUser("admin");
    final ModelAndView mv = this.form.showForm(this.filters, request, new MockHttpServletResponse());
    Assert.assertEquals("caseform", mv.getViewName());
    final AlphaCase aCase = (AlphaCase) mv.getModel().get("case");
    AlphaCase dbCase = this.caseManager.get(CaseFormControllerTest.caseId);
    Assert.assertEquals(dbCase, aCase);
    Assert.assertEquals(dbCase.getAlphaCards(), mv.getModel().get("cards"));
    Assert.assertEquals(dbCase.getListOfParticipants(), mv.getModel().get("participants"));

    request = this.newPost("/caseform");
    request.setRemoteUser("admin");
    aCase.setName("test case with a new name");
    final BindingResult errors = new DataBinder(aCase).getBindingResult();
    final String view = this.form.saveCase(aCase, errors, request, new MockHttpServletResponse());
    Assert.assertEquals("redirect:/caseform?caseId=" + aCase.getCaseId(), view);
    Assert.assertFalse(errors.hasErrors());
    Assert.assertNotNull(request.getSession().getAttribute("successMessages"));

    final Locale locale = request.getLocale();
    final ArrayList<Object> msgs = (ArrayList<Object>) request.getSession().getAttribute("successMessages");
    Assert.assertTrue(msgs.contains(this.form.getText("case.updated", locale)));

    dbCase = this.caseManager.get(CaseFormControllerTest.caseId);
    /* FIXME: something is broken (return structure is an empty thing) */
    // Assert.assertEquals(dbCase, aCase);
}

From source file:org.springframework.test.web.servlet.htmlunit.HtmlUnitRequestBuilderTests.java

@Test
public void buildRequestLocaleEnGbQ08() {
    webRequest.setAdditionalHeader("Accept-Language", "en-gb;q=0.8");

    MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);

    assertThat(actualRequest.getLocale(), equalTo(new Locale("en", "gb")));
}

From source file:org.springframework.test.web.servlet.htmlunit.HtmlUnitRequestBuilderTests.java

@Test
public void buildRequestLocaleEnQ07() {
    webRequest.setAdditionalHeader("Accept-Language", "en");

    MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);

    assertThat(actualRequest.getLocale(), equalTo(new Locale("en", "")));
}