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