55import com .bootsignal .domain .course .entity .Course ;
66import com .bootsignal .domain .course .repository .CourseRepository ;
77import com .bootsignal .domain .course_session .entity .CourseSession ;
8+ import com .bootsignal .domain .user .entity .User ;
9+ import com .bootsignal .domain .user .repository .UserRepository ;
810import jakarta .persistence .criteria .JoinType ;
911import java .math .BigDecimal ;
1012import java .time .LocalDate ;
1416import org .springframework .boot .test .autoconfigure .jdbc .AutoConfigureTestDatabase ;
1517import org .springframework .boot .test .autoconfigure .orm .jpa .DataJpaTest ;
1618import org .springframework .jdbc .core .JdbcTemplate ;
19+ import org .springframework .test .context .ActiveProfiles ;
1720import org .springframework .data .domain .Page ;
1821import org .springframework .data .domain .PageRequest ;
1922import org .springframework .data .domain .Sort ;
2730 "spring.datasource.driver-class-name=org.h2.Driver"
2831})
2932@ AutoConfigureTestDatabase (replace = AutoConfigureTestDatabase .Replace .NONE )
33+ @ ActiveProfiles ("test" )
3034class CourseSessionRepositorySortTest {
3135
3236 @ Autowired
@@ -38,7 +42,10 @@ class CourseSessionRepositorySortTest {
3842 @ Autowired
3943 private JdbcTemplate jdbcTemplate ;
4044
41- private long bookmarkUserSequence = 1L ;
45+ @ Autowired
46+ private UserRepository userRepository ;
47+
48+ private int bookmarkUserSequence = 1 ;
4249
4350 @ Test
4451 void findAllSortsByCourseSatisfactionWithFetchJoin () {
@@ -158,11 +165,14 @@ private CourseSession session(String trprId, Integer trprDegr, Course course, Lo
158165
159166 private void saveBookmarks (CourseSession courseSession , int count ) {
160167 for (int i = 0 ; i < count ; i ++) {
161- // 인기순 검증에는 user 엔티티 내용이 필요하지 않아 bookmark 집계 행만 직접 추가합니다.
168+ int seq = bookmarkUserSequence ++;
169+ User user = userRepository .save (
170+ User .signupLocal ("bookmark-user-" + seq + "@test.com" , "pw" , "bm-nick-" + seq )
171+ );
162172 jdbcTemplate .update (
163173 "INSERT INTO bookmark (course_session_id, user_id, start_date, end_date) VALUES (?, ?, ?, ?)" ,
164174 courseSession .getId (),
165- bookmarkUserSequence ++ ,
175+ user . getId () ,
166176 courseSession .getTraStartDate (),
167177 courseSession .getTraEndDate ()
168178 );
0 commit comments