-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Playlist 삭제시 완전 종속 하위요소 삭제 테스트
- Loading branch information
Showing
2 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/test/java/MusicPlatform/service/playlist/PlaylistServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package MusicPlatform.service.playlist; | ||
|
||
import static org.hibernate.validator.internal.util.Contracts.assertTrue; | ||
|
||
import MusicPlatform.domain.playlist.entity.Playlist; | ||
import MusicPlatform.domain.playlist.repository.PlaylistRepository; | ||
import MusicPlatform.domain.playlist.service.PlaylistService; | ||
import jakarta.transaction.Transactional; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.test.context.jdbc.Sql; | ||
|
||
@Transactional | ||
@SpringBootTest | ||
@Sql("/sql/service-test-data.sql") | ||
public class PlaylistServiceTest { | ||
|
||
@Autowired | ||
private JdbcTemplate jdbcTemplate; | ||
@Autowired | ||
PlaylistService playlistService; | ||
@Autowired | ||
PlaylistRepository playlistRepository; | ||
|
||
@Test | ||
@DisplayName("Playlist 삭제 시 그 하위 종속 요소가 함께 삭제된다.") | ||
public void Playlist_삭제시_하위_종속_항목이_삭제된다() throws Exception { | ||
//given | ||
Playlist playlist = playlistRepository.findById(1L).orElseThrow(); | ||
//when | ||
playlistService.deletePlaylist(playlist.getArtist().getUuid(), playlist.getUuid()); | ||
playlistRepository.flush(); | ||
//then | ||
int count = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM playlist_item pi WHERE pi.playlist_id = ?",Integer.class, playlist.getId()); | ||
assertTrue(count == 0 , "하위 종속 요소 PlaylistItem 삭제되지 않음"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
insert into artist (id, uuid, name, email, link1, link2, description, provider, artist_image, role, is_deleted) | ||
values (1, UUID(), 'artist1', '[email protected]', 'https://instagram.com', NULL, 'hello I am artist1', 'google', 'image.jpg', 'ROLE_USER', false); | ||
insert into album (`id`, `uuid`, `title`, `description`, `art_image`, `release_date`, `artist_id`, `is_deleted`) | ||
insert into album (id, uuid, title, description, art_image, release_date, artist_id, is_deleted) | ||
values (1, UUID(), 'album1', 'This is a description of the album', 'image.jpg', '2025-01-01', 1, false); | ||
insert into album_like (`id`, `uuid`, `artist_id`, `album_id`) | ||
insert into album_like (id, uuid, artist_id, album_id) | ||
values (1, UUID(), 1, 1); | ||
insert into album_comment (`id`, `uuid`, `comment`, `artist_id`, `album_id`, `is_deleted`) | ||
insert into album_comment (id, uuid, comment, artist_id, album_id, is_deleted) | ||
values (1, UUID(), 'awesome song!', 1, 1, false); | ||
insert into track (`id`, `uuid`, `title`, `lyric`, `track_url`, `duration`, `album_id`, `is_deleted`) | ||
insert into track (id, uuid, title, lyric, track_url, duration, album_id, is_deleted) | ||
values (1, UUID(), 'title', 'lyric', 's3.com', 360, 1, false); | ||
insert into playlist (id, uuid, title, description, cover_image_url, artist_id, is_deleted) | ||
values (1, UUID(), 'title', 'cool playlist', 'image.jpg', 1, false); | ||
insert into playlist_item (id, uuid, track_id, playlist_id) | ||
values (1, UUID(), 1,1); |