use of org.neusoft.neubbs.entity.TopicDO in project neubbs by nuitcoder.
the class TopicDAOTest method testUpdateRepliesCutOneById.
/**
* 测试更新评论回复数(自动 -1)
*/
@Test
@Transactional
public void testUpdateRepliesCutOneById() {
TopicDO topic = this.saveTestTopicToDB();
Assert.assertEquals(1, topicDAO.updateRepliesCutOneById(topic.getId()));
// default 0 - 1 = -1
Integer expectReplies = -1;
Assert.assertEquals(expectReplies, topicDAO.getTopicById(topic.getId()).getReplies());
System.out.println("update topicId=" + topic.getId() + " topic replies-1 success!");
}
use of org.neusoft.neubbs.entity.TopicDO in project neubbs by nuitcoder.
the class MapFilterUtilTest method testFilterTopicInfo.
/**
* 测试 filterTopicInfo()
*/
@Test
public void testFilterTopicInfo() {
TopicDO topic = new TopicDO();
topic.setId(1);
topic.setUserid(1);
topic.setCategoryid(1);
topic.setLastreplyuserid(2);
Map<String, Object> topicInfoMap = JsonUtil.toMapByObject(topic);
System.out.println("filter before: " + topicInfoMap);
MapFilterUtil.filterTopicInfo(topicInfoMap);
System.out.println("filter after: " + topicInfoMap);
Assert.assertNotNull(topicInfoMap);
Assert.assertNull(topicInfoMap.get(ParamConst.ID));
Assert.assertNull(topicInfoMap.get(ParamConst.USER_ID));
Assert.assertNull(topicInfoMap.get(ParamConst.CATEGORY_ID));
Assert.assertNull(topicInfoMap.get(ParamConst.LAST_REPLY_USER_ID));
Assert.assertNotNull(topicInfoMap.get(ParamConst.TOPIC_ID));
}
use of org.neusoft.neubbs.entity.TopicDO in project neubbs by nuitcoder.
the class TopicControllerTest method testUpdateTopicSuccess.
/**
* 测试 /api/topic-update
* - 编辑话题成功
* - 需要权限:@LoginAuthorization @AccountActivation
*/
@Test
@Transactional
public void testUpdateTopicSuccess() throws Exception {
int topicId = 1;
String newCategoryNick = "school";
String newTitle = "new title";
String newContent = "update new content";
String requestBody = "{" + util.getJsonField("topicid", topicId) + "," + util.getJsonField("category", newCategoryNick) + "," + util.getJsonField("title", newTitle) + "," + util.getJsonField("content", newContent) + "}";
System.out.println("input request-body: " + requestBody);
mockMvc.perform(MockMvcRequestBuilders.post("/api/topic-update").cookie(util.getAlreadyLoginUserCookie()).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());
// compare database data, topic content, topic title and topic content
TopicDO afterTopic = topicDAO.getTopicById(topicId);
TopicContentDO afterTopicContent = topicContentDAO.getTopicContentByTopicId(topicId);
TopicCategoryDO afterTopicCategory = topicCategoryDAO.getTopicCategoryById(afterTopic.getCategoryid());
String afterCategory = afterTopicCategory.getNick();
String afterTitle = afterTopic.getTitle();
String afterContent = afterTopicContent.getContent();
Assert.assertEquals(newCategoryNick, afterCategory);
Assert.assertEquals(newTitle, afterTitle);
Assert.assertEquals(newContent, afterContent);
util.printSuccessMessage();
}
use of org.neusoft.neubbs.entity.TopicDO in project neubbs by nuitcoder.
the class TopicControllerTest method testRemoveTopicReply.
/**
* 测试 /api/topic/reply-remove
* - 删除回复成功
* - 需要权限:@LoginAuthorization @AccountActivation
*/
@Test
@Transactional
public void testRemoveTopicReply() throws Exception {
int replyId = 1;
String requestBody = "{" + util.getJsonField("replyid", replyId) + "}";
System.out.println("input request-body: " + requestBody);
// save reply before to remove
TopicReplyDO reply = topicReplyDAO.getTopicReplyById(replyId);
Assert.assertNotNull(reply);
int replyTopicId = reply.getTopicid();
TopicDO beforeTopic = topicDAO.getTopicById(replyTopicId);
mockMvc.perform(MockMvcRequestBuilders.post("/api/topic/reply-remove").cookie(util.getAlreadyLoginUserCookie()).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").value(CoreMatchers.notNullValue()));
// confirm database already remove reply and related topic 'replies' - 1
Assert.assertNull(topicReplyDAO.getTopicReplyById(replyId));
TopicDO afterTopic = topicDAO.getTopicById(replyTopicId);
Assert.assertEquals(beforeTopic.getReplies() - 1, (int) afterTopic.getReplies());
util.printSuccessMessage();
}
use of org.neusoft.neubbs.entity.TopicDO in project neubbs by nuitcoder.
the class TopicDAOTest method testListTopicByStartByCount.
/**
* 测试(降序)获取话题列表
*/
@Test
@Transactional
public void testListTopicByStartByCount() {
this.saveTestTopicToDB();
// first page
int startRow = 0, count = 10;
List<TopicDO> listTopic = topicDAO.listTopicDESCByStartRowByCount(startRow, count);
Assert.assertTrue(listTopic.size() >= 1);
// foreach list
int recordCount = 1;
for (TopicDO topic : listTopic) {
System.out.println("output topic information (No." + (recordCount++) + " recoders): " + topic);
}
}
Aggregations