-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor/UDT-277 스프링 배치 통합 테스트 #211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dnjstjt1297
wants to merge
2
commits into
develop
Choose a base branch
from
refactor/UDT-277-배치-통합-테스트
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "refactor/UDT-277-\uBC30\uCE58-\uD1B5\uD569-\uD14C\uC2A4\uD2B8"
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
202 changes: 202 additions & 0 deletions
202
src/test/java/com/example/udtbe/batch/config/BatchConfigTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| package com.example.udtbe.batch.config; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import com.example.udtbe.common.fixture.AdminContentDeleteJobFixture; | ||
| import com.example.udtbe.common.fixture.AdminContentRegisterJobFixture; | ||
| import com.example.udtbe.common.fixture.AdminContentUpdateJobFixture; | ||
| import com.example.udtbe.common.fixture.ContentFixture; | ||
| import com.example.udtbe.common.fixture.ContentMetadataFixture; | ||
| import com.example.udtbe.common.support.ApiSupport; | ||
| import com.example.udtbe.domain.batch.entity.AdminContentDeleteJob; | ||
| import com.example.udtbe.domain.batch.entity.AdminContentRegisterJob; | ||
| import com.example.udtbe.domain.batch.entity.AdminContentUpdateJob; | ||
| import com.example.udtbe.domain.batch.entity.enums.BatchStatus; | ||
| import com.example.udtbe.domain.batch.repository.AdminContentDeleteJobRepository; | ||
| import com.example.udtbe.domain.batch.repository.AdminContentRegisterJobRepository; | ||
| import com.example.udtbe.domain.batch.repository.AdminContentUpdateJobRepository; | ||
| import com.example.udtbe.domain.content.entity.Content; | ||
| import com.example.udtbe.domain.content.entity.ContentMetadata; | ||
| import com.example.udtbe.domain.content.repository.ContentMetadataRepository; | ||
| import com.example.udtbe.domain.content.repository.ContentRepository; | ||
| import java.time.LocalDateTime; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.batch.core.ExitStatus; | ||
| import org.springframework.batch.core.JobExecution; | ||
| import org.springframework.batch.core.JobParameters; | ||
| import org.springframework.batch.core.JobParametersBuilder; | ||
| import org.springframework.batch.test.JobLauncherTestUtils; | ||
| import org.springframework.batch.test.context.SpringBatchTest; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.test.context.jdbc.Sql; | ||
|
|
||
| @Sql( | ||
| scripts = "classpath:data-test.sql", | ||
| executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS | ||
| ) | ||
| @SpringBatchTest | ||
| class BatchConfigTest extends ApiSupport { | ||
|
|
||
| @Autowired | ||
| private JobLauncherTestUtils jobLauncherTestUtils; | ||
|
|
||
| @Autowired | ||
| private AdminContentRegisterJobRepository adminContentRegisterJobRepository; | ||
|
|
||
| @Autowired | ||
| private AdminContentUpdateJobRepository adminContentUpdateJobRepository; | ||
|
|
||
| @Autowired | ||
| private AdminContentDeleteJobRepository adminContentDeleteJobRepository; | ||
|
|
||
| @Autowired | ||
| private ContentRepository contentRepository; | ||
|
|
||
| @Autowired | ||
| private ContentMetadataRepository contentMetadataRepository; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| adminContentRegisterJobRepository.deleteAllInBatch(); | ||
| adminContentUpdateJobRepository.deleteAllInBatch(); | ||
| adminContentDeleteJobRepository.deleteAllInBatch(); | ||
| contentMetadataRepository.deleteAllInBatch(); | ||
| contentRepository.deleteAllInBatch(); | ||
| } | ||
|
|
||
| @DisplayName("contentRegisterStep을 성공할 수 있다.") | ||
| @Test | ||
| void contentRegisterStep() { | ||
| // given | ||
| AdminContentRegisterJob pendingJob = AdminContentRegisterJobFixture.createPendingJob(1L, | ||
| "체인소 맨", "레제"); | ||
| adminContentRegisterJobRepository.save(pendingJob); | ||
|
|
||
| JobParameters jobParameters = new JobParametersBuilder() | ||
| .addString("type", "all") | ||
| .addString("date", LocalDateTime.now().toString()) | ||
| .toJobParameters(); | ||
|
|
||
| // when | ||
| JobExecution jobExecution = jobLauncherTestUtils.launchStep("contentRegisterStep", | ||
| jobParameters); | ||
|
|
||
| // then | ||
| assertThat(jobExecution.getExitStatus()).isEqualTo(ExitStatus.COMPLETED); | ||
|
|
||
| AdminContentRegisterJob completedJob = adminContentRegisterJobRepository.findAll().get(0); | ||
| assertThat(completedJob.getStatus()).isEqualTo(BatchStatus.COMPLETED); | ||
|
|
||
| long contentCount = contentRepository.count(); | ||
| assertThat(contentCount).isEqualTo(1); | ||
| } | ||
|
|
||
| @DisplayName("contentUpdateStep을 성공할 수 있다.") | ||
| @Test | ||
| void contentUpdateStep() { | ||
| // given | ||
| Content content = ContentFixture.content("체인소 맨", "레제"); | ||
| ContentMetadata contentMetadata = ContentMetadataFixture.dramaMetadata(content); | ||
|
|
||
| contentRepository.save(content); | ||
| contentMetadataRepository.save(contentMetadata); | ||
|
|
||
| String updatedTitle = "체인소 맨 극장판"; | ||
| String updatedDesc = "지배의 악마"; | ||
|
|
||
| AdminContentUpdateJob pendingJob = AdminContentUpdateJobFixture.createPendingJob(1L, | ||
| content.getId(), updatedTitle, updatedDesc); | ||
| adminContentUpdateJobRepository.save(pendingJob); | ||
|
|
||
| JobParameters jobParameters = new JobParametersBuilder() | ||
| .addString("type", "all") | ||
| .addString("date", LocalDateTime.now().toString()) | ||
| .toJobParameters(); | ||
|
|
||
| // when | ||
| JobExecution jobExecution = jobLauncherTestUtils.launchStep("contentUpdateStep", | ||
| jobParameters); | ||
|
|
||
| // then | ||
| assertThat(jobExecution.getExitStatus()).isEqualTo(ExitStatus.COMPLETED); | ||
|
|
||
| AdminContentUpdateJob completedJob = adminContentUpdateJobRepository.findAll().get(0); | ||
| assertThat(completedJob.getStatus()).isEqualTo(BatchStatus.COMPLETED); | ||
|
|
||
| Content updatedContent = contentRepository.findById(content.getId()).get(); | ||
| assertThat(updatedContent.getTitle()).isEqualTo(updatedTitle); | ||
| assertThat(updatedContent.getDescription()).isEqualTo(updatedDesc); | ||
| } | ||
|
|
||
| @DisplayName("contentUpdateStep에서 예외 발생 시 스킵 처리될 수 있다.") | ||
| @Test | ||
| void contentUpdateStepWhenExceptionThenSkipHandled() throws Exception { | ||
|
|
||
| Content content = ContentFixture.content("체인소 맨", "레제"); | ||
| ContentMetadata contentMetadata = ContentMetadataFixture.dramaMetadata(content); | ||
| contentRepository.save(content); | ||
| contentMetadataRepository.save(contentMetadata); | ||
|
|
||
| // given | ||
| AdminContentUpdateJob pendingJob = AdminContentUpdateJobFixture.createPendingJob( | ||
| 1L, | ||
| 100L, | ||
| "체인소 맨 극장판", | ||
| "마키마 씨는 어떤 맛일까?" | ||
| ); | ||
| adminContentUpdateJobRepository.save(pendingJob); | ||
|
|
||
| JobParameters jobParameters = new JobParametersBuilder() | ||
| .addString("type", "all") | ||
| .addString("date", LocalDateTime.now().toString()) | ||
| .toJobParameters(); | ||
|
|
||
| // when | ||
| JobExecution jobExecution = jobLauncherTestUtils.launchStep("contentUpdateStep", | ||
| jobParameters); | ||
|
|
||
| assertThat(jobExecution.getExitStatus().getExitCode()) | ||
| .isIn(ExitStatus.COMPLETED.getExitCode(), ExitStatus.FAILED.getExitCode()); | ||
|
|
||
| AdminContentUpdateJob failedJob = adminContentUpdateJobRepository.findAll().get(0); | ||
| assertThat(failedJob.getStatus()).isEqualTo(BatchStatus.INVALID); | ||
|
|
||
| Content unUpdatedContent = contentRepository.findById(content.getId()).get(); | ||
| assertThat(unUpdatedContent.getTitle()).isEqualTo(content.getTitle()); | ||
| } | ||
|
|
||
| @DisplayName("contentDeleteStep을 성공할 수 있다.") | ||
| @Test | ||
| void contentDeleteStep() { | ||
| // given | ||
| Content content = ContentFixture.content("체인소 맨", "덴지"); | ||
| ContentMetadata contentMetadata = ContentMetadataFixture.deletedMetadata(content); | ||
| contentRepository.save(content); | ||
| contentMetadataRepository.save(contentMetadata); | ||
|
|
||
| AdminContentDeleteJob pendingJob = AdminContentDeleteJobFixture.createPendingJob(1L, | ||
| content.getId()); | ||
| adminContentDeleteJobRepository.save(pendingJob); | ||
|
|
||
| JobParameters jobParameters = new JobParametersBuilder() | ||
| .addString("type", "all") | ||
| .addString("date", LocalDateTime.now().toString()) | ||
| .toJobParameters(); | ||
|
|
||
| // when | ||
| JobExecution jobExecution = jobLauncherTestUtils.launchStep("contentDeleteStep", | ||
| jobParameters); | ||
|
|
||
| // then | ||
| assertThat(jobExecution.getExitStatus()).isEqualTo(ExitStatus.COMPLETED); | ||
|
|
||
| AdminContentDeleteJob completedJob = adminContentDeleteJobRepository.findAll().get(0); | ||
| assertThat(completedJob.getStatus()).isEqualTo(BatchStatus.COMPLETED); | ||
|
|
||
| Content deletedContent = contentRepository.findById(content.getId()).get(); | ||
| assertThat(deletedContent.isDeleted()).isEqualTo(true); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
스프링배치입장에서는 COMPLETED가 나와요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아마 job 상태는 INVALID일 것 같아요!
