Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 정처기필기
- 리눅스
- cisco packet
- 원형그래프
- 오라클
- 라우터
- php
- 참조타입
- Java
- ciscopacket
- VLAN
- html
- 정보처리기사
- 데이터베이스
- javaee
- 네트워크관리사
- ospf
- Cisco
- sql
- w3school
- 자바
- 이것이 자바다
- NCS
- Oracle
- 네트워크
- autoset
- jsp
- 버추얼머신
- rinux
- jsp연결
Archives
- Today
- Total
기록해! 정리해!
JPAJarTymeleaf-1 Test(Crudrepository 메소드사용) 본문
UI없이 이렇게 Test부터 할 수 있음
* insert , update : save
* selectAll : findAll
* selectOne : findById
* delete : deleteById
- BoardInsertTest
package com.rubypaper;
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.test.context.junit4.SpringRunner;
import com.rubypaper.board.Board;
import com.rubypaper.board.BoardRepository;
@RunWith(SpringRunner.class)
@SpringBootTest
public class BoardInsertTest {
@Autowired
private BoardRepository BoardRepo;
@Test // ( insert )
public void testInsert() {
for(Long i = 1L; i<= 10 ; i++ ) {
Board board = new Board();
board.setTitle("게시판 제목" + i);
board.setPassword("1234");
board.setWriter("소금빵"+i);
board.setContent("게시판 내용" + i);
BoardRepo.save(board);
}
}
}
- BoardSelectAllTest
package com.rubypaper;
import java.util.List;
import java.util.Optional;
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.test.context.junit4.SpringRunner;
import com.rubypaper.board.Board;
import com.rubypaper.board.BoardRepository;
@RunWith(SpringRunner.class)
@SpringBootTest
public class BoardSelectAllTest {
@Autowired
private BoardRepository BoardRepo;
@Test // ( selectAll )
public void testSelectAll() {
List<Board> li = (List<Board>)BoardRepo.findAll();
for(Board m :li ) {
System.out.println(m.toString());
}
}
}
>>
- BoardSelectOneTest
package com.rubypaper;
import java.util.Optional;
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.test.context.junit4.SpringRunner;
import com.rubypaper.board.Board;
import com.rubypaper.board.BoardRepository;
@RunWith(SpringRunner.class)
@SpringBootTest
public class BoardSelectOneTest {
@Autowired
private BoardRepository BoardRepo;
@Test // ( selectOne )
public void testSelectOne() {
// Optional 이란? Null Point Exception 을 방지해준다.
Optional<Board> m = BoardRepo.findById(5L);
System.out.println(m.toString());
}
}
>>
- BoardDeleteTest
package com.rubypaper;
import java.util.List;
import java.util.Optional;
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.test.context.junit4.SpringRunner;
import com.rubypaper.board.Board;
import com.rubypaper.board.BoardRepository;
@RunWith(SpringRunner.class)
@SpringBootTest
public class BoardDeleteTest {
@Autowired
private BoardRepository BoardRepo;
@Test // ( Delete + select )
public void testDeleteSelect() {
BoardRepo.deleteById(5L);
List<Board> li = (List<Board>)BoardRepo.findAll();
for(Board m :li ) {
System.out.println(m.toString());
}
}
}
- BoardUpdateTest
package com.rubypaper;
import java.util.List;
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.test.context.junit4.SpringRunner;
import com.rubypaper.board.Board;
import com.rubypaper.board.BoardRepository;
@RunWith(SpringRunner.class)
@SpringBootTest
public class BoardUpdateTest {
@Autowired
private BoardRepository BoardRepo;
@Test // ( Update + select )
public void testUpdateSelect() {
Board board = new Board();
board.setTitle("게시판 제목100");
board.setPassword("1234");
board.setWriter("소금빵100");
board.setContent("게시판 내용100");
board.setSeq(7L);
BoardRepo.save(board); // insert 와 update 는 메소드가 같다.
List<Board> li = (List<Board>)BoardRepo.findAll();
for(Board m :li ) {
System.out.println(m.toString());
}
}
}
>>
'SpringBoot' 카테고리의 다른 글
JPAJarTymeleaf-1 상세보기, 삭제하기, 수정하기 (0) | 2022.10.18 |
---|---|
JPAJarTymeleaf-1 UI (getBoardList, form) (0) | 2022.10.18 |
JPAJarTymeleaf-1 (board) (0) | 2022.10.18 |
JPA - Board(Junit -2) (0) | 2022.10.17 |
JPA - Board(Junit-1) (0) | 2022.10.17 |
Comments