| 13 | import static org.junit.Assert.*; |
| 14 | |
| 15 | @RunWith(SpringJUnit4ClassRunner.class) |
| 16 | @ContextConfiguration(locations = {"file:src/main/webapp/WEB-INF/spring/root-context.xml"}) |
| 17 | public class CommentServiceImplTest { |
| 18 | @Autowired |
| 19 | CommentService commentService; |
| 20 | @Autowired |
| 21 | CommentDao commentDao; |
| 22 | @Autowired |
| 23 | BoardDao boardDao; |
| 24 | |
| 25 | @Test |
| 26 | public void remove() throws Exception { |
| 27 | boardDao.deleteAll(); |
| 28 | |
| 29 | BoardDto boardDto = new BoardDto("hello", "hello", "asdf"); |
| 30 | assertTrue(boardDao.insert(boardDto) == 1); |
| 31 | Integer bno = boardDao.selectAll().get(0).getBno(); |
| 32 | System.out.println("bno = " + bno); |
| 33 | |
| 34 | commentDao.deleteAll(bno); |
| 35 | CommentDto commentDto = new CommentDto(bno,0,"hi","qwer"); |
| 36 | |
| 37 | assertTrue(boardDao.select(bno).getComment_cnt() == 0); |
| 38 | assertTrue(commentService.write(commentDto)==1); |
| 39 | assertTrue(boardDao.select(bno).getComment_cnt() == 1); |
| 40 | |
| 41 | Integer cno = commentDao.selectAll(bno).get(0).getCno(); |
| 42 | |
| 43 | // 일부러 예외를 발생시키고 Tx가 취소되는지 확인해야. |
| 44 | int rowCnt = commentService.remove(cno, bno, commentDto.getCommenter()); |
| 45 | assertTrue(rowCnt==1); |
| 46 | assertTrue(boardDao.select(bno).getComment_cnt() == 0); |
| 47 | } |
| 48 | |
| 49 | @Test |
| 50 | public void write() throws Exception { |
| 51 | boardDao.deleteAll(); |
| 52 | |
| 53 | BoardDto boardDto = new BoardDto("hello", "hello", "asdf"); |
| 54 | assertTrue(boardDao.insert(boardDto) == 1); |
| 55 | Integer bno = boardDao.selectAll().get(0).getBno(); |
| 56 | System.out.println("bno = " + bno); |
| 57 | |
| 58 | commentDao.deleteAll(bno); |
| 59 | CommentDto commentDto = new CommentDto(bno,0,"hi","qwer"); |
| 60 | |
| 61 | assertTrue(boardDao.select(bno).getComment_cnt() == 0); |
| 62 | assertTrue(commentService.write(commentDto)==1); |
| 63 | |
| 64 | Integer cno = commentDao.selectAll(bno).get(0).getCno(); |
| 65 | assertTrue(boardDao.select(bno).getComment_cnt() == 1); |
| 66 | } |
| 67 | } |
nothing calls this directly
no outgoing calls
no test coverage detected