Skip to content

Commit

Permalink
test: 테스트 리팩터링 (#458)
Browse files Browse the repository at this point in the history
* test: 시간 제어 구성 및 Activity Fixture 추가

* test: 로그인 테스트 최적화

* test: bus API 테스트 수정

* test: community 테스트 수정

* test: dept 테스트 수정

* test: dining test 수정

* test: land test 수정

* test: member test 수정

* test: notification test 수정

* test: owner test 수정

* test: ownerShop test 수정

* test: shop test 수정

* test: lecture test 수정

* test: track test 수정

* test: version test 수정

* test: log 제거

* test: SuppressWarnings 추가

* test: 라인 포맷팅

* test: ExtractableResponse var로 대체

* test: objectMapper static으로 변경

* chore: admin 패키지 위치 수정

* test: log 제거

* test: 불필요한 설정 제거
  • Loading branch information
Choi-JJunho committed May 9, 2024
1 parent afe1007 commit 1304ac8
Show file tree
Hide file tree
Showing 68 changed files with 4,285 additions and 4,772 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package in.koreatech.koin.domain.admin.land.controller;
package in.koreatech.koin.admin.land.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import in.koreatech.koin.domain.admin.land.dto.AdminLandsResponse;
import in.koreatech.koin.domain.land.dto.LandsGroupResponse;
import in.koreatech.koin.admin.land.dto.AdminLandsResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package in.koreatech.koin.domain.admin.land.controller;
package in.koreatech.koin.admin.land.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import in.koreatech.koin.domain.admin.land.dto.AdminLandsResponse;
import in.koreatech.koin.domain.admin.land.service.AdminLandService;
import in.koreatech.koin.domain.land.dto.LandsGroupResponse;
import in.koreatech.koin.admin.land.dto.AdminLandsResponse;
import in.koreatech.koin.admin.land.service.AdminLandService;
import lombok.RequiredArgsConstructor;

@RestController
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package in.koreatech.koin.domain.admin.land.dto;
package in.koreatech.koin.admin.land.dto;

import static com.fasterxml.jackson.databind.PropertyNamingStrategies.*;
import static com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

import in.koreatech.koin.domain.land.model.Land;
Expand All @@ -26,7 +25,7 @@ public record AdminLandResponse(
@Schema(description = "전세", example = "3500")
String charterFee,

@Schema(description = "삭제(soft delete) 여부", example = "false", required = true)
@Schema(description = "삭제(soft delete) 여부", example = "false", requiredMode = REQUIRED)
Boolean isDeleted
) {
public static AdminLandResponse from(Land land) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package in.koreatech.koin.domain.admin.land.dto;
package in.koreatech.koin.admin.land.dto;

import static com.fasterxml.jackson.databind.PropertyNamingStrategies.*;
import static com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.data.domain.Page;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

import in.koreatech.koin.domain.land.model.Land;
Expand Down Expand Up @@ -42,7 +40,7 @@ public static AdminLandsResponse of(Page<Land> pagedResult, Criteria criteria) {
pagedResult.getContent()
.stream()
.map(AdminLandResponse::from)
.collect(Collectors.toList())
.toList()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package in.koreatech.koin.domain.admin.land.repository;
package in.koreatech.koin.admin.land.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package in.koreatech.koin.domain.admin.land.service;
package in.koreatech.koin.admin.land.service;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import in.koreatech.koin.domain.admin.land.dto.AdminLandsResponse;
import in.koreatech.koin.domain.admin.land.repository.AdminLandRepository;
import in.koreatech.koin.admin.land.dto.AdminLandsResponse;
import in.koreatech.koin.admin.land.repository.AdminLandRepository;
import in.koreatech.koin.domain.land.model.Land;
import in.koreatech.koin.global.model.Criteria;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ public class Activity extends BaseEntity {
private boolean isDeleted = false;

@Builder
private Activity(Integer id, String title, String description, String imageUrls, LocalDate date,
boolean isDeleted) {
this.id = id;
private Activity(
String title,
String description,
String imageUrls,
LocalDate date,
boolean isDeleted
) {
this.title = title;
this.description = description;
this.imageUrls = imageUrls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.time.LocalDateTime;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

import in.koreatech.koin.domain.bus.model.BusTimetable;
Expand All @@ -25,6 +26,8 @@ public record BusTimetableResponse(
List<? extends BusTimetable> busTimetable,

@Schema(description = "업데이트 시각", example = "2024-04-20 18:00:00", requiredMode = NOT_REQUIRED)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
LocalDateTime updatedAt
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ default ExpressBusCache getById(String busRoute) {

List<ExpressBusCache> findAll();

Boolean existsById(String id);
boolean existsById(String id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ public List<? extends BusTimetable> getBusTimetable(BusType busType, String dire
}

public BusTimetableResponse getBusTimetableWithUpdatedAt(BusType busType, String direction, String region){
List<? extends BusTimetable> BusTimetables = getBusTimetable(busType, direction, region);
List<? extends BusTimetable> busTimetables = getBusTimetable(busType, direction, region);

if (busType.equals(BusType.COMMUTING)){
busType = BusType.SHUTTLE;
}

VersionResponse version = versionService.getVersion(busType.name().toLowerCase() + "_bus_timetable");
return new BusTimetableResponse(BusTimetables, version.updatedAt());
return new BusTimetableResponse(busTimetables, version.updatedAt());
}

public List<BusCourseResponse> getBusCourses() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public CityBusOpenApiClient(

public List<CityBusRemainTime> getBusRemainTime(String nodeId) {
Version version = versionRepository.getByType(VersionType.CITY);
if (isCacheExpired(version, clock)) {
if (isCacheExpired(version, clock) || cityBusCacheRepository.findById(nodeId).isEmpty()) {
storeRemainTimeByOpenApi();
}
return getCityBusArrivalInfoByCache(nodeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public List<ExpressBusRemainTime> getBusRemainTime(BusStation depart, BusStation
if (!expressBusCacheRepository.existsById(busCacheId)) {
storeRemainTimeByOpenApi(depart.name().toLowerCase(), arrival.name().toLowerCase());
}
return getStoredRemainTime(depart.name().toLowerCase(), arrival.name().toLowerCase());
return getStoredRemainTime(busCacheId);
}

private void storeRemainTimeByOpenApi(String departName, String arrivalName) {
Expand Down Expand Up @@ -139,7 +139,7 @@ private void storeRemainTimeByOpenApi(String departName, String arrivalName) {
private JsonObject getBusApiResponse(String departName, String arrivalName) {
try {
URL url = getBusApiURL(departName, arrivalName);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-type", "application/json");
BufferedReader reader;
Expand Down Expand Up @@ -202,8 +202,7 @@ private List<OpenApiExpressBusArrival> extractBusArrivalInfo(JsonObject jsonObje
}
}

private List<ExpressBusRemainTime> getStoredRemainTime(String departName, String arrivalName) {
String busCacheId = ExpressBusCache.generateId(new ExpressBusRoute(departName, arrivalName));
private List<ExpressBusRemainTime> getStoredRemainTime(String busCacheId) {
ExpressBusCache expressBusCache = expressBusCacheRepository.getById(busCacheId);
if (Objects.isNull(expressBusCache)) {
return Collections.emptyList();
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/in/koreatech/koin/domain/community/model/Board.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,16 @@ public List<Board> getChildren() {
}

@Builder
private Board(String tag, String name, boolean isAnonymous, Integer articleCount, boolean isDeleted,
boolean isNotice, Integer parentId, Integer seq) {
private Board(
String tag,
String name,
boolean isAnonymous,
Integer articleCount,
boolean isDeleted,
boolean isNotice,
Integer parentId,
Integer seq
) {
this.tag = tag;
this.name = name;
this.isAnonymous = isAnonymous;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import in.koreatech.koin.domain.community.model.ArticleViewLog;
import in.koreatech.koin.domain.community.model.Board;
import in.koreatech.koin.domain.community.model.BoardTag;
import in.koreatech.koin.global.model.Criteria;
import in.koreatech.koin.domain.community.repository.ArticleRepository;
import in.koreatech.koin.domain.community.repository.ArticleViewLogRepository;
import in.koreatech.koin.domain.community.repository.BoardRepository;
import in.koreatech.koin.domain.user.repository.UserRepository;
import in.koreatech.koin.global.model.Criteria;
import lombok.RequiredArgsConstructor;

@Service
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package in.koreatech.koin.domain.coop.dto;

import static com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

@JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class)
@JsonNaming(value = SnakeCaseStrategy.class)
public record SoldOutRequest(
@Schema(description = "메뉴 고유 ID", example = "1", requiredMode = REQUIRED)
@NotNull(message = "메뉴 ID는 필수입니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ public class TechStack extends BaseEntity {
private boolean isDeleted = false;

@Builder
private TechStack(String imageUrl, String name, String description, Integer trackId, boolean isDeleted) {
private TechStack(
String imageUrl,
String name,
String description,
Integer trackId
) {
this.imageUrl = imageUrl;
this.name = name;
this.description = description;
this.trackId = trackId;
this.isDeleted = isDeleted;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.time.Clock;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -273,7 +272,6 @@ public void createEvent(Integer ownerId, Integer shopId, CreateEventRequest shop
Shop shop = getOwnerShopById(shopId, ownerId);
EventArticle eventArticle = EventArticle.builder()
.shop(shop)
.thumbnailImages(new ArrayList<>())
.startDate(shopEventRequest.startDate())
.endDate(shopEventRequest.endDate())
.title(shopEventRequest.title())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public static MenuDetailResponse createForMultipleOption(Menu menu, List<MenuCat
menu.isHidden(),
false,
null,
menu.getMenuOptions().stream().map(InnerOptionPriceResponse::of).toList(), menu.getDescription(),
menu.getMenuOptions().stream().map(InnerOptionPriceResponse::of).toList(),
menu.getDescription(),
shopMenuCategories.stream().map(MenuCategory::getId).toList(),
menu.getMenuImages().stream().map(MenuImage::getImageUrl).toList()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package in.koreatech.koin.domain.shop.model;

import static jakarta.persistence.CascadeType.MERGE;
import static jakarta.persistence.CascadeType.PERSIST;
import static jakarta.persistence.CascadeType.ALL;
import static jakarta.persistence.FetchType.LAZY;
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;
Expand Down Expand Up @@ -51,7 +50,7 @@ public class EventArticle extends BaseEntity {
@Column(name = "title", nullable = false)
private String title;

@OneToMany(mappedBy = "eventArticle", cascade = {MERGE, PERSIST})
@OneToMany(mappedBy = "eventArticle", orphanRemoval = true, cascade = ALL)
private List<EventArticleImage> thumbnailImages = new ArrayList<>();

/**
Expand Down Expand Up @@ -123,7 +122,6 @@ private EventArticle(
String title,
String content,
User user,
List<EventArticleImage> thumbnailImages,
Integer hit,
String ip,
LocalDate startDate,
Expand All @@ -133,7 +131,6 @@ private EventArticle(
this.title = title;
this.content = content;
this.user = user;
this.thumbnailImages = thumbnailImages;
this.hit = hit;
this.ip = ip;
this.startDate = startDate;
Expand All @@ -152,7 +149,6 @@ public void modifyArticle(
this.content = content;
this.startDate = startDate;
this.endDate = endDate;
this.thumbnailImages.forEach(entityManager::remove);
this.thumbnailImages.clear();
entityManager.flush();
for (String imageUrl : thumbnailImages) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package in.koreatech.koin.domain.shop.model;

import static jakarta.persistence.FetchType.LAZY;
import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

import in.koreatech.koin.global.domain.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
Expand All @@ -28,7 +28,7 @@ public class EventArticleImage extends BaseEntity {
@GeneratedValue(strategy = IDENTITY)
private Integer id;

@ManyToOne(fetch = LAZY)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "event_id", nullable = false)
private EventArticle eventArticle;

Expand All @@ -38,7 +38,10 @@ public class EventArticleImage extends BaseEntity {
private String thumbnailImage;

@Builder
private EventArticleImage(EventArticle eventArticle, String thumbnailImage) {
private EventArticleImage(
EventArticle eventArticle,
String thumbnailImage
) {
this.eventArticle = eventArticle;
this.thumbnailImage = thumbnailImage;
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/in/koreatech/koin/domain/shop/model/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ public class Menu extends BaseEntity {
private List<MenuImage> menuImages = new ArrayList<>();

@Builder
private Menu(Integer shopId, String name, String description) {
private Menu(
Integer shopId,
String name,
String description
) {
this.shopId = shopId;
this.name = name;
this.description = description;
Expand Down
Loading

0 comments on commit 1304ac8

Please sign in to comment.