Skip to content

Commit

Permalink
Merge branch 'main' into ADM-727
Browse files Browse the repository at this point in the history
  • Loading branch information
Lei010 authored Jan 10, 2024
2 parents 7cab7c3 + fb3d989 commit 3a66895
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class JiraController {

private final JiraService jiraService;

@Deprecated
@PostMapping("/{boardType}")
public BoardConfigDTO getBoard(@PathVariable @NotBlank BoardType boardType,
@Valid @RequestBody BoardRequestParam boardRequestParam) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@ public static BoardType fromValue(String type) {
};
}

public static BoardType fromStyle(String style) {
return switch (style) {
case "next-gen" -> JIRA;
case "classic" -> CLASSIC_JIRA;
default -> throw new IllegalArgumentException("Board type does not find!");
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ public String verify(BoardType boardType, BoardVerifyRequestParam boardVerifyReq
}
catch (RuntimeException e) {
Throwable cause = Optional.ofNullable(e.getCause()).orElse(e);
log.error("Failed when call Jira to verify board, board id: {}, e: {}",
boardVerifyRequestParam.getBoardId(), cause.getMessage());
log.error("Failed to call Jira to verify board, board id: {}, e: {}", boardVerifyRequestParam.getBoardId(),
cause.getMessage());
if (cause instanceof BaseException baseException) {
throw baseException;
}
throw new InternalServerErrorException(
String.format("Failed when call Jira to verify board, cause is %s", cause.getMessage()));
String.format("Failed to call Jira to verify board, cause is %s", cause.getMessage()));
}
}

Expand All @@ -138,7 +138,7 @@ public BoardConfigDTO getInfo(BoardType boardType, BoardRequestParam boardReques
String jiraBoardStyle = jiraFeignClient
.getProject(baseUrl, boardRequestParam.getProjectKey(), boardRequestParam.getToken())
.getStyle();
BoardType jiraBoardType = "classic".equals(jiraBoardStyle) ? BoardType.CLASSIC_JIRA : BoardType.JIRA;
BoardType jiraBoardType = BoardType.fromStyle(jiraBoardStyle);

Map<Boolean, List<TargetField>> partitions = getTargetFieldAsync(baseUrl, boardRequestParam).join()
.stream()
Expand All @@ -159,16 +159,17 @@ public BoardConfigDTO getInfo(BoardType boardType, BoardRequestParam boardReques
}
catch (RuntimeException e) {
Throwable cause = Optional.ofNullable(e.getCause()).orElse(e);
log.error("Failed when call Jira to get board config, project key: {}, board id: {}, e: {}",
log.error("Failed to call Jira to get board config, project key: {}, board id: {}, e: {}",
boardRequestParam.getBoardId(), boardRequestParam.getProjectKey(), cause.getMessage());
if (cause instanceof BaseException baseException) {
throw baseException;
}
throw new InternalServerErrorException(
String.format("Failed when call Jira to get board config, cause is %s", cause.getMessage()));
String.format("Failed to call Jira to get board config, cause is %s", cause.getMessage()));
}
}

@Deprecated
public BoardConfigDTO getJiraConfiguration(BoardType boardType, BoardRequestParam boardRequestParam) {
URI baseUrl = urlGenerator.getUri(boardRequestParam.getSite());
try {
Expand All @@ -192,13 +193,13 @@ public BoardConfigDTO getJiraConfiguration(BoardType boardType, BoardRequestPara
}
catch (RuntimeException e) {
Throwable cause = Optional.ofNullable(e.getCause()).orElse(e);
log.error("Failed when call Jira to get board config, project key: {}, board id: {}, e: {}",
log.error("Failed to call Jira to get board config, project key: {}, board id: {}, e: {}",
boardRequestParam.getBoardId(), boardRequestParam.getProjectKey(), cause.getMessage());
if (cause instanceof BaseException baseException) {
throw baseException;
}
throw new InternalServerErrorException(
String.format("Failed when call Jira to get board config, cause is %s", cause.getMessage()));
String.format("Failed to call Jira to get board config, cause is %s", cause.getMessage()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class JiraControllerTest {
private MockMvc mockMvc;

@Test
@Deprecated
void shouldReturnCorrectBoardConfigResponseWhenGivenTheCorrectBoardRequest() throws Exception {
BoardConfigDTO boardConfigDTO = BOARD_CONFIG_RESPONSE_BUILDER().build();
BoardRequestParam boardRequestParam = BOARD_REQUEST_BUILDER().build();
Expand Down Expand Up @@ -85,6 +86,7 @@ void shouldReturnCorrectBoardVerificationResponseWhenGivenTheCorrectBoardRequest
}

@Test
@Deprecated
void shouldHandleServiceExceptionAndReturnWithStatusAndMessage() throws Exception {
RequestFailedException mockException = mock(RequestFailedException.class);
String message = "message";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ public class BoardTypeTest {
public void shouldConvertValueToType() {
BoardType jiraBoardType = BoardType.fromValue("jira");
BoardType classicJiraBoardType = BoardType.fromValue("classic-jira");
BoardType jiraBoardStyle = BoardType.fromStyle("next-gen");
BoardType classicJiraBoardStyle = BoardType.fromStyle("classic");
assertEquals(jiraBoardType, BoardType.JIRA);
assertEquals(classicJiraBoardType, BoardType.CLASSIC_JIRA);
assertEquals(jiraBoardStyle, BoardType.JIRA);
assertEquals(classicJiraBoardStyle, BoardType.CLASSIC_JIRA);
}

}
35 changes: 30 additions & 5 deletions backend/src/test/java/heartbeat/service/jira/JiraServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ class JiraServiceTest {

public static final String SITE_ATLASSIAN_NET = "https://site.atlassian.net";

private final BoardType boardTypeJira = BoardType.fromValue("jira");
private final BoardType boardTypeJira = BoardType.fromStyle("next-gen");

private final BoardType boardTypeClassicJira = BoardType.fromValue("classic-jira");
private final BoardType boardTypeClassicJira = BoardType.fromStyle("classic");

private static final String ALL_CARDS_JQL = "status changed during (%s, %s)";

Expand Down Expand Up @@ -159,6 +159,7 @@ public ThreadPoolTaskExecutor getTaskExecutor() {
}

@Test
@Deprecated
void shouldCallJiraFeignClientAndReturnBoardConfigResponseWhenGetJiraBoardConfig() throws JsonProcessingException {
JiraBoardConfigDTO jiraBoardConfigDTO = JIRA_BOARD_CONFIG_RESPONSE_BUILDER().build();
StatusSelfDTO doneStatusSelf = DONE_STATUS_SELF_RESPONSE_BUILDER().build();
Expand Down Expand Up @@ -260,6 +261,7 @@ void shouldCallJiraFeignClientAndReturnBoardVerifyResponseWhenVerifyJiraBoard()
}

@Test
@Deprecated
void shouldCallJiraFeignClientAndReturnBoardConfigResponseWhenGetJiraBoardConfigHasTwoPage() throws IOException {
JiraBoardConfigDTO jiraBoardConfigDTO = JIRA_BOARD_CONFIG_RESPONSE_BUILDER().build();
StatusSelfDTO doneStatusSelf = DONE_STATUS_SELF_RESPONSE_BUILDER().build();
Expand Down Expand Up @@ -340,6 +342,7 @@ void shouldCallJiraFeignClientAndReturnBoardInfoResponseWhenGetJiraBoardInfoHasT
}

@Test
@Deprecated
void shouldCallJiraFeignClientAndReturnBoardConfigResponseWhenGetClassicJiraBoardConfig()
throws JsonProcessingException {
JiraBoardConfigDTO jiraBoardConfigDTO = CLASSIC_JIRA_BOARD_CONFIG_RESPONSE_BUILDER().build();
Expand Down Expand Up @@ -424,6 +427,7 @@ void shouldCallJiraFeignClientAndReturnBoardInfoResponseWhenGetClassicJiraBoardI
}

@Test
@Deprecated
void shouldCallJiraFeignClientAndThrowParamExceptionWhenGetJiraBoardConfig() {
JiraBoardConfigDTO jiraBoardConfigDTO = JIRA_BOARD_CONFIG_RESPONSE_BUILDER().build();
StatusSelfDTO doneStatusSelf = DONE_STATUS_SELF_RESPONSE_BUILDER().build();
Expand Down Expand Up @@ -472,10 +476,11 @@ void shouldCallJiraFeignClientAndThrowNonColumnWhenVerifyJiraBoard() {

Throwable thrown = catchThrowable(() -> jiraService.verify(boardTypeJira, boardVerifyRequestParam));
assertThat(thrown).isInstanceOf(InternalServerErrorException.class)
.hasMessageContaining("Failed when call Jira to verify board, cause is");
.hasMessageContaining("Failed to call Jira to verify board, cause is");
}

@Test
@Deprecated
void shouldCallJiraFeignClientAndThrowNotFoundExceptionWhenGetJiraBoardConfig() throws JsonProcessingException {
JiraBoardConfigDTO jiraBoardConfigDTO = JIRA_BOARD_CONFIG_RESPONSE_BUILDER().build();
StatusSelfDTO doneStatusSelf = DONE_STATUS_SELF_RESPONSE_BUILDER().build();
Expand Down Expand Up @@ -532,6 +537,7 @@ void shouldCallJiraFeignClientTwiceGivenTwoPageHistoryDataWhenGetJiraBoardConfig
}

@Test
@Deprecated
void shouldCallJiraFeignClientAndThrowNonContentCodeWhenGetJiraBoardConfig() throws JsonProcessingException {
JiraBoardConfigDTO jiraBoardConfigDTO = JIRA_BOARD_CONFIG_RESPONSE_BUILDER().build();
StatusSelfDTO doneStatusSelf = DONE_STATUS_SELF_RESPONSE_BUILDER().build();
Expand Down Expand Up @@ -582,6 +588,7 @@ void shouldCallJiraFeignClientAndThrowNonContentCodeWhenGetJiraBoardInfo() throw
}

@Test
@Deprecated
void shouldCallJiraFeignClientAndThrowNonColumnWhenGetJiraBoardConfig() {
JiraBoardConfigDTO jiraBoardConfigDTO = JIRA_BOARD_CONFIG_RESPONSE_BUILDER().build();
StatusSelfDTO noneStatusSelf = NONE_STATUS_SELF_RESPONSE_BUILDER().build();
Expand All @@ -600,7 +607,7 @@ void shouldCallJiraFeignClientAndThrowNonColumnWhenGetJiraBoardConfig() {
jiraService.getJiraConfiguration(boardTypeJira, boardRequestParam);
});
assertThat(thrown).isInstanceOf(InternalServerErrorException.class)
.hasMessageContaining("Failed when call Jira to get board config, cause is");
.hasMessageContaining("Failed to call Jira to get board config, cause is");
}

@Test
Expand All @@ -624,7 +631,7 @@ void shouldCallJiraFeignClientAndThrowNonColumnWhenGetJiraBoardInfo() {
jiraService.getInfo(boardTypeJira, boardRequestParam);
});
assertThat(thrown).isInstanceOf(InternalServerErrorException.class)
.hasMessageContaining("Failed when call Jira to get board config, cause is");
.hasMessageContaining("Failed to call Jira to get board config, cause is");
}

@Test
Expand Down Expand Up @@ -661,6 +668,7 @@ void shouldGetCardsWhenCallGetStoryPointsAndCycleTimeGiveStoryPointKey() throws
}

@Test
@Deprecated
void shouldThrowExceptionWhenGetJiraConfigurationThrowsUnExpectedException() {
URI baseUrl = URI.create(SITE_ATLASSIAN_NET);
BoardRequestParam boardRequestParam = BOARD_REQUEST_BUILDER().build();
Expand Down Expand Up @@ -692,6 +700,7 @@ void shouldThrowExceptionWhenGetJiraInfoThrowsUnExpectedException() {
}

@Test
@Deprecated
void shouldReturnAssigneeNameFromDoneCardWhenGetAssigneeSet() throws JsonProcessingException {
JiraBoardConfigDTO jiraBoardConfigDTO = JIRA_BOARD_CONFIG_RESPONSE_BUILDER().build();
StatusSelfDTO doneStatusSelf = DONE_STATUS_SELF_RESPONSE_BUILDER().build();
Expand Down Expand Up @@ -750,6 +759,7 @@ void shouldReturnAssigneeNameFromDoneCardWhenGetBoardInfoAndGetAssigneeSet() thr
}

@Test
@Deprecated
void shouldThrowExceptionWhenGetTargetFieldFailed() {
URI baseUrl = URI.create(SITE_ATLASSIAN_NET);
String token = "token";
Expand Down Expand Up @@ -782,6 +792,7 @@ void shouldThrowExceptionWhenGetBoardInfoAndGetTargetFieldFailed() {
}

@Test
@Deprecated
void shouldThrowExceptionWhenGetTargetFieldReturnNull() {
URI baseUrl = URI.create(SITE_ATLASSIAN_NET);
String token = "token";
Expand Down Expand Up @@ -812,6 +823,7 @@ void shouldThrowExceptionWhenGetBoardInfoAndGetTargetFieldReturnNull() {
}

@Test
@Deprecated
void shouldThrowExceptionWhenGetTargetFieldReturnEmpty() {
URI baseUrl = URI.create(SITE_ATLASSIAN_NET);
String token = "token";
Expand Down Expand Up @@ -850,6 +862,7 @@ void shouldThrowExceptionWhenGetBoardInfoAndGetTargetFieldReturnEmpty() {
}

@Test
@Deprecated
void shouldThrowCustomExceptionWhenGetJiraBoardConfig() {
when(urlGenerator.getUri(any())).thenReturn(URI.create(SITE_ATLASSIAN_NET));

Expand All @@ -872,6 +885,7 @@ void shouldThrowCustomExceptionWhenGetJiraBoardInfo() {
}

@Test
@Deprecated
void shouldThrowCustomExceptionWhenCallJiraFeignClientToGetBoardConfigFailed() {
URI baseUrl = URI.create(SITE_ATLASSIAN_NET);
when(urlGenerator.getUri(any())).thenReturn(URI.create(SITE_ATLASSIAN_NET));
Expand Down Expand Up @@ -998,6 +1012,16 @@ void shouldReturnBadRequestExceptionWhenBoardTypeIsNotCorrect() {
.hasMessageContaining("Board type does not find!");
}

@Test
void shouldReturnBadRequestExceptionWhenBoardStyleIsNotCorrect() {
BoardRequestParam boardRequestParam = BOARD_REQUEST_BUILDER().build();
when(jiraFeignClient.getProject(any(), any(), any()))
.thenReturn(JiraBoardProject.builder().style("unknown").build());
assertThatThrownBy(() -> jiraService.getInfo(boardTypeJira, boardRequestParam))
.isInstanceOf(InternalServerErrorException.class)
.hasMessageContaining("Board type does not find!");
}

@Test
public void shouldProcessCustomFieldsForCardsWhenCallGetStoryPointsAndCycleTime() {
URI baseUrl = URI.create(SITE_ATLASSIAN_NET);
Expand Down Expand Up @@ -1255,6 +1279,7 @@ void shouldGetRealDoneCardGivenCallGetStoryPointsAndCycleTimeWhenUseLastAssignee
}

@Test
@Deprecated
void shouldFilterOutUnreasonableTargetField() throws JsonProcessingException {
JiraBoardConfigDTO jiraBoardConfigDTO = CLASSIC_JIRA_BOARD_CONFIG_RESPONSE_BUILDER().build();
StatusSelfDTO doneStatusSelf = DONE_STATUS_SELF_RESPONSE_BUILDER().build();
Expand Down

0 comments on commit 3a66895

Please sign in to comment.