use of javax.transaction.Transactional in project neubbs by nuitcoder.
the class UserDAOTest method testUpdateUser.
/**
* 测试更新用户个人资料
*/
@Test
@Transactional
public void testUpdateUser() {
UserDO user = this.getTestUserDO();
Assert.assertEquals(1, userDAO.saveUser(user));
System.out.println("old user information: " + JsonUtil.toJsonString(userDAO.getUserByName(user.getName())));
String username = user.getName();
int sex = 1;
String birthday = "2012-12-8";
String position = "Guangdong province, Shengzhen city";
String description = "Nothing is impossible";
UserDO newUser = new UserDO();
newUser.setName(username);
newUser.setSex(sex);
newUser.setPosition(position);
newUser.setBirthday(birthday);
newUser.setDescription(description);
Assert.assertEquals(1, userDAO.updateUser(newUser));
UserDO reSelectUser = userDAO.getUserByName(username);
Assert.assertEquals(sex, (int) reSelectUser.getSex());
Assert.assertEquals(birthday, reSelectUser.getBirthday());
Assert.assertEquals(position, reSelectUser.getPosition());
Assert.assertEquals(description, reSelectUser.getDescription());
System.out.println("new user information: " + reSelectUser);
System.out.println("update name=" + username + " user information success!");
}
use of javax.transaction.Transactional in project neubbs by nuitcoder.
the class UserDynamicDAOTest method testUpdatePublicInfoJsonArrayByOneDynamicInforToAppendEnd.
/**
* 测试发布用户动态信息 JSON 数组(JSON 数组,末尾追加)
*/
@Test
@Transactional
public void testUpdatePublicInfoJsonArrayByOneDynamicInforToAppendEnd() {
UserDynamicDO userDynamic = this.saveTestUserDynamicDOToDatabase();
int userId = userDynamic.getUserId();
System.out.println("before append: " + userDynamic);
// build user dynamic json information:
JSONArray jsonUserDynamic = JSON.parseArray(userDynamic.getPublicInfoJsonArray());
int currentJsonLength = jsonUserDynamic.size();
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", currentJsonLength + 1);
jsonObject.put("createTime", System.currentTimeMillis());
jsonObject.put("content", "today very happy");
jsonObject.put("visibilityType", "myself");
Assert.assertEquals(1, userDynamicDAO.updatePublicInfoJsonArrayByOneDynamicInfoToAppendEnd(userId, jsonObject.toJSONString()));
UserDynamicDO afterUserDynamic = userDynamicDAO.getUserDynamic(userId);
Assert.assertEquals(1, JSON.parseArray(afterUserDynamic.getPublicInfoJsonArray()).size());
System.out.println("after append: " + afterUserDynamic);
System.out.println("update user dynamic append on information success!");
}
use of javax.transaction.Transactional in project neubbs by nuitcoder.
the class UserDAOTest method testUpdateUserPasswordByName.
/**
* 测试更新用户密码
*/
@Test
@Transactional
public void testUpdateUserPasswordByName() {
UserDO user = this.getTestUserDO();
Assert.assertEquals(1, userDAO.saveUser(user));
String username = "testUser";
String newPassword = SecretUtil.encryptMd5(SecretUtil.encryptMd5("45678") + "45678");
Assert.assertEquals(1, userDAO.updateUserPasswordByName(username, newPassword));
Assert.assertEquals(newPassword, userDAO.getUserByName(username).getPassword());
System.out.println("update username=" + username + " password to <" + newPassword + "> success!");
}
use of javax.transaction.Transactional in project neubbs by nuitcoder.
the class UserDAOTest method testGetUserByName.
/**
* 测试 name 查询用户
*/
@Test
@Transactional
public void testGetUserByName() {
UserDO user = this.getTestUserDO();
Assert.assertEquals(1, userDAO.saveUser(user));
Assert.assertNotNull(userDAO.getUserByName(user.getName()));
System.out.println("get name=" + user.getName() + " user information:" + user);
}
use of javax.transaction.Transactional 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