package cn.itcast.article.service; import cn.itcast.article.po.Comment; import com.alibaba.fastjson2.JSON; import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.Page; import org.springframework.test.context.junit4.SpringRunner; import java.time.LocalDateTime; import java.util.List; @Slf4j @RunWith(SpringRunner.class) @SpringBootTest public class CommentServiceTest { @Autowired private CommentService commentService; /** * 查询所有文档 */ @Test public void testFindCommentList() { List commentList = commentService.findCommentList(); log.info(JSON.toJSONString(commentList)); } @Test public void testFindCommentById() { Comment commentById = commentService.findCommentById("1"); System.out.println(commentById); } @Test public void testSaveComment() { Comment comment = new Comment(); comment.setArticleid("100000"); comment.setContent("测试添加的数据"); comment.setCreatedatetime(LocalDateTime.now()); comment.setUserid("1003"); comment.setNickname("凯撒大帝"); comment.setState("1"); comment.setLikenum(0); comment.setReplynum(0); commentService.saveComment(comment); } @Test public void testFindCommentListByParentid() { Page page = commentService.findCommentListByParentid("3", 1, 2); System.out.println(page.getTotalElements()); System.out.println(page.getContent()); } @Test public void testUpdateCommentLikenum() { commentService.updateCommentLikenum("1"); } }