-
Notifications
You must be signed in to change notification settings - Fork 9
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
1 parent
1a10bc1
commit 22748cc
Showing
13 changed files
with
249 additions
and
38 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
gg-admin-repo/src/main/java/gg/admin/repo/recruit/RecruitmentAdminRepository.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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package gg.admin.repo.recruit; | ||
|
||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import gg.data.recruit.recruitment.Recruitment; | ||
|
||
public interface RecruitmentAdminRepository extends JpaRepository<Recruitment, Long> { | ||
Slice<Recruitment> findAllByOrderByEndTimeDesc(Pageable pageable); | ||
} |
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
14 changes: 14 additions & 0 deletions
14
...pi/src/main/java/gg/recruit/api/admin/controller/response/CreatedRecruitmentResponse.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,14 @@ | ||
package gg.recruit.api.admin.controller.response; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class CreatedRecruitmentResponse { | ||
private Long id; | ||
|
||
public CreatedRecruitmentResponse(Long id) { | ||
this.id = id; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
gg-recruit-api/src/main/java/gg/recruit/api/admin/controller/response/RecruitmentDto.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 gg.recruit.api.admin.controller.response; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import gg.data.recruit.recruitment.Recruitment; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class RecruitmentDto { | ||
private Long id; | ||
private String title; | ||
private String status; | ||
private String generation; | ||
private LocalDateTime startDate; | ||
private LocalDateTime endDate; | ||
|
||
@Builder | ||
public RecruitmentDto(Long id, String title, String status, String generation, LocalDateTime startDate, | ||
LocalDateTime endDate) { | ||
this.id = id; | ||
this.title = title; | ||
this.status = status; | ||
this.generation = generation; | ||
this.startDate = startDate; | ||
this.endDate = endDate; | ||
} | ||
|
||
public static RecruitmentDto toRecruitmentDto(Recruitment recruitment) { | ||
return RecruitmentDto.builder() | ||
.id(recruitment.getId()) | ||
.title(recruitment.getTitle()) | ||
.generation(recruitment.getGeneration()) | ||
.startDate(recruitment.getStartTime()) | ||
.endDate(recruitment.getEndTime()) | ||
.build(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ruit-api/src/main/java/gg/recruit/api/admin/controller/response/RecruitmentsResponse.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,20 @@ | ||
package gg.recruit.api.admin.controller.response; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import gg.data.recruit.recruitment.Recruitment; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class RecruitmentsResponse { | ||
private List<RecruitmentDto> recruitmentDtoList = new ArrayList<>(); | ||
|
||
public RecruitmentsResponse(List<Recruitment> recruitments) { | ||
for (Recruitment recruitment : recruitments) { | ||
recruitmentDtoList.add(RecruitmentDto.toRecruitmentDto(recruitment)); | ||
} | ||
} | ||
} |
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: 1 addition & 1 deletion
2
.../gg/recruit/api/user/RecruitMockData.java → .../java/gg/recruit/api/RecruitMockData.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package gg.recruit.api.user; | ||
package gg.recruit.api; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
20 changes: 0 additions & 20 deletions
20
gg-recruit-api/src/test/java/gg/recruit/api/admin/RecruitAdminMockData.java
This file was deleted.
Oops, something went wrong.
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
89 changes: 89 additions & 0 deletions
89
...t-api/src/test/java/gg/recruit/api/admin/integration/RecruitmentAdminIntegrationTest.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,89 @@ | ||
package gg.recruit.api.admin.integration; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import javax.transaction.Transactional; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.testcontainers.shaded.com.google.common.net.HttpHeaders; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import gg.admin.repo.recruit.RecruitmentAdminRepository; | ||
import gg.data.recruit.recruitment.Recruitment; | ||
import gg.recruit.api.RecruitMockData; | ||
import gg.utils.TestDataUtils; | ||
import gg.utils.annotation.IntegrationTest; | ||
|
||
@IntegrationTest | ||
@Transactional | ||
@AutoConfigureMockMvc | ||
public class RecruitmentAdminIntegrationTest { | ||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
@Autowired | ||
private TestDataUtils testDataUtils; | ||
|
||
@Autowired | ||
private RecruitMockData recruitMockData; | ||
|
||
@Autowired | ||
private RecruitmentAdminRepository recruitmentAdminRepository; | ||
|
||
@Nested | ||
@DisplayName("공고 전체 조회 시 - POST /admin/recruitments") | ||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
class PostRecruitment { | ||
|
||
@DisplayName("공고 종료 날짜 기준 최신순으로 조회된다.") | ||
@ParameterizedTest | ||
@MethodSource("getRecruitments") | ||
void getAllRecruitments(List<Recruitment> recruitments) throws Exception { | ||
// given | ||
int page = 1; | ||
int size = 10; | ||
String url = String.format("/admin/recruitments?page=%d&size=%d", page, size); | ||
String accessToken = testDataUtils.getAdminLoginAccessToken(); | ||
recruitmentAdminRepository.saveAll(recruitments); | ||
|
||
// when | ||
String response = mockMvc.perform(get(url) | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken)) | ||
.andExpect(status().isOk()) | ||
.andReturn().getResponse().getContentAsString(); | ||
|
||
System.out.println(response); | ||
} | ||
|
||
/** | ||
* parameterized test에 사용할 List<Recruitment>를 반환하는 메소드 | ||
* @return 종료 날짜가 서로 다른 3개의 공고 리스트, empty list | ||
*/ | ||
private Stream<List<Recruitment>> getRecruitments() { | ||
LocalDateTime startDate = LocalDateTime.of(2021, 1, 1, 0, 0, 0); | ||
return Stream.of(List.of( | ||
new Recruitment("title", "contents", "generation", startDate, startDate.plusDays(1)), | ||
new Recruitment("title", "contents", "generation", startDate, startDate.plusDays(2)), | ||
new Recruitment("title", "contents", "generation", startDate, startDate.plusDays(3)) | ||
), | ||
List.of()); | ||
} | ||
|
||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...cruit-api/src/test/java/gg/recruit/api/admin/service/RecruitmentAdminServiceUnitTest.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,38 @@ | ||
package gg.recruit.api.admin.service; | ||
|
||
import static org.mockito.BDDMockito.*; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Slice; | ||
|
||
import gg.admin.repo.recruit.RecruitmentAdminRepository; | ||
import gg.data.recruit.recruitment.Recruitment; | ||
import gg.utils.annotation.UnitTest; | ||
|
||
@UnitTest | ||
class RecruitmentAdminServiceUnitTest { | ||
@InjectMocks | ||
private RecruitmentAdminService recruitmentAdminService; | ||
|
||
@Mock | ||
private RecruitmentAdminRepository recruitmentAdminRepository; | ||
|
||
@Test | ||
@DisplayName("공고 조회") | ||
void getAllRecruitments() { | ||
// given | ||
Slice<Recruitment> mock = mock(Slice.class); | ||
Pageable mockPageable = mock(Pageable.class); | ||
given(recruitmentAdminRepository.findAllByOrderByEndTimeDesc(mockPageable)).willReturn(mock); | ||
|
||
// when | ||
recruitmentAdminService.getAllRecruitments(mockPageable); | ||
|
||
// then | ||
verify(recruitmentAdminRepository, times(1)).findAllByOrderByEndTimeDesc(mockPageable); | ||
} | ||
} |
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