Search in sources :

Example 11 with TopicDO

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

Example 12 with TopicDO

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

Example 13 with TopicDO

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

Example 14 with TopicDO

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

Example 15 with TopicDO

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

Aggregations

TopicDO (org.neusoft.neubbs.entity.TopicDO)28 Test (org.junit.Test)19 Transactional (javax.transaction.Transactional)18 Map (java.util.Map)5 TopicContentDO (org.neusoft.neubbs.entity.TopicContentDO)4 TopicReplyDO (org.neusoft.neubbs.entity.TopicReplyDO)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 TopicCategoryDO (org.neusoft.neubbs.entity.TopicCategoryDO)3 TopicActionDO (org.neusoft.neubbs.entity.TopicActionDO)2 ServiceException (org.neusoft.neubbs.exception.ServiceException)2 MvcResult (org.springframework.test.web.servlet.MvcResult)2 Date (java.util.Date)1 UserDO (org.neusoft.neubbs.entity.UserDO)1