Search in sources :

Example 91 with Transactional

use of javax.transaction.Transactional in project neubbs by nuitcoder.

the class TopicControllerTest method testListHomeTopicSuccess.

/**
 * 测试 /api/topics
 *      - 获取首页话题信息列表成功
 *          - input different param
 *              - [ ] input page
 *              - [✔] input limit, page
 *              - [ ] input page, category
 *              - [ ] input limit, page category
 *              - [ ] input page, category
 *              - [ ] input limit, page, username
 *              - [ ] input page, username
 *              - [ ] input limit, page, category, username
 *              - [ ] input page, category, username
 *              - [ ] input limit, page, category, username
 */
@Test
@Transactional
public void testListHomeTopicSuccess() throws Exception {
    // input limit, page
    MvcResult result = mockMvc.perform(MockMvcRequestBuilders.get("/api/topics").param("limit", "1").param("page", "1")).andExpect(MockMvcResultMatchers.jsonPath("$.success").value(true)).andExpect(MockMvcResultMatchers.jsonPath("$.message").value("")).andExpect(MockMvcResultMatchers.jsonPath("$.model").exists()).andDo(MockMvcResultHandlers.print()).andReturn();
    // get model.[0] element map
    Map resultMap = (Map) JSON.parse(result.getResponse().getContentAsString());
    List modelList = (List) resultMap.get("model");
    Assert.assertEquals(1, modelList.size());
    Map firstModelListMap = (Map) modelList.get(0);
    // judge $.model
    util.confirmMapShouldHavaKeyItems(firstModelListMap, "title", "replies", "lastreplytime", "createtime", "topicid", "content", "read", "like", "category", "user", "lastreplyuser");
    // judge $.mode.category
    util.confirmMapShouldHavaKeyItems((Map) firstModelListMap.get("category"), "id", "name", "description");
    // judge $.model.user
    util.confirmMapShouldHavaKeyItems((Map) firstModelListMap.get("user"), "avator", "username");
    // $judge $.model.lastreplyuser
    util.confirmMapShouldHavaKeyItems((Map) firstModelListMap.get("lastreplyuser"), "avator", "username");
    util.printSuccessMessage();
}
Also used : List(java.util.List) MvcResult(org.springframework.test.web.servlet.MvcResult) Map(java.util.Map) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 92 with Transactional

use of javax.transaction.Transactional 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 93 with Transactional

use of javax.transaction.Transactional in project neubbs by nuitcoder.

the class TopicCategoryDAOTest method testListAllTopicCategory.

/**
 * 测试获取所有话题分类
 */
@Test
@Transactional
public void testListAllTopicCategory() {
    this.savaTestTopicCategoryDOToDatabase();
    List<TopicCategoryDO> categoryList = topicCategoryDAO.listAllTopicCategory();
    Assert.assertTrue(categoryList.size() >= 1);
    int categoryCount = 1;
    for (TopicCategoryDO topicCategory : categoryList) {
        System.out.println("output topic category information ( No." + (categoryCount++) + " records):" + JsonUtil.toJsonString(topicCategory));
    }
    System.out.println("get all category list success!");
}
Also used : TopicCategoryDO(org.neusoft.neubbs.entity.TopicCategoryDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 94 with Transactional

use of javax.transaction.Transactional in project neubbs by nuitcoder.

the class TopicCategoryDAOTest method testUpdateDescriptionByNick.

/**
 * 测试修改话题分类描述
 */
@Test
@Transactional
public void testUpdateDescriptionByNick() {
    TopicCategoryDO category = this.savaTestTopicCategoryDOToDatabase();
    String newDescription = "this is new category description";
    Assert.assertEquals(1, topicCategoryDAO.updateDescriptionByNick(category.getNick(), newDescription));
    Assert.assertEquals(newDescription, topicCategoryDAO.getTopicCategoryById(category.getId()).getDescription());
    System.out.println("update categoryNick=" + category.getNick() + " category description=<" + newDescription + ">");
}
Also used : TopicCategoryDO(org.neusoft.neubbs.entity.TopicCategoryDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 95 with Transactional

use of javax.transaction.Transactional in project neubbs by nuitcoder.

the class TopicCategoryDAOTest method testSaveTopicCategory.

/**
 * 测试保存保存话题分类
 */
@Test
@Transactional
public void testSaveTopicCategory() {
    TopicCategoryDO category = this.savaTestTopicCategoryDOToDatabase();
    System.out.println("insert topic category information: " + category);
}
Also used : TopicCategoryDO(org.neusoft.neubbs.entity.TopicCategoryDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Aggregations

Transactional (javax.transaction.Transactional)299 Test (org.junit.Test)99 PostResult (org.collectiveone.common.dto.PostResult)29 ArrayList (java.util.ArrayList)24 UserDO (org.neusoft.neubbs.entity.UserDO)21 Timestamp (java.sql.Timestamp)18 TopicDO (org.neusoft.neubbs.entity.TopicDO)18 Initiative (org.collectiveone.modules.initiatives.Initiative)16 GetResult (org.collectiveone.common.dto.GetResult)15 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)13 TopicReplyDO (org.neusoft.neubbs.entity.TopicReplyDO)13 HashMap (java.util.HashMap)12 Date (java.util.Date)11 AppUser (org.collectiveone.modules.users.AppUser)11 UUID (java.util.UUID)10 RolesAllowed (javax.annotation.security.RolesAllowed)10 PeerReviewedAssignation (org.collectiveone.modules.assignations.evaluationlogic.PeerReviewedAssignation)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 IOException (java.io.IOException)9 TopicContentDO (org.neusoft.neubbs.entity.TopicContentDO)9