Skip to content
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

ADM-794:[backend]fix: repair test #1019

Merged
merged 10 commits into from
Feb 1, 2024
Prev Previous commit
Next Next commit
ADM-794:[backend]fix: refactor code
yulongcai committed Feb 1, 2024
commit 65b2d4adfefaf9350d814175d8947daf24b1a4b2
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ class KanbanServiceTest {
private KanbanCsvService kanbanCsvService;

@Test
void shouldCallCsvServiceToGenerateScvInfo() {
void shouldCallCsvServiceToGenerateCSVInfoWhenJiraBoardSettingIsNotNull() {
JiraBoardSetting mockJiraBoardSetting = KanbanFixture.MOCK_JIRA_BOARD_SETTING();
GenerateReportRequest request = GenerateReportRequest.builder()
.jiraBoardSetting(mockJiraBoardSetting)
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import heartbeat.service.report.calculator.model.FetchedData;
import heartbeat.service.source.github.GitHubService;
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -57,12 +58,24 @@ public class PipelineServiceTest {
@Captor
ArgumentCaptor<Map<String, String>> roadMapArgumentCaptor;

private String token;

private String startTime;

private String endTime;

@BeforeEach
public void setup() {
startTime = "startTime";
endTime = "endTime";
token = "token";
}

@Nested
class FetchGithubData {

@Test
void shouldReturnEmptyBuildInfosListAndEmptyLeadTimeWhenDeploymentEnvironmentsIsEmpty() {
String token = "token";
GenerateReportRequest request = GenerateReportRequest.builder()
.buildKiteSetting(BuildKiteSetting.builder().deploymentEnvList(new ArrayList<>()).build())
.metrics(new ArrayList<>())
@@ -90,9 +103,6 @@ void shouldReturnEmptyPipelineLeadTimeWhenCodebaseSettingIsEmpty() {
@Test
void shouldGetPipelineLeadTimeFromGithubServiceAndBuildKiteServiceWhenCodebaseSettingIsNotEmpty() {
List<BuildKiteBuildInfo> fakeBuildKiteBuildInfos = new ArrayList<>();
String startTime = "startTime";
String endTime = "endTime";
String token = "token";
GenerateReportRequest request = GenerateReportRequest.builder()
.buildKiteSetting(BuildKiteSetting.builder()
.deploymentEnvList(List.of(DeploymentEnvironment.builder().id("env1").repository("repo1").build(),
@@ -124,9 +134,6 @@ void shouldGetPipelineLeadTimeFromGithubServiceAndBuildKiteServiceWhenCodebaseSe
@Test
void shouldGetSecondValueInRoadMapWhenDeployEnvironmentListHasTwoElementWithSameKey() {
List<BuildKiteBuildInfo> fakeBuildKiteBuildInfos = new ArrayList<>();
String startTime = "startTime";
String endTime = "endTime";
String token = "token";
GenerateReportRequest request = GenerateReportRequest.builder()
.buildKiteSetting(BuildKiteSetting.builder()
.deploymentEnvList(List.of(DeploymentEnvironment.builder().id("env1").repository("repo1").build(),
@@ -161,9 +168,6 @@ void shouldFilterAuthorByInputCrews() {
BuildKiteBuildInfo.builder()
.author(BuildKiteBuildInfo.Author.builder().name("test-author2").build())
.build());
String startTime = "startTime";
String endTime = "endTime";
String token = "token";
GenerateReportRequest request = GenerateReportRequest.builder()
.buildKiteSetting(BuildKiteSetting.builder()
.deploymentEnvList(List.of(DeploymentEnvironment.builder().id("env1").repository("repo1").build()))
@@ -217,9 +221,6 @@ void shouldReturnValueWhenDeploymentEnvListIsNotEmpty() {
List<BuildKiteBuildInfo> fakeBuildKiteBuildInfos = List.of(BuildKiteBuildInfo.builder()
.creator(BuildKiteBuildInfo.Creator.builder().name("someone").build())
.build());
String startTime = "startTime";
String endTime = "endTime";
String token = "token";
GenerateReportRequest request = GenerateReportRequest.builder()
.buildKiteSetting(BuildKiteSetting.builder()
.token(token)
@@ -254,9 +255,6 @@ void shouldFilterCreatorByInputCrews() {
.creator(BuildKiteBuildInfo.Creator.builder().name("test-creator2").build())
.build(),
BuildKiteBuildInfo.builder().creator(null).build());
String startTime = "startTime";
String endTime = "endTime";
String token = "token";
GenerateReportRequest request = GenerateReportRequest.builder()
.buildKiteSetting(BuildKiteSetting.builder()
.deploymentEnvList(List.of(DeploymentEnvironment.builder().id("env1").repository("repo1").build()))
@@ -288,8 +286,6 @@ class GenerateCSVForPipelineWithCodebase {

@Test
void shouldReturnEmptyWhenDeploymentEnvironmentsIsEmpty() {
String startTime = "startTime";
String endTime = "endTime";
List<PipelineCSVInfo> result = pipelineService.generateCSVForPipelineWithCodebase(
CodebaseSetting.builder().build(), startTime, endTime, FetchedData.BuildKiteData.builder().build(),
Lists.list());
@@ -300,8 +296,6 @@ void shouldReturnEmptyWhenDeploymentEnvironmentsIsEmpty() {

@Test
void shouldReturnEmptyWhenNoBuildInfoFoundForDeploymentEnvironment() {
String startTime = "startTime";
String endTime = "endTime";
List<PipelineCSVInfo> result = pipelineService.generateCSVForPipelineWithCodebase(
CodebaseSetting.builder().build(), startTime, endTime,
FetchedData.BuildKiteData.builder().buildInfosList(List.of(Map.entry("env1", List.of()))).build(),
@@ -313,8 +307,6 @@ void shouldReturnEmptyWhenNoBuildInfoFoundForDeploymentEnvironment() {

@Test
void shouldReturnEmptyWhenPipelineStepsIsEmpty() {
String startTime = "startTime";
String endTime = "endTime";
List<BuildKiteBuildInfo> kiteBuildInfos = List.of(BuildKiteBuildInfo.builder().build());
when(buildKiteService.getPipelineStepNames(eq(kiteBuildInfos))).thenReturn(List.of());

@@ -331,8 +323,6 @@ void shouldReturnEmptyWhenPipelineStepsIsEmpty() {

@Test
void shouldReturnEmptyWhenBuildJobIsEmpty() {
String startTime = "startTime";
String endTime = "endTime";
List<BuildKiteBuildInfo> kiteBuildInfos = List.of(BuildKiteBuildInfo.builder().build());
when(buildKiteService.getPipelineStepNames(eq(kiteBuildInfos))).thenReturn(List.of("check"));
when(buildKiteService.getBuildKiteJob(any(), any(), any(), eq(startTime), eq(endTime))).thenReturn(null);
@@ -351,8 +341,6 @@ void shouldReturnEmptyWhenBuildJobIsEmpty() {

@Test
void shouldFilterOutInvalidBuildOfCommentIsEmtpy() {
String startTime = "startTime";
String endTime = "endTime";
List<BuildKiteBuildInfo> kiteBuildInfos = List.of(BuildKiteBuildInfo.builder().commit("").build());
when(buildKiteService.getPipelineStepNames(eq(kiteBuildInfos))).thenReturn(List.of("check"));
when(buildKiteService.getStepsBeforeEndStep(any(), any())).thenReturn(List.of("check"));
@@ -373,8 +361,6 @@ void shouldFilterOutInvalidBuildOfCommentIsEmtpy() {

@Test
void shouldGenerateValueWithoutCommitWhenCodebaseSettingIsEmpty() {
String startTime = "startTime";
String endTime = "endTime";
List<BuildKiteBuildInfo> kiteBuildInfos = List.of(BuildKiteBuildInfo.builder().commit("commit").build());
when(buildKiteService.getPipelineStepNames(eq(kiteBuildInfos))).thenReturn(List.of("check"));
when(buildKiteService.getStepsBeforeEndStep(any(), any())).thenReturn(List.of("check"));
@@ -397,8 +383,6 @@ void shouldGenerateValueWithoutCommitWhenCodebaseSettingIsEmpty() {

@Test
void shouldGenerateValueWithoutCommitWhenCodebaseSettingTokenIsEmpty() {
String startTime = "startTime";
String endTime = "endTime";
List<BuildKiteBuildInfo> kiteBuildInfos = List.of(BuildKiteBuildInfo.builder().commit("commit").build());
when(buildKiteService.getPipelineStepNames(eq(kiteBuildInfos))).thenReturn(List.of("check"));
when(buildKiteService.getStepsBeforeEndStep(any(), any())).thenReturn(List.of("check"));
@@ -422,8 +406,6 @@ void shouldGenerateValueWithoutCommitWhenCodebaseSettingTokenIsEmpty() {

@Test
void shouldGenerateValueWithoutCommitWhenCommitIdIsEmpty() {
String startTime = "startTime";
String endTime = "endTime";
List<BuildKiteBuildInfo> kiteBuildInfos = List.of(BuildKiteBuildInfo.builder().commit("commit").build());
when(buildKiteService.getPipelineStepNames(eq(kiteBuildInfos))).thenReturn(List.of("check"));
when(buildKiteService.getStepsBeforeEndStep(any(), any())).thenReturn(List.of("check"));
@@ -447,8 +429,6 @@ void shouldGenerateValueWithoutCommitWhenCommitIdIsEmpty() {

@Test
void shouldGenerateValueHasCommit() {
String startTime = "startTime";
String endTime = "endTime";
List<BuildKiteBuildInfo> kiteBuildInfos = List.of(BuildKiteBuildInfo.builder().commit("commit").build());
CommitInfo fakeCommitInfo = CommitInfo.builder().build();
when(buildKiteService.getPipelineStepNames(eq(kiteBuildInfos))).thenReturn(List.of("check"));
@@ -477,8 +457,6 @@ void shouldGenerateValueHasCommit() {

@Test
void shouldGenerateValueWithLeadTimeWhenLeadTimeExisting() {
String startTime = "startTime";
String endTime = "endTime";
List<BuildKiteBuildInfo> kiteBuildInfos = List.of(BuildKiteBuildInfo.builder().commit("commit").build());
CommitInfo fakeCommitInfo = CommitInfo.builder().build();
when(buildKiteService.getPipelineStepNames(eq(kiteBuildInfos))).thenReturn(List.of("check"));
Original file line number Diff line number Diff line change
@@ -24,6 +24,8 @@
import java.util.List;
import java.util.stream.Collectors;

import static heartbeat.controller.report.dto.request.MetricEnum.LEAD_TIME_FOR_CHANGES;
import static heartbeat.controller.report.dto.request.MetricEnum.VELOCITY;
import static heartbeat.service.report.scheduler.DeleteExpireCSVScheduler.EXPORT_CSV_VALIDITY_TIME;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -102,16 +104,16 @@ void ShouldInitializeMetricsDataCompletedInHandlerWithPreOneWhenPreOneExisted()
}

@Test
void ShouldInitializeMetricsDataCompletedInHandlerWhenRequestMetricsExist() throws InterruptedException {
void ShouldInitializeMetricsDataCompletedInHandlerWhenRequestMetricsExist() {
GenerateReportRequest request = GenerateReportRequest.builder()
.csvTimeStamp("csvTimeStamp")
.metrics(List.of("velocity", "lead time for changes"))
.metrics(List.of(VELOCITY.getValue(), LEAD_TIME_FOR_CHANGES.getValue()))
.build();
when(asyncMetricsDataHandler.getMetricsDataCompleted(any()))
.thenReturn(MetricsDataCompleted.builder().pipelineMetricsCompleted(true).build());
doAnswer(invocation -> null).when(generateReporterService).generateBoardReport(request);

reportService.generateReportByType(request, MetricType.BOARD);
Thread.sleep(100);
MetricsDataCompleted expectMetricsDataResult = MetricsDataCompleted.builder()
.boardMetricsCompleted(false)
.pipelineMetricsCompleted(true)
Loading