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