Search in sources :

Example 21 with TopicDO

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

the class TopicDAOTest method testUpdateCategoryById.

/**
 * 测试更新话题分类
 *      - need insert categoryId == 2;
 */
@Test
@Transactional
public void testUpdateCategoryById() {
    TopicDO topic = this.saveTestTopicToDB();
    int newCategoryId = 2;
    Assert.assertEquals(1, topicDAO.updateCategoryById(topic.getId(), newCategoryId));
    Assert.assertNotEquals(topic.getCategoryid(), topicDAO.getTopicById(topic.getId()).getCategoryid());
    System.out.println("update topicId=" + topic.getId() + " topic categoryid=<" + newCategoryId + "> success!");
}
Also used : TopicDO(org.neusoft.neubbs.entity.TopicDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 22 with TopicDO

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

the class TopicDAOTest method testRemoveTopicById.

/**
 * 测试删除话题
 */
@Test
@Transactional
public void testRemoveTopicById() {
    TopicDO topic = this.saveTestTopicToDB();
    Assert.assertEquals(1, topicDAO.removeTopicById(topic.getId()));
    System.out.println("remove id=" + topic.getId() + " topic");
}
Also used : TopicDO(org.neusoft.neubbs.entity.TopicDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 23 with TopicDO

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

the class TopicDAOTest method testListTopicByStartRowByCountByUsername.

/**
 * 测试(降序,用户 id 分类)获取话题列表
 */
@Test
@Transactional
public void testListTopicByStartRowByCountByUsername() {
    this.saveTestTopicToDB();
    // first page
    int startRow = 0, count = 10;
    int userId = 1;
    List<TopicDO> listTopic = topicDAO.listTopicDESCByStartRowByCountByUserId(startRow, count, userId);
    Assert.assertTrue(listTopic.size() >= 1);
    // foreach list
    int recordCount = 1;
    for (TopicDO topic : listTopic) {
        System.out.println("output userid=" + userId + " topic information (No." + (recordCount++) + " recoders): " + topic);
    }
}
Also used : TopicDO(org.neusoft.neubbs.entity.TopicDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 24 with TopicDO

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

the class TopicDAOTest method testSaveTopic.

/**
 * 测试保存话题
 */
@Test
@Transactional
public void testSaveTopic() {
    TopicDO topic = this.getTestTopicDO();
    Assert.assertEquals(1, topicDAO.saveTopic(topic));
    Assert.assertTrue(topic.getId() > 0);
    Assert.assertNotNull(topicDAO.getTopicById(topic.getId()));
    System.out.println("insert topic informatioin : " + topicDAO.getTopicById(topic.getId()));
}
Also used : TopicDO(org.neusoft.neubbs.entity.TopicDO) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 25 with TopicDO

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

the class TopicServiceImpl method saveTopic.

@Override
public Map<String, Object> saveTopic(int userId, String categoryNick, String title, String topicContent) {
    // judge whether exist category(nick)
    TopicCategoryDO category = this.getTopicCategoryNotNullByNick(categoryNick);
    // build TopicDO, TopicContentDO, TopicActionDO
    TopicDO topic = new TopicDO();
    topic.setUserid(userId);
    topic.setCategoryid(category.getId());
    topic.setTitle(title);
    // insert forum_topic, get new topic id
    if (topicDAO.saveTopic(topic) == 0) {
        throw new ServiceException(ApiMessage.DATABASE_EXCEPTION).log(LogWarnEnum.TS1);
    }
    // insert forum_topic_content
    TopicContentDO topicContentDO = new TopicContentDO();
    topicContentDO.setTopicid(topic.getId());
    topicContentDO.setContent(topicContent);
    if (topicContentDAO.saveTopicContent(topicContentDO) == 0) {
        throw new ServiceException(ApiMessage.DATABASE_EXCEPTION).log(LogWarnEnum.TS2);
    }
    // insert forum_topic_action
    TopicActionDO topicAction = new TopicActionDO();
    topicAction.setTopicId(topic.getId());
    if (topicActionDAO.saveTopicAction(topicAction) == 0) {
        throw new ServiceException(ApiMessage.DATABASE_EXCEPTION).log(LogWarnEnum.TS24);
    }
    return MapFilterUtil.generateMap(ParamConst.TOPIC_ID, topic.getId());
}
Also used : ServiceException(org.neusoft.neubbs.exception.ServiceException) TopicContentDO(org.neusoft.neubbs.entity.TopicContentDO) TopicDO(org.neusoft.neubbs.entity.TopicDO) TopicCategoryDO(org.neusoft.neubbs.entity.TopicCategoryDO) TopicActionDO(org.neusoft.neubbs.entity.TopicActionDO)

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