use of org.neusoft.neubbs.service.ICacheService in project neubbs by nuitcoder.
the class AccountControllerTest method testActivateAccountException.
/**
* 测试 /api/account/activate
* - 测试激活账户异常
* - request param error
* - [✔] null
* - [✔] format not norm
* - service exception
* - [✔] no user
* - [✔] 60s send mail interval time for the same account
*/
@Test
@Transactional
public void testActivateAccountException() throws Exception {
// request param error
String[] params = { null, "123", "test@", "liushuwei0925@gmail.com" };
for (String email : params) {
String requestBody = "{\"email\":\"" + email + "\"}";
System.out.println("input post param request-body: " + requestBody);
try {
mockMvc.perform(MockMvcRequestBuilders.post("/api/account/activate").contentType(MediaType.APPLICATION_JSON).content(requestBody).accept(MediaType.APPLICATION_JSON)).andExpect(MockMvcResultMatchers.jsonPath("$.success").value(false)).andExpect(MockMvcResultMatchers.jsonPath("$.message").exists()).andExpect(MockMvcResultMatchers.jsonPath("$.model").exists());
} catch (NestedServletException ne) {
Assert.assertThat(ne.getRootCause(), CoreMatchers.anyOf(CoreMatchers.instanceOf(ParamsErrorException.class), CoreMatchers.instanceOf(ServiceException.class)));
}
}
// test again send mail, exist interval time(not sent repeatedly)
String email = "testActivate@test.com";
userService.registerUser(email.substring(0, email.indexOf("@")), "123456", email);
// cache server set 60s send mail interval time for the same account
ICacheService redisService = (ICacheService) webApplicationContext.getBean("redisServiceImpl");
redisService.saveUserEmailKey(email);
mockMvc.perform(MockMvcRequestBuilders.post("/api/account/activate").contentType(MediaType.APPLICATION_JSON).content("{\"email\":\"" + email + "\"}").accept(MediaType.APPLICATION_JSON)).andExpect(MockMvcResultMatchers.jsonPath("$.success").value(false)).andExpect(MockMvcResultMatchers.jsonPath("$.message").value(ApiMessage.WAIT_TIMER)).andExpect(MockMvcResultMatchers.jsonPath("$.model").exists()).andExpect(MockMvcResultMatchers.jsonPath("$.model.timer").value(CoreMatchers.notNullValue()));
System.out.println("send email exist interval time limit , test success!");
util.printSuccessMessage();
}
Aggregations