From 9b5a1631aec3bbf5839b358f56d52ce0ce69830e Mon Sep 17 00:00:00 2001 From: shkisme Date: Thu, 22 Dec 2022 22:54:15 +0900 Subject: [PATCH 1/9] =?UTF-8?q?feat:=20CtfChallengeHasCtfChallenge=20Entit?= =?UTF-8?q?y,=20Repository=20=EC=83=9D=EC=84=B1=20issue:=20#471?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...hallengeHasCtfChallengeCategoryEntity.java | 35 +++++++++++++++++++ ...llengeHasCtfChallengeCategoryEntityPK.java | 19 ++++++++++ ...engeHasCtfChallengeCategoryRepository.java | 10 ++++++ 3 files changed, 64 insertions(+) create mode 100644 src/main/java/keeper/project/homepage/ctf/entity/CtfChallengeHasCtfChallengeCategoryEntity.java create mode 100644 src/main/java/keeper/project/homepage/ctf/entity/CtfChallengeHasCtfChallengeCategoryEntityPK.java create mode 100644 src/main/java/keeper/project/homepage/ctf/repository/CtfChallengeHasCtfChallengeCategoryRepository.java diff --git a/src/main/java/keeper/project/homepage/ctf/entity/CtfChallengeHasCtfChallengeCategoryEntity.java b/src/main/java/keeper/project/homepage/ctf/entity/CtfChallengeHasCtfChallengeCategoryEntity.java new file mode 100644 index 00000000..740b5609 --- /dev/null +++ b/src/main/java/keeper/project/homepage/ctf/entity/CtfChallengeHasCtfChallengeCategoryEntity.java @@ -0,0 +1,35 @@ +package keeper.project.homepage.ctf.entity; + +import java.io.Serializable; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.IdClass; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Builder +@Entity +@Getter +@NoArgsConstructor +@AllArgsConstructor +@IdClass(CtfChallengeHasCtfChallengeCategoryEntityPK.class) // 정의한 idclass 주입 +@Table(name = "ctf_challenge_has_ctf_challenge_category") +public class CtfChallengeHasCtfChallengeCategoryEntity implements Serializable { + + @Id + @ManyToOne(targetEntity = CtfChallengeEntity.class, fetch = FetchType.LAZY) + @JoinColumn(name = "ctf_challenge_id") + private CtfChallengeEntity challenge; + + @Id + @ManyToOne(targetEntity = CtfChallengeCategoryEntity.class, fetch = FetchType.LAZY) + @JoinColumn(name = "ctf_challenge_category_id") + private CtfChallengeCategoryEntity category; + +} diff --git a/src/main/java/keeper/project/homepage/ctf/entity/CtfChallengeHasCtfChallengeCategoryEntityPK.java b/src/main/java/keeper/project/homepage/ctf/entity/CtfChallengeHasCtfChallengeCategoryEntityPK.java new file mode 100644 index 00000000..e80faa8e --- /dev/null +++ b/src/main/java/keeper/project/homepage/ctf/entity/CtfChallengeHasCtfChallengeCategoryEntityPK.java @@ -0,0 +1,19 @@ +package keeper.project.homepage.ctf.entity; + +import java.io.Serializable; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@EqualsAndHashCode +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class CtfChallengeHasCtfChallengeCategoryEntityPK implements Serializable { + + private Long challenge; + private Long category; +} diff --git a/src/main/java/keeper/project/homepage/ctf/repository/CtfChallengeHasCtfChallengeCategoryRepository.java b/src/main/java/keeper/project/homepage/ctf/repository/CtfChallengeHasCtfChallengeCategoryRepository.java new file mode 100644 index 00000000..0ebf9988 --- /dev/null +++ b/src/main/java/keeper/project/homepage/ctf/repository/CtfChallengeHasCtfChallengeCategoryRepository.java @@ -0,0 +1,10 @@ +package keeper.project.homepage.ctf.repository; + +import keeper.project.homepage.ctf.entity.CtfChallengeHasCtfChallengeCategoryEntity; +import keeper.project.homepage.ctf.entity.CtfChallengeHasCtfChallengeCategoryEntityPK; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CtfChallengeHasCtfChallengeCategoryRepository extends + JpaRepository { + +} From be40d07bf1e84c4eeae8d0f592ab247bef27c1e7 Mon Sep 17 00:00:00 2001 From: shkisme Date: Thu, 22 Dec 2022 22:56:20 +0900 Subject: [PATCH 2/9] =?UTF-8?q?fix:=20CtfChallengeEntity=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20issue:=20#471?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/homepage/ctf/entity/CtfChallengeEntity.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/keeper/project/homepage/ctf/entity/CtfChallengeEntity.java b/src/main/java/keeper/project/homepage/ctf/entity/CtfChallengeEntity.java index ce29bab4..df79af77 100644 --- a/src/main/java/keeper/project/homepage/ctf/entity/CtfChallengeEntity.java +++ b/src/main/java/keeper/project/homepage/ctf/entity/CtfChallengeEntity.java @@ -57,10 +57,9 @@ public class CtfChallengeEntity { @JoinColumn(name = "type_id", nullable = false) CtfChallengeTypeEntity ctfChallengeTypeEntity; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "category_id", nullable = false) - CtfChallengeCategoryEntity ctfChallengeCategoryEntity; - + @Builder.Default + @OneToMany(mappedBy = "challenge", cascade = CascadeType.REMOVE) + List ctfChallengeHasCtfChallengeCategoryList = new ArrayList<>(); @Column(nullable = false) @Setter Long score; From eee24cab80c1c14e4b9f077f3ad6e320c0b8c781 Mon Sep 17 00:00:00 2001 From: shkisme Date: Thu, 22 Dec 2022 22:57:20 +0900 Subject: [PATCH 3/9] =?UTF-8?q?fix:=20Dto,=20Service=20=EC=BD=94=EB=93=9C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20issue:=20#471?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ctf/dto/CtfChallengeAdminDto.java | 12 ++++--- .../ctf/dto/CtfChallengeCategoryDto.java | 15 ++++++++ .../homepage/ctf/dto/CtfChallengeDto.java | 9 +++-- .../ctf/dto/CtfCommonChallengeDto.java | 13 ++++--- .../homepage/ctf/service/CtfAdminService.java | 36 ++++++++++++++++--- 5 files changed, 69 insertions(+), 16 deletions(-) diff --git a/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeAdminDto.java b/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeAdminDto.java index 52633748..bf4b1d08 100644 --- a/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeAdminDto.java +++ b/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeAdminDto.java @@ -1,5 +1,7 @@ package keeper.project.homepage.ctf.dto; +import static java.util.stream.Collectors.toList; + import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty.Access; import com.fasterxml.jackson.databind.annotation.JsonSerialize; @@ -38,12 +40,12 @@ public class CtfChallengeAdminDto extends CtfChallengeDto { private CtfDynamicChallengeInfoDto dynamicInfo; public CtfChallengeEntity toEntity(CtfContestEntity contest, CtfChallengeTypeEntity type, - CtfChallengeCategoryEntity category, FileEntity fileEntity, MemberEntity creator) { + FileEntity fileEntity, MemberEntity creator) { return CtfChallengeEntity.builder() .name(title) .description(content) .ctfContestEntity(contest) - .ctfChallengeCategoryEntity(category) + .ctfChallengeHasCtfChallengeCategoryList(new ArrayList<>()) .ctfChallengeTypeEntity(type) .isSolvable(isSolvable) .registerTime(LocalDateTime.now()) @@ -56,8 +58,6 @@ public CtfChallengeEntity toEntity(CtfContestEntity contest, CtfChallengeTypeEnt } public static CtfChallengeAdminDto toDto(CtfChallengeEntity challenge, Long solvedTeamCount) { - CtfChallengeCategoryDto category = CtfChallengeCategoryDto.toDto( - challenge.getCtfChallengeCategoryEntity()); CtfChallengeTypeDto type = CtfChallengeTypeDto.toDto( challenge.getCtfChallengeTypeEntity()); FileDto file = FileDto.toDto( @@ -70,7 +70,9 @@ public static CtfChallengeAdminDto toDto(CtfChallengeEntity challenge, Long solv .title(challenge.getName()) .content(challenge.getDescription()) .contestId(challenge.getCtfContestEntity().getId()) - .category(category) + .category(challenge.getCtfChallengeHasCtfChallengeCategoryList().stream() + .map(CtfChallengeCategoryDto::toDto).collect( + toList())) .type(type) .flag(getVirtualTeamFlag(challenge).getContent()) .isSolvable(challenge.getIsSolvable()) diff --git a/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeCategoryDto.java b/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeCategoryDto.java index 0f3a06e5..c087f6be 100644 --- a/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeCategoryDto.java +++ b/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeCategoryDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty.Access; import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; +import keeper.project.homepage.ctf.entity.CtfChallengeHasCtfChallengeCategoryEntity; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -24,10 +25,24 @@ public class CtfChallengeCategoryDto { @JsonProperty(access = Access.READ_ONLY) private String name; + public static CtfChallengeCategoryEntity toEntity(CtfChallengeCategoryDto ctfChallengeCategoryDto){ + return CtfChallengeCategoryEntity.builder() + .id(ctfChallengeCategoryDto.getId()) + .name(ctfChallengeCategoryDto.getName()) + .build(); + } + public static CtfChallengeCategoryDto toDto(CtfChallengeCategoryEntity ctfChallengeCategoryEntity) { return CtfChallengeCategoryDto.builder() .id(ctfChallengeCategoryEntity.getId()) .name(ctfChallengeCategoryEntity.getName()) .build(); } + + public static CtfChallengeCategoryDto toDto(CtfChallengeHasCtfChallengeCategoryEntity ctfChallengeHasCtfChallengeCategoryEntity) { + return CtfChallengeCategoryDto.builder() + .id(ctfChallengeHasCtfChallengeCategoryEntity.getCategory().getId()) + .name(ctfChallengeHasCtfChallengeCategoryEntity.getCategory().getName()) + .build(); + } } diff --git a/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeDto.java b/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeDto.java index 410273db..83992748 100644 --- a/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeDto.java +++ b/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeDto.java @@ -1,5 +1,7 @@ package keeper.project.homepage.ctf.dto; +import static java.util.stream.Collectors.toList; + import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; @@ -32,8 +34,6 @@ public class CtfChallengeDto extends CtfCommonChallengeDto { public static CtfChallengeDto toDto(CtfChallengeEntity challenge, Long solvedTeamCount, Boolean isSolved, CtfFlagEntity ctfFlagEntity) { - CtfChallengeCategoryDto category = CtfChallengeCategoryDto.toDto( - challenge.getCtfChallengeCategoryEntity()); FileDto file = FileDto.toDto(challenge.getFileEntity()); return CtfChallengeDto.builder() @@ -41,7 +41,10 @@ public static CtfChallengeDto toDto(CtfChallengeEntity challenge, Long solvedTea .title(challenge.getName()) .content(challenge.getDescription()) .contestId(challenge.getCtfContestEntity().getId()) - .category(category) + .category(challenge.getCtfChallengeHasCtfChallengeCategoryList() + .stream() + .map(CtfChallengeCategoryDto::toDto) + .collect(toList())) .creatorName(challenge.getCreator().getNickName()) .score(challenge.getScore()) .solvedTeamCount(solvedTeamCount) diff --git a/src/main/java/keeper/project/homepage/ctf/dto/CtfCommonChallengeDto.java b/src/main/java/keeper/project/homepage/ctf/dto/CtfCommonChallengeDto.java index f69da1d1..656f891a 100644 --- a/src/main/java/keeper/project/homepage/ctf/dto/CtfCommonChallengeDto.java +++ b/src/main/java/keeper/project/homepage/ctf/dto/CtfCommonChallengeDto.java @@ -1,10 +1,14 @@ package keeper.project.homepage.ctf.dto; +import static java.util.stream.Collectors.toList; + import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty.Access; import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.annotation.Nulls; import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.Collectors; import javax.validation.constraints.Max; import javax.validation.constraints.Min; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; @@ -28,7 +32,7 @@ public class CtfCommonChallengeDto { protected String title; protected Long score; - protected CtfChallengeCategoryDto category; + protected List category; protected Long contestId; @Max(MAX_SUBMIT_COUNT) @Min(MIN_SUBMIT_COUNT) @@ -48,14 +52,15 @@ public class CtfCommonChallengeDto { public static CtfCommonChallengeDto toDto(CtfChallengeEntity challenge, Boolean isSolved, CtfFlagEntity ctfFlagEntity) { - CtfChallengeCategoryDto category = CtfChallengeCategoryDto.toDto( - challenge.getCtfChallengeCategoryEntity()); return CtfCommonChallengeDto.builder() .challengeId(challenge.getId()) .title(challenge.getName()) .contestId(challenge.getCtfContestEntity().getId()) - .category(category) + .category(challenge.getCtfChallengeHasCtfChallengeCategoryList() + .stream() + .map(CtfChallengeCategoryDto::toDto) + .collect(toList())) .score(challenge.getScore()) .isSolved(isSolved) .remainedSubmitCount(ctfFlagEntity.getRemainedSubmitCount()) diff --git a/src/main/java/keeper/project/homepage/ctf/service/CtfAdminService.java b/src/main/java/keeper/project/homepage/ctf/service/CtfAdminService.java index 99207bad..15225481 100644 --- a/src/main/java/keeper/project/homepage/ctf/service/CtfAdminService.java +++ b/src/main/java/keeper/project/homepage/ctf/service/CtfAdminService.java @@ -5,15 +5,19 @@ import static keeper.project.homepage.util.service.CtfUtilService.VIRTUAL_TEAM_ID; import java.nio.file.AccessDeniedException; +import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import keeper.project.homepage.ctf.dto.CtfChallengeAdminDto; +import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto; import keeper.project.homepage.ctf.dto.CtfContestAdminDto; import keeper.project.homepage.ctf.dto.CtfDynamicChallengeInfoDto; import keeper.project.homepage.ctf.dto.CtfProbMakerDto; import keeper.project.homepage.ctf.dto.CtfSubmitLogDto; import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; +import keeper.project.homepage.ctf.entity.CtfChallengeHasCtfChallengeCategoryEntity; import keeper.project.homepage.ctf.entity.CtfChallengeTypeEntity; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.ctf.entity.CtfDynamicChallengeInfoEntity; @@ -24,6 +28,7 @@ import keeper.project.homepage.ctf.exception.CustomCtfChallengeNotFoundException; import keeper.project.homepage.ctf.exception.CustomCtfTypeNotFoundException; import keeper.project.homepage.ctf.repository.CtfChallengeCategoryRepository; +import keeper.project.homepage.ctf.repository.CtfChallengeHasCtfChallengeCategoryRepository; import keeper.project.homepage.ctf.repository.CtfChallengeRepository; import keeper.project.homepage.ctf.repository.CtfChallengeTypeRepository; import keeper.project.homepage.ctf.repository.CtfContestRepository; @@ -63,6 +68,8 @@ public class CtfAdminService { private final CtfContestRepository ctfContestRepository; private final CtfTeamRepository ctfTeamRepository; private final CtfChallengeCategoryRepository ctfChallengeCategoryRepository; + + private final CtfChallengeHasCtfChallengeCategoryRepository ctfChallengeHasCtfChallengeCategoryRepository; private final CtfSubmitLogRepository ctfSubmitLogRepository; private final CtfChallengeTypeRepository ctfChallengeTypeRepository; private final CtfChallengeRepository challengeRepository; @@ -111,6 +118,8 @@ public CtfProbMakerDto designateProbMaker(CtfProbMakerDto probMakerDto) { @Transactional public CtfChallengeAdminDto createChallenge(CtfChallengeAdminDto challengeAdminDto) { CtfChallengeEntity newChallenge = createChallengeEntity(challengeAdminDto); + + setChallengeCategory(newChallenge, challengeAdminDto); if (ctfUtilService.isTypeDynamic(newChallenge)) { trySetDynamicInfoInChallenge(newChallenge, challengeAdminDto); } @@ -317,14 +326,32 @@ private Long getCtfId(CtfChallengeEntity challenge) { private CtfChallengeEntity createChallengeEntityWithFileEntity( CtfChallengeAdminDto challengeAdminDto, FileEntity fileEntity) { CtfContestEntity contest = getCtfContestEntity(challengeAdminDto.getContestId()); - CtfChallengeCategoryEntity category = getCategoryEntity(challengeAdminDto); + CtfChallengeTypeEntity type = getTypeEntity(challengeAdminDto); MemberEntity creator = authService.getMemberEntityWithJWT(); + CtfChallengeEntity challenge = challengeAdminDto - .toEntity(contest, type, category, fileEntity, creator); + .toEntity(contest, type, fileEntity, creator); + return challengeRepository.save(challenge); } + private void setChallengeCategory(CtfChallengeEntity challenge, + CtfChallengeAdminDto challengeAdminDto) { + List ctfChallengeCategoryEntityList = challengeAdminDto.getCategory() + .stream() + .map(CtfChallengeCategoryDto::toEntity).toList(); + + for (CtfChallengeCategoryEntity ctfChallengeCategory : ctfChallengeCategoryEntityList) { + CtfChallengeHasCtfChallengeCategoryEntity save = ctfChallengeHasCtfChallengeCategoryRepository.save( + CtfChallengeHasCtfChallengeCategoryEntity.builder() + .challenge(challenge) + .category(ctfChallengeCategory) + .build()); + challenge.getCtfChallengeHasCtfChallengeCategoryList().add(save); + } + } + private CtfChallengeEntity createChallengeEntity(CtfChallengeAdminDto challengeAdminDto) { return createChallengeEntityWithFileEntity(challengeAdminDto, null); } @@ -335,9 +362,10 @@ private CtfChallengeTypeEntity getTypeEntity(CtfChallengeAdminDto challengeAdmin .orElseThrow(CustomCtfTypeNotFoundException::new); } - private CtfChallengeCategoryEntity getCategoryEntity(CtfChallengeAdminDto challengeAdminDto) { + private CtfChallengeCategoryEntity getCategoryEntity( + CtfChallengeCategoryDto ctfChallengeCategoryDto) { return ctfChallengeCategoryRepository - .findById(challengeAdminDto.getCategory().getId()) + .findById(ctfChallengeCategoryDto.getId()) .orElseThrow(CustomCtfCategoryNotFoundException::new); } From 6918f6993b40568dd58a15b64265f9ddb65dee6e Mon Sep 17 00:00:00 2001 From: shkisme Date: Thu, 22 Dec 2022 23:01:22 +0900 Subject: [PATCH 4/9] =?UTF-8?q?test:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EA=B0=9C=EC=88=98=EC=97=90=20=EB=94=B0=EB=A5=B8=20?= =?UTF-8?q?Service=20Test=20=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1=20issu?= =?UTF-8?q?e:=20#471?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ctf/service/CtfAdminServiceTest.java | 79 ++++++++++++++++--- 1 file changed, 67 insertions(+), 12 deletions(-) diff --git a/src/test/java/keeper/project/homepage/ctf/service/CtfAdminServiceTest.java b/src/test/java/keeper/project/homepage/ctf/service/CtfAdminServiceTest.java index 49c39f6f..44b53743 100644 --- a/src/test/java/keeper/project/homepage/ctf/service/CtfAdminServiceTest.java +++ b/src/test/java/keeper/project/homepage/ctf/service/CtfAdminServiceTest.java @@ -4,12 +4,14 @@ import static keeper.project.homepage.ApiControllerTestHelper.MemberJobName.회장; import static keeper.project.homepage.ApiControllerTestHelper.MemberRankName.일반회원; import static keeper.project.homepage.ApiControllerTestHelper.MemberTypeName.정회원; +import static keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory.FORENSIC; import static keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory.WEB; import static keeper.project.homepage.ctf.entity.CtfChallengeTypeEntity.CtfChallengeType.DYNAMIC; import static keeper.project.homepage.ctf.entity.CtfChallengeTypeEntity.CtfChallengeType.STANDARD; import static org.assertj.core.api.Assertions.assertThat; import java.nio.file.AccessDeniedException; +import java.util.ArrayList; import java.util.List; import java.util.UUID; import javax.persistence.EntityManager; @@ -20,6 +22,7 @@ import keeper.project.homepage.ctf.dto.CtfDynamicChallengeInfoDto; import keeper.project.homepage.ctf.dto.CtfFlagDto; import keeper.project.homepage.ctf.dto.CtfTeamDetailDto; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.ctf.entity.CtfFlagEntity; import keeper.project.homepage.member.entity.MemberEntity; @@ -65,9 +68,46 @@ private static void setAuthentication(MemberEntity contestCreator, MemberJobName } @Test - @DisplayName("문제 생성 테스트") + @DisplayName("문제 생성 테스트 - 카테고리 1개") void createChallenge() { - CtfChallengeAdminDto result = createStandardChallenge(1234L, "flag", "content", "title", 123L); + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(WEB.getId()) + .name(WEB.getName()) + .build())); + CtfChallengeAdminDto result = createStandardChallenge(1234L, "flag", "content", "title", category, 123L); + CtfFlagEntity flag = ctfFlagRepository.findByCtfChallengeEntityIdAndCtfTeamEntityId( + result.getChallengeId(), CtfUtilService.VIRTUAL_TEAM_ID).orElseThrow(); + + assertThat(result.getFlag()).isEqualTo("flag"); + assertThat(result.getRemainedSubmitCount()).isEqualTo(123L); + assertThat(result.getType().getId()).isEqualTo(getStandardType().getId()); + assertThat(result.getDynamicInfo().getMaxScore()).isNull(); + assertThat(result.getDynamicInfo().getMinScore()).isNull(); + assertThat(result.getContent()).isEqualTo("content"); + assertThat(result.getTitle()).isEqualTo("title"); + assertThat(result.getScore()).isEqualTo(1234L); + assertThat(result.getCategory().size()).isEqualTo(1); + assertThat(result.getCategory().get(0).getId()).isEqualTo(category.get(0).getId()); + assertThat(result.getCategory().size()).isEqualTo(1); + assertThat(result.getContestId()).isEqualTo(ctfContestEntity.getId()); + assertThat(flag.getRemainedSubmitCount()).isEqualTo(123L); + assertThat(flag.getIsCorrect()).isEqualTo(false); + } + + @Test + @DisplayName("문제 생성 테스트 - 카테고리 2개이상") + void createChallengeHasManyCategory() { + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(WEB.getId()) + .name(WEB.getName()) + .build())); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(FORENSIC.getId()) + .name(FORENSIC.getName()) + .build())); + CtfChallengeAdminDto result = createStandardChallenge(1234L, "flag", "content", "title", category, 123L); CtfFlagEntity flag = ctfFlagRepository.findByCtfChallengeEntityIdAndCtfTeamEntityId( result.getChallengeId(), CtfUtilService.VIRTUAL_TEAM_ID).orElseThrow(); @@ -79,19 +119,22 @@ void createChallenge() { assertThat(result.getContent()).isEqualTo("content"); assertThat(result.getTitle()).isEqualTo("title"); assertThat(result.getScore()).isEqualTo(1234L); - assertThat(result.getCategory().getId()).isEqualTo(getWebCategory().getId()); + assertThat(result.getCategory().get(0).getId()).isEqualTo(category.get(0).getId()); + assertThat(result.getCategory().get(1).getId()).isEqualTo(category.get(1).getId()); + assertThat(result.getCategory().size()).isEqualTo(2); assertThat(result.getContestId()).isEqualTo(ctfContestEntity.getId()); assertThat(flag.getRemainedSubmitCount()).isEqualTo(123L); assertThat(flag.getIsCorrect()).isEqualTo(false); } - private CtfChallengeAdminDto createStandardChallenge(long score) { - return createStandardChallenge(score, getRandomUUID(), getRandomUUID(), getRandomUUID(), 15L); + private CtfChallengeAdminDto createStandardChallenge(long score, List category) { + return createStandardChallenge(score, getRandomUUID(), getRandomUUID(), getRandomUUID(), category, 15L); } private CtfChallengeAdminDto createStandardChallenge(long score, String flag, String content, - String title, long maxSubmitCount) { + String title, List category, long maxSubmitCount) { setAuthentication(contestCreator, 회장); + CtfChallengeAdminDto challengeAdminDto = CtfChallengeAdminDto.builder() .isSolvable(true) .flag(flag) @@ -100,7 +143,7 @@ private CtfChallengeAdminDto createStandardChallenge(long score, String flag, St .content(content) .title(title) .score(score) - .category(getWebCategory()) + .category(category) .contestId(ctfContestEntity.getId()) .maxSubmitCount(maxSubmitCount) .build(); @@ -116,6 +159,13 @@ private CtfChallengeAdminDto createDynamicChallenge(CtfDynamicChallengeInfoDto d private CtfChallengeAdminDto createDynamicChallenge(CtfDynamicChallengeInfoDto dynamicScore, String flag, String content, String title, long maxSubmitCount) { setAuthentication(contestCreator, 회장); + + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(WEB.getId()) + .name(WEB.getName()) + .build())); + CtfChallengeAdminDto challengeAdminDto = CtfChallengeAdminDto.builder() .isSolvable(true) .flag(flag) @@ -124,7 +174,7 @@ private CtfChallengeAdminDto createDynamicChallenge(CtfDynamicChallengeInfoDto d .content(content) .title(title) .score(0L) - .category(getWebCategory()) + .category(category) .contestId(ctfContestEntity.getId()) .maxSubmitCount(maxSubmitCount) .build(); @@ -156,9 +206,14 @@ private static CtfChallengeTypeDto getDynamicType() { @Test @DisplayName("[시나리오1] STANDRAD 문제 삭제 시 점수 반영 제대로 되는지 테스트") void deleteProblem_scenario1() { - CtfChallengeAdminDto challenge1 = createStandardChallenge(100L); - CtfChallengeAdminDto challenge2 = createStandardChallenge(200L); - CtfChallengeAdminDto challenge3 = createStandardChallenge(400L); + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(WEB.getId()) + .name(WEB.getName()) + .build())); + CtfChallengeAdminDto challenge1 = createStandardChallenge(100L, category); + CtfChallengeAdminDto challenge2 = createStandardChallenge(200L, category); + CtfChallengeAdminDto challenge3 = createStandardChallenge(400L, category); MemberEntity user1 = generateMemberEntity(회원, 정회원, 일반회원); CtfTeamDetailDto team1 = createCtfTeam(user1); // 1번, 2번 문제 해결 @@ -192,7 +247,7 @@ void deleteProblem_scenario1() { assertThat(ctfTeamRepository.getById(team2.getId()).getScore()).isEqualTo(400L); assertThat(ctfTeamRepository.getById(team3.getId()).getScore()).isEqualTo(400L); - CtfChallengeAdminDto challenge4 = createStandardChallenge(800L); + CtfChallengeAdminDto challenge4 = createStandardChallenge(800L, category); assertThat(solveChallenge(challenge4, user1)).isTrue(); assertThat(solveChallenge(challenge4, user2)).isTrue(); From 365f10b3e5a236d98c168a2fd1696143ca934a9c Mon Sep 17 00:00:00 2001 From: shkisme Date: Thu, 22 Dec 2022 23:02:06 +0900 Subject: [PATCH 5/9] =?UTF-8?q?test:=20=EA=B4=80=EB=A0=A8=20Test=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95=20issue:=20#471?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CtfAdminControllerTest.java | 138 ++++++++++++++---- .../CtfChallengeControllerTest.java | 62 +++++--- .../ctf/controller/CtfSpringTestHelper.java | 43 ++++-- .../ctf/controller/CtfTeamControllerTest.java | 13 +- .../CtfChallengeRepositoryTest.java | 10 +- .../ctf/repository/CtfFlagRepositoryTest.java | 8 +- .../CtfSubmitLogRepositoryTest.java | 5 +- .../ctf/repository/CtfTestHelper.java | 10 +- .../ctf/service/CtfChallengeServiceTest.java | 10 +- .../homepage/ctf/service/CtfServiceTest.java | 14 +- .../ctf/service/CtfTeamServiceTest.java | 12 +- .../util/service/CtfUtilServiceTest.java | 9 +- 12 files changed, 255 insertions(+), 79 deletions(-) diff --git a/src/test/java/keeper/project/homepage/ctf/controller/CtfAdminControllerTest.java b/src/test/java/keeper/project/homepage/ctf/controller/CtfAdminControllerTest.java index 5fe187aa..686ffee1 100644 --- a/src/test/java/keeper/project/homepage/ctf/controller/CtfAdminControllerTest.java +++ b/src/test/java/keeper/project/homepage/ctf/controller/CtfAdminControllerTest.java @@ -32,12 +32,15 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.util.ArrayList; +import java.util.List; import keeper.project.homepage.ctf.dto.CtfChallengeAdminDto; import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto; import keeper.project.homepage.ctf.dto.CtfChallengeTypeDto; import keeper.project.homepage.ctf.dto.CtfContestAdminDto; import keeper.project.homepage.ctf.dto.CtfDynamicChallengeInfoDto; import keeper.project.homepage.ctf.dto.CtfProbMakerDto; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.ctf.entity.CtfFlagEntity; @@ -267,8 +270,16 @@ private boolean isDisqualifyProbMakerRole(MemberEntity probMaker, MemberJobEntit @Test @DisplayName("출제자 권한으로 문제 생성 - 성공") public void createProblemSuccess() throws Exception { - CtfChallengeCategoryDto category = CtfChallengeCategoryDto.toDto( - ctfChallengeCategoryRepository.getById(FORENSIC.getId())); + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(FORENSIC.getId()) + .name(FORENSIC.getName()) + .build())); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(MISC.getId()) + .name(MISC.getName()) + .build())); + CtfChallengeTypeDto type = CtfChallengeTypeDto.toDto( ctfChallengeTypeRepository.getById(DYNAMIC.getId())); MemberEntity creator = generateMemberEntity(출제자, 정회원, 일반회원); @@ -301,7 +312,8 @@ public void createProblemSuccess() throws Exception { .andExpect(jsonPath("$.data.title").value(title)) .andExpect(jsonPath("$.data.content").value(content)) .andExpect(jsonPath("$.data.contestId").value(contestEntity.getId())) - .andExpect(jsonPath("$.data.category.id").value(category.getId())) + .andExpect(jsonPath("$.data.category[0].id").value(category.get(0).getId())) + .andExpect(jsonPath("$.data.category[1].id").value(category.get(1).getId())) .andExpect(jsonPath("$.data.type.id").value(type.getId())) .andExpect(jsonPath("$.data.isSolvable").value(isSolvable)) .andExpect(jsonPath("$.data.creatorName").value(creator.getNickName())) @@ -314,7 +326,7 @@ public void createProblemSuccess() throws Exception { fieldWithPath("title").description("문제 제목"), fieldWithPath("content").description("문제 내용"), fieldWithPath("contestId").description("문제가 등록 될 CTF id"), - fieldWithPath("category.id").description("문제 카테고리 Id"), + fieldWithPath("category[].id").description("문제 카테고리 Id"), fieldWithPath("type.id").description("문제 Type Id"), fieldWithPath("isSolvable").description("현재 풀 수 있는 지 여부"), fieldWithPath("score").description( @@ -343,8 +355,13 @@ public void createProblemSuccess() throws Exception { @Test @DisplayName("회장 권한으로 STANDARD 문제 생성 - 성공") public void createStandardProblemSuccess() throws Exception { - CtfChallengeCategoryDto category = CtfChallengeCategoryDto.toDto( - ctfChallengeCategoryRepository.getById(FORENSIC.getId())); + + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(FORENSIC.getId()) + .name(FORENSIC.getName()) + .build())); + CtfChallengeTypeDto type = CtfChallengeTypeDto.toDto( ctfChallengeTypeRepository.getById(STANDARD.getId())); MemberEntity creator = generateMemberEntity(출제자, 정회원, 일반회원); @@ -366,7 +383,7 @@ public void createStandardProblemSuccess() throws Exception { .andExpect(jsonPath("$.data.title").value(title)) .andExpect(jsonPath("$.data.content").value(content)) .andExpect(jsonPath("$.data.contestId").value(contestEntity.getId())) - .andExpect(jsonPath("$.data.category.id").value(category.getId())) + .andExpect(jsonPath("$.data.category[0].id").value(category.get(0).getId())) .andExpect(jsonPath("$.data.type.id").value(type.getId())) .andExpect(jsonPath("$.data.isSolvable").value(isSolvable)) .andExpect(jsonPath("$.data.creatorName").value(adminEntity.getNickName())) @@ -377,8 +394,12 @@ public void createStandardProblemSuccess() throws Exception { @Test @DisplayName("문제 생성 시 maxSubmitCount를 넣지 않을 경우 default value가 들어가야 한다.") public void createProblem_maxSubmitCount_defaultValue() throws Exception { - CtfChallengeCategoryDto category = CtfChallengeCategoryDto.toDto( - ctfChallengeCategoryRepository.getById(FORENSIC.getId())); + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(FORENSIC.getId()) + .name(FORENSIC.getName()) + .build())); + CtfChallengeTypeDto type = CtfChallengeTypeDto.toDto( ctfChallengeTypeRepository.getById(STANDARD.getId())); MemberEntity creator = generateMemberEntity(출제자, 정회원, 일반회원); @@ -401,7 +422,7 @@ public void createProblem_maxSubmitCount_defaultValue() throws Exception { .andExpect(jsonPath("$.data.title").value(title)) .andExpect(jsonPath("$.data.content").value(content)) .andExpect(jsonPath("$.data.contestId").value(contestEntity.getId())) - .andExpect(jsonPath("$.data.category.id").value(category.getId())) + .andExpect(jsonPath("$.data.category[0].id").value(category.get(0).getId())) .andExpect(jsonPath("$.data.type.id").value(type.getId())) .andExpect(jsonPath("$.data.isSolvable").value(isSolvable)) .andExpect(jsonPath("$.data.creatorName").value(adminEntity.getNickName())) @@ -423,8 +444,14 @@ private ResultActions createChallengeControllerTest(CtfChallengeAdminDto challen @ValueSource(longs = {-10, 0, 1, 3, 15, 45, 50, 51, 123, Integer.MAX_VALUE}) @DisplayName("회장 권한으로 STANDARD 문제 생성 - 성공") public void createProblem_maxSubmitCount_validValue(long maxSubmitCount) throws Exception { - CtfChallengeCategoryDto category = CtfChallengeCategoryDto.toDto( - ctfChallengeCategoryRepository.getById(FORENSIC.getId())); + + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(FORENSIC.getId()) + .name(FORENSIC.getName()) + .build())); + + CtfChallengeTypeDto type = CtfChallengeTypeDto.toDto( ctfChallengeTypeRepository.getById(STANDARD.getId())); MemberEntity creator = generateMemberEntity(출제자, 정회원, 일반회원); @@ -447,7 +474,7 @@ public void createProblem_maxSubmitCount_validValue(long maxSubmitCount) throws .andExpect(jsonPath("$.data.title").value(title)) .andExpect(jsonPath("$.data.content").value(content)) .andExpect(jsonPath("$.data.contestId").value(contestEntity.getId())) - .andExpect(jsonPath("$.data.category.id").value(category.getId())) + .andExpect(jsonPath("$.data.category[0].id").value(category.get(0).getId())) .andExpect(jsonPath("$.data.type.id").value(type.getId())) .andExpect(jsonPath("$.data.isSolvable").value(isSolvable)) .andExpect(jsonPath("$.data.creatorName").value(adminEntity.getNickName())) @@ -463,14 +490,14 @@ public void createProblem_maxSubmitCount_validValue(long maxSubmitCount) throws } private CtfChallengeAdminDto generateCtfChallengeAdminDto(Long maxSubmitCount, - CtfChallengeCategoryDto category, CtfChallengeTypeDto type, MemberEntity creator, + List category, CtfChallengeTypeDto type, MemberEntity creator, String title, String content, Boolean isSolvable, Long score, String flag) { return generateCtfChallengeAdminDto( maxSubmitCount, category, type, creator, title, content, isSolvable, score, flag, null); } private CtfChallengeAdminDto generateCtfChallengeAdminDto(Long maxSubmitCount, - CtfChallengeCategoryDto category, CtfChallengeTypeDto type, MemberEntity creator, + List category, CtfChallengeTypeDto type, MemberEntity creator, String title, String content, Boolean isSolvable, Long score, String flag, CtfDynamicChallengeInfoDto dynamicInfo) { CtfChallengeAdminDto challenge = CtfChallengeAdminDto.builder() @@ -495,8 +522,13 @@ public void fileRegistrationInProblemSuccess() throws Exception { MockMultipartFile file = new MockMultipartFile("file", "image.png", "image/png", "<>".getBytes()); Long score = 1234L; + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(FORENSIC.getId()) + .name(FORENSIC.getName()) + .build())); CtfChallengeEntity challenge = generateCtfChallenge( - contestEntity, DYNAMIC, FORENSIC, score, true); + contestEntity, DYNAMIC, category, score, true); mockMvc.perform(multipart("/v1/admin/ctf/prob/file") .file(file) .param("challengeId", String.valueOf(challenge.getId())) @@ -523,13 +555,17 @@ public void fileRegistrationInProblemSuccess() throws Exception { @Test @DisplayName("문제 오픈 - 성공") public void openProblemSuccess() throws Exception { - + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(FORENSIC.getId()) + .name(FORENSIC.getName()) + .build())); MemberEntity creator = generateMemberEntity(출제자, 정회원, 일반회원); Long teamScore = 0L; Long score = 1234L; CtfTeamEntity team = generateCtfTeam(contestEntity, creator, teamScore); CtfChallengeEntity challenge = generateCtfChallenge( - contestEntity, STANDARD, MISC, score, false); + contestEntity, STANDARD, category, score, false); generateCtfFlag(team, challenge, false); mockMvc.perform(patch("/v1/admin/ctf/prob/{pid}/open", challenge.getId()) @@ -557,13 +593,17 @@ public void openProblemSuccess() throws Exception { @Test @DisplayName("문제 닫기 - 성공") public void closeProblemSuccess() throws Exception { - MemberEntity creator = generateMemberEntity(출제자, 정회원, 일반회원); Long teamScore = 0L; Long score = 1234L; CtfTeamEntity team = generateCtfTeam(contestEntity, creator, teamScore); + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(MISC.getId()) + .name(MISC.getName()) + .build())); CtfChallengeEntity challenge = generateCtfChallenge( - contestEntity, STANDARD, MISC, score, false); + contestEntity, STANDARD, category, score, false); generateCtfFlag(team, challenge, false); mockMvc.perform(patch("/v1/admin/ctf/prob/{pid}/close", challenge.getId()) @@ -596,7 +636,12 @@ public void deleteProblemSuccess() throws Exception { Long teamScore = 0L; Long score = 1234L; CtfTeamEntity team = generateCtfTeam(contestEntity, creator, teamScore); - CtfChallengeEntity challenge = generateCtfChallenge(contestEntity, STANDARD, MISC, score, true); + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(MISC.getId()) + .name(MISC.getName()) + .build())); + CtfChallengeEntity challenge = generateCtfChallenge(contestEntity, STANDARD, category, score, true); generateCtfFlag(team, challenge, false); // when @@ -634,8 +679,15 @@ public void deleteStandardProblemScoreRollbackSuccess() throws Exception { Long teamScore = 0L; Long score = 1234L; CtfTeamEntity team = generateCtfTeam(contestEntity, creator, teamScore); + + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(MISC.getId()) + .name(MISC.getName()) + .build())); + CtfChallengeEntity challenge = generateCtfChallenge( - contestEntity, STANDARD, MISC, score, true); + contestEntity, STANDARD, category, score, true); CtfFlagEntity flag = generateCtfFlag(team, challenge, false); // when @@ -672,8 +724,15 @@ public void deleteDynamicProblemScoreRollbackSuccess() throws Exception { Long teamScore = 0L; Long score = 1234L; CtfTeamEntity team = generateCtfTeam(contestEntity, creator, teamScore); + + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(MISC.getId()) + .name(MISC.getName()) + .build())); + CtfChallengeEntity challenge = generateCtfChallenge(contestEntity, - DYNAMIC, MISC, score, true); + DYNAMIC, category, score, true); Long maxScore = 2000L; Long minScore = 100L; generateDynamicChallengeInfo(challenge, maxScore, minScore); @@ -736,10 +795,23 @@ public void getProblemListSuccess() throws Exception { Long teamScore = 0L; Long score = 1234L; CtfTeamEntity team = generateCtfTeam(contestEntity, creator, teamScore); + + List category1 = new ArrayList<>(); + category1.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(MISC.getId()) + .name(MISC.getName()) + .build())); + CtfChallengeEntity challenge = generateCtfChallenge( - contestEntity, STANDARD, MISC, score, false); + contestEntity, STANDARD, category1, score, false); + + List category2 = new ArrayList<>(); + category2.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(FORENSIC.getId()) + .name(FORENSIC.getName()) + .build())); CtfChallengeEntity challenge2 = generateCtfChallenge( - contestEntity, DYNAMIC, FORENSIC, score, false); + contestEntity, DYNAMIC, category2, score, false); generateDynamicChallengeInfo(challenge2, 1000L, 100L); generateCtfFlag(team, challenge2, false); generateCtfFlag(team, challenge, false); @@ -783,10 +855,22 @@ public void getSubmitLogListSuccess() throws Exception { Long teamScore = 0L; Long score = 1234L; CtfTeamEntity team = generateCtfTeam(contestEntity, creator, teamScore); + List category1 = new ArrayList<>(); + category1.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(MISC.getId()) + .name(MISC.getName()) + .build())); + CtfChallengeEntity challenge = generateCtfChallenge( - contestEntity, STANDARD, MISC, score, false); + contestEntity, STANDARD, category1, score, false); + + List category2 = new ArrayList<>(); + category2.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(FORENSIC.getId()) + .name(FORENSIC.getName()) + .build())); CtfChallengeEntity challenge2 = generateCtfChallenge( - contestEntity, DYNAMIC, FORENSIC, score, false); + contestEntity, DYNAMIC, category2, score, false); generateDynamicChallengeInfo(challenge2, 1000L, 100L); generateCtfFlag(team, challenge2, false); generateCtfFlag(team, challenge, false); diff --git a/src/test/java/keeper/project/homepage/ctf/controller/CtfChallengeControllerTest.java b/src/test/java/keeper/project/homepage/ctf/controller/CtfChallengeControllerTest.java index bad60c13..ff7f0a65 100644 --- a/src/test/java/keeper/project/homepage/ctf/controller/CtfChallengeControllerTest.java +++ b/src/test/java/keeper/project/homepage/ctf/controller/CtfChallengeControllerTest.java @@ -19,6 +19,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.ctf.entity.CtfFlagEntity; @@ -54,13 +58,17 @@ public void getProblemListSuccess() throws Exception { CtfContestEntity contest = generateCtfContest(adminEntity, true); Long score = 1000L; - + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(MISC.getId()) + .name(MISC.getName()) + .build())); CtfChallengeEntity dynamicChallenge = generateCtfChallenge( - contest, DYNAMIC, FORENSIC, score, true); + contest, DYNAMIC, category, score, true); CtfChallengeEntity standardChallenge = generateCtfChallenge( - contest, STANDARD, MISC, score, true); + contest, STANDARD, category, score, true); CtfChallengeEntity notSolvable = generateCtfChallenge( - contest, DYNAMIC, WEB, score, false); + contest, DYNAMIC, category, score, false); CtfTeamEntity team = generateCtfTeam(contest, userEntity, 0L); @@ -79,8 +87,8 @@ public void getProblemListSuccess() throws Exception { .andExpect(jsonPath("$.list[0].content").doesNotExist()) .andExpect(jsonPath("$.list[0].contestId") .value(dynamicChallenge.getCtfContestEntity().getId())) - .andExpect(jsonPath("$.list[0].category.id") - .value(dynamicChallenge.getCtfChallengeCategoryEntity().getId())) + .andExpect(jsonPath("$.list[0].category[0].id") + .value(category.get(0).getId())) .andExpect(jsonPath("$.list[0].type.id").doesNotExist()) .andExpect(jsonPath("$.list[0].isSolvable").doesNotExist()) .andExpect(jsonPath("$.list[0].score").value(dynamicChallenge.getScore())) @@ -91,8 +99,8 @@ public void getProblemListSuccess() throws Exception { .andExpect(jsonPath("$.list[1].content").doesNotExist()) .andExpect(jsonPath("$.list[1].contestId") .value(standardChallenge.getCtfContestEntity().getId())) - .andExpect(jsonPath("$.list[1].category.id") - .value(standardChallenge.getCtfChallengeCategoryEntity().getId())) + .andExpect(jsonPath("$.list[1].category[0].id") + .value(category.get(0).getId())) .andExpect(jsonPath("$.list[1].type.id").doesNotExist()) .andExpect(jsonPath("$.list[1].isSolvable").doesNotExist()) .andExpect(jsonPath("$.list[1].score").value(standardChallenge.getScore())) @@ -116,11 +124,17 @@ public void getProblemListSuccess_lastTryTimeNullable() throws Exception { CtfContestEntity contest = generateCtfContest(adminEntity, true); Long score = 1000L; + List category = new ArrayList<>(); + + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(FORENSIC.getId()) + .name(FORENSIC.getName()) + .build())); CtfChallengeEntity dynamicChallenge = generateCtfChallenge( - contest, DYNAMIC, FORENSIC, score, true); + contest, DYNAMIC, category, score, true); CtfChallengeEntity standardChallenge = generateCtfChallenge( - contest, STANDARD, MISC, score, true); + contest, STANDARD, category, score, true); CtfTeamEntity team = generateCtfTeam(contest, userEntity, 0L); @@ -148,8 +162,14 @@ public void checkFlagSuccess() throws Exception { Long maxScore = 1234L; Long minScore = 567L; + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(FORENSIC.getId()) + .name(FORENSIC.getName()) + .build())); + CtfChallengeEntity dynamicChallenge = generateCtfChallenge( - contest, DYNAMIC, FORENSIC, score, true); + contest, DYNAMIC, category, score, true); generateDynamicChallengeInfo(dynamicChallenge, maxScore, minScore); CtfTeamEntity team = generateCtfTeam(contest, userEntity, 0L); @@ -193,9 +213,13 @@ public void checkFlagFailedByNotEnoughSubmitCount() throws Exception { Long score = 1000L; Long maxScore = 1234L; Long minScore = 567L; - + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(FORENSIC.getId()) + .name(FORENSIC.getName()) + .build())); CtfChallengeEntity dynamicChallenge = generateCtfChallenge( - contest, DYNAMIC, FORENSIC, score, true); + contest, DYNAMIC, category, score, true); generateDynamicChallengeInfo(dynamicChallenge, maxScore, minScore); CtfTeamEntity team = generateCtfTeam(contest, userEntity, 0L); CtfFlagEntity flag = generateCtfFlag(team, dynamicChallenge, false, 0L); @@ -220,9 +244,13 @@ public void getProblemDetailSuccess() throws Exception { CtfContestEntity contest = generateCtfContest(adminEntity, true); Long score = 1000L; - + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(FORENSIC.getId()) + .name(FORENSIC.getName()) + .build())); CtfChallengeEntity dynamicChallenge = generateCtfChallenge( - contest, DYNAMIC, FORENSIC, score, true); + contest, DYNAMIC, category, score, true); generateFileInChallenge(dynamicChallenge); CtfTeamEntity team = generateCtfTeam(contest, userEntity, 0L); @@ -239,8 +267,8 @@ public void getProblemDetailSuccess() throws Exception { .andExpect(jsonPath("$.data.content").value(dynamicChallenge.getDescription())) .andExpect(jsonPath("$.data.contestId") .value(dynamicChallenge.getCtfContestEntity().getId())) - .andExpect(jsonPath("$.data.category.id") - .value(dynamicChallenge.getCtfChallengeCategoryEntity().getId())) + .andExpect(jsonPath("$.data.category[0].id") + .value(category.get(0).getId())) .andExpect(jsonPath("$.data.type.id").doesNotExist()) .andExpect(jsonPath("$.data.isSolvable").doesNotExist()) .andExpect( diff --git a/src/test/java/keeper/project/homepage/ctf/controller/CtfSpringTestHelper.java b/src/test/java/keeper/project/homepage/ctf/controller/CtfSpringTestHelper.java index cfd5adff..6439d4e3 100644 --- a/src/test/java/keeper/project/homepage/ctf/controller/CtfSpringTestHelper.java +++ b/src/test/java/keeper/project/homepage/ctf/controller/CtfSpringTestHelper.java @@ -1,5 +1,6 @@ package keeper.project.homepage.ctf.controller; +import static java.util.stream.Collectors.toList; import static keeper.project.homepage.ctf.service.CtfChallengeService.RETRY_SECONDS; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.subsectionWithPath; @@ -10,9 +11,10 @@ import java.util.Arrays; import java.util.List; import keeper.project.homepage.ApiControllerTestHelper; +import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto; import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; -import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; +import keeper.project.homepage.ctf.entity.CtfChallengeHasCtfChallengeCategoryEntity; import keeper.project.homepage.ctf.entity.CtfChallengeTypeEntity; import keeper.project.homepage.ctf.entity.CtfChallengeTypeEntity.CtfChallengeType; import keeper.project.homepage.ctf.entity.CtfContestEntity; @@ -22,6 +24,7 @@ import keeper.project.homepage.ctf.entity.CtfTeamEntity; import keeper.project.homepage.ctf.entity.CtfTeamHasMemberEntity; import keeper.project.homepage.ctf.repository.CtfChallengeCategoryRepository; +import keeper.project.homepage.ctf.repository.CtfChallengeHasCtfChallengeCategoryRepository; import keeper.project.homepage.ctf.repository.CtfChallengeRepository; import keeper.project.homepage.ctf.repository.CtfChallengeTypeRepository; import keeper.project.homepage.ctf.repository.CtfContestRepository; @@ -42,6 +45,9 @@ public class CtfSpringTestHelper extends ApiControllerTestHelper { @Autowired protected CtfChallengeCategoryRepository ctfChallengeCategoryRepository; + @Autowired + protected CtfChallengeHasCtfChallengeCategoryRepository ctfChallengeHasCtfChallengeCategoryRepository; + @Autowired protected CtfChallengeTypeRepository ctfChallengeTypeRepository; @@ -182,14 +188,13 @@ protected CtfTeamEntity generateCtfTeam(CtfContestEntity ctfContestEntity, Membe protected CtfChallengeEntity generateCtfChallenge( CtfContestEntity ctfContestEntity, CtfChallengeType ctfChallengeType, - CtfChallengeCategory ctfChallengeCategory, + List category, Long score, boolean isSolvable) { final long epochTime = System.nanoTime(); CtfChallengeTypeEntity ctfChallengeTypeEntity = ctfChallengeTypeRepository.getById( ctfChallengeType.getId()); - CtfChallengeCategoryEntity ctfChallengeCategoryEntity = ctfChallengeCategoryRepository.getById( - ctfChallengeCategory.getId()); + CtfChallengeEntity entity = CtfChallengeEntity.builder() .name("name_" + epochTime) .description("desc_" + epochTime) @@ -197,13 +202,26 @@ protected CtfChallengeEntity generateCtfChallenge( .creator(memberRepository.getById(1L)) // Virtual Member .isSolvable(isSolvable) .ctfChallengeTypeEntity(ctfChallengeTypeEntity) - .ctfChallengeCategoryEntity(ctfChallengeCategoryEntity) + .ctfChallengeHasCtfChallengeCategoryList(new ArrayList<>()) .score(score) .ctfContestEntity(ctfContestEntity) .ctfFlagEntity(new ArrayList<>()) .maxSubmitCount(100L) .build(); ctfChallengeRepository.save(entity); + + List ctfChallengeCategoryEntityList = category.stream() + .map(CtfChallengeCategoryDto::toEntity).toList(); + + for (CtfChallengeCategoryEntity ctfChallengeCategory : ctfChallengeCategoryEntityList) { + CtfChallengeHasCtfChallengeCategoryEntity save = ctfChallengeHasCtfChallengeCategoryRepository.save( + CtfChallengeHasCtfChallengeCategoryEntity.builder() + .challenge(entity) + .category(ctfChallengeCategory) + .build()); + entity.getCtfChallengeHasCtfChallengeCategoryList().add(save); + } + return entity; } @@ -284,8 +302,8 @@ protected List generateChallengeCommonDtoResponseFields(Respons commonFields.addAll(Arrays.asList( fieldWithPath(prefix + ".challengeId").description("해당 문제의 Id"), fieldWithPath(prefix + ".title").description("문제 제목"), - fieldWithPath(prefix + ".category.id").description("문제가 속한 카테고리의 id"), - fieldWithPath(prefix + ".category.name").description("문제가 속한 카테고리의 이름"), + fieldWithPath(prefix + ".category[].id").description("문제가 속한 카테고리의 id"), + fieldWithPath(prefix + ".category[].name").description("문제가 속한 카테고리의 이름"), fieldWithPath(prefix + ".score").description("문제의 점수"), fieldWithPath(prefix + ".isSolved").description("내가 풀었는 지"), fieldWithPath(prefix + ".maxSubmitCount").description("최대 제출 횟수"), @@ -315,8 +333,8 @@ protected List generateChallengeAdminDtoResponseFields(Response fieldWithPath(prefix + ".challengeId").description("해당 문제의 Id"), fieldWithPath(prefix + ".title").description("문제 제목"), fieldWithPath(prefix + ".content").description("문제 설명"), - fieldWithPath(prefix + ".category.id").description("문제가 속한 카테고리의 id"), - fieldWithPath(prefix + ".category.name").description("문제가 속한 카테고리의 이름"), + fieldWithPath(prefix + ".category[].id").description("문제가 속한 카테고리의 id"), + fieldWithPath(prefix + ".category[].name").description("문제가 속한 카테고리의 이름"), fieldWithPath(prefix + ".type.id").description("문제가 속한 타입의 id"), fieldWithPath(prefix + ".type.name").description("문제가 속한 타입의 이름"), fieldWithPath(prefix + ".flag").description("문제에 설정 된 flag (현재는 모든 팀이 동일한 flag를 가집니다."), @@ -370,8 +388,8 @@ protected List generateChallengeDtoResponseFields(ResponseType fieldWithPath(prefix + ".challengeId").description("해당 문제의 Id"), fieldWithPath(prefix + ".title").description("문제 제목"), fieldWithPath(prefix + ".content").description("문제 설명"), - fieldWithPath(prefix + ".category.id").description("문제가 속한 카테고리의 id"), - fieldWithPath(prefix + ".category.name").description("문제가 속한 카테고리의 이름"), + fieldWithPath(prefix + ".category[].id").description("문제가 속한 카테고리의 id"), + fieldWithPath(prefix + ".category[].name").description("문제가 속한 카테고리의 이름"), fieldWithPath(prefix + ".score").description("문제의 점수"), fieldWithPath(prefix + ".creatorName").description("문제 생성자 이름"), fieldWithPath(prefix + ".contestId").description("문제의 대회 Id"), @@ -548,7 +566,8 @@ protected List generateTeamDetailDtoResponseFields(ResponseType fieldWithPath(prefix + ".creatorId").description("team 생성자 Id"), fieldWithPath(prefix + ".contestId").description("team이 속한 contest Id"), subsectionWithPath(prefix + ".teamMembers").description("team에 속한 팀원 정보"), - subsectionWithPath(prefix + ".solvedChallengeList").description("team이 푼 문제들 정보 (푼 문제이므로 남은 제출 횟수가 0으로 표기되어 나갑니다.)") + subsectionWithPath(prefix + ".solvedChallengeList").description( + "team이 푼 문제들 정보 (푼 문제이므로 남은 제출 횟수가 0으로 표기되어 나갑니다.)") )); commonFields.addAll(generateTeamDtoResponseFields(type, success, code, msg)); if (addDescriptors.length > 0) { diff --git a/src/test/java/keeper/project/homepage/ctf/controller/CtfTeamControllerTest.java b/src/test/java/keeper/project/homepage/ctf/controller/CtfTeamControllerTest.java index cbe7e733..a39b987b 100644 --- a/src/test/java/keeper/project/homepage/ctf/controller/CtfTeamControllerTest.java +++ b/src/test/java/keeper/project/homepage/ctf/controller/CtfTeamControllerTest.java @@ -1,5 +1,6 @@ package keeper.project.homepage.ctf.controller; +import static keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory.FORENSIC; import static keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory.MISC; import static keeper.project.homepage.ctf.entity.CtfChallengeTypeEntity.CtfChallengeType.STANDARD; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; @@ -17,7 +18,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.util.ArrayList; +import java.util.List; import keeper.project.homepage.ctf.controller.CtfSpringTestHelper; +import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.ctf.entity.CtfTeamEntity; @@ -189,8 +194,12 @@ void getTeamDetail() throws Exception { .build(); ctfTeamHasMemberRepository.save(teamHasMemberEntity); team.getCtfTeamHasMemberEntityList().add(teamHasMemberEntity); - - CtfChallengeEntity challenge = generateCtfChallenge(contestEntity, STANDARD, MISC, 1234L, + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(MISC.getId()) + .name(MISC.getName()) + .build())); + CtfChallengeEntity challenge = generateCtfChallenge(contestEntity, STANDARD, category, 1234L, false); generateCtfFlag(team, challenge, true); diff --git a/src/test/java/keeper/project/homepage/ctf/repository/CtfChallengeRepositoryTest.java b/src/test/java/keeper/project/homepage/ctf/repository/CtfChallengeRepositoryTest.java index bd903705..31d42685 100644 --- a/src/test/java/keeper/project/homepage/ctf/repository/CtfChallengeRepositoryTest.java +++ b/src/test/java/keeper/project/homepage/ctf/repository/CtfChallengeRepositoryTest.java @@ -27,8 +27,6 @@ public void saveChallengeList() { boolean isSolvable = true; CtfChallengeTypeEntity ctfChallengeTypeEntity = ctfChallengeTypeRepository.getById( STANDARD.getId()); - CtfChallengeCategoryEntity ctfChallengeCategoryEntity = ctfChallengeCategoryRepository.getById( - SYSTEM.getId()); Long score = 1000L; CtfContestEntity contest = generateCtfContest(member); @@ -40,7 +38,7 @@ public void saveChallengeList() { .creator(member) // Virtual Member .isSolvable(isSolvable) .ctfChallengeTypeEntity(ctfChallengeTypeEntity) - .ctfChallengeCategoryEntity(ctfChallengeCategoryEntity) + .ctfChallengeHasCtfChallengeCategoryList(new ArrayList<>()) .score(score) .ctfContestEntity(contest) .ctfFlagEntity(new ArrayList<>()) @@ -55,7 +53,6 @@ public void saveChallengeList() { assertThat(findChallenge.getCreator()).isEqualTo(member); assertThat(findChallenge.getIsSolvable()).isEqualTo(isSolvable); assertThat(findChallenge.getCtfChallengeTypeEntity()).isEqualTo(ctfChallengeTypeEntity); - assertThat(findChallenge.getCtfChallengeCategoryEntity()).isEqualTo(ctfChallengeCategoryEntity); assertThat(findChallenge.getScore()).isEqualTo(score); assertThat(findChallenge.getCtfContestEntity()).isEqualTo(contest); } @@ -71,8 +68,6 @@ public void saveLargeDescriptionChallengeList() { boolean isSolvable = true; CtfChallengeTypeEntity ctfChallengeTypeEntity = ctfChallengeTypeRepository.getById( STANDARD.getId()); - CtfChallengeCategoryEntity ctfChallengeCategoryEntity = ctfChallengeCategoryRepository.getById( - SYSTEM.getId()); Long score = 1000L; CtfContestEntity contest = generateCtfContest(member); @@ -84,7 +79,7 @@ public void saveLargeDescriptionChallengeList() { .creator(member) // Virtual Member .isSolvable(isSolvable) .ctfChallengeTypeEntity(ctfChallengeTypeEntity) - .ctfChallengeCategoryEntity(ctfChallengeCategoryEntity) + .ctfChallengeHasCtfChallengeCategoryList(new ArrayList<>()) .score(score) .ctfContestEntity(contest) .ctfFlagEntity(new ArrayList<>()) @@ -99,7 +94,6 @@ public void saveLargeDescriptionChallengeList() { assertThat(findChallenge.getCreator()).isEqualTo(member); assertThat(findChallenge.getIsSolvable()).isEqualTo(isSolvable); assertThat(findChallenge.getCtfChallengeTypeEntity()).isEqualTo(ctfChallengeTypeEntity); - assertThat(findChallenge.getCtfChallengeCategoryEntity()).isEqualTo(ctfChallengeCategoryEntity); assertThat(findChallenge.getScore()).isEqualTo(score); assertThat(findChallenge.getCtfContestEntity()).isEqualTo(contest); } diff --git a/src/test/java/keeper/project/homepage/ctf/repository/CtfFlagRepositoryTest.java b/src/test/java/keeper/project/homepage/ctf/repository/CtfFlagRepositoryTest.java index 64bc1ada..aff43d89 100644 --- a/src/test/java/keeper/project/homepage/ctf/repository/CtfFlagRepositoryTest.java +++ b/src/test/java/keeper/project/homepage/ctf/repository/CtfFlagRepositoryTest.java @@ -6,7 +6,12 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; +import keeper.project.homepage.ctf.entity.CtfChallengeHasCtfChallengeCategoryEntity; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.ctf.entity.CtfFlagEntity; import keeper.project.homepage.ctf.entity.CtfTeamEntity; @@ -30,7 +35,8 @@ private CtfFlagEntity generateFlag(long remainedSubmitCount) { MemberEntity member = memberRepository.getById(1L); CtfContestEntity contest = generateCtfContest(member); CtfTeamEntity ctfTeam = generateCtfTeam(contest, member, 0L); - CtfChallengeEntity ctfChallenge = generateCtfChallenge(contest, STANDARD, MISC, 1000L); + + CtfChallengeEntity ctfChallenge = generateCtfChallenge(contest, STANDARD, 1000L); return CtfFlagEntity.builder() .content(content) .ctfTeamEntity(ctfTeam) diff --git a/src/test/java/keeper/project/homepage/ctf/repository/CtfSubmitLogRepositoryTest.java b/src/test/java/keeper/project/homepage/ctf/repository/CtfSubmitLogRepositoryTest.java index e6e78277..3d7e9414 100644 --- a/src/test/java/keeper/project/homepage/ctf/repository/CtfSubmitLogRepositoryTest.java +++ b/src/test/java/keeper/project/homepage/ctf/repository/CtfSubmitLogRepositoryTest.java @@ -5,6 +5,8 @@ import static org.assertj.core.api.Assertions.assertThat; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; import keeper.project.homepage.ctf.entity.CtfContestEntity; @@ -26,7 +28,8 @@ void testContest() { MemberEntity member = memberRepository.getById(1L); CtfContestEntity contest = generateCtfContest(member); CtfTeamEntity ctfTeam = generateCtfTeam(contest, member, 0L); - CtfChallengeEntity ctfChallenge = generateCtfChallenge(contest, STANDARD, MISC, 1000L); + + CtfChallengeEntity ctfChallenge = generateCtfChallenge(contest, STANDARD, 1000L); // when CtfSubmitLogEntity submitLog = CtfSubmitLogEntity.builder() diff --git a/src/test/java/keeper/project/homepage/ctf/repository/CtfTestHelper.java b/src/test/java/keeper/project/homepage/ctf/repository/CtfTestHelper.java index 50d8d4c0..fadfdf81 100644 --- a/src/test/java/keeper/project/homepage/ctf/repository/CtfTestHelper.java +++ b/src/test/java/keeper/project/homepage/ctf/repository/CtfTestHelper.java @@ -3,6 +3,8 @@ import static java.time.LocalDateTime.now; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; @@ -111,13 +113,12 @@ protected CtfTeamEntity generateCtfTeam(CtfContestEntity ctfContestEntity, Membe protected CtfChallengeEntity generateCtfChallenge( CtfContestEntity ctfContestEntity, CtfChallengeType ctfChallengeType, - CtfChallengeCategory ctfChallengeCategory, Long score) { final long epochTime = System.nanoTime(); CtfChallengeTypeEntity ctfChallengeTypeEntity = ctfChallengeTypeRepository.getById( ctfChallengeType.getId()); - CtfChallengeCategoryEntity ctfChallengeCategoryEntity = ctfChallengeCategoryRepository.getById( - ctfChallengeCategory.getId()); + + CtfChallengeEntity entity = CtfChallengeEntity.builder() .name("name_" + epochTime) .description("desc_" + epochTime) @@ -125,11 +126,12 @@ protected CtfChallengeEntity generateCtfChallenge( .creator(memberRepository.getById(1L)) // Virtual Member .isSolvable(false) .ctfChallengeTypeEntity(ctfChallengeTypeEntity) - .ctfChallengeCategoryEntity(ctfChallengeCategoryEntity) + .ctfChallengeHasCtfChallengeCategoryList(new ArrayList<>()) .score(score) .ctfContestEntity(ctfContestEntity) .maxSubmitCount(123L) .build(); + ctfChallengeRepository.save(entity); return entity; } diff --git a/src/test/java/keeper/project/homepage/ctf/service/CtfChallengeServiceTest.java b/src/test/java/keeper/project/homepage/ctf/service/CtfChallengeServiceTest.java index 400db93e..d6f2d752 100644 --- a/src/test/java/keeper/project/homepage/ctf/service/CtfChallengeServiceTest.java +++ b/src/test/java/keeper/project/homepage/ctf/service/CtfChallengeServiceTest.java @@ -13,9 +13,12 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import keeper.project.homepage.ctf.controller.CtfSpringTestHelper; +import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto; import keeper.project.homepage.ctf.dto.CtfFlagDto; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.ctf.entity.CtfFlagEntity; @@ -50,7 +53,12 @@ void setCtfChallenge() { Long score = 1000L; Long maxScore = 1234L; Long minScore = 567L; - dynamicChallenge = generateCtfChallenge(contest, DYNAMIC, FORENSIC, score, true); + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(FORENSIC.getId()) + .name(FORENSIC.getName()) + .build())); + dynamicChallenge = generateCtfChallenge(contest, DYNAMIC, category, score, true); generateDynamicChallengeInfo(dynamicChallenge, maxScore, minScore); teamEntity = generateCtfTeam(contest, userEntity, 0L); setAuthentication(userEntity, "ROLE_회원"); diff --git a/src/test/java/keeper/project/homepage/ctf/service/CtfServiceTest.java b/src/test/java/keeper/project/homepage/ctf/service/CtfServiceTest.java index f4652d0d..085a8398 100644 --- a/src/test/java/keeper/project/homepage/ctf/service/CtfServiceTest.java +++ b/src/test/java/keeper/project/homepage/ctf/service/CtfServiceTest.java @@ -4,9 +4,11 @@ import static keeper.project.homepage.ApiControllerTestHelper.MemberRankName.우수회원; import static keeper.project.homepage.ApiControllerTestHelper.MemberTypeName.정회원; import static keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory.MISC; +import static keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory.WEB; import static keeper.project.homepage.ctf.entity.CtfChallengeTypeEntity.CtfChallengeType.STANDARD; import static org.assertj.core.api.Assertions.assertThat; +import java.util.ArrayList; import java.util.List; import keeper.project.homepage.ctf.controller.CtfSpringTestHelper; import keeper.project.homepage.ctf.dto.CtfChallengeAdminDto; @@ -14,6 +16,7 @@ import keeper.project.homepage.ctf.dto.CtfChallengeTypeDto; import keeper.project.homepage.ctf.dto.CtfFlagDto; import keeper.project.homepage.ctf.dto.CtfTeamDetailDto; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.ctf.entity.CtfFlagEntity; import keeper.project.homepage.ctf.entity.CtfSubmitLogEntity; @@ -155,6 +158,13 @@ private CtfChallengeAdminDto createChallenge(Long contestId, MemberEntity member new UsernamePasswordAuthenticationToken(member.getId(), member.getPassword(), List.of(new SimpleGrantedAuthority("ROLE_회원")))); final long epochTime = System.nanoTime(); + + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(MISC.getId()) + .name(MISC.getName()) + .build())); + CtfChallengeAdminDto createChallenge = CtfChallengeAdminDto.builder() .title("TITLE_" + epochTime) .content("CONTENT_" + epochTime) @@ -165,9 +175,7 @@ private CtfChallengeAdminDto createChallenge(Long contestId, MemberEntity member .type(CtfChallengeTypeDto.builder() .id(STANDARD.getId()) .build()) - .category(CtfChallengeCategoryDto.builder() - .id(MISC.getId()) - .build()) + .category(category) .maxSubmitCount(100L) .build(); return ctfAdminService.createChallenge(createChallenge); diff --git a/src/test/java/keeper/project/homepage/ctf/service/CtfTeamServiceTest.java b/src/test/java/keeper/project/homepage/ctf/service/CtfTeamServiceTest.java index ff8a1185..fd00e4e3 100644 --- a/src/test/java/keeper/project/homepage/ctf/service/CtfTeamServiceTest.java +++ b/src/test/java/keeper/project/homepage/ctf/service/CtfTeamServiceTest.java @@ -1,15 +1,18 @@ package keeper.project.homepage.ctf.service; +import static keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory.MISC; import static keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory.SYSTEM; import static keeper.project.homepage.ctf.entity.CtfChallengeTypeEntity.CtfChallengeType.STANDARD; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import keeper.project.homepage.ctf.controller.CtfSpringTestHelper; import keeper.project.homepage.ctf.dto.CtfChallengeAdminDto; import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto; import keeper.project.homepage.ctf.dto.CtfChallengeTypeDto; import keeper.project.homepage.ctf.dto.CtfTeamDetailDto; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.member.entity.MemberEntity; import org.assertj.core.api.Assertions; @@ -174,14 +177,19 @@ void leaveTeam() { String testFlag = "testFlag"; Long testScore = 1234L; + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(SYSTEM.getId()) + .name(SYSTEM.getName()) + .build())); + CtfChallengeAdminDto createChallengeInfo = CtfChallengeAdminDto.builder() .content(testContent) .contestId(contest.getId()) .flag(testFlag) .isSolvable(true) .type(CtfChallengeTypeDto.builder().id(STANDARD.getId()).build()) - .category( - CtfChallengeCategoryDto.builder().id(SYSTEM.getId()).build()) + .category(category) .title(testTitle) .score(testScore) .maxSubmitCount(123L) diff --git a/src/test/java/keeper/project/homepage/util/service/CtfUtilServiceTest.java b/src/test/java/keeper/project/homepage/util/service/CtfUtilServiceTest.java index 3ebf3770..79db3e09 100644 --- a/src/test/java/keeper/project/homepage/util/service/CtfUtilServiceTest.java +++ b/src/test/java/keeper/project/homepage/util/service/CtfUtilServiceTest.java @@ -10,6 +10,8 @@ import java.util.List; import java.util.stream.IntStream; import keeper.project.homepage.ctf.controller.CtfSpringTestHelper; +import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.ctf.entity.CtfFlagEntity; @@ -55,8 +57,13 @@ void setUp() { validTeamList.add(generateCtfTeam(validCtf, generateMemberEntity(회원, 정회원, 일반회원), 0L))); validChallengeList = new ArrayList<>(); + List category = new ArrayList<>(); + category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() + .id(FORENSIC.getId()) + .name(FORENSIC.getName()) + .build())); IntStream.range(0, VALID_CHALLENGE_COUNT).forEach(n -> { - CtfChallengeEntity challenge = generateCtfChallenge(validCtf, DYNAMIC, FORENSIC, 0L, true); + CtfChallengeEntity challenge = generateCtfChallenge(validCtf, DYNAMIC, category, 0L, true); generateDynamicChallengeInfo(challenge, 1000L, 100L); validChallengeList.add(challenge); }); From 9c91ed3e1cb61f4e4480f2c63a8996a7cd2bf86c Mon Sep 17 00:00:00 2001 From: shkisme Date: Fri, 23 Dec 2022 00:41:14 +0900 Subject: [PATCH 6/9] =?UTF-8?q?chore:=20=EC=BD=94=EB=93=9C=20=EB=9D=BC?= =?UTF-8?q?=EC=9D=B8=20=EB=B3=80=EA=B2=BD=20issue:=20#471=20pr:=20#472?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keeper/project/homepage/ctf/dto/CtfChallengeAdminDto.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeAdminDto.java b/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeAdminDto.java index bf4b1d08..f2150081 100644 --- a/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeAdminDto.java +++ b/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeAdminDto.java @@ -71,8 +71,8 @@ public static CtfChallengeAdminDto toDto(CtfChallengeEntity challenge, Long solv .content(challenge.getDescription()) .contestId(challenge.getCtfContestEntity().getId()) .category(challenge.getCtfChallengeHasCtfChallengeCategoryList().stream() - .map(CtfChallengeCategoryDto::toDto).collect( - toList())) + .map(CtfChallengeCategoryDto::toDto) + .collect(toList())) .type(type) .flag(getVirtualTeamFlag(challenge).getContent()) .isSolvable(challenge.getIsSolvable()) From 7279e94c3ab1b503ca379bc3c055f8b83b0968d9 Mon Sep 17 00:00:00 2001 From: shkisme Date: Fri, 23 Dec 2022 00:42:59 +0900 Subject: [PATCH 7/9] =?UTF-8?q?chore:=20=EC=A4=91=EB=B3=B5=EB=90=9C=20size?= =?UTF-8?q?=20=ED=99=95=EC=9D=B8=20=EC=BD=94=EB=93=9C=20=EC=A0=9C=EA=B1=B0?= =?UTF-8?q?=20issue:=20#471=20pr:=20#472?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homepage/ctf/service/CtfAdminServiceTest.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/test/java/keeper/project/homepage/ctf/service/CtfAdminServiceTest.java b/src/test/java/keeper/project/homepage/ctf/service/CtfAdminServiceTest.java index 44b53743..ebcb2850 100644 --- a/src/test/java/keeper/project/homepage/ctf/service/CtfAdminServiceTest.java +++ b/src/test/java/keeper/project/homepage/ctf/service/CtfAdminServiceTest.java @@ -75,7 +75,8 @@ void createChallenge() { .id(WEB.getId()) .name(WEB.getName()) .build())); - CtfChallengeAdminDto result = createStandardChallenge(1234L, "flag", "content", "title", category, 123L); + CtfChallengeAdminDto result = createStandardChallenge(1234L, "flag", "content", "title", + category, 123L); CtfFlagEntity flag = ctfFlagRepository.findByCtfChallengeEntityIdAndCtfTeamEntityId( result.getChallengeId(), CtfUtilService.VIRTUAL_TEAM_ID).orElseThrow(); @@ -87,7 +88,6 @@ void createChallenge() { assertThat(result.getContent()).isEqualTo("content"); assertThat(result.getTitle()).isEqualTo("title"); assertThat(result.getScore()).isEqualTo(1234L); - assertThat(result.getCategory().size()).isEqualTo(1); assertThat(result.getCategory().get(0).getId()).isEqualTo(category.get(0).getId()); assertThat(result.getCategory().size()).isEqualTo(1); assertThat(result.getContestId()).isEqualTo(ctfContestEntity.getId()); @@ -107,7 +107,8 @@ void createChallengeHasManyCategory() { .id(FORENSIC.getId()) .name(FORENSIC.getName()) .build())); - CtfChallengeAdminDto result = createStandardChallenge(1234L, "flag", "content", "title", category, 123L); + CtfChallengeAdminDto result = createStandardChallenge(1234L, "flag", "content", "title", + category, 123L); CtfFlagEntity flag = ctfFlagRepository.findByCtfChallengeEntityIdAndCtfTeamEntityId( result.getChallengeId(), CtfUtilService.VIRTUAL_TEAM_ID).orElseThrow(); @@ -127,8 +128,10 @@ void createChallengeHasManyCategory() { assertThat(flag.getIsCorrect()).isEqualTo(false); } - private CtfChallengeAdminDto createStandardChallenge(long score, List category) { - return createStandardChallenge(score, getRandomUUID(), getRandomUUID(), getRandomUUID(), category, 15L); + private CtfChallengeAdminDto createStandardChallenge(long score, + List category) { + return createStandardChallenge(score, getRandomUUID(), getRandomUUID(), getRandomUUID(), + category, 15L); } private CtfChallengeAdminDto createStandardChallenge(long score, String flag, String content, From bebaf38ce92928846d0c3e63bd704800139b750b Mon Sep 17 00:00:00 2001 From: shkisme Date: Fri, 23 Dec 2022 08:57:36 +0900 Subject: [PATCH 8/9] =?UTF-8?q?style:=20category=EB=A5=BC=20categories?= =?UTF-8?q?=EB=A1=9C=20=EB=84=A4=EC=9D=B4=EB=B0=8D=20=EB=B3=80=EA=B2=BD=20?= =?UTF-8?q?issue:=20#471=20pr:=20#472?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ctf/dto/CtfChallengeAdminDto.java | 3 +- .../homepage/ctf/dto/CtfChallengeDto.java | 3 +- .../ctf/dto/CtfCommonChallengeDto.java | 5 +- .../controller/CtfAdminControllerTest.java | 172 +++++++----------- .../CtfChallengeControllerTest.java | 65 +++---- .../ctf/controller/CtfSpringTestHelper.java | 26 ++- .../ctf/controller/CtfTeamControllerTest.java | 13 +- .../ctf/service/CtfAdminServiceTest.java | 90 +++++---- .../ctf/service/CtfChallengeServiceTest.java | 11 +- .../homepage/ctf/service/CtfServiceTest.java | 16 +- .../ctf/service/CtfTeamServiceTest.java | 20 +- .../util/service/CtfUtilServiceTest.java | 10 +- 12 files changed, 188 insertions(+), 246 deletions(-) diff --git a/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeAdminDto.java b/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeAdminDto.java index f2150081..29b7aeba 100644 --- a/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeAdminDto.java +++ b/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeAdminDto.java @@ -8,7 +8,6 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; import java.time.LocalDateTime; import java.util.ArrayList; -import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; import keeper.project.homepage.ctf.entity.CtfChallengeTypeEntity; import keeper.project.homepage.ctf.entity.CtfContestEntity; @@ -70,7 +69,7 @@ public static CtfChallengeAdminDto toDto(CtfChallengeEntity challenge, Long solv .title(challenge.getName()) .content(challenge.getDescription()) .contestId(challenge.getCtfContestEntity().getId()) - .category(challenge.getCtfChallengeHasCtfChallengeCategoryList().stream() + .categories(challenge.getCtfChallengeHasCtfChallengeCategoryList().stream() .map(CtfChallengeCategoryDto::toDto) .collect(toList())) .type(type) diff --git a/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeDto.java b/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeDto.java index 83992748..29392815 100644 --- a/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeDto.java +++ b/src/main/java/keeper/project/homepage/ctf/dto/CtfChallengeDto.java @@ -3,7 +3,6 @@ import static java.util.stream.Collectors.toList; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty.Access; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; @@ -41,7 +40,7 @@ public static CtfChallengeDto toDto(CtfChallengeEntity challenge, Long solvedTea .title(challenge.getName()) .content(challenge.getDescription()) .contestId(challenge.getCtfContestEntity().getId()) - .category(challenge.getCtfChallengeHasCtfChallengeCategoryList() + .categories(challenge.getCtfChallengeHasCtfChallengeCategoryList() .stream() .map(CtfChallengeCategoryDto::toDto) .collect(toList())) diff --git a/src/main/java/keeper/project/homepage/ctf/dto/CtfCommonChallengeDto.java b/src/main/java/keeper/project/homepage/ctf/dto/CtfCommonChallengeDto.java index 656f891a..41665309 100644 --- a/src/main/java/keeper/project/homepage/ctf/dto/CtfCommonChallengeDto.java +++ b/src/main/java/keeper/project/homepage/ctf/dto/CtfCommonChallengeDto.java @@ -8,7 +8,6 @@ import com.fasterxml.jackson.annotation.Nulls; import java.time.LocalDateTime; import java.util.List; -import java.util.stream.Collectors; import javax.validation.constraints.Max; import javax.validation.constraints.Min; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; @@ -32,7 +31,7 @@ public class CtfCommonChallengeDto { protected String title; protected Long score; - protected List category; + protected List categories; protected Long contestId; @Max(MAX_SUBMIT_COUNT) @Min(MIN_SUBMIT_COUNT) @@ -57,7 +56,7 @@ public static CtfCommonChallengeDto toDto(CtfChallengeEntity challenge, Boolean .challengeId(challenge.getId()) .title(challenge.getName()) .contestId(challenge.getCtfContestEntity().getId()) - .category(challenge.getCtfChallengeHasCtfChallengeCategoryList() + .categories(challenge.getCtfChallengeHasCtfChallengeCategoryList() .stream() .map(CtfChallengeCategoryDto::toDto) .collect(toList())) diff --git a/src/test/java/keeper/project/homepage/ctf/controller/CtfAdminControllerTest.java b/src/test/java/keeper/project/homepage/ctf/controller/CtfAdminControllerTest.java index 686ffee1..1cff6449 100644 --- a/src/test/java/keeper/project/homepage/ctf/controller/CtfAdminControllerTest.java +++ b/src/test/java/keeper/project/homepage/ctf/controller/CtfAdminControllerTest.java @@ -40,7 +40,7 @@ import keeper.project.homepage.ctf.dto.CtfContestAdminDto; import keeper.project.homepage.ctf.dto.CtfDynamicChallengeInfoDto; import keeper.project.homepage.ctf.dto.CtfProbMakerDto; -import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.ctf.entity.CtfFlagEntity; @@ -270,15 +270,9 @@ private boolean isDisqualifyProbMakerRole(MemberEntity probMaker, MemberJobEntit @Test @DisplayName("출제자 권한으로 문제 생성 - 성공") public void createProblemSuccess() throws Exception { - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(FORENSIC.getId()) - .name(FORENSIC.getName()) - .build())); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(MISC.getId()) - .name(MISC.getName()) - .build())); + List categories = new ArrayList<>(); + categories.add(FORENSIC); + categories.add(MISC); CtfChallengeTypeDto type = CtfChallengeTypeDto.toDto( ctfChallengeTypeRepository.getById(DYNAMIC.getId())); @@ -299,7 +293,7 @@ public void createProblemSuccess() throws Exception { Long score = 1234L; String flag = "flag{keeper}"; CtfChallengeAdminDto challenge = generateCtfChallengeAdminDto(35L, - category, type, creator, title, content, isSolvable, score, flag, dynamicInfo); + categories, type, creator, title, content, isSolvable, score, flag, dynamicInfo); mockMvc.perform(post("/v1/admin/ctf/prob") .header("Authorization", creatorToken) @@ -312,8 +306,8 @@ public void createProblemSuccess() throws Exception { .andExpect(jsonPath("$.data.title").value(title)) .andExpect(jsonPath("$.data.content").value(content)) .andExpect(jsonPath("$.data.contestId").value(contestEntity.getId())) - .andExpect(jsonPath("$.data.category[0].id").value(category.get(0).getId())) - .andExpect(jsonPath("$.data.category[1].id").value(category.get(1).getId())) + .andExpect(jsonPath("$.data.categories[0].id").value(categories.get(0).getId())) + .andExpect(jsonPath("$.data.categories[1].id").value(categories.get(1).getId())) .andExpect(jsonPath("$.data.type.id").value(type.getId())) .andExpect(jsonPath("$.data.isSolvable").value(isSolvable)) .andExpect(jsonPath("$.data.creatorName").value(creator.getNickName())) @@ -326,7 +320,7 @@ public void createProblemSuccess() throws Exception { fieldWithPath("title").description("문제 제목"), fieldWithPath("content").description("문제 내용"), fieldWithPath("contestId").description("문제가 등록 될 CTF id"), - fieldWithPath("category[].id").description("문제 카테고리 Id"), + fieldWithPath("categories[].id").description("문제 카테고리 Id"), fieldWithPath("type.id").description("문제 Type Id"), fieldWithPath("isSolvable").description("현재 풀 수 있는 지 여부"), fieldWithPath("score").description( @@ -356,11 +350,8 @@ public void createProblemSuccess() throws Exception { @DisplayName("회장 권한으로 STANDARD 문제 생성 - 성공") public void createStandardProblemSuccess() throws Exception { - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(FORENSIC.getId()) - .name(FORENSIC.getName()) - .build())); + List categories = new ArrayList<>(); + categories.add(FORENSIC); CtfChallengeTypeDto type = CtfChallengeTypeDto.toDto( ctfChallengeTypeRepository.getById(STANDARD.getId())); @@ -374,7 +365,7 @@ public void createStandardProblemSuccess() throws Exception { Long score = 1234L; String flag = "flag{keeper}"; CtfChallengeAdminDto challenge = generateCtfChallengeAdminDto(35L, - category, type, creator, title, content, isSolvable, score, flag); + categories, type, creator, title, content, isSolvable, score, flag); createChallengeControllerTest(challenge) .andExpect(status().isOk()) @@ -383,7 +374,7 @@ public void createStandardProblemSuccess() throws Exception { .andExpect(jsonPath("$.data.title").value(title)) .andExpect(jsonPath("$.data.content").value(content)) .andExpect(jsonPath("$.data.contestId").value(contestEntity.getId())) - .andExpect(jsonPath("$.data.category[0].id").value(category.get(0).getId())) + .andExpect(jsonPath("$.data.categories[0].id").value(categories.get(0).getId())) .andExpect(jsonPath("$.data.type.id").value(type.getId())) .andExpect(jsonPath("$.data.isSolvable").value(isSolvable)) .andExpect(jsonPath("$.data.creatorName").value(adminEntity.getNickName())) @@ -394,11 +385,8 @@ public void createStandardProblemSuccess() throws Exception { @Test @DisplayName("문제 생성 시 maxSubmitCount를 넣지 않을 경우 default value가 들어가야 한다.") public void createProblem_maxSubmitCount_defaultValue() throws Exception { - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(FORENSIC.getId()) - .name(FORENSIC.getName()) - .build())); + List categories = new ArrayList<>(); + categories.add(FORENSIC); CtfChallengeTypeDto type = CtfChallengeTypeDto.toDto( ctfChallengeTypeRepository.getById(STANDARD.getId())); @@ -413,7 +401,7 @@ public void createProblem_maxSubmitCount_defaultValue() throws Exception { String flag = "flag{keeper}"; CtfChallengeAdminDto challenge = generateCtfChallengeAdminDto( - null, category, type, creator, title, content, isSolvable, score, flag); + null, categories, type, creator, title, content, isSolvable, score, flag); createChallengeControllerTest(challenge) .andExpect(status().isOk()) @@ -422,7 +410,7 @@ public void createProblem_maxSubmitCount_defaultValue() throws Exception { .andExpect(jsonPath("$.data.title").value(title)) .andExpect(jsonPath("$.data.content").value(content)) .andExpect(jsonPath("$.data.contestId").value(contestEntity.getId())) - .andExpect(jsonPath("$.data.category[0].id").value(category.get(0).getId())) + .andExpect(jsonPath("$.data.categories[0].id").value(categories.get(0).getId())) .andExpect(jsonPath("$.data.type.id").value(type.getId())) .andExpect(jsonPath("$.data.isSolvable").value(isSolvable)) .andExpect(jsonPath("$.data.creatorName").value(adminEntity.getNickName())) @@ -445,12 +433,8 @@ private ResultActions createChallengeControllerTest(CtfChallengeAdminDto challen @DisplayName("회장 권한으로 STANDARD 문제 생성 - 성공") public void createProblem_maxSubmitCount_validValue(long maxSubmitCount) throws Exception { - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(FORENSIC.getId()) - .name(FORENSIC.getName()) - .build())); - + List categories = new ArrayList<>(); + categories.add(FORENSIC); CtfChallengeTypeDto type = CtfChallengeTypeDto.toDto( ctfChallengeTypeRepository.getById(STANDARD.getId())); @@ -464,7 +448,7 @@ public void createProblem_maxSubmitCount_validValue(long maxSubmitCount) throws Long score = 1234L; String flag = "flag{keeper}"; CtfChallengeAdminDto challenge = generateCtfChallengeAdminDto( - maxSubmitCount, category, type, creator, title, content, isSolvable, score, flag); + maxSubmitCount, categories, type, creator, title, content, isSolvable, score, flag); if (MIN_SUBMIT_COUNT <= maxSubmitCount && maxSubmitCount <= MAX_SUBMIT_COUNT) { createChallengeControllerTest(challenge) @@ -474,7 +458,7 @@ public void createProblem_maxSubmitCount_validValue(long maxSubmitCount) throws .andExpect(jsonPath("$.data.title").value(title)) .andExpect(jsonPath("$.data.content").value(content)) .andExpect(jsonPath("$.data.contestId").value(contestEntity.getId())) - .andExpect(jsonPath("$.data.category[0].id").value(category.get(0).getId())) + .andExpect(jsonPath("$.data.categories[0].id").value(categories.get(0).getId())) .andExpect(jsonPath("$.data.type.id").value(type.getId())) .andExpect(jsonPath("$.data.isSolvable").value(isSolvable)) .andExpect(jsonPath("$.data.creatorName").value(adminEntity.getNickName())) @@ -490,21 +474,30 @@ public void createProblem_maxSubmitCount_validValue(long maxSubmitCount) throws } private CtfChallengeAdminDto generateCtfChallengeAdminDto(Long maxSubmitCount, - List category, CtfChallengeTypeDto type, MemberEntity creator, + List categories, CtfChallengeTypeDto type, MemberEntity creator, String title, String content, Boolean isSolvable, Long score, String flag) { return generateCtfChallengeAdminDto( - maxSubmitCount, category, type, creator, title, content, isSolvable, score, flag, null); + maxSubmitCount, categories, type, creator, title, content, isSolvable, score, flag, null); } private CtfChallengeAdminDto generateCtfChallengeAdminDto(Long maxSubmitCount, - List category, CtfChallengeTypeDto type, MemberEntity creator, + List categories, CtfChallengeTypeDto type, MemberEntity creator, String title, String content, Boolean isSolvable, Long score, String flag, CtfDynamicChallengeInfoDto dynamicInfo) { + + List categoryDtos = categories + .stream() + .map(ctfChallengeCategory -> CtfChallengeCategoryDto + .builder() + .id(ctfChallengeCategory.getId()) + .name(ctfChallengeCategory.getName()).build()) + .toList(); + CtfChallengeAdminDto challenge = CtfChallengeAdminDto.builder() .title(title) .content(content) .contestId(contestEntity.getId()) - .category(category) + .categories(categoryDtos) .type(type) .isSolvable(isSolvable) .creatorName(creator.getNickName()) @@ -522,13 +515,12 @@ public void fileRegistrationInProblemSuccess() throws Exception { MockMultipartFile file = new MockMultipartFile("file", "image.png", "image/png", "<>".getBytes()); Long score = 1234L; - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(FORENSIC.getId()) - .name(FORENSIC.getName()) - .build())); + + List categories = new ArrayList<>(); + categories.add(FORENSIC); + CtfChallengeEntity challenge = generateCtfChallenge( - contestEntity, DYNAMIC, category, score, true); + contestEntity, DYNAMIC, categories, score, true); mockMvc.perform(multipart("/v1/admin/ctf/prob/file") .file(file) .param("challengeId", String.valueOf(challenge.getId())) @@ -555,17 +547,14 @@ public void fileRegistrationInProblemSuccess() throws Exception { @Test @DisplayName("문제 오픈 - 성공") public void openProblemSuccess() throws Exception { - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(FORENSIC.getId()) - .name(FORENSIC.getName()) - .build())); + List categories = new ArrayList<>(); + categories.add(FORENSIC); MemberEntity creator = generateMemberEntity(출제자, 정회원, 일반회원); Long teamScore = 0L; Long score = 1234L; CtfTeamEntity team = generateCtfTeam(contestEntity, creator, teamScore); CtfChallengeEntity challenge = generateCtfChallenge( - contestEntity, STANDARD, category, score, false); + contestEntity, STANDARD, categories, score, false); generateCtfFlag(team, challenge, false); mockMvc.perform(patch("/v1/admin/ctf/prob/{pid}/open", challenge.getId()) @@ -597,13 +586,10 @@ public void closeProblemSuccess() throws Exception { Long teamScore = 0L; Long score = 1234L; CtfTeamEntity team = generateCtfTeam(contestEntity, creator, teamScore); - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(MISC.getId()) - .name(MISC.getName()) - .build())); + List categories = new ArrayList<>(); + categories.add(MISC); CtfChallengeEntity challenge = generateCtfChallenge( - contestEntity, STANDARD, category, score, false); + contestEntity, STANDARD, categories, score, false); generateCtfFlag(team, challenge, false); mockMvc.perform(patch("/v1/admin/ctf/prob/{pid}/close", challenge.getId()) @@ -636,12 +622,9 @@ public void deleteProblemSuccess() throws Exception { Long teamScore = 0L; Long score = 1234L; CtfTeamEntity team = generateCtfTeam(contestEntity, creator, teamScore); - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(MISC.getId()) - .name(MISC.getName()) - .build())); - CtfChallengeEntity challenge = generateCtfChallenge(contestEntity, STANDARD, category, score, true); + List categories = new ArrayList<>(); + categories.add(MISC); + CtfChallengeEntity challenge = generateCtfChallenge(contestEntity, STANDARD, categories, score, true); generateCtfFlag(team, challenge, false); // when @@ -680,14 +663,11 @@ public void deleteStandardProblemScoreRollbackSuccess() throws Exception { Long score = 1234L; CtfTeamEntity team = generateCtfTeam(contestEntity, creator, teamScore); - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(MISC.getId()) - .name(MISC.getName()) - .build())); + List categories = new ArrayList<>(); + categories.add(MISC); CtfChallengeEntity challenge = generateCtfChallenge( - contestEntity, STANDARD, category, score, true); + contestEntity, STANDARD, categories, score, true); CtfFlagEntity flag = generateCtfFlag(team, challenge, false); // when @@ -725,14 +705,11 @@ public void deleteDynamicProblemScoreRollbackSuccess() throws Exception { Long score = 1234L; CtfTeamEntity team = generateCtfTeam(contestEntity, creator, teamScore); - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(MISC.getId()) - .name(MISC.getName()) - .build())); + List categories = new ArrayList<>(); + categories.add(MISC); CtfChallengeEntity challenge = generateCtfChallenge(contestEntity, - DYNAMIC, category, score, true); + DYNAMIC, categories, score, true); Long maxScore = 2000L; Long minScore = 100L; generateDynamicChallengeInfo(challenge, maxScore, minScore); @@ -796,32 +773,27 @@ public void getProblemListSuccess() throws Exception { Long score = 1234L; CtfTeamEntity team = generateCtfTeam(contestEntity, creator, teamScore); - List category1 = new ArrayList<>(); - category1.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(MISC.getId()) - .name(MISC.getName()) - .build())); + List categories1 = new ArrayList<>(); + categories1.add(MISC); - CtfChallengeEntity challenge = generateCtfChallenge( - contestEntity, STANDARD, category1, score, false); + CtfChallengeEntity challenge1 = generateCtfChallenge( + contestEntity, STANDARD, categories1, score, false); + + List categories2 = new ArrayList<>(); + categories2.add(FORENSIC); - List category2 = new ArrayList<>(); - category2.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(FORENSIC.getId()) - .name(FORENSIC.getName()) - .build())); CtfChallengeEntity challenge2 = generateCtfChallenge( - contestEntity, DYNAMIC, category2, score, false); + contestEntity, DYNAMIC, categories2, score, false); generateDynamicChallengeInfo(challenge2, 1000L, 100L); generateCtfFlag(team, challenge2, false); - generateCtfFlag(team, challenge, false); + generateCtfFlag(team, challenge1, false); // when MockMultipartFile file = new MockMultipartFile("file", "image.png", "image/png", "<>".getBytes()); mockMvc.perform(multipart("/v1/admin/ctf/prob/file") .file(file) - .param("challengeId", String.valueOf(challenge.getId())) + .param("challengeId", String.valueOf(challenge1.getId())) .param("page", "0") .param("size", "10") .header("Authorization", adminToken) @@ -855,22 +827,16 @@ public void getSubmitLogListSuccess() throws Exception { Long teamScore = 0L; Long score = 1234L; CtfTeamEntity team = generateCtfTeam(contestEntity, creator, teamScore); - List category1 = new ArrayList<>(); - category1.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(MISC.getId()) - .name(MISC.getName()) - .build())); + List categories1 = new ArrayList<>(); + categories1.add(MISC); CtfChallengeEntity challenge = generateCtfChallenge( - contestEntity, STANDARD, category1, score, false); + contestEntity, STANDARD, categories1, score, false); - List category2 = new ArrayList<>(); - category2.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(FORENSIC.getId()) - .name(FORENSIC.getName()) - .build())); + List categories2 = new ArrayList<>(); + categories2.add(FORENSIC); CtfChallengeEntity challenge2 = generateCtfChallenge( - contestEntity, DYNAMIC, category2, score, false); + contestEntity, DYNAMIC, categories2, score, false); generateDynamicChallengeInfo(challenge2, 1000L, 100L); generateCtfFlag(team, challenge2, false); generateCtfFlag(team, challenge, false); diff --git a/src/test/java/keeper/project/homepage/ctf/controller/CtfChallengeControllerTest.java b/src/test/java/keeper/project/homepage/ctf/controller/CtfChallengeControllerTest.java index ff7f0a65..09839e52 100644 --- a/src/test/java/keeper/project/homepage/ctf/controller/CtfChallengeControllerTest.java +++ b/src/test/java/keeper/project/homepage/ctf/controller/CtfChallengeControllerTest.java @@ -21,8 +21,8 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; -import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto; import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.ctf.entity.CtfFlagEntity; @@ -58,17 +58,14 @@ public void getProblemListSuccess() throws Exception { CtfContestEntity contest = generateCtfContest(adminEntity, true); Long score = 1000L; - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(MISC.getId()) - .name(MISC.getName()) - .build())); + List categories = new ArrayList<>(); + categories.add(MISC); CtfChallengeEntity dynamicChallenge = generateCtfChallenge( - contest, DYNAMIC, category, score, true); + contest, DYNAMIC, categories, score, true); CtfChallengeEntity standardChallenge = generateCtfChallenge( - contest, STANDARD, category, score, true); + contest, STANDARD, categories, score, true); CtfChallengeEntity notSolvable = generateCtfChallenge( - contest, DYNAMIC, category, score, false); + contest, DYNAMIC, categories, score, false); CtfTeamEntity team = generateCtfTeam(contest, userEntity, 0L); @@ -87,8 +84,8 @@ public void getProblemListSuccess() throws Exception { .andExpect(jsonPath("$.list[0].content").doesNotExist()) .andExpect(jsonPath("$.list[0].contestId") .value(dynamicChallenge.getCtfContestEntity().getId())) - .andExpect(jsonPath("$.list[0].category[0].id") - .value(category.get(0).getId())) + .andExpect(jsonPath("$.list[0].categories[0].id") + .value(categories.get(0).getId())) .andExpect(jsonPath("$.list[0].type.id").doesNotExist()) .andExpect(jsonPath("$.list[0].isSolvable").doesNotExist()) .andExpect(jsonPath("$.list[0].score").value(dynamicChallenge.getScore())) @@ -99,8 +96,8 @@ public void getProblemListSuccess() throws Exception { .andExpect(jsonPath("$.list[1].content").doesNotExist()) .andExpect(jsonPath("$.list[1].contestId") .value(standardChallenge.getCtfContestEntity().getId())) - .andExpect(jsonPath("$.list[1].category[0].id") - .value(category.get(0).getId())) + .andExpect(jsonPath("$.list[1].categories[0].id") + .value(categories.get(0).getId())) .andExpect(jsonPath("$.list[1].type.id").doesNotExist()) .andExpect(jsonPath("$.list[1].isSolvable").doesNotExist()) .andExpect(jsonPath("$.list[1].score").value(standardChallenge.getScore())) @@ -124,17 +121,14 @@ public void getProblemListSuccess_lastTryTimeNullable() throws Exception { CtfContestEntity contest = generateCtfContest(adminEntity, true); Long score = 1000L; - List category = new ArrayList<>(); + List categories = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(FORENSIC.getId()) - .name(FORENSIC.getName()) - .build())); + categories.add(FORENSIC); CtfChallengeEntity dynamicChallenge = generateCtfChallenge( - contest, DYNAMIC, category, score, true); + contest, DYNAMIC, categories, score, true); CtfChallengeEntity standardChallenge = generateCtfChallenge( - contest, STANDARD, category, score, true); + contest, STANDARD, categories, score, true); CtfTeamEntity team = generateCtfTeam(contest, userEntity, 0L); @@ -162,14 +156,11 @@ public void checkFlagSuccess() throws Exception { Long maxScore = 1234L; Long minScore = 567L; - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(FORENSIC.getId()) - .name(FORENSIC.getName()) - .build())); + List categories = new ArrayList<>(); + categories.add(FORENSIC); CtfChallengeEntity dynamicChallenge = generateCtfChallenge( - contest, DYNAMIC, category, score, true); + contest, DYNAMIC, categories, score, true); generateDynamicChallengeInfo(dynamicChallenge, maxScore, minScore); CtfTeamEntity team = generateCtfTeam(contest, userEntity, 0L); @@ -213,13 +204,10 @@ public void checkFlagFailedByNotEnoughSubmitCount() throws Exception { Long score = 1000L; Long maxScore = 1234L; Long minScore = 567L; - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(FORENSIC.getId()) - .name(FORENSIC.getName()) - .build())); + List categories = new ArrayList<>(); + categories.add(FORENSIC); CtfChallengeEntity dynamicChallenge = generateCtfChallenge( - contest, DYNAMIC, category, score, true); + contest, DYNAMIC, categories, score, true); generateDynamicChallengeInfo(dynamicChallenge, maxScore, minScore); CtfTeamEntity team = generateCtfTeam(contest, userEntity, 0L); CtfFlagEntity flag = generateCtfFlag(team, dynamicChallenge, false, 0L); @@ -244,13 +232,10 @@ public void getProblemDetailSuccess() throws Exception { CtfContestEntity contest = generateCtfContest(adminEntity, true); Long score = 1000L; - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(FORENSIC.getId()) - .name(FORENSIC.getName()) - .build())); + List categories = new ArrayList<>(); + categories.add(FORENSIC); CtfChallengeEntity dynamicChallenge = generateCtfChallenge( - contest, DYNAMIC, category, score, true); + contest, DYNAMIC, categories, score, true); generateFileInChallenge(dynamicChallenge); CtfTeamEntity team = generateCtfTeam(contest, userEntity, 0L); @@ -267,8 +252,8 @@ public void getProblemDetailSuccess() throws Exception { .andExpect(jsonPath("$.data.content").value(dynamicChallenge.getDescription())) .andExpect(jsonPath("$.data.contestId") .value(dynamicChallenge.getCtfContestEntity().getId())) - .andExpect(jsonPath("$.data.category[0].id") - .value(category.get(0).getId())) + .andExpect(jsonPath("$.data.categories[0].id") + .value(categories.get(0).getId())) .andExpect(jsonPath("$.data.type.id").doesNotExist()) .andExpect(jsonPath("$.data.isSolvable").doesNotExist()) .andExpect( diff --git a/src/test/java/keeper/project/homepage/ctf/controller/CtfSpringTestHelper.java b/src/test/java/keeper/project/homepage/ctf/controller/CtfSpringTestHelper.java index 6439d4e3..4bececce 100644 --- a/src/test/java/keeper/project/homepage/ctf/controller/CtfSpringTestHelper.java +++ b/src/test/java/keeper/project/homepage/ctf/controller/CtfSpringTestHelper.java @@ -11,8 +11,8 @@ import java.util.Arrays; import java.util.List; import keeper.project.homepage.ApiControllerTestHelper; -import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto; import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; import keeper.project.homepage.ctf.entity.CtfChallengeHasCtfChallengeCategoryEntity; import keeper.project.homepage.ctf.entity.CtfChallengeTypeEntity; @@ -188,7 +188,7 @@ protected CtfTeamEntity generateCtfTeam(CtfContestEntity ctfContestEntity, Membe protected CtfChallengeEntity generateCtfChallenge( CtfContestEntity ctfContestEntity, CtfChallengeType ctfChallengeType, - List category, + List category, Long score, boolean isSolvable) { final long epochTime = System.nanoTime(); @@ -210,8 +210,14 @@ protected CtfChallengeEntity generateCtfChallenge( .build(); ctfChallengeRepository.save(entity); - List ctfChallengeCategoryEntityList = category.stream() - .map(CtfChallengeCategoryDto::toEntity).toList(); + List ctfChallengeCategoryEntityList = category + .stream() + .map(ctfChallengeCategory -> CtfChallengeCategoryEntity + .builder() + .id(ctfChallengeCategory.getId()) + .name(ctfChallengeCategory.getName()) + .build()) + .toList(); for (CtfChallengeCategoryEntity ctfChallengeCategory : ctfChallengeCategoryEntityList) { CtfChallengeHasCtfChallengeCategoryEntity save = ctfChallengeHasCtfChallengeCategoryRepository.save( @@ -302,8 +308,8 @@ protected List generateChallengeCommonDtoResponseFields(Respons commonFields.addAll(Arrays.asList( fieldWithPath(prefix + ".challengeId").description("해당 문제의 Id"), fieldWithPath(prefix + ".title").description("문제 제목"), - fieldWithPath(prefix + ".category[].id").description("문제가 속한 카테고리의 id"), - fieldWithPath(prefix + ".category[].name").description("문제가 속한 카테고리의 이름"), + fieldWithPath(prefix + ".categories[].id").description("문제가 속한 카테고리의 id"), + fieldWithPath(prefix + ".categories[].name").description("문제가 속한 카테고리의 이름"), fieldWithPath(prefix + ".score").description("문제의 점수"), fieldWithPath(prefix + ".isSolved").description("내가 풀었는 지"), fieldWithPath(prefix + ".maxSubmitCount").description("최대 제출 횟수"), @@ -333,8 +339,8 @@ protected List generateChallengeAdminDtoResponseFields(Response fieldWithPath(prefix + ".challengeId").description("해당 문제의 Id"), fieldWithPath(prefix + ".title").description("문제 제목"), fieldWithPath(prefix + ".content").description("문제 설명"), - fieldWithPath(prefix + ".category[].id").description("문제가 속한 카테고리의 id"), - fieldWithPath(prefix + ".category[].name").description("문제가 속한 카테고리의 이름"), + fieldWithPath(prefix + ".categories[].id").description("문제가 속한 카테고리의 id"), + fieldWithPath(prefix + ".categories[].name").description("문제가 속한 카테고리의 이름"), fieldWithPath(prefix + ".type.id").description("문제가 속한 타입의 id"), fieldWithPath(prefix + ".type.name").description("문제가 속한 타입의 이름"), fieldWithPath(prefix + ".flag").description("문제에 설정 된 flag (현재는 모든 팀이 동일한 flag를 가집니다."), @@ -388,8 +394,8 @@ protected List generateChallengeDtoResponseFields(ResponseType fieldWithPath(prefix + ".challengeId").description("해당 문제의 Id"), fieldWithPath(prefix + ".title").description("문제 제목"), fieldWithPath(prefix + ".content").description("문제 설명"), - fieldWithPath(prefix + ".category[].id").description("문제가 속한 카테고리의 id"), - fieldWithPath(prefix + ".category[].name").description("문제가 속한 카테고리의 이름"), + fieldWithPath(prefix + ".categories[].id").description("문제가 속한 카테고리의 id"), + fieldWithPath(prefix + ".categories[].name").description("문제가 속한 카테고리의 이름"), fieldWithPath(prefix + ".score").description("문제의 점수"), fieldWithPath(prefix + ".creatorName").description("문제 생성자 이름"), fieldWithPath(prefix + ".contestId").description("문제의 대회 Id"), diff --git a/src/test/java/keeper/project/homepage/ctf/controller/CtfTeamControllerTest.java b/src/test/java/keeper/project/homepage/ctf/controller/CtfTeamControllerTest.java index a39b987b..e6a71227 100644 --- a/src/test/java/keeper/project/homepage/ctf/controller/CtfTeamControllerTest.java +++ b/src/test/java/keeper/project/homepage/ctf/controller/CtfTeamControllerTest.java @@ -20,9 +20,7 @@ import java.util.ArrayList; import java.util.List; -import keeper.project.homepage.ctf.controller.CtfSpringTestHelper; -import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto; -import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.ctf.entity.CtfTeamEntity; @@ -194,12 +192,9 @@ void getTeamDetail() throws Exception { .build(); ctfTeamHasMemberRepository.save(teamHasMemberEntity); team.getCtfTeamHasMemberEntityList().add(teamHasMemberEntity); - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(MISC.getId()) - .name(MISC.getName()) - .build())); - CtfChallengeEntity challenge = generateCtfChallenge(contestEntity, STANDARD, category, 1234L, + List categories = new ArrayList<>(); + categories.add(MISC); + CtfChallengeEntity challenge = generateCtfChallenge(contestEntity, STANDARD, categories, 1234L, false); generateCtfFlag(team, challenge, true); diff --git a/src/test/java/keeper/project/homepage/ctf/service/CtfAdminServiceTest.java b/src/test/java/keeper/project/homepage/ctf/service/CtfAdminServiceTest.java index ebcb2850..f921d745 100644 --- a/src/test/java/keeper/project/homepage/ctf/service/CtfAdminServiceTest.java +++ b/src/test/java/keeper/project/homepage/ctf/service/CtfAdminServiceTest.java @@ -22,7 +22,7 @@ import keeper.project.homepage.ctf.dto.CtfDynamicChallengeInfoDto; import keeper.project.homepage.ctf.dto.CtfFlagDto; import keeper.project.homepage.ctf.dto.CtfTeamDetailDto; -import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.ctf.entity.CtfFlagEntity; import keeper.project.homepage.member.entity.MemberEntity; @@ -70,13 +70,10 @@ private static void setAuthentication(MemberEntity contestCreator, MemberJobName @Test @DisplayName("문제 생성 테스트 - 카테고리 1개") void createChallenge() { - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(WEB.getId()) - .name(WEB.getName()) - .build())); + List categories = new ArrayList<>(); + categories.add(WEB); CtfChallengeAdminDto result = createStandardChallenge(1234L, "flag", "content", "title", - category, 123L); + categories, 123L); CtfFlagEntity flag = ctfFlagRepository.findByCtfChallengeEntityIdAndCtfTeamEntityId( result.getChallengeId(), CtfUtilService.VIRTUAL_TEAM_ID).orElseThrow(); @@ -88,8 +85,8 @@ void createChallenge() { assertThat(result.getContent()).isEqualTo("content"); assertThat(result.getTitle()).isEqualTo("title"); assertThat(result.getScore()).isEqualTo(1234L); - assertThat(result.getCategory().get(0).getId()).isEqualTo(category.get(0).getId()); - assertThat(result.getCategory().size()).isEqualTo(1); + assertThat(result.getCategories().get(0).getId()).isEqualTo(categories.get(0).getId()); + assertThat(result.getCategories().size()).isEqualTo(1); assertThat(result.getContestId()).isEqualTo(ctfContestEntity.getId()); assertThat(flag.getRemainedSubmitCount()).isEqualTo(123L); assertThat(flag.getIsCorrect()).isEqualTo(false); @@ -98,17 +95,11 @@ void createChallenge() { @Test @DisplayName("문제 생성 테스트 - 카테고리 2개이상") void createChallengeHasManyCategory() { - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(WEB.getId()) - .name(WEB.getName()) - .build())); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(FORENSIC.getId()) - .name(FORENSIC.getName()) - .build())); + List categories = new ArrayList<>(); + categories.add(WEB); + categories.add(FORENSIC); CtfChallengeAdminDto result = createStandardChallenge(1234L, "flag", "content", "title", - category, 123L); + categories, 123L); CtfFlagEntity flag = ctfFlagRepository.findByCtfChallengeEntityIdAndCtfTeamEntityId( result.getChallengeId(), CtfUtilService.VIRTUAL_TEAM_ID).orElseThrow(); @@ -120,24 +111,32 @@ void createChallengeHasManyCategory() { assertThat(result.getContent()).isEqualTo("content"); assertThat(result.getTitle()).isEqualTo("title"); assertThat(result.getScore()).isEqualTo(1234L); - assertThat(result.getCategory().get(0).getId()).isEqualTo(category.get(0).getId()); - assertThat(result.getCategory().get(1).getId()).isEqualTo(category.get(1).getId()); - assertThat(result.getCategory().size()).isEqualTo(2); + assertThat(result.getCategories().get(0).getId()).isEqualTo(categories.get(0).getId()); + assertThat(result.getCategories().get(1).getId()).isEqualTo(categories.get(1).getId()); + assertThat(result.getCategories().size()).isEqualTo(2); assertThat(result.getContestId()).isEqualTo(ctfContestEntity.getId()); assertThat(flag.getRemainedSubmitCount()).isEqualTo(123L); assertThat(flag.getIsCorrect()).isEqualTo(false); } private CtfChallengeAdminDto createStandardChallenge(long score, - List category) { + List categories) { return createStandardChallenge(score, getRandomUUID(), getRandomUUID(), getRandomUUID(), - category, 15L); + categories, 15L); } private CtfChallengeAdminDto createStandardChallenge(long score, String flag, String content, - String title, List category, long maxSubmitCount) { + String title, List categories, long maxSubmitCount) { setAuthentication(contestCreator, 회장); + List categoryDtos = categories + .stream() + .map(ctfChallengeCategory -> CtfChallengeCategoryDto + .builder() + .id(ctfChallengeCategory.getId()) + .name(ctfChallengeCategory.getName()).build()) + .toList(); + CtfChallengeAdminDto challengeAdminDto = CtfChallengeAdminDto.builder() .isSolvable(true) .flag(flag) @@ -146,7 +145,7 @@ private CtfChallengeAdminDto createStandardChallenge(long score, String flag, St .content(content) .title(title) .score(score) - .category(category) + .categories(categoryDtos) .contestId(ctfContestEntity.getId()) .maxSubmitCount(maxSubmitCount) .build(); @@ -163,11 +162,16 @@ private CtfChallengeAdminDto createDynamicChallenge(CtfDynamicChallengeInfoDto d String flag, String content, String title, long maxSubmitCount) { setAuthentication(contestCreator, 회장); - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(WEB.getId()) - .name(WEB.getName()) - .build())); + List categories = new ArrayList<>(); + categories.add(WEB); + + List categoryDtos = categories + .stream() + .map(ctfChallengeCategory -> CtfChallengeCategoryDto + .builder() + .id(ctfChallengeCategory.getId()) + .name(ctfChallengeCategory.getName()).build()) + .toList(); CtfChallengeAdminDto challengeAdminDto = CtfChallengeAdminDto.builder() .isSolvable(true) @@ -177,7 +181,7 @@ private CtfChallengeAdminDto createDynamicChallenge(CtfDynamicChallengeInfoDto d .content(content) .title(title) .score(0L) - .category(category) + .categories(categoryDtos) .contestId(ctfContestEntity.getId()) .maxSubmitCount(maxSubmitCount) .build(); @@ -185,13 +189,6 @@ private CtfChallengeAdminDto createDynamicChallenge(CtfDynamicChallengeInfoDto d return ctfAdminService.createChallenge(challengeAdminDto); } - private static CtfChallengeCategoryDto getWebCategory() { - return CtfChallengeCategoryDto.builder() - .id(WEB.getId()) - .name(WEB.getName()) - .build(); - } - private static CtfChallengeTypeDto getStandardType() { return CtfChallengeTypeDto.builder() .id(STANDARD.getId()) @@ -209,14 +206,11 @@ private static CtfChallengeTypeDto getDynamicType() { @Test @DisplayName("[시나리오1] STANDRAD 문제 삭제 시 점수 반영 제대로 되는지 테스트") void deleteProblem_scenario1() { - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(WEB.getId()) - .name(WEB.getName()) - .build())); - CtfChallengeAdminDto challenge1 = createStandardChallenge(100L, category); - CtfChallengeAdminDto challenge2 = createStandardChallenge(200L, category); - CtfChallengeAdminDto challenge3 = createStandardChallenge(400L, category); + List categories = new ArrayList<>(); + categories.add(WEB); + CtfChallengeAdminDto challenge1 = createStandardChallenge(100L, categories); + CtfChallengeAdminDto challenge2 = createStandardChallenge(200L, categories); + CtfChallengeAdminDto challenge3 = createStandardChallenge(400L, categories); MemberEntity user1 = generateMemberEntity(회원, 정회원, 일반회원); CtfTeamDetailDto team1 = createCtfTeam(user1); // 1번, 2번 문제 해결 @@ -250,7 +244,7 @@ void deleteProblem_scenario1() { assertThat(ctfTeamRepository.getById(team2.getId()).getScore()).isEqualTo(400L); assertThat(ctfTeamRepository.getById(team3.getId()).getScore()).isEqualTo(400L); - CtfChallengeAdminDto challenge4 = createStandardChallenge(800L, category); + CtfChallengeAdminDto challenge4 = createStandardChallenge(800L, categories); assertThat(solveChallenge(challenge4, user1)).isTrue(); assertThat(solveChallenge(challenge4, user2)).isTrue(); diff --git a/src/test/java/keeper/project/homepage/ctf/service/CtfChallengeServiceTest.java b/src/test/java/keeper/project/homepage/ctf/service/CtfChallengeServiceTest.java index d6f2d752..cbd3a296 100644 --- a/src/test/java/keeper/project/homepage/ctf/service/CtfChallengeServiceTest.java +++ b/src/test/java/keeper/project/homepage/ctf/service/CtfChallengeServiceTest.java @@ -16,9 +16,9 @@ import java.util.ArrayList; import java.util.List; import keeper.project.homepage.ctf.controller.CtfSpringTestHelper; -import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto; import keeper.project.homepage.ctf.dto.CtfFlagDto; import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.ctf.entity.CtfFlagEntity; @@ -53,12 +53,9 @@ void setCtfChallenge() { Long score = 1000L; Long maxScore = 1234L; Long minScore = 567L; - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(FORENSIC.getId()) - .name(FORENSIC.getName()) - .build())); - dynamicChallenge = generateCtfChallenge(contest, DYNAMIC, category, score, true); + List categories = new ArrayList<>(); + categories.add(FORENSIC); + dynamicChallenge = generateCtfChallenge(contest, DYNAMIC, categories, score, true); generateDynamicChallengeInfo(dynamicChallenge, maxScore, minScore); teamEntity = generateCtfTeam(contest, userEntity, 0L); setAuthentication(userEntity, "ROLE_회원"); diff --git a/src/test/java/keeper/project/homepage/ctf/service/CtfServiceTest.java b/src/test/java/keeper/project/homepage/ctf/service/CtfServiceTest.java index 085a8398..8cfd094f 100644 --- a/src/test/java/keeper/project/homepage/ctf/service/CtfServiceTest.java +++ b/src/test/java/keeper/project/homepage/ctf/service/CtfServiceTest.java @@ -4,7 +4,6 @@ import static keeper.project.homepage.ApiControllerTestHelper.MemberRankName.우수회원; import static keeper.project.homepage.ApiControllerTestHelper.MemberTypeName.정회원; import static keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory.MISC; -import static keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory.WEB; import static keeper.project.homepage.ctf.entity.CtfChallengeTypeEntity.CtfChallengeType.STANDARD; import static org.assertj.core.api.Assertions.assertThat; @@ -16,7 +15,7 @@ import keeper.project.homepage.ctf.dto.CtfChallengeTypeDto; import keeper.project.homepage.ctf.dto.CtfFlagDto; import keeper.project.homepage.ctf.dto.CtfTeamDetailDto; -import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.ctf.entity.CtfFlagEntity; import keeper.project.homepage.ctf.entity.CtfSubmitLogEntity; @@ -159,11 +158,12 @@ private CtfChallengeAdminDto createChallenge(Long contestId, MemberEntity member List.of(new SimpleGrantedAuthority("ROLE_회원")))); final long epochTime = System.nanoTime(); - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(MISC.getId()) - .name(MISC.getName()) - .build())); + List categories = new ArrayList<>(); + categories.add(MISC); + + List categoryDtos = categories.stream().map( + ctfChallengeCategory -> CtfChallengeCategoryDto.builder().id(ctfChallengeCategory.getId()) + .name(ctfChallengeCategory.getName()).build()).toList(); CtfChallengeAdminDto createChallenge = CtfChallengeAdminDto.builder() .title("TITLE_" + epochTime) @@ -175,7 +175,7 @@ private CtfChallengeAdminDto createChallenge(Long contestId, MemberEntity member .type(CtfChallengeTypeDto.builder() .id(STANDARD.getId()) .build()) - .category(category) + .categories(categoryDtos) .maxSubmitCount(100L) .build(); return ctfAdminService.createChallenge(createChallenge); diff --git a/src/test/java/keeper/project/homepage/ctf/service/CtfTeamServiceTest.java b/src/test/java/keeper/project/homepage/ctf/service/CtfTeamServiceTest.java index fd00e4e3..0be2d65f 100644 --- a/src/test/java/keeper/project/homepage/ctf/service/CtfTeamServiceTest.java +++ b/src/test/java/keeper/project/homepage/ctf/service/CtfTeamServiceTest.java @@ -1,6 +1,5 @@ package keeper.project.homepage.ctf.service; -import static keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory.MISC; import static keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory.SYSTEM; import static keeper.project.homepage.ctf.entity.CtfChallengeTypeEntity.CtfChallengeType.STANDARD; @@ -12,7 +11,7 @@ import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto; import keeper.project.homepage.ctf.dto.CtfChallengeTypeDto; import keeper.project.homepage.ctf.dto.CtfTeamDetailDto; -import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.member.entity.MemberEntity; import org.assertj.core.api.Assertions; @@ -177,11 +176,16 @@ void leaveTeam() { String testFlag = "testFlag"; Long testScore = 1234L; - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(SYSTEM.getId()) - .name(SYSTEM.getName()) - .build())); + List categories = new ArrayList<>(); + categories.add(SYSTEM); + + List categoryDtos = categories + .stream() + .map(ctfChallengeCategory -> CtfChallengeCategoryDto + .builder() + .id(ctfChallengeCategory.getId()) + .name(ctfChallengeCategory.getName()).build()) + .toList(); CtfChallengeAdminDto createChallengeInfo = CtfChallengeAdminDto.builder() .content(testContent) @@ -189,7 +193,7 @@ void leaveTeam() { .flag(testFlag) .isSolvable(true) .type(CtfChallengeTypeDto.builder().id(STANDARD.getId()).build()) - .category(category) + .categories(categoryDtos) .title(testTitle) .score(testScore) .maxSubmitCount(123L) diff --git a/src/test/java/keeper/project/homepage/util/service/CtfUtilServiceTest.java b/src/test/java/keeper/project/homepage/util/service/CtfUtilServiceTest.java index 79db3e09..11f2fb64 100644 --- a/src/test/java/keeper/project/homepage/util/service/CtfUtilServiceTest.java +++ b/src/test/java/keeper/project/homepage/util/service/CtfUtilServiceTest.java @@ -12,6 +12,7 @@ import keeper.project.homepage.ctf.controller.CtfSpringTestHelper; import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto; import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity; +import keeper.project.homepage.ctf.entity.CtfChallengeCategoryEntity.CtfChallengeCategory; import keeper.project.homepage.ctf.entity.CtfChallengeEntity; import keeper.project.homepage.ctf.entity.CtfContestEntity; import keeper.project.homepage.ctf.entity.CtfFlagEntity; @@ -57,13 +58,10 @@ void setUp() { validTeamList.add(generateCtfTeam(validCtf, generateMemberEntity(회원, 정회원, 일반회원), 0L))); validChallengeList = new ArrayList<>(); - List category = new ArrayList<>(); - category.add(CtfChallengeCategoryDto.toDto(CtfChallengeCategoryEntity.builder() - .id(FORENSIC.getId()) - .name(FORENSIC.getName()) - .build())); + List categories = new ArrayList<>(); + categories.add(FORENSIC); IntStream.range(0, VALID_CHALLENGE_COUNT).forEach(n -> { - CtfChallengeEntity challenge = generateCtfChallenge(validCtf, DYNAMIC, category, 0L, true); + CtfChallengeEntity challenge = generateCtfChallenge(validCtf, DYNAMIC, categories, 0L, true); generateDynamicChallengeInfo(challenge, 1000L, 100L); validChallengeList.add(challenge); }); From cab11aed401a259e9e69098319190f2158013405 Mon Sep 17 00:00:00 2001 From: shkisme Date: Fri, 23 Dec 2022 09:00:41 +0900 Subject: [PATCH 9/9] =?UTF-8?q?fix:=20CtfChallengeHasCtfChallengeCategoryL?= =?UTF-8?q?ist=20=EC=97=90=20Entity=EB=A5=BC=20add=20=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80=20issue:=20#47?= =?UTF-8?q?1=20pr:=20#472?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homepage/ctf/entity/CtfChallengeEntity.java | 5 +++++ .../homepage/ctf/service/CtfAdminService.java | 12 +++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/keeper/project/homepage/ctf/entity/CtfChallengeEntity.java b/src/main/java/keeper/project/homepage/ctf/entity/CtfChallengeEntity.java index df79af77..873dcc6b 100644 --- a/src/main/java/keeper/project/homepage/ctf/entity/CtfChallengeEntity.java +++ b/src/main/java/keeper/project/homepage/ctf/entity/CtfChallengeEntity.java @@ -60,6 +60,7 @@ public class CtfChallengeEntity { @Builder.Default @OneToMany(mappedBy = "challenge", cascade = CascadeType.REMOVE) List ctfChallengeHasCtfChallengeCategoryList = new ArrayList<>(); + @Column(nullable = false) @Setter Long score; @@ -89,4 +90,8 @@ public class CtfChallengeEntity { @PrimaryKeyJoinColumn @Setter CtfDynamicChallengeInfoEntity dynamicChallengeInfoEntity; + + public void addCtfChallengeHasCtfChallengeCategory(CtfChallengeHasCtfChallengeCategoryEntity ctfChallengeHasCtfChallengeCategoryEntity) { + this.getCtfChallengeHasCtfChallengeCategoryList().add(ctfChallengeHasCtfChallengeCategoryEntity); + } } diff --git a/src/main/java/keeper/project/homepage/ctf/service/CtfAdminService.java b/src/main/java/keeper/project/homepage/ctf/service/CtfAdminService.java index 15225481..8d7ef33b 100644 --- a/src/main/java/keeper/project/homepage/ctf/service/CtfAdminService.java +++ b/src/main/java/keeper/project/homepage/ctf/service/CtfAdminService.java @@ -5,9 +5,7 @@ import static keeper.project.homepage.util.service.CtfUtilService.VIRTUAL_TEAM_ID; import java.nio.file.AccessDeniedException; -import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import keeper.project.homepage.ctf.dto.CtfChallengeAdminDto; import keeper.project.homepage.ctf.dto.CtfChallengeCategoryDto; @@ -338,17 +336,17 @@ private CtfChallengeEntity createChallengeEntityWithFileEntity( private void setChallengeCategory(CtfChallengeEntity challenge, CtfChallengeAdminDto challengeAdminDto) { - List ctfChallengeCategoryEntityList = challengeAdminDto.getCategory() + List ctfChallengeCategoryEntityList = challengeAdminDto.getCategories() .stream() .map(CtfChallengeCategoryDto::toEntity).toList(); for (CtfChallengeCategoryEntity ctfChallengeCategory : ctfChallengeCategoryEntityList) { - CtfChallengeHasCtfChallengeCategoryEntity save = ctfChallengeHasCtfChallengeCategoryRepository.save( - CtfChallengeHasCtfChallengeCategoryEntity.builder() + challenge.addCtfChallengeHasCtfChallengeCategory(ctfChallengeHasCtfChallengeCategoryRepository + .save(CtfChallengeHasCtfChallengeCategoryEntity + .builder() .challenge(challenge) .category(ctfChallengeCategory) - .build()); - challenge.getCtfChallengeHasCtfChallengeCategoryList().add(save); + .build())); } }