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));
}
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;
}
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();
}
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();
}
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();
}
Aggregations