Skip to content

Commit

Permalink
test(#98): SelectSecondPassUseCaseTest
Browse files Browse the repository at this point in the history
- 2차 합격 자동화 스프링 통합 테스트를 작성했어요.
- 스프링 부트 테스트를 위해 테스트 프로필이 있는 application.yml을 분리하여 작성했어요.
  • Loading branch information
cabbage16 committed Sep 3, 2024
1 parent 2f1b285 commit 95dcad5
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<User> userList = userRepository.saveAll(
UserFixture.generateUserList(FixedNumber.TOTAL * 2)
);
List<Form> formList = FormFixture.generateFormList(userList);
formList.forEach(form -> {
assignExaminationNumberService.execute(form);
form.receive();
calculateFormScoreService.execute(form);
formRepository.save(form);
});
selectFirstPassUseCase.execute();
List<Form> 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<Form> comparator = Comparator
.comparing(Form::getType)
.thenComparing(form -> form.getScore().getTotalScore());

List<Form> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
}

Expand Down
63 changes: 63 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit 95dcad5

Please sign in to comment.