Ejemplo n.º 1
0
  @Test
  @TransactionalReadWrite
  public void testInitSettingsPage() {
    User user =
        testUtils.createAuthenticatedTestUser("SettingsControllerTest@testInitSettingsPage");

    ModelMap model = new ModelMap();
    assertEquals("logged/settings", controller.initSettingsPage(model));
    assertTrue(model.containsAttribute("settingsform"));
    SettingsForm settingsForm = (SettingsForm) model.get("settingsform");
    assertEquals(user.getEmail(), settingsForm.getEmail());
    assertEquals(user.getEmail(), settingsForm.getCurrentEmail());
    assertEquals("no", settingsForm.getEditPassword());
    assertEquals(user.getLanguage().getCode(), settingsForm.getLang());
  }
Ejemplo n.º 2
0
  @Test
  @TransactionalReadWrite
  public void testUpdateAccountWithErrors() {
    testUtils.createAuthenticatedTestUser("SettingsControllerTest@testUpdateAccountWithErrors");

    // Create request and session
    MockHttpServletRequest request = new MockHttpServletRequest("post", "/settings");
    MockHttpSession session = new MockHttpSession();
    request.setSession(session);
    assertNull(session.getAttribute("settings_ko"));

    // Create settings
    SettingsForm settingsForm = new SettingsForm();
    settingsForm.setEditPassword("no");
    settingsForm.setEmail("OTHER_EMAIL");
    ModelAndView modelAndView = getModelAndViewSettingsPage(null, settingsForm, request);

    assertNotNull(session.getAttribute("settings_ko"));
    assertEquals("logged/settings", modelAndView.getViewName());
  }
Ejemplo n.º 3
0
  @Test
  @TransactionalReadWrite
  public void testUpdateAccount() {
    User user = testUtils.createAuthenticatedTestUser("SettingsControllerTest@testUpdateAccount");

    // Create request and session
    MockHttpServletRequest request = new MockHttpServletRequest("post", "/settings");
    MockHttpSession session = new MockHttpSession();
    request.setSession(session);
    assertNull(session.getAttribute("settings_ok"));

    // Create settings
    SettingsForm settingsForm = new SettingsForm();
    settingsForm.setEditPassword("no");
    settingsForm.setEmail(user.getEmail());
    settingsForm.setLang(testUtils.LOCALE_US);
    ModelAndView modelAndView = getModelAndViewSettingsPage(null, settingsForm, request);

    assertNotNull(session.getAttribute("settings_ok"));
    assertEquals("redirectWithoutModel:settings", modelAndView.getViewName());
  }