-
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.
- Loading branch information
김교휘
authored and
김교휘
committed
Jun 30, 2024
1 parent
efcb11c
commit 7c1e15a
Showing
9 changed files
with
112 additions
and
17 deletions.
There are no files selected for viewing
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
2 changes: 2 additions & 0 deletions
2
src/main/java/com/soongsil/CoffeeChat/dto/CreateMentorRequest.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
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
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
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
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
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
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
99 changes: 99 additions & 0 deletions
99
src/test/java/com/soongsil/CoffeeChat/Mentor/MentorSaveTest.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,99 @@ | ||
package com.soongsil.CoffeeChat.Mentor; | ||
|
||
import com.soongsil.CoffeeChat.dto.CreateMentorRequest; | ||
import com.soongsil.CoffeeChat.entity.Mentor; | ||
import com.soongsil.CoffeeChat.entity.PossibleDate; | ||
import com.soongsil.CoffeeChat.entity.User; | ||
import com.soongsil.CoffeeChat.repository.MentorRepository; | ||
import com.soongsil.CoffeeChat.repository.PossibleDateRepository; | ||
import com.soongsil.CoffeeChat.repository.UserRepository; | ||
import com.soongsil.CoffeeChat.service.UserService; | ||
import jakarta.transaction.Transactional; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.annotation.Commit; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalTime; | ||
import java.util.Optional; | ||
import java.util.stream.IntStream; | ||
import java.util.stream.LongStream; | ||
|
||
@SpringBootTest | ||
@Transactional | ||
@Commit | ||
public class MentorSaveTest { | ||
@Autowired | ||
private MentorRepository mentorRepository; | ||
@Autowired | ||
private PossibleDateRepository possibleDateRepository; | ||
@Autowired | ||
private UserRepository userRepository; | ||
@Autowired | ||
private UserService userService; | ||
|
||
@Test | ||
public void testCreate500UsersWithMentors() { | ||
IntStream.range(0, 500).forEach(i -> { | ||
String username = "user" + i; | ||
// User 객체 생성 | ||
User user = new User(); | ||
user.setUsername(username); | ||
user.setRole("ROLE_USER"); // 초기 역할 설정 | ||
|
||
// User 객체 저장 | ||
userRepository.save(user); | ||
|
||
// CreateMentorRequest DTO 생성 | ||
CreateMentorRequest mentorRequest = new CreateMentorRequest(); | ||
mentorRequest.setPhoneNum("010-0000-000" + i); | ||
mentorRequest.setBirth("1990-01-01"); | ||
mentorRequest.setPart("BE"); | ||
|
||
// saveMentorInformation 메소드 호출 | ||
userService.saveMentorInformation(username, mentorRequest); | ||
}); | ||
|
||
// 사용자와 멘토 생성 확인 | ||
long userCount = userRepository.count(); | ||
assert(userCount == 500); | ||
} | ||
|
||
|
||
//멘토 500개생성 | ||
@Test | ||
public void add500Mentors() { | ||
IntStream.range(0, 500).forEach(i -> { | ||
Mentor mentor = Mentor.builder() | ||
.phoneNum("010-1234-" + String.format("%04d", i)) | ||
.birth("1990-01-01") | ||
.part("BE") | ||
.build(); | ||
mentorRepository.save(mentor); | ||
}); | ||
} | ||
|
||
@Test | ||
@Transactional | ||
public void addPossibleDatesForMentors() { | ||
LongStream.range(1, 501).forEach(mentorId -> { | ||
Optional<Mentor> mentorOptional = mentorRepository.findById(mentorId); | ||
if (mentorOptional.isPresent()) { | ||
Mentor mentor = mentorOptional.get(); | ||
for (int i = 0; i < 3; i++) { | ||
PossibleDate possibleDate = PossibleDate.builder() | ||
.mentor(mentor) | ||
.date(LocalDate.now().plusDays(i)) | ||
.startTime(LocalTime.of(10, 0).plusHours(i)) | ||
.endTime(LocalTime.of(11, 0).plusHours(i)) | ||
.apply(false) | ||
.build(); | ||
possibleDateRepository.save(possibleDate); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
|
||
} |