Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test : 게시판 관련 로직 테스트 코드 작성 #398

Merged
merged 27 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
14b6073
Merge branch 'test/#393-base-test' into dev
oxix97 Mar 20, 2024
c9912a0
Merge branch 'develop' of https://github.com/Kernel360/f1-Orury-Backe…
oxix97 Mar 20, 2024
08cc657
chore : 리팩토링 전 테스트코드 삭제
GBGreenBravo Mar 20, 2024
5bf30d2
fix : 크루지원자의 검증으로 변경
GBGreenBravo Mar 20, 2024
b3f808a
fix : Gym 생성자에 createdAt, updatedAt 추가
GBGreenBravo Mar 20, 2024
fc88782
feat : Request, Response를 생성하는 ClientFixtureFactory
GBGreenBravo Mar 20, 2024
e57f5ab
feat : Entity, Dto를 생성하는 DomainFixtureFactory
GBGreenBravo Mar 20, 2024
d2d7670
test : FixtureFactory의 생성 메서드를 호출하도록 리팩토링
GBGreenBravo Mar 20, 2024
678943b
Chore : Post, PostDto, PostLike 추가
oxix97 Mar 20, 2024
03b3efb
Test : 게시판 조회 테스트
oxix97 Mar 20, 2024
612aec4
Refactor : 인기 게시글 조회 로직 수정
oxix97 Mar 20, 2024
d26aed2
Chore : 테스트 코드 팩토리 누락 사항 추가
oxix97 Mar 20, 2024
e0896d9
Chore : 테스트 중 알림 관련 Bean 생성 오류로 인한 조치
oxix97 Mar 20, 2024
404a9ac
Test : 게시판 Facade 테스트
oxix97 Mar 20, 2024
928379e
Test : 게시판 컨트롤러 테스트 (없어도 될거같음)
oxix97 Mar 20, 2024
05af0b9
test : (Batch 모듈) FixtureFactory의 생성 메서드를 호출하도록 리팩토링
GBGreenBravo Mar 20, 2024
19aa825
chore : GymDto of() 인자 추가
GBGreenBravo Mar 20, 2024
f8cc5ee
settings : (client 모듈) build.gradle 재배치 및 불필요 의존성 제거
GBGreenBravo Mar 20, 2024
9b8cdc9
test : (domain 모듈) FixtureFactory의 생성 메서드를 호출하도록 리팩토링
GBGreenBravo Mar 20, 2024
8e8fe17
refactor : (domain 모듈) 도메인에 맞게 Fixture 생성 클래스 분리
GBGreenBravo Mar 20, 2024
49f98e4
chore : 다른 Fixture 생성 코드 삭제
GBGreenBravo Mar 20, 2024
46c50ef
Merge pull request #397 from GBGreenBravo/test/#396_Test_Fixtures_Int…
GBGreenBravo Mar 21, 2024
1a70a9d
Chore : 메서드 이름 변경
oxix97 Mar 21, 2024
fda1ec7
Chore : 테스트 코드 수정사항 반영
oxix97 Mar 21, 2024
53cd7d5
git merge
oxix97 Mar 21, 2024
20473e8
Chore : 테스트 코드 수정 반영
oxix97 Mar 21, 2024
c774f51
Chore : 테스트 코드 변경
oxix97 Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions orury-batch/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ dependencies {

//mysql
runtimeOnly 'com.mysql:mysql-connector-j'

//test fixtures
testImplementation testFixtures(project(':orury-domain'))
}

tasks.named('bootJar') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.orury.batch;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import lombok.Builder;
import lombok.Getter;
import org.orury.batch.dto.GymResponse;

public class BatchFixtureFactory {

private BatchFixtureFactory() {
throw new IllegalStateException("Utility class");
}

private static final ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule());

@Getter
@Builder
public static class TestGymResponse {
private @Builder.Default String placeName = "placeName";
private @Builder.Default String kakaoId = "kakaoId";
private @Builder.Default String roadAddressName = "roadAddressName";
private @Builder.Default String phone = "phone";
private @Builder.Default String y = "y";
private @Builder.Default String x = "x";
private @Builder.Default String addressName = "addressName";

public static TestGymResponse.TestGymResponseBuilder createGymResponse() {
return TestGymResponse.builder();
}

public GymResponse get() {
return mapper.convertValue(this, GymResponse.class);
}
}
}
56 changes: 7 additions & 49 deletions orury-batch/src/test/java/org/orury/batch/job/StepItemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
import static org.orury.batch.BatchFixtureFactory.TestGymResponse.createGymResponse;
import static org.orury.domain.GymDomainFixture.TestGym.createGym;

@ExtendWith(MockitoExtension.class)
@DisplayName("Step 아이템 관련 테스트")
Expand All @@ -32,7 +32,7 @@ class StepItemTest {
@Test
void when_GymResponse_Then_ItemReader_Successfully() throws Exception {
// ItemReader가 데이터를 정상적으로 읽는지 검증
var response = createResponse();
var response = createGymResponse().build().get();
when(itemReader.read()).thenReturn(response);

assertThat(itemReader.read())
Expand All @@ -44,8 +44,8 @@ void when_GymResponse_Then_ItemReader_Successfully() throws Exception {
@Test
void when_GymResponse_Then_ItemProcessor_Successfully() throws Exception {
// ItemProcessor가 데이터를 정상적으로 처리하는지 검증
var preItem = createResponse();
var expected = createGym();
var preItem = createGymResponse().build().get();
var expected = createGym().build().get();

when(itemProcessor.process(preItem)).thenReturn(expected);

Expand All @@ -57,50 +57,8 @@ void when_GymResponse_Then_ItemProcessor_Successfully() throws Exception {
@DisplayName("Step Item Writer Test")
@Test
void when_GymResponse_Then_ItemWriter_Successfully() throws Exception {
var expected = Chunk.of(createGym());
itemWriter.write(Chunk.of(createGym()));
var expected = Chunk.of(createGym().build().get());
itemWriter.write(Chunk.of(createGym().build().get()));
verify(itemWriter, times(1)).write(expected);
}

private Gym createGym() {
return Gym.of(
null,
"name",
"kakaoId",
"roadAddress",
"address",
1.0f,
0,
0,
List.of(),
33.6514212,
126.2312121,
"brand",
"phoneNumber",
"instagramLink",
"settingDay",
"serviceMon",
"serviceTue",
"serviceWed",
"serviceThu",
"serviceFri",
"serviceSat",
"serviceSun",
"homepageLink",
"remark"
);
}

private GymResponse createResponse() {
return GymResponse.of(
"placeName",
"kakaoId",
"roadAddressName",
"phone",
"y",
"x",
"addressName"
);
}

}
38 changes: 18 additions & 20 deletions orury-client/build.gradle
Original file line number Diff line number Diff line change
@@ -1,25 +1,8 @@
//build.gradle 파일
jacoco {
toolVersion = "0.8.7"
}

jacocoTestReport {
reports {
html.destination file("${buildDir}/jacoco/html")
}
}

test {
finalizedBy 'jacocoTestReport'
}

dependencies {
implementation project(':orury-common')
implementation project(':orury-domain')

//test fixtures
testImplementation(testFixtures(project(':orury-domain')))

//devtools
developmentOnly 'org.springframework.boot:spring-boot-devtools'

Expand All @@ -45,9 +28,6 @@ dependencies {
//validation
implementation 'org.springframework.boot:spring-boot-starter-validation'

testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'

//mysql
runtimeOnly 'com.mysql:mysql-connector-j'

Expand All @@ -59,6 +39,10 @@ dependencies {

// feign client
implementation "org.springframework.cloud:spring-cloud-starter-openfeign"

//test fixtures
testImplementation testFixtures(project(':orury-domain'))

}

dependencyManagement {
Expand All @@ -78,3 +62,17 @@ tasks.named('jar') {
tasks.named('test') {
useJUnitPlatform()
}

jacoco {
toolVersion = "0.8.7"
}

jacocoTestReport {
reports {
html.destination file("${buildDir}/jacoco/html")
}
}

test {
finalizedBy 'jacocoTestReport'
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void applyCrew(CrewDto crewDto, UserDto userDto, String answer) {
throw new BusinessException(CrewErrorCode.ALREADY_MEMBER);

// 크루 참여 검증 (멤버로 참여한 크루 + 신청한 크루 <= 5)
validateCrewParticipationCount(crewDto.userDto().id());
validateCrewParticipationCount(userDto.id());

// 지원하는 크루 연령기준에 만족하지 않는 경우
if (!meetAgeCriteria(userDto.birthday(), crewDto))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
package org.orury.client.notification.interfaces;

import static org.orury.client.notification.interfaces.message.NotificationMessage.NOTIFICATIONS_READ;
import static org.orury.client.notification.interfaces.message.NotificationMessage.NOTIFICATION_STATUS_READ;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.orury.client.notification.application.NotificationFacade;
import org.orury.client.notification.application.NotificationService;
import org.orury.domain.base.converter.ApiResponse;
import org.orury.domain.notification.infrastructure.EmitterRepositoryImpl;
import org.orury.domain.notification.infrastructure.EmitterRepository;
import org.orury.domain.user.domain.dto.UserPrincipal;
import org.springframework.http.MediaType;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.util.Map;

import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import static org.orury.client.notification.interfaces.message.NotificationMessage.NOTIFICATIONS_READ;
import static org.orury.client.notification.interfaces.message.NotificationMessage.NOTIFICATION_STATUS_READ;

@Slf4j
@RequiredArgsConstructor
@RequestMapping("/notification")
@RestController
public class NotificationController {
private final NotificationService notificationService;
private final NotificationFacade notificationFacade;

// 서버 메모리에 저장된 emitter, event cache를 파악하기 위해 임시로 추가했습니다.
private final EmitterRepositoryImpl emitterRepository;
private final EmitterRepository emitterRepository;
private final ObjectMapper objectMapper = new ObjectMapper();

@Operation(summary = "SSE 연결", description = "SSE 연결을 위해 호출한다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.List;

import static org.orury.common.util.S3Folder.POST;
Expand Down Expand Up @@ -60,11 +59,8 @@ public List<PostDto> getPostDtosByUserId(Long userId, Long cursor, Pageable page
@Override
@Transactional(readOnly = true)
public Page<PostDto> getHotPostDtos(Pageable pageable) {
return postReader.findByLikeCountGreaterThanEqualAndCreatedAtGreaterThanEqualOrderByLikeCountDescCreatedAtDesc(
NumberConstants.HOT_POSTS_BOUNDARY,
LocalDateTime.now().minusMonths(1L),
pageable
).map(this::postDtoConverter);
return postReader.findByLikeCountGreaterDescAndCreatedAtDesc(pageable)
.map(this::postDtoConverter);
}

@Override
Expand Down
Loading
Loading