diff --git a/backend/src/main/java/heartbeat/service/board/jira/JiraService.java b/backend/src/main/java/heartbeat/service/board/jira/JiraService.java index e8cc483402..e40cbcca57 100644 --- a/backend/src/main/java/heartbeat/service/board/jira/JiraService.java +++ b/backend/src/main/java/heartbeat/service/board/jira/JiraService.java @@ -412,8 +412,7 @@ private JiraCardWithFields getAllCards(BoardType boardType, URI baseUrl, BoardRe private AllCardsResponseDTO formatAllCards(String allCardResponse, List targetFields, List overrideFields) { - Gson gson = new Gson(); - AllCardsResponseDTO allCardsResponseDTO = gson.fromJson(allCardResponse, AllCardsResponseDTO.class); + AllCardsResponseDTO allCardsResponseDTO = new Gson().fromJson(allCardResponse, AllCardsResponseDTO.class); List jiraCards = allCardsResponseDTO.getIssues(); JsonArray elements = JsonParser.parseString(allCardResponse).getAsJsonObject().get("issues").getAsJsonArray(); @@ -440,41 +439,40 @@ private AllCardsResponseDTO formatAllCards(String allCardResponse, List { + Sprint sprint = sprintMap.get(jiraCard.getKey()); + jiraCard.getFields().setSprint(sprint); + }); return allCardsResponseDTO; } - private static Map getCustomfieldMap(Gson gson, Map sprintMap, - Map resultMap, JsonElement element, JsonObject jsonElement) { + private Map getCustomFieldMap(JsonElement element, Map resultMap, + JsonObject jsonElement, Map sprintMap) { Map customFieldMap = new HashMap<>(); - for (Map.Entry entry : resultMap.entrySet()) { - String customFieldKey = entry.getKey(); - String customFieldValue = entry.getValue(); + resultMap.forEach((customFieldKey, customFieldValue) -> { if (jsonElement.has(customFieldKey)) { JsonElement fieldValue = jsonElement.get(customFieldKey); - if (customFieldValue.equals("Sprint") && !fieldValue.isJsonNull() && fieldValue.isJsonArray()) { - JsonArray jsonArray = fieldValue.getAsJsonArray(); - if (!jsonArray.isJsonNull() && !jsonArray.isEmpty()) { - Type listType = new TypeToken>() { - }.getType(); - List sprints = gson.fromJson(jsonArray, listType); - sprints.sort(Comparator.comparing(Sprint::getCompleteDate, - Comparator.nullsLast(Comparator.comparing(ZonedDateTime::parse)))); - sprintMap.put(element.getAsJsonObject().get("key").getAsString(), - sprints.get(sprints.size() - 1)); - } - } - else if (customFieldValue.equals("Story point estimate") && !fieldValue.isJsonNull() - && fieldValue.isJsonPrimitive()) { + fieldValue = mapFieldValue(element, sprintMap, customFieldValue, fieldValue); + customFieldMap.put(customFieldKey, fieldValue); + } + }); + return customFieldMap; + } + + private JsonElement mapFieldValue(JsonElement element, Map sprintMap, String customFieldValue, + JsonElement fieldValue) { + switch (customFieldValue) { + case "Sprint" -> Optional.ofNullable(getSprint(fieldValue)) + .ifPresentOrElse(it -> sprintMap.put(element.getAsJsonObject().get("key").getAsString(), it), () -> { + }); + case "Story point estimate" -> { + if (!fieldValue.isJsonNull() && fieldValue.isJsonPrimitive()) { JsonPrimitive jsonPrimitive = fieldValue.getAsJsonPrimitive(); if (jsonPrimitive.isNumber()) { Number numberValue = jsonPrimitive.getAsNumber(); @@ -482,17 +480,35 @@ else if (customFieldValue.equals("Story point estimate") && !fieldValue.isJsonNu fieldValue = new JsonPrimitive(doubleValue); } } - else if (customFieldValue.equals("Flagged") && !fieldValue.isJsonNull() && fieldValue.isJsonArray()) { + } + case "Flagged" -> { + if (!fieldValue.isJsonNull() && fieldValue.isJsonArray()) { JsonArray jsonArray = fieldValue.getAsJsonArray(); if (!jsonArray.isJsonNull() && !jsonArray.isEmpty()) { JsonElement targetField = jsonArray.get(jsonArray.size() - 1); fieldValue = targetField.getAsJsonObject().get("value"); } } - customFieldMap.put(customFieldKey, fieldValue); + } + default -> { } } - return customFieldMap; + return fieldValue; + } + + private Sprint getSprint(JsonElement fieldValue) { + if (!fieldValue.isJsonNull() && fieldValue.isJsonArray()) { + JsonArray jsonArray = fieldValue.getAsJsonArray(); + if (!jsonArray.isJsonNull() && !jsonArray.isEmpty()) { + Type listType = new TypeToken>() { + }.getType(); + List sprints = new Gson().fromJson(jsonArray, listType); + sprints.sort(Comparator.comparing(Sprint::getCompleteDate, + Comparator.nullsLast(Comparator.comparing(ZonedDateTime::parse)))); + return sprints.get(sprints.size() - 1); + } + } + return null; } private String parseJiraJql(BoardType boardType, List doneColumns, BoardRequestParam boardRequestParam) { diff --git a/backend/src/main/java/heartbeat/service/pipeline/buildkite/CachePageService.java b/backend/src/main/java/heartbeat/service/pipeline/buildkite/CachePageService.java index f5e60d8518..6fc635f2d7 100644 --- a/backend/src/main/java/heartbeat/service/pipeline/buildkite/CachePageService.java +++ b/backend/src/main/java/heartbeat/service/pipeline/buildkite/CachePageService.java @@ -46,11 +46,23 @@ private int parseTotalPage(@Nullable List linkHeader) { return 1; } String lastLink = linkHeader.stream().map(link -> link.replaceAll("per_page=\\d+", "")).findFirst().orElse(""); - Matcher matcher = Pattern.compile("page=(\\d+)[^>]*>.*?rel=\"last\"").matcher(lastLink); - if (matcher.find()) { - return Integer.parseInt(matcher.group(1)); + int lastIndex = lastLink.indexOf("rel=\"last\""); + if (lastIndex == -1) { + return 1; + } + String beforeLastRel = lastLink.substring(0, lastIndex); + Matcher matcher = Pattern.compile("page=(\\d+)").matcher(beforeLastRel); + + String lastNumber = null; + while (matcher.find()) { + lastNumber = matcher.group(1); // 每次找到匹配项时更新lastNumber + } + if (lastNumber != null) { + return Integer.parseInt(lastNumber); + } + else { + return 1; } - return 1; } } diff --git a/backend/src/main/java/heartbeat/service/report/CSVFileGenerator.java b/backend/src/main/java/heartbeat/service/report/CSVFileGenerator.java index e5acff11b3..84d82bda68 100644 --- a/backend/src/main/java/heartbeat/service/report/CSVFileGenerator.java +++ b/backend/src/main/java/heartbeat/service/report/CSVFileGenerator.java @@ -101,43 +101,7 @@ public void convertPipelineDataToCSV(List leadTimeData, String csvWriter.writeNext(headers); - for (PipelineCSVInfo csvInfo : leadTimeData) { - String committerName = null; - String commitDate = null; - String creatorName = null; - String organization = csvInfo.getOrganizationName(); - String pipelineName = csvInfo.getPipeLineName(); - String stepName = csvInfo.getStepName(); - String valid = String.valueOf(csvInfo.getValid()).toLowerCase(); - String buildNumber = String.valueOf(csvInfo.getBuildInfo().getNumber()); - String state = csvInfo.getPiplineStatus().equals(CANCELED_STATUS) ? CANCELED_STATUS - : csvInfo.getDeployInfo().getState(); - String branch = csvInfo.getBuildInfo().getBranch(); - if (csvInfo.getCommitInfo() != null) { - committerName = csvInfo.getCommitInfo().getCommit().getAuthor().getName(); - commitDate = csvInfo.getCommitInfo().getCommit().getAuthor().getDate(); - } - - if (csvInfo.getBuildInfo().getCreator() != null - && csvInfo.getBuildInfo().getCreator().getName() != null) { - creatorName = csvInfo.getBuildInfo().getCreator().getName(); - } - - LeadTimeInfo leadTimeInfo = csvInfo.getLeadTimeInfo(); - String firstCommitTimeInPr = leadTimeInfo.getFirstCommitTimeInPr(); - String prCreatedTime = leadTimeInfo.getPrCreatedTime(); - String prMergedTime = leadTimeInfo.getPrMergedTime(); - String jobFinishTime = csvInfo.getDeployInfo().getJobFinishTime(); - String totalTime = leadTimeInfo.getTotalTime(); - String prLeadTime = leadTimeInfo.getPrLeadTime(); - String pipelineLeadTime = leadTimeInfo.getPipelineLeadTime(); - - String[] rowData = { organization, pipelineName, stepName, valid, buildNumber, committerName, - creatorName, firstCommitTimeInPr, commitDate, prCreatedTime, prMergedTime, jobFinishTime, - totalTime, prLeadTime, pipelineLeadTime, state, branch }; - - csvWriter.writeNext(rowData); - } + leadTimeData.stream().map(this::getRowData).forEach(csvWriter::writeNext); } catch (IOException e) { log.error("Failed to write pipeline file", e); @@ -149,6 +113,42 @@ public void convertPipelineDataToCSV(List leadTimeData, String } } + private String[] getRowData(PipelineCSVInfo csvInfo) { + String committerName = null; + String commitDate = null; + if (csvInfo.getCommitInfo() != null) { + committerName = csvInfo.getCommitInfo().getCommit().getAuthor().getName(); + commitDate = csvInfo.getCommitInfo().getCommit().getAuthor().getDate(); + } + + String creatorName = null; + if (csvInfo.getBuildInfo().getCreator() != null && csvInfo.getBuildInfo().getCreator().getName() != null) { + creatorName = csvInfo.getBuildInfo().getCreator().getName(); + } + + String organization = csvInfo.getOrganizationName(); + String pipelineName = csvInfo.getPipeLineName(); + String stepName = csvInfo.getStepName(); + String valid = String.valueOf(csvInfo.getValid()).toLowerCase(); + String buildNumber = String.valueOf(csvInfo.getBuildInfo().getNumber()); + String state = csvInfo.getPiplineStatus().equals(CANCELED_STATUS) ? CANCELED_STATUS + : csvInfo.getDeployInfo().getState(); + String branch = csvInfo.getBuildInfo().getBranch(); + + LeadTimeInfo leadTimeInfo = csvInfo.getLeadTimeInfo(); + String firstCommitTimeInPr = leadTimeInfo.getFirstCommitTimeInPr(); + String prCreatedTime = leadTimeInfo.getPrCreatedTime(); + String prMergedTime = leadTimeInfo.getPrMergedTime(); + String jobFinishTime = csvInfo.getDeployInfo().getJobFinishTime(); + String totalTime = leadTimeInfo.getTotalTime(); + String prLeadTime = leadTimeInfo.getPrLeadTime(); + String pipelineLeadTime = leadTimeInfo.getPipelineLeadTime(); + + return new String[] { organization, pipelineName, stepName, valid, buildNumber, committerName, creatorName, + firstCommitTimeInPr, commitDate, prCreatedTime, prMergedTime, jobFinishTime, totalTime, prLeadTime, + pipelineLeadTime, state, branch }; + } + public InputStreamResource getDataFromCSV(ReportType reportDataType, long csvTimeStamp) { return switch (reportDataType) { case METRIC -> readStringFromCsvFile( @@ -289,33 +289,7 @@ private String[] getFixedDataPerRow(JiraCardDTO cardDTO, int columnCount) { rowData[0] = cardDTO.getBaseInfo().getKey(); if (cardDTO.getBaseInfo().getFields() != null) { - rowData[1] = cardDTO.getBaseInfo().getFields().getSummary(); - rowData[2] = cardDTO.getBaseInfo().getFields().getIssuetype().getName(); - rowData[3] = cardDTO.getBaseInfo().getFields().getStatus().getName(); - if (cardDTO.getBaseInfo().getFields().getLastStatusChangeDate() != null) { - rowData[4] = convertToSimpleISOFormat(cardDTO.getBaseInfo().getFields().getLastStatusChangeDate()); - } - rowData[5] = String.valueOf(cardDTO.getBaseInfo().getFields().getStoryPoints()); - if (cardDTO.getBaseInfo().getFields().getAssignee() != null) { - rowData[6] = cardDTO.getBaseInfo().getFields().getAssignee().getDisplayName(); - } - if (cardDTO.getBaseInfo().getFields().getReporter() != null) { - rowData[7] = cardDTO.getBaseInfo().getFields().getReporter().getDisplayName(); - } - - rowData[8] = cardDTO.getBaseInfo().getFields().getProject().getKey(); - rowData[9] = cardDTO.getBaseInfo().getFields().getProject().getName(); - rowData[10] = cardDTO.getBaseInfo().getFields().getPriority().getName(); - - if (cardDTO.getBaseInfo().getFields().getParent() != null) { - rowData[11] = cardDTO.getBaseInfo().getFields().getParent().getFields().getSummary(); - } - - if (cardDTO.getBaseInfo().getFields().getSprint() != null) { - rowData[12] = cardDTO.getBaseInfo().getFields().getSprint().getName(); - } - - rowData[13] = String.join(",", cardDTO.getBaseInfo().getFields().getLabels()); + fixDataWithFields(cardDTO, rowData); } } @@ -332,6 +306,36 @@ private String[] getFixedDataPerRow(JiraCardDTO cardDTO, int columnCount) { return rowData; } + private void fixDataWithFields(JiraCardDTO cardDTO, String[] rowData) { + rowData[1] = cardDTO.getBaseInfo().getFields().getSummary(); + rowData[2] = cardDTO.getBaseInfo().getFields().getIssuetype().getName(); + rowData[3] = cardDTO.getBaseInfo().getFields().getStatus().getName(); + if (cardDTO.getBaseInfo().getFields().getLastStatusChangeDate() != null) { + rowData[4] = convertToSimpleISOFormat(cardDTO.getBaseInfo().getFields().getLastStatusChangeDate()); + } + rowData[5] = String.valueOf(cardDTO.getBaseInfo().getFields().getStoryPoints()); + if (cardDTO.getBaseInfo().getFields().getAssignee() != null) { + rowData[6] = cardDTO.getBaseInfo().getFields().getAssignee().getDisplayName(); + } + if (cardDTO.getBaseInfo().getFields().getReporter() != null) { + rowData[7] = cardDTO.getBaseInfo().getFields().getReporter().getDisplayName(); + } + + rowData[8] = cardDTO.getBaseInfo().getFields().getProject().getKey(); + rowData[9] = cardDTO.getBaseInfo().getFields().getProject().getName(); + rowData[10] = cardDTO.getBaseInfo().getFields().getPriority().getName(); + + if (cardDTO.getBaseInfo().getFields().getParent() != null) { + rowData[11] = cardDTO.getBaseInfo().getFields().getParent().getFields().getSummary(); + } + + if (cardDTO.getBaseInfo().getFields().getSprint() != null) { + rowData[12] = cardDTO.getBaseInfo().getFields().getSprint().getName(); + } + + rowData[13] = String.join(",", cardDTO.getBaseInfo().getFields().getLabels()); + } + private String getExtraDataPerRow(Object object, BoardCSVConfig extraField) { Map elementMap = (Map) object; if (elementMap == null) { diff --git a/backend/src/main/java/heartbeat/service/report/KanbanCsvService.java b/backend/src/main/java/heartbeat/service/report/KanbanCsvService.java index 359f7d12f5..808b926d2c 100644 --- a/backend/src/main/java/heartbeat/service/report/KanbanCsvService.java +++ b/backend/src/main/java/heartbeat/service/report/KanbanCsvService.java @@ -33,7 +33,6 @@ import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.stream.Collectors; import java.util.stream.Stream; @Service @@ -80,51 +79,14 @@ private void generateCSVForBoard(List allDoneCards, List emptyJiraCard = List.of(JiraCardDTO.builder().build()); if (allDoneCards != null) { - if (allDoneCards.size() > 1) { - allDoneCards.sort((preCard, nextCard) -> { - Status preStatus = preCard.getBaseInfo().getFields().getStatus(); - Status nextStatus = nextCard.getBaseInfo().getFields().getStatus(); - Long preDateTimeStamp = preCard.getBaseInfo().getFields().getLastStatusChangeDate(); - Long nextDateTimeStamp = nextCard.getBaseInfo().getFields().getLastStatusChangeDate(); - if (Objects.isNull(preStatus) || Objects.isNull(nextStatus) || Objects.isNull(preDateTimeStamp) - || Objects.isNull(nextDateTimeStamp)) { - return jiraColumns.size() + 1; - } - else { - return nextDateTimeStamp.compareTo(preDateTimeStamp); - } - }); - } + sortAllDoneCardsByTime(allDoneCards, jiraColumns); cardDTOList.addAll(allDoneCards); } cardDTOList.addAll(emptyJiraCard); if (nonDoneCards != null) { - if (nonDoneCards.size() > 1) { - nonDoneCards.sort((preCard, nextCard) -> { - Status preStatus = preCard.getBaseInfo().getFields().getStatus(); - Status nextStatus = nextCard.getBaseInfo().getFields().getStatus(); - Long preDateTimeStamp = preCard.getBaseInfo().getFields().getLastStatusChangeDate(); - Long nextDateTimeStamp = nextCard.getBaseInfo().getFields().getLastStatusChangeDate(); - if (Objects.isNull(preStatus) || Objects.isNull(nextStatus)) { - return jiraColumns.size() + 1; - } - else { - String preCardStatusName = preStatus.getName(); - String nextCardStatusName = nextStatus.getName(); - int statusIndexComparison = getIndexForStatus(jiraColumns, nextCardStatusName) - - getIndexForStatus(jiraColumns, preCardStatusName); - - if (statusIndexComparison == 0 && Objects.nonNull(preDateTimeStamp) - && Objects.nonNull(nextDateTimeStamp)) { - return nextDateTimeStamp.compareTo(preDateTimeStamp); - } - - return statusIndexComparison; - } - }); - } + sortNonDoneCardsByStatusAndTime(nonDoneCards, jiraColumns); cardDTOList.addAll(nonDoneCards); } @@ -162,6 +124,51 @@ private void generateCSVForBoard(List allDoneCards, List nonDoneCards, List jiraColumns) { + if (nonDoneCards.size() > 1) { + nonDoneCards.sort((preCard, nextCard) -> { + Status preStatus = preCard.getBaseInfo().getFields().getStatus(); + Status nextStatus = nextCard.getBaseInfo().getFields().getStatus(); + Long preDateTimeStamp = preCard.getBaseInfo().getFields().getLastStatusChangeDate(); + Long nextDateTimeStamp = nextCard.getBaseInfo().getFields().getLastStatusChangeDate(); + if (Objects.isNull(preStatus) || Objects.isNull(nextStatus)) { + return jiraColumns.size() + 1; + } + else { + String preCardStatusName = preStatus.getName(); + String nextCardStatusName = nextStatus.getName(); + int statusIndexComparison = getIndexForStatus(jiraColumns, nextCardStatusName) + - getIndexForStatus(jiraColumns, preCardStatusName); + + if (statusIndexComparison == 0 && Objects.nonNull(preDateTimeStamp) + && Objects.nonNull(nextDateTimeStamp)) { + return nextDateTimeStamp.compareTo(preDateTimeStamp); + } + + return statusIndexComparison; + } + }); + } + } + + private void sortAllDoneCardsByTime(List allDoneCards, List jiraColumns) { + if (allDoneCards.size() > 1) { + allDoneCards.sort((preCard, nextCard) -> { + Status preStatus = preCard.getBaseInfo().getFields().getStatus(); + Status nextStatus = nextCard.getBaseInfo().getFields().getStatus(); + Long preDateTimeStamp = preCard.getBaseInfo().getFields().getLastStatusChangeDate(); + Long nextDateTimeStamp = nextCard.getBaseInfo().getFields().getLastStatusChangeDate(); + if (Objects.isNull(preStatus) || Objects.isNull(nextStatus) || Objects.isNull(preDateTimeStamp) + || Objects.isNull(nextDateTimeStamp)) { + return jiraColumns.size() + 1; + } + else { + return nextDateTimeStamp.compareTo(preDateTimeStamp); + } + }); + } + } + private List insertExtraFieldsAfterCycleTime(final List extraFields, final List fixedBoardFields) { List modifiedFields = new ArrayList<>(fixedBoardFields); @@ -255,7 +262,7 @@ private List getExtraFields(List targetFields, List private List getFixedBoardFields() { return Arrays.stream(BoardCSVConfigEnum.values()) .map(field -> BoardCSVConfig.builder().label(field.getLabel()).value(field.getValue()).build()) - .collect(Collectors.toList()); + .toList(); } private String getFieldDisplayValue(Object object) { diff --git a/backend/src/main/java/heartbeat/service/report/calculator/ClassificationCalculator.java b/backend/src/main/java/heartbeat/service/report/calculator/ClassificationCalculator.java index 37612be702..c9f4255dc5 100644 --- a/backend/src/main/java/heartbeat/service/report/calculator/ClassificationCalculator.java +++ b/backend/src/main/java/heartbeat/service/report/calculator/ClassificationCalculator.java @@ -46,54 +46,52 @@ public List calculate(List targetFields, CardCollec JiraCardField jiraCardFields = jiraCardResponse.getBaseInfo().getFields(); Map tempFields = extractFields(jiraCardFields); - for (String tempFieldsKey : tempFields.keySet()) { - Object object = tempFields.get(tempFieldsKey); - if (object instanceof JsonArray objectArray) { - List objectList = new ArrayList<>(); - for (JsonElement element : objectArray) { - if (element.isJsonObject()) { - JsonObject jsonObject = element.getAsJsonObject(); - objectList.add(jsonObject); - } - } - mapArrayField(resultMap, tempFieldsKey, (List.of(objectList))); - } - else if (object instanceof List) { - mapArrayField(resultMap, tempFieldsKey, (List.of(object))); - } - else if (object != null) { - Map countMap = resultMap.get(tempFieldsKey); - if (countMap != null) { - String displayName = pickDisplayNameFromObj(object); - Integer count = countMap.getOrDefault(displayName, 0); - countMap.put(displayName, count > 0 ? count + 1 : 1); - countMap.put(NONE_KEY, countMap.get(NONE_KEY) - 1); - } - } - } + mapFields(tempFields, resultMap); } - for (Map.Entry> entry : resultMap.entrySet()) { - String fieldName = entry.getKey(); - Map valueMap = entry.getValue(); + resultMap.forEach((fieldName, valueMap) -> { List classificationNameValuePair = new ArrayList<>(); if (valueMap.get(NONE_KEY) == 0) { valueMap.remove(NONE_KEY); } - for (Map.Entry mapEntry : valueMap.entrySet()) { - String displayName = mapEntry.getKey(); - Integer count = mapEntry.getValue(); - classificationNameValuePair - .add(new ClassificationNameValuePair(displayName, (double) count / cards.getCardsNumber())); - } + valueMap.forEach((displayName, count) -> classificationNameValuePair + .add(new ClassificationNameValuePair(displayName, (double) count / cards.getCardsNumber()))); classificationFields.add(new Classification(nameMap.get(fieldName), classificationNameValuePair)); - } + }); + return classificationFields; } + private void mapFields(Map tempFields, Map> resultMap) { + tempFields.forEach((tempFieldsKey, object) -> { + if (object instanceof JsonArray objectArray) { + List objectList = new ArrayList<>(); + objectArray.forEach(element -> { + if (element.isJsonObject()) { + JsonObject jsonObject = element.getAsJsonObject(); + objectList.add(jsonObject); + } + }); + mapArrayField(resultMap, tempFieldsKey, (List.of(objectList))); + } + else if (object instanceof List) { + mapArrayField(resultMap, tempFieldsKey, (List.of(object))); + } + else if (object != null) { + Map countMap = resultMap.get(tempFieldsKey); + if (countMap != null) { + String displayName = pickDisplayNameFromObj(object); + Integer count = countMap.getOrDefault(displayName, 0); + countMap.put(displayName, count > 0 ? count + 1 : 1); + countMap.put(NONE_KEY, countMap.get(NONE_KEY) - 1); + } + } + }); + } + private void mapArrayField(Map> resultMap, String fieldsKey, List objects) { Map countMap = resultMap.get(fieldsKey); if (countMap != null) { diff --git a/backend/src/test/java/heartbeat/service/pipeline/buildkite/CachePageServiceTest.java b/backend/src/test/java/heartbeat/service/pipeline/buildkite/CachePageServiceTest.java index 73edb65fbe..e1b3719bb2 100644 --- a/backend/src/test/java/heartbeat/service/pipeline/buildkite/CachePageServiceTest.java +++ b/backend/src/test/java/heartbeat/service/pipeline/buildkite/CachePageServiceTest.java @@ -52,6 +52,13 @@ class CachePageServiceTest { ; rel="last" """; + public static final String NONE_PAGE_HEADER = """ + ; rel="first", + ; rel="prev", + ; rel="next", + ; rel="last" + """; + public static final String NONE_TOTAL_PAGE_HEADER = """ ; rel="first", ; rel="prev", @@ -131,4 +138,27 @@ void shouldReturnPageStepsInfoDtoWhenFetchPageStepsInfoSuccessGivenExistButNotMa assertThat(pageStepsInfoDto.getTotalPage()).isEqualTo(1); } + @Test + void shouldReturnPageStepsInfoDtoWhenFetchPageStepsInfoSuccessGivenExistButNotMatchedPageLinkHeader() { + List linkHeader = new ArrayList<>(); + linkHeader.add(NONE_PAGE_HEADER); + HttpHeaders httpHeaders = new HttpHeaders(); + httpHeaders.addAll(HttpHeaders.LINK, linkHeader); + List buildKiteBuildInfoList = new ArrayList<>(); + BuildKiteJob testJob = BuildKiteJob.builder().name(TEST_JOB_NAME).build(); + buildKiteBuildInfoList.add(BuildKiteBuildInfo.builder().jobs(List.of(testJob)).build()); + ResponseEntity> responseEntity = new ResponseEntity<>(buildKiteBuildInfoList, + httpHeaders, HttpStatus.OK); + when(buildKiteFeignClient.getPipelineSteps(anyString(), anyString(), anyString(), anyString(), anyString(), + anyString(), anyString(), any())) + .thenReturn(responseEntity); + + PageStepsInfoDto pageStepsInfoDto = cachePageService.fetchPageStepsInfo(MOCK_TOKEN, TEST_ORG_ID, + TEST_PIPELINE_ID, "1", "100", MOCK_START_TIME, MOCK_END_TIME, List.of("main")); + + assertNotNull(pageStepsInfoDto); + assertThat(pageStepsInfoDto.getFirstPageStepsInfo()).isEqualTo(responseEntity.getBody()); + assertThat(pageStepsInfoDto.getTotalPage()).isEqualTo(1); + } + }