From 95dcad5f25b139c888ac887992aa8f9ee4da4bba Mon Sep 17 00:00:00 2001 From: cabbage16 Date: Tue, 3 Sep 2024 16:07:19 +0900 Subject: [PATCH] =?UTF-8?q?test(#98):=20SelectSecondPassUseCaseTest=20-=20?= =?UTF-8?q?2=EC=B0=A8=20=ED=95=A9=EA=B2=A9=20=EC=9E=90=EB=8F=99=ED=99=94?= =?UTF-8?q?=20=EC=8A=A4=ED=94=84=EB=A7=81=20=ED=86=B5=ED=95=A9=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EB=A5=BC=20=EC=9E=91=EC=84=B1=ED=96=88?= =?UTF-8?q?=EC=96=B4=EC=9A=94.=20-=20=EC=8A=A4=ED=94=84=EB=A7=81=20?= =?UTF-8?q?=EB=B6=80=ED=8A=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EB=A5=BC=20?= =?UTF-8?q?=EC=9C=84=ED=95=B4=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=EC=9D=B4=20=EC=9E=88=EB=8A=94=20application.?= =?UTF-8?q?yml=EC=9D=84=20=EB=B6=84=EB=A6=AC=ED=95=98=EC=97=AC=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=ED=96=88=EC=96=B4=EC=9A=94.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../form/SelectSecondPassUseCaseTest.java | 100 ++++++++++++++++++ .../maru/shared/fixture/FormFixture.java | 2 +- src/test/resources/application.yml | 63 +++++++++++ 3 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/bamdoliro/maru/application/form/SelectSecondPassUseCaseTest.java create mode 100644 src/test/resources/application.yml diff --git a/src/test/java/com/bamdoliro/maru/application/form/SelectSecondPassUseCaseTest.java b/src/test/java/com/bamdoliro/maru/application/form/SelectSecondPassUseCaseTest.java new file mode 100644 index 00000000..e18956d3 --- /dev/null +++ b/src/test/java/com/bamdoliro/maru/application/form/SelectSecondPassUseCaseTest.java @@ -0,0 +1,100 @@ +package com.bamdoliro.maru.application.form; + +import com.bamdoliro.maru.domain.form.domain.Form; +import com.bamdoliro.maru.domain.form.domain.type.FormStatus; +import com.bamdoliro.maru.domain.form.service.AssignExaminationNumberService; +import com.bamdoliro.maru.domain.form.service.CalculateFormScoreService; +import com.bamdoliro.maru.domain.user.domain.User; +import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository; +import com.bamdoliro.maru.infrastructure.persistence.user.UserRepository; +import com.bamdoliro.maru.shared.constants.FixedNumber; +import com.bamdoliro.maru.shared.fixture.FormFixture; +import com.bamdoliro.maru.shared.fixture.UserFixture; +import com.bamdoliro.maru.shared.util.RandomUtil; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; + +import java.util.Comparator; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@Disabled +@Slf4j +@ActiveProfiles("test") +@SpringBootTest +public class SelectSecondPassUseCaseTest { + + @Autowired + private SelectSecondPassUseCase selectSecondPassUseCase; + + @Autowired + private SelectFirstPassUseCase selectFirstPassUseCase; + + @Autowired + private UserRepository userRepository; + + @Autowired + private FormRepository formRepository; + + @Autowired + private CalculateFormScoreService calculateFormScoreService; + + @Autowired + private AssignExaminationNumberService assignExaminationNumberService; + + @BeforeEach + void setUp() { + List userList = userRepository.saveAll( + UserFixture.generateUserList(FixedNumber.TOTAL * 2) + ); + List
formList = FormFixture.generateFormList(userList); + formList.forEach(form -> { + assignExaminationNumberService.execute(form); + form.receive(); + calculateFormScoreService.execute(form); + formRepository.save(form); + }); + selectFirstPassUseCase.execute(); + List firstPassedFormList = formRepository.findByStatus(FormStatus.FIRST_PASSED); + firstPassedFormList.forEach(form -> { + if (form.getType().isMeister()) { + form.getScore().updateSecondRoundMeisterScore(RandomUtil.randomDouble(0, 100), RandomUtil.randomDouble(0, 100), RandomUtil.randomDouble(0, 100)); + } else { + form.getScore().updateSecondRoundScore(RandomUtil.randomDouble(0, 100), RandomUtil.randomDouble(0, 100)); + } + formRepository.save(form); + }); + } + + @Test + void 정상적으로_2차전형_합격자를_선발한다() { + selectSecondPassUseCase.execute(); + + Comparator comparator = Comparator + .comparing(Form::getType) + .thenComparing(form -> form.getScore().getTotalScore()); + + List formList = formRepository.findAll() + .stream() + .filter(form -> form.isPassedNow() || form.isFailedNow()) + .sorted(comparator) + .toList(); + + formList.forEach(form -> { + log.info("===================="); + log.info("id: {}", form.getId()); + log.info("examinationNumber: {}", form.getExaminationNumber()); + log.info("type: {}", form.getType()); + log.info("score: {}", form.getScore().getTotalScore()); + log.info("status: {}", form.getStatus()); + }); + int passedFormCount = (int)formList.stream().filter(Form::isPassedNow).count(); + assertEquals(FixedNumber.TOTAL, passedFormCount); + } +} diff --git a/src/test/java/com/bamdoliro/maru/shared/fixture/FormFixture.java b/src/test/java/com/bamdoliro/maru/shared/fixture/FormFixture.java index 908a2bce..5c6aebb9 100644 --- a/src/test/java/com/bamdoliro/maru/shared/fixture/FormFixture.java +++ b/src/test/java/com/bamdoliro/maru/shared/fixture/FormFixture.java @@ -326,7 +326,7 @@ private static AchievementLevel random3AchievementLevel() { } private static FormType randomFormType() { - FormType[] values = {FormType.REGULAR, FormType.REGULAR, FormType.REGULAR, FormType.REGULAR, FormType.MEISTER_TALENT, FormType.MEISTER_TALENT, FormType.MEISTER_TALENT, FormType.MEISTER_TALENT, FormType.ONE_PARENT, FormType.MULTI_CHILDREN, FormType.SPECIAL_ADMISSION}; + FormType[] values = {FormType.REGULAR, FormType.REGULAR, FormType.REGULAR, FormType.REGULAR, FormType.MEISTER_TALENT, FormType.MEISTER_TALENT, FormType.MEISTER_TALENT, FormType.MEISTER_TALENT, FormType.ONE_PARENT, FormType.MULTI_CHILDREN}; return values[new Random().nextInt(values.length)]; } diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml new file mode 100644 index 00000000..47349d00 --- /dev/null +++ b/src/test/resources/application.yml @@ -0,0 +1,63 @@ +spring: + profiles: + active: test + + data: + redis: + host:localhost + port:6379 + timeout:6 + h2: + console: + enabled: true + path: /h2-console + datasource: + driver-class-name: org.h2.Driver + url: jdbc:h2:mem:db;MODE=MYSQL + username: sa + password: + jpa: + generate-ddl: 'true' + hibernate: + ddl-auto: create + properties: + hibernate: + format_sql: true + use_sql_comments: true + + + cloud: + aws: + s3: + bucket: ${BUCKET_NAME} + stack: + auto: false + region: + static: ${S3_REGION} + credentials: + instance-profile: true + access-key: ${S3_ACCESS_KEY} + secret-key: ${S3_SECRET_KEY} + + logging: + level: + com.amazonaws.util.EC2MetadataUtils: error + + servlet: + multipart: + max-file-size: 10MB + +jwt: + refresh-expiration-time: 1296000000 # 15일 + access-expiration-time: 3600000 # 1시간 + prefix: Bearer + secret-key: ${JWT_SECRET} + +neis: + key: ${NEIS_KEY} + +message: + api-key: ${MESSAGE_API_KEY} + api-secret: ${MESSAGE_API_SECRET} + api-domain: ${MESSAGE_API_DOMAIN} + from: ${MESSAGE_FROM} \ No newline at end of file