ReplyRepositoryTest
페이지 정보
본문
package web.repository;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.log4j.Log4j2;
import web.domain.Board;
import web.domain.Reply;
@SpringBootTest
@Log4j2
public class ReplyRepositoryTest {
@Autowired
private ReplyRepository replyRepository;
//@Test
public void testInsert() {
//DB - board 테이블에 존재하는 bno 값
Long bno = 100L;
Board board = Board.builder().bno(bno).build();
Reply reply = Reply.builder()
.board(board)
.replyer("홍길동")
.replyText("두번째 댓글 내용이다.")
.build();
replyRepository.save(reply);
}
@Transactional //추가
@Test
public void testBoardReplys() {
Long bno = 100L;
Pageable pageable = PageRequest.of(0, 10, Sort.by("rno").descending());
Page<Reply> result = replyRepository.listOfBoard(bno, pageable);
result.getContent().forEach(reply -> {
log.info(reply);
});
}
}
댓글목록
등록된 댓글이 없습니다.