Search in sources :

Example 96 with Transactional

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!");
}
Also used : UserDO(org.neusoft.neubbs.entity.UserDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 97 with Transactional

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!");
}
Also used : UserDynamicDO(org.neusoft.neubbs.entity.UserDynamicDO) JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 98 with Transactional

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!");
}
Also used : UserDO(org.neusoft.neubbs.entity.UserDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 99 with Transactional

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);
}
Also used : UserDO(org.neusoft.neubbs.entity.UserDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 100 with Transactional

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();
}
Also used : ParamsErrorException(org.neusoft.neubbs.exception.ParamsErrorException) NestedServletException(org.springframework.web.util.NestedServletException) ServiceException(org.neusoft.neubbs.exception.ServiceException) ICacheService(org.neusoft.neubbs.service.ICacheService) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Aggregations

Transactional (javax.transaction.Transactional)299 Test (org.junit.Test)99 PostResult (org.collectiveone.common.dto.PostResult)29 ArrayList (java.util.ArrayList)24 UserDO (org.neusoft.neubbs.entity.UserDO)21 Timestamp (java.sql.Timestamp)18 TopicDO (org.neusoft.neubbs.entity.TopicDO)18 Initiative (org.collectiveone.modules.initiatives.Initiative)16 GetResult (org.collectiveone.common.dto.GetResult)15 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)13 TopicReplyDO (org.neusoft.neubbs.entity.TopicReplyDO)13 HashMap (java.util.HashMap)12 Date (java.util.Date)11 AppUser (org.collectiveone.modules.users.AppUser)11 UUID (java.util.UUID)10 RolesAllowed (javax.annotation.security.RolesAllowed)10 PeerReviewedAssignation (org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 IOException (java.io.IOException)9 TopicContentDO (org.neusoft.neubbs.entity.TopicContentDO)9