Search in sources :

Example 6 with TopicContentDO

use of org.neusoft.neubbs.entity.TopicContentDO 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 7 with TopicContentDO

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

the class TopicContentDAOTest method testSaveTopiContent.

/**
 * 测试保存话题
 */
@Test
@Transactional
public void testSaveTopiContent() {
    TopicContentDO topicContent = this.savaTestTopicContentDOToDatabase();
    System.out.println("insert topic content information: " + topicContentDAO.getTopicContentByTopicId(topicContent.getTopicid()));
}
Also used : TopicContentDO(org.neusoft.neubbs.entity.TopicContentDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 8 with TopicContentDO

use of org.neusoft.neubbs.entity.TopicContentDO 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 9 with TopicContentDO

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

the class TopicControllerTest method testNewLikeTopicSuccess.

/**
 * 测试 /topic/newlike
 *      - 点赞话题新接口成功 + 1 和 -1
 *      - 需要权限:@LoginAuthorization @AccountActivation
 *      - 新接口,不需要输入 command(inc | dec),重复调用即自判断点暂(or 取消)
 */
@Test
@Transactional
public void testNewLikeTopicSuccess() 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) + "}";
    // like topic + 1
    TopicContentDO topicContent = topicContentDAO.getTopicContentByTopicId(topicId);
    int beforeTopicLike = topicContent.getLike();
    System.out.println("request 'inc' request-body: " + requestBody);
    mockMvc.perform(MockMvcRequestBuilders.post("/api/topic/newlike").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.userLikeTopicId").isArray()).andExpect(MockMvcResultMatchers.jsonPath("$.model.like").value(beforeTopicLike + 1));
    // judge forum_user_action 'fua_like_ft_id_array'
    JSONArray jsonArray = JSON.parseArray(userActionDAO.getUserActionLikeTopicIdJsonArray(cookieUserId));
    Assert.assertEquals(topicId, jsonArray.get(jsonArray.size() - 1));
    // judge forum_topic_action 'fta_like_fu_id_array'
    jsonArray = JSON.parseArray(topicActionDAO.getTopicActionLikeUserIdJsonArray(topicId));
    Assert.assertEquals(cookieUserId, jsonArray.get(jsonArray.size() - 1));
    // like topic - 1
    System.out.println("request 'dec' request-body: " + requestBody);
    mockMvc.perform(MockMvcRequestBuilders.post("/api/topic/newlike").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()).andExpect(MockMvcResultMatchers.jsonPath("$.model.userLikeTopicId").isArray()).andExpect(MockMvcResultMatchers.jsonPath("$.model.like").value(beforeTopicLike));
    Assert.assertEquals(-1, JsonUtil.getIntElementIndex(userActionDAO.getUserActionLikeTopicIdJsonArray(cookieUserId), topicId));
    Assert.assertEquals(-1, JsonUtil.getIntElementIndex(topicActionDAO.getTopicActionLikeUserIdJsonArray(topicId), cookieUserId));
    util.printSuccessMessage();
}
Also used : Cookie(javax.servlet.http.Cookie) TopicContentDO(org.neusoft.neubbs.entity.TopicContentDO) UserDO(org.neusoft.neubbs.entity.UserDO) JSONArray(com.alibaba.fastjson.JSONArray) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 10 with TopicContentDO

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

the class TopicContentDAOTest method testTopicContentByTopicId.

/**
 * 测试(topicid) 获取话题内容
 */
@Test
@Transactional
public void testTopicContentByTopicId() {
    TopicContentDO topicContent = this.savaTestTopicContentDOToDatabase();
    TopicContentDO selectTopicContent = topicContentDAO.getTopicContentByTopicId(topicContent.getTopicid());
    Assert.assertNotNull(selectTopicContent);
    System.out.println("get topic content information:" + selectTopicContent);
}
Also used : TopicContentDO(org.neusoft.neubbs.entity.TopicContentDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Aggregations

TopicContentDO (org.neusoft.neubbs.entity.TopicContentDO)14 Test (org.junit.Test)10 Transactional (javax.transaction.Transactional)9 TopicDO (org.neusoft.neubbs.entity.TopicDO)4 TopicCategoryDO (org.neusoft.neubbs.entity.TopicCategoryDO)3 UserDO (org.neusoft.neubbs.entity.UserDO)2 ServiceException (org.neusoft.neubbs.exception.ServiceException)2 JSONArray (com.alibaba.fastjson.JSONArray)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Cookie (javax.servlet.http.Cookie)1 TopicActionDO (org.neusoft.neubbs.entity.TopicActionDO)1 TopicReplyDO (org.neusoft.neubbs.entity.TopicReplyDO)1