Search in sources :

Example 1 with TopicDO

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

the class TopicControllerTest method testReleaseTopicReplySuccess.

/**
 * 测试 /api/topic/reply (POST)
 *      - 发布话题回复成功
 *      - 需要权限: @LoginAuthorization @AccountActivation
 */
@Test
@Transactional
public void testReleaseTopicReplySuccess() throws Exception {
    int topicId = 1;
    String content = "new reply content";
    String requestBody = "{" + util.getJsonField("topicid", topicId) + "," + util.getJsonField("content", content) + "}";
    System.out.println("input request-body: " + requestBody);
    // before publish reply
    TopicDO beforeTopic = topicDAO.getTopicById(topicId);
    Assert.assertNotNull(beforeTopic);
    MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post("/api/topic/reply").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()).andReturn();
    Map resultMap = (Map) JSON.parse(result.getResponse().getContentAsString());
    // judge $.model.replyid
    Map modelMap = (Map) resultMap.get("model");
    // validate reply information
    TopicReplyDO reply = topicReplyDAO.getTopicReplyById((Integer) modelMap.get("replyid"));
    Assert.assertEquals(topicId, (int) reply.getTopicid());
    Assert.assertEquals(content, reply.getContent());
    // validate topic information
    TopicDO afterTopic = topicDAO.getTopicById(reply.getTopicid());
    Assert.assertNotNull(afterTopic);
    Assert.assertEquals(beforeTopic.getReplies() + 1, (int) afterTopic.getReplies());
    Assert.assertNotEquals(beforeTopic.getLastreplytime(), afterTopic.getLastreplytime());
    Assert.assertEquals(reply.getCreatetime(), afterTopic.getLastreplytime());
    util.printSuccessMessage();
}
Also used : TopicReplyDO(org.neusoft.neubbs.entity.TopicReplyDO) TopicDO(org.neusoft.neubbs.entity.TopicDO) MvcResult(org.springframework.test.web.servlet.MvcResult) Map(java.util.Map) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 2 with TopicDO

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

the class TopicControllerTest method testReleaseTopicSuccess.

/**
 * 测试 /api/topic (POST)
 *      - 测试发布话题成功
 *      - 需要权限:@LoginAuthorization @AccountActivation
 */
@Test
@Transactional
public void testReleaseTopicSuccess() throws Exception {
    // build request-body
    String categoryNick = "game";
    String title = "new topic title";
    String content = "new topic content";
    String requestBody = "{\"category\":\"" + categoryNick + "\"," + "\"title\":\"" + title + "\"," + "\"content\":\"" + content + "\"}";
    System.out.println("input request-body: " + requestBody);
    MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post("/api/topic").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()).andReturn();
    // judge $.model.topicid
    Map resultMap = (Map) JSON.parse(result.getResponse().getContentAsString());
    Map modelMap = (Map) resultMap.get("model");
    int topicId = (Integer) modelMap.get("topicid");
    // validate topic information
    TopicDO topic = topicDAO.getTopicById(topicId);
    Assert.assertNotNull(topic);
    Assert.assertEquals(title, topic.getTitle());
    Assert.assertEquals(content, topicContentDAO.getTopicContentByTopicId(topicId).getContent());
    // validate category
    int categoryId = topic.getCategoryid();
    Assert.assertEquals(categoryNick, topicCategoryDAO.getTopicCategoryById(categoryId).getNick());
    // validate topic action
    Assert.assertNotNull(topicActionDAO.getTopicAction(topicId));
    util.printSuccessMessage();
}
Also used : TopicDO(org.neusoft.neubbs.entity.TopicDO) MvcResult(org.springframework.test.web.servlet.MvcResult) Map(java.util.Map) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 3 with TopicDO

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

the class TopicContentDAOTest method savaTestTopicContentDOToDatabase.

/**
 * 保存话题内容至数据库
 *      - need exist
 *           - fu_id from forum_user
 *           - ftcg_id from forum_topic_category
 *           - ft_id from forum_topic
 *
 * @return TopicContent 数据库保存后,重新查询的话题内容
 */
private TopicContentDO savaTestTopicContentDOToDatabase() {
    // build TopicDO, sava database
    TopicDO topic = new TopicDO();
    topic.setUserid(1);
    topic.setCategoryid(1);
    topic.setTitle("topic title");
    Assert.assertEquals(1, topicDAO.saveTopic(topic));
    // build TopicContentDO, sava database
    TopicContentDO topicContent = new TopicContentDO();
    topicContent.setTopicid(topic.getId());
    topicContent.setContent("topic content");
    Assert.assertEquals(1, topicContentDAO.saveTopicContent(topicContent));
    return topicContentDAO.getTopicContentByTopicId(topic.getId());
}
Also used : TopicContentDO(org.neusoft.neubbs.entity.TopicContentDO) TopicDO(org.neusoft.neubbs.entity.TopicDO)

Example 4 with TopicDO

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

the class TopicReplyDAOTest method saveTestReplyToDatabase.

/**
 * 保存回复至数据库
 *      - need exist
 *          - fu_id from forum_user
 *          - ft_id from forum_topic
 *
 * @return TopicReplyDO 数据库保存后,重新查询回复
 */
private TopicReplyDO saveTestReplyToDatabase() {
    // build TopicDO, sava database
    TopicDO topic = new TopicDO();
    topic.setUserid(1);
    topic.setCategoryid(1);
    topic.setTitle("topic title");
    Assert.assertEquals(1, topicDAO.saveTopic(topic));
    // build TopicReplyDO, save database
    TopicReplyDO reply = new TopicReplyDO();
    reply.setUserid(1);
    reply.setTopicid(topic.getId());
    reply.setContent("reply content");
    Assert.assertEquals(1, topicReplyDAO.saveTopicReply(reply));
    return topicReplyDAO.getTopicReplyById(reply.getId());
}
Also used : TopicReplyDO(org.neusoft.neubbs.entity.TopicReplyDO) TopicDO(org.neusoft.neubbs.entity.TopicDO)

Example 5 with TopicDO

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

the class TopicDAOTest method testTopicById.

/**
 * 测试 (id)查询话题
 */
@Test
@Transactional
public void testTopicById() {
    TopicDO topic = this.saveTestTopicToDB();
    TopicDO selectTopic = topicDAO.getTopicById(topic.getId());
    Assert.assertNotNull(selectTopic);
    System.out.println("get id=" + topic.getId() + " topic information: " + selectTopic);
}
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