Search in sources :

Example 1 with UserDO

use of org.neusoft.neubbs.entity.UserDO in project neubbs by nuitcoder.

the class TopicController method attentionTopic.

/**
 * 关注话题
 *
 * @param requestBodyParamsMap request-body 内 JSON 数据
 * @return ApiJsonDTO 接口 JSON 传输对象
 */
@LoginAuthorization
@AccountActivation
@RequestMapping(value = "/topic/attention", method = RequestMethod.POST, consumes = "application/json")
public ApiJsonDTO attentionTopic(@RequestBody Map<String, Object> requestBodyParamsMap) {
    Integer topicId = (Integer) requestBodyParamsMap.get(ParamConst.TOPIC_ID);
    validationService.check(ParamConst.TOPIC_ID, String.valueOf(topicId));
    UserDO cookieUser = secretService.getUserInfoByAuthentication(httpService.getAuthenticationCookieValue());
    return new ApiJsonDTO().success().model(topicService.operateAttentionTopic(cookieUser.getId(), topicId));
}
Also used : UserDO(org.neusoft.neubbs.entity.UserDO) ApiJsonDTO(org.neusoft.neubbs.dto.ApiJsonDTO) AccountActivation(org.neusoft.neubbs.controller.annotation.AccountActivation) LoginAuthorization(org.neusoft.neubbs.controller.annotation.LoginAuthorization) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with UserDO

use of org.neusoft.neubbs.entity.UserDO in project neubbs by nuitcoder.

the class TopicServiceImpl method getTopicReplyModelMap.

@Override
public Map<String, Object> getTopicReplyModelMap(int replyId) {
    TopicReplyDO reply = this.getTopicReplyNotNull(replyId);
    UserDO replyUser = this.getUserNotNullById(reply.getUserid());
    Map<String, Object> replyInfoMap = this.getTopicReplyInfoMap(reply);
    replyInfoMap.put(ParamConst.USER, this.getTopicUserInfoMap(replyUser));
    return replyInfoMap;
}
Also used : TopicReplyDO(org.neusoft.neubbs.entity.TopicReplyDO) UserDO(org.neusoft.neubbs.entity.UserDO)

Example 3 with UserDO

use of org.neusoft.neubbs.entity.UserDO in project neubbs by nuitcoder.

the class TopicControllerTest method testLikeTopicSuccess.

/**
 * 测试 /api/topic/like
 *      - 话题点赞 + 1 成功 & 话题点赞 - 1 成功
 *      - 需要权限:@LoginAuthorization @AccountActivation
 *      - 旧接口,需要输入 command 命令参数(inc - 点赞 or dec - 取消)
 */
@Test
@Transactional
public void testLikeTopicSuccess() throws Exception {
    int topicId = 1;
    // topic like + 1
    String command = "inc";
    String requestBody = "{" + util.getJsonField("topicid", topicId) + ", " + util.getJsonField("command", command) + "}";
    System.out.println("input dec request-body: " + requestBody);
    Cookie cookie = util.getAlreadyLoginUserCookie();
    UserDO cookieUser = SecretUtil.decryptUserInfoToken(cookie.getValue());
    int cookieUserId = cookieUser.getId();
    int beforeTopicContentLike = topicContentDAO.getTopicContentByTopicId(topicId).getLike();
    mockMvc.perform(MockMvcRequestBuilders.post("/api/topic/like").cookie(cookie).contentType(MediaType.APPLICATION_JSON).content(requestBody).accept(MediaType.APPLICATION_JSON)).andExpect(MockMvcResultMatchers.jsonPath("$.success").value(true)).andExpect(MockMvcResultMatchers.jsonPath("$.message").value("")).andExpect(MockMvcResultMatchers.jsonPath("$.model").exists()).andExpect(MockMvcResultMatchers.jsonPath("$.model.like").value(CoreMatchers.is(beforeTopicContentLike + 1)));
    // judge 'forum_user_action' new insert topicId
    JSONArray jsonArray = JSON.parseArray(userActionDAO.getUserActionLikeTopicIdJsonArray(cookieUserId));
    Assert.assertEquals(topicId, (int) jsonArray.get(jsonArray.size() - 1));
    // judge 'forum_topic_action' new insert userId
    jsonArray = JSON.parseArray(topicActionDAO.getTopicActionLikeUserIdJsonArray(topicId));
    Assert.assertEquals(cookieUserId, jsonArray.get(jsonArray.size() - 1));
    // topic like - 1
    command = "dec";
    requestBody = "{" + util.getJsonField("topicid", topicId) + ", " + util.getJsonField("command", command) + "}";
    System.out.println("input 'dec' request-body: " + requestBody);
    mockMvc.perform(MockMvcRequestBuilders.post("/api/topic/like").cookie(cookie).contentType(MediaType.APPLICATION_JSON).content(requestBody).accept(MediaType.APPLICATION_JSON)).andExpect(MockMvcResultMatchers.jsonPath("$.success").value(true)).andExpect(MockMvcResultMatchers.jsonPath("$.message").value("")).andExpect(MockMvcResultMatchers.jsonPath("$.model").exists()).andExpect(MockMvcResultMatchers.jsonPath("$.model.like").value(CoreMatchers.is(beforeTopicContentLike)));
    Assert.assertEquals(beforeTopicContentLike, (int) topicContentDAO.getTopicContentByTopicId(topicId).getLike());
    Assert.assertEquals(-1, JsonUtil.getIntElementIndex(userActionDAO.getUserActionLikeTopicIdJsonArray(cookieUserId), topicId));
    Assert.assertEquals(-1, JsonUtil.getIntElementIndex(topicActionDAO.getTopicActionLikeUserIdJsonArray(topicId), cookieUserId));
    util.printSuccessMessage();
}
Also used : Cookie(javax.servlet.http.Cookie) UserDO(org.neusoft.neubbs.entity.UserDO) JSONArray(com.alibaba.fastjson.JSONArray) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 4 with UserDO

use of org.neusoft.neubbs.entity.UserDO in project neubbs by nuitcoder.

the class FileControllerTest method testUploadUserAvatarSuccess.

/*
     * ***********************************************
     * api test method
     * ***********************************************
     */
/**
 * 测试 /api/file/avatar
 *      - 测试上传用户头像成功
 *      - 需要权限:@LoginAuthorization, @AccountActivation
 */
@Test
@Transactional
public void testUploadUserAvatarSuccess() throws Exception {
    // build MultipartFile type(html <> name, file name,file type,size)
    String htmlInputName = "avatarImageFile";
    String uploadFileName = "testAvatarFile";
    byte[] fileBytes = new byte[1024 * 1];
    MockMultipartFile[] files = { new MockMultipartFile(htmlInputName, uploadFileName + ".jpg", "image/jpg", fileBytes), new MockMultipartFile(htmlInputName, uploadFileName + ".png", "image/png", fileBytes), new MockMultipartFile(htmlInputName, uploadFileName + ".jpeg", "image/jpeg", fileBytes) };
    // upload user avatar image file
    for (MockMultipartFile file : files) {
        mockMvc.perform(MockMvcRequestBuilders.fileUpload("/api/file/avatar").file(file).cookie(util.getAlreadyLoginUserCookie()).contentType(MediaType.MULTIPART_FORM_DATA_VALUE).accept(MediaType.APPLICATION_JSON)).andExpect(MockMvcResultMatchers.jsonPath("$.success").value(true)).andExpect(MockMvcResultMatchers.jsonPath("$.message").value(ApiMessage.UPLOAD_SUCCESS)).andExpect(MockMvcResultMatchers.jsonPath("$.model").value(CoreMatchers.notNullValue()));
        System.out.println("upload " + file.getOriginalFilename() + " success!");
    }
    /*
         * delete already upload user avatar image file
         *      - test local
         *          - upload path: user.image.upload.path = ... (neubbs.properties)
         *      - test ftp server
         */
    // System.out.println("delete local has bean uploaded test avatar file ......");
    // String localUploadPath = webApplicationContext.getServletContext()
    // .getRealPath(neubbsConfig.getUserImageUploadPath());
    // File directory = new File(localUploadPath);
    // File[] allFiles = directory.listFiles();
    // for (File file: allFiles) {
    // if (file.getName().contains(uploadFileName)) {
    // file.deleteOnExit();
    // System.out.println("already delete " + file.getName());
    // }
    // }
    // System.out.println("all local test file delete finished!");
    System.out.println("delete ftp server has bean uploaded test avatar file ......");
    UserDO user = userService.getUserInfoByName("suvan");
    String ftpUserAvatarPath = "/user/" + user.getId() + "-" + user.getName() + "/avator/";
    List<String> listFileName = FtpUtil.listServerPathFileName(ftpUserAvatarPath);
    for (String fName : listFileName) {
        if (fName.contains(uploadFileName)) {
            FtpUtil.delete(ftpUserAvatarPath, fName);
            System.out.println("already delete " + fName);
        }
    }
    System.out.println("all ftp server test file delete finished!");
    util.printSuccessMessage();
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) UserDO(org.neusoft.neubbs.entity.UserDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 5 with UserDO

use of org.neusoft.neubbs.entity.UserDO in project neubbs by nuitcoder.

the class TopicControllerTest method testAttentionTopicSuccess.

/**
 * 测试 /api/topic/attention
 *      - 关注话题成功 + 1 和 -1
 *      - 需要权限: @LoginAuthorization @AccountActivation
 */
@Test
@Transactional
public void testAttentionTopicSuccess() throws Exception {
    int topicId = 1;
    Cookie cookie = util.getAlreadyLoginUserCookie();
    UserDO cookieUser = SecretUtil.decryptUserInfoToken(cookie.getValue());
    int cookieUserId = cookieUser.getId();
    String requestBody = "{" + util.getJsonField("topicid", topicId) + "}";
    // attention topic + 1
    System.out.println("input 'inc' request-body: " + requestBody);
    mockMvc.perform(MockMvcRequestBuilders.post("/api/topic/attention").cookie(cookie).contentType(MediaType.APPLICATION_JSON).content(requestBody).accept(MediaType.APPLICATION_JSON)).andExpect(MockMvcResultMatchers.jsonPath("$.success").value(true)).andExpect(MockMvcResultMatchers.jsonPath("$.message").value("")).andExpect(MockMvcResultMatchers.jsonPath("$.model").exists()).andExpect(MockMvcResultMatchers.jsonPath("$.model.userAttentionTopicId").value(CoreMatchers.hasItem(topicId)));
    // compare forum_topic_action 'fta_attention_fu_id_array'
    JSONArray jsonArray = JSON.parseArray(topicActionDAO.getTopicActionAttentionUserIdJsonArray(topicId));
    Assert.assertEquals(cookieUserId, jsonArray.get(jsonArray.size() - 1));
    // compare forum_user_action 'fua_following_fu_id_array'
    jsonArray = JSON.parseArray(userActionDAO.getUserActionAttentionTopicIdJsonArray(cookieUserId));
    Assert.assertEquals(topicId, jsonArray.get(jsonArray.size() - 1));
    // collect topic - 1
    System.out.println("input 'dec' request-body: " + requestBody);
    mockMvc.perform(MockMvcRequestBuilders.post("/api/topic/attention").cookie(cookie).contentType(MediaType.APPLICATION_JSON).content(requestBody).accept(MediaType.APPLICATION_JSON)).andExpect(MockMvcResultMatchers.jsonPath("$.success").value(true)).andExpect(MockMvcResultMatchers.jsonPath("$.message").value("")).andExpect(MockMvcResultMatchers.jsonPath("$.message").exists()).andExpect(MockMvcResultMatchers.jsonPath("$.model.userAttentionTopicId").isArray());
    Assert.assertEquals(-1, JsonUtil.getIntElementIndex(topicActionDAO.getTopicActionAttentionUserIdJsonArray(topicId), cookieUserId));
    Assert.assertEquals(-1, JsonUtil.getIntElementIndex(userActionDAO.getUserActionAttentionTopicIdJsonArray(cookieUserId), topicId));
    util.printSuccessMessage();
}
Also used : Cookie(javax.servlet.http.Cookie) UserDO(org.neusoft.neubbs.entity.UserDO) JSONArray(com.alibaba.fastjson.JSONArray) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Aggregations

UserDO (org.neusoft.neubbs.entity.UserDO)60 Test (org.junit.Test)28 Transactional (javax.transaction.Transactional)21 ApiJsonDTO (org.neusoft.neubbs.dto.ApiJsonDTO)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 AccountActivation (org.neusoft.neubbs.controller.annotation.AccountActivation)11 LoginAuthorization (org.neusoft.neubbs.controller.annotation.LoginAuthorization)11 Cookie (javax.servlet.http.Cookie)6 JSONArray (com.alibaba.fastjson.JSONArray)4 Map (java.util.Map)4 LinkedHashMap (java.util.LinkedHashMap)3 UserActionDO (org.neusoft.neubbs.entity.UserActionDO)3 ServiceException (org.neusoft.neubbs.exception.ServiceException)3 TopicContentDO (org.neusoft.neubbs.entity.TopicContentDO)2 TopicReplyDO (org.neusoft.neubbs.entity.TopicReplyDO)2 UserDynamicDO (org.neusoft.neubbs.entity.UserDynamicDO)2 PermissionException (org.neusoft.neubbs.exception.PermissionException)2 HandlerMethod (org.springframework.web.method.HandlerMethod)2 JWTVerifier (com.auth0.jwt.JWTVerifier)1 TokenExpiredException (com.auth0.jwt.exceptions.TokenExpiredException)1