③ BoardRepositoryTest ( modify )
페이지 정보
본문
package web.repository;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.IntStream;
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.test.annotation.Commit;
import jakarta.transaction.Transactional;
import lombok.extern.log4j.Log4j2;
import web.domain.Board;
import web.domain.BoardImage;
import web.dto.BoardListReplyCountDTO;
@SpringBootTest
@Log4j2
public class BoardRepositoryTest {
@Autowired
private BoardRepository boardRepository;
@Transactional
@Commit
@Test
public void testModifyImages() {
Optional<Board> result = boardRepository.findByIdWithImages(1L);
Board board= result.orElseThrow();
//기존 첨부파일들 삭제
board.clearImage();
//새로운 첨부파일들
for(int i=0; i<2; i++) {
board.addImage(UUID.randomUUID().toString(), "file"+i+".jpg");
}
boardRepository.save(board);
}
}
- 이전글② BoardRepositoryTest ( read ) 24.06.28
- 다음글Board ( orphanRemoval 속성 적용 ) 24.06.28
댓글목록
등록된 댓글이 없습니다.