-
Notifications
You must be signed in to change notification settings - Fork 292
/
Copy pathSessionRepositoryTest.java
105 lines (88 loc) · 4.45 KB
/
SessionRepositoryTest.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package nextstep.courses.infrastructure;
import nextstep.courses.domain.course.image.Image;
import nextstep.courses.domain.course.image.ImageRepository;
import nextstep.courses.domain.course.image.ImageType;
import nextstep.courses.domain.course.session.*;
import nextstep.payments.domain.Payment;
import nextstep.qna.NotFoundException;
import nextstep.users.domain.NsUser;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest;
import org.springframework.jdbc.core.JdbcTemplate;
import java.time.LocalDate;
import java.time.LocalDateTime;
import static org.assertj.core.api.Assertions.assertThat;
@JdbcTest
public class SessionRepositoryTest {
private static final Logger LOGGER = LoggerFactory.getLogger(SessionRepositoryTest.class);
private static final NsUser JAVAJIGI = new NsUser(1L, "javajigi", "password", "name", "[email protected]");
@Autowired
private JdbcTemplate jdbcTemplate;
private SessionRepository sessionRepository;
private ImageRepository imageRepository;
private ApplicantsRepository applicantsRepository;
private Image image;
private Payment payment;
private LocalDate localDate;
private LocalDateTime localDateTime;
private Applicants applicants;
private Duration duration;
private SessionState sessionState;
private Session session;
private Apply apply;
@BeforeEach
void setUp() {
sessionRepository = new JdbcSessionRepository(jdbcTemplate);
imageRepository = new JdbcImageRepository(jdbcTemplate);
applicantsRepository = new JdbcApplicantsRepository(jdbcTemplate);
image = new Image(1024, ImageType.JPG, 300, 200, 1L, LocalDateTime.now());
payment = new Payment("1", 1L, 1L, 1000L);
localDate = LocalDate.of(2023, 12, 5);
localDateTime = LocalDateTime.of(2023, 12, 5, 12, 0);
applicants = new Applicants();
duration = new Duration(localDate, localDate);
sessionState = new SessionState(SessionType.CHARGE, 1000L, 10);
apply = new Apply(1L, JAVAJIGI.getId(), JAVAJIGI.getId(), localDateTime, localDateTime);
}
@Test
void save_success() {
imageRepository.save(image);
Image savedImage = imageRepository.findById(1L).orElseThrow(NotFoundException::new);
session = new Session(savedImage, duration, sessionState, 1L, localDateTime);
int count = sessionRepository.save(1L, session);
Session savedSession = sessionRepository.findById(1L).orElseThrow(NotFoundException::new);
assertThat(savedSession.getId()).isEqualTo(1L);
assertThat(savedSession.getImage()).isEqualTo(session.getImage());
assertThat(savedSession.getDuration()).isEqualTo(session.getDuration());
assertThat(savedSession.getSessionState()).isEqualTo(session.getSessionState());
LOGGER.debug("Session: {}", savedSession);
}
@Test
void applySave_success() {
session = new Session(1L, image, duration, sessionState, new Applicants(),
SessionStatus.RECRUIT, 1L, localDateTime, localDateTime);
int count = sessionRepository.saveApply(apply);
Apply savedApply = sessionRepository.findApplyByIds(JAVAJIGI.getId(), session.getId())
.orElseThrow(NotFoundException::new);
assertThat(savedApply.getNsUserId()).isEqualTo(JAVAJIGI.getId());
assertThat(savedApply.getSessionId()).isEqualTo(session.getId());
}
@Test
void update_success() {
imageRepository.save(image);
Image savedImage = imageRepository.findById(2L).orElseThrow(NotFoundException::new);
session = new Session(savedImage, duration, sessionState, 1L, localDateTime);
int count = sessionRepository.save(1L, session);
SessionState updateSessionState = new SessionState(SessionType.CHARGE, 2000L, 30);
session = new Session(2L, savedImage, duration, updateSessionState, new Applicants(), session.getSessionStatus(), 1L, localDateTime, null);
sessionRepository.update(session.getId(), session);
Session updatedSession = sessionRepository.findById(2L).orElseThrow(NotFoundException::new);
assertThat(updatedSession.getId()).isEqualTo(2L);
assertThat(updatedSession.getSessionState()).isEqualTo(updateSessionState);
LOGGER.debug("Session: {}", updatedSession);
}
}