Search in sources :

Example 1 with ResetViewData

use of org.motechproject.server.web.dto.ResetViewData in project motech by motech.

the class ResetControllerTest method testValidationErrors.

@Test
public void testValidationErrors() throws Exception {
    ResetViewData expected = getResetViewData(false, false, asList(ERROR), getResetForm(TOKEN, null, null));
    when(resetFormValidator.validate(any(ResetForm.class))).thenReturn(asList(ERROR));
    controller.perform(post("/forgotreset").locale(Locale.ENGLISH).body(new ObjectMapper().writeValueAsBytes(getResetForm(TOKEN, null, null))).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().string(new ObjectMapper().writeValueAsString(expected)));
}
Also used : ResetViewData(org.motechproject.server.web.dto.ResetViewData) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) ResetForm(org.motechproject.server.web.form.ResetForm) Test(org.junit.Test)

Example 2 with ResetViewData

use of org.motechproject.server.web.dto.ResetViewData in project motech by motech.

the class ResetControllerTest method testInvalidTokenOnView.

@Test
public void testInvalidTokenOnView() throws Exception {
    ResetViewData expected = getResetViewData(true, false, null, new ResetForm());
    when(recoveryService.validateToken(TOKEN)).thenReturn(false);
    controller.perform(get("/forgotresetviewdata").locale(Locale.ENGLISH)).andExpect(status().isOk()).andExpect(content().string(new ObjectMapper().writeValueAsString(expected)));
}
Also used : ResetViewData(org.motechproject.server.web.dto.ResetViewData) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) ResetForm(org.motechproject.server.web.form.ResetForm) Test(org.junit.Test)

Example 3 with ResetViewData

use of org.motechproject.server.web.dto.ResetViewData in project motech by motech.

the class ResetControllerTest method testReset.

@Test
public void testReset() throws Exception {
    ResetViewData expected = getResetViewData(false, true, new ArrayList<String>(), getResetForm(TOKEN, PASSWORD, PASSWORD));
    controller.perform(post("/forgotreset").locale(Locale.ENGLISH).body(new ObjectMapper().writeValueAsBytes(getResetForm(TOKEN, PASSWORD, PASSWORD))).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().string(new ObjectMapper().writeValueAsString(expected)));
    verify(recoveryService).resetPassword(TOKEN, PASSWORD, PASSWORD);
}
Also used : ResetViewData(org.motechproject.server.web.dto.ResetViewData) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 4 with ResetViewData

use of org.motechproject.server.web.dto.ResetViewData in project motech by motech.

the class ResetControllerTest method getResetViewData.

private ResetViewData getResetViewData(boolean invalidToken, boolean resetSuceed, List<String> errors, ResetForm resetForm) {
    ResetViewData resetViewData = new ResetViewData();
    resetViewData.setInvalidToken(invalidToken);
    resetViewData.setResetSucceed(resetSuceed);
    resetViewData.setPageLang(Locale.ENGLISH);
    resetViewData.setErrors(errors);
    resetViewData.setResetForm(resetForm);
    return resetViewData;
}
Also used : ResetViewData(org.motechproject.server.web.dto.ResetViewData)

Example 5 with ResetViewData

use of org.motechproject.server.web.dto.ResetViewData in project motech by motech.

the class ResetControllerTest method testValidView.

@Test
public void testValidView() throws Exception {
    ResetViewData expected = getResetViewData(false, false, null, getResetForm(TOKEN, null, null));
    when(recoveryService.validateToken(TOKEN)).thenReturn(true);
    controller.perform(get("/forgotresetviewdata").locale(Locale.ENGLISH).param(TOKEN, TOKEN)).andExpect(status().isOk()).andExpect(content().string(new ObjectMapper().writeValueAsString(expected)));
}
Also used : ResetViewData(org.motechproject.server.web.dto.ResetViewData) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Aggregations

ResetViewData (org.motechproject.server.web.dto.ResetViewData)8 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)5 Test (org.junit.Test)5 ResetForm (org.motechproject.server.web.form.ResetForm)3 InvalidTokenException (org.motechproject.security.exception.InvalidTokenException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2