diff --git a/backend/src/main/java/heartbeat/controller/board/JiraController.java b/backend/src/main/java/heartbeat/controller/board/JiraController.java index fbcd51f97a..45725c10d2 100644 --- a/backend/src/main/java/heartbeat/controller/board/JiraController.java +++ b/backend/src/main/java/heartbeat/controller/board/JiraController.java @@ -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) { diff --git a/backend/src/main/java/heartbeat/controller/board/dto/request/BoardType.java b/backend/src/main/java/heartbeat/controller/board/dto/request/BoardType.java index 7ede536fba..e6672e69c9 100644 --- a/backend/src/main/java/heartbeat/controller/board/dto/request/BoardType.java +++ b/backend/src/main/java/heartbeat/controller/board/dto/request/BoardType.java @@ -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!"); + }; + } + } 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 b7773dc746..daf96550b2 100644 --- a/backend/src/main/java/heartbeat/service/board/jira/JiraService.java +++ b/backend/src/main/java/heartbeat/service/board/jira/JiraService.java @@ -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())); } } @@ -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> partitions = getTargetFieldAsync(baseUrl, boardRequestParam).join() .stream() @@ -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 { @@ -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())); } } diff --git a/backend/src/test/java/heartbeat/controller/board/JiraControllerTest.java b/backend/src/test/java/heartbeat/controller/board/JiraControllerTest.java index bdc58f7ec1..6ce6ea355c 100644 --- a/backend/src/test/java/heartbeat/controller/board/JiraControllerTest.java +++ b/backend/src/test/java/heartbeat/controller/board/JiraControllerTest.java @@ -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(); @@ -85,6 +86,7 @@ void shouldReturnCorrectBoardVerificationResponseWhenGivenTheCorrectBoardRequest } @Test + @Deprecated void shouldHandleServiceExceptionAndReturnWithStatusAndMessage() throws Exception { RequestFailedException mockException = mock(RequestFailedException.class); String message = "message"; diff --git a/backend/src/test/java/heartbeat/controller/board/dto/request/BoardTypeTest.java b/backend/src/test/java/heartbeat/controller/board/dto/request/BoardTypeTest.java index 5cec2d13a1..50d9eadfd3 100644 --- a/backend/src/test/java/heartbeat/controller/board/dto/request/BoardTypeTest.java +++ b/backend/src/test/java/heartbeat/controller/board/dto/request/BoardTypeTest.java @@ -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); } } diff --git a/backend/src/test/java/heartbeat/service/jira/JiraServiceTest.java b/backend/src/test/java/heartbeat/service/jira/JiraServiceTest.java index 983c74bb7d..1dc9332440 100644 --- a/backend/src/test/java/heartbeat/service/jira/JiraServiceTest.java +++ b/backend/src/test/java/heartbeat/service/jira/JiraServiceTest.java @@ -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)"; @@ -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(); @@ -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(); @@ -340,6 +342,7 @@ void shouldCallJiraFeignClientAndReturnBoardInfoResponseWhenGetJiraBoardInfoHasT } @Test + @Deprecated void shouldCallJiraFeignClientAndReturnBoardConfigResponseWhenGetClassicJiraBoardConfig() throws JsonProcessingException { JiraBoardConfigDTO jiraBoardConfigDTO = CLASSIC_JIRA_BOARD_CONFIG_RESPONSE_BUILDER().build(); @@ -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(); @@ -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(); @@ -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(); @@ -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(); @@ -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 @@ -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 @@ -661,6 +668,7 @@ void shouldGetCardsWhenCallGetStoryPointsAndCycleTimeGiveStoryPointKey() throws } @Test + @Deprecated void shouldThrowExceptionWhenGetJiraConfigurationThrowsUnExpectedException() { URI baseUrl = URI.create(SITE_ATLASSIAN_NET); BoardRequestParam boardRequestParam = BOARD_REQUEST_BUILDER().build(); @@ -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(); @@ -750,6 +759,7 @@ void shouldReturnAssigneeNameFromDoneCardWhenGetBoardInfoAndGetAssigneeSet() thr } @Test + @Deprecated void shouldThrowExceptionWhenGetTargetFieldFailed() { URI baseUrl = URI.create(SITE_ATLASSIAN_NET); String token = "token"; @@ -782,6 +792,7 @@ void shouldThrowExceptionWhenGetBoardInfoAndGetTargetFieldFailed() { } @Test + @Deprecated void shouldThrowExceptionWhenGetTargetFieldReturnNull() { URI baseUrl = URI.create(SITE_ATLASSIAN_NET); String token = "token"; @@ -812,6 +823,7 @@ void shouldThrowExceptionWhenGetBoardInfoAndGetTargetFieldReturnNull() { } @Test + @Deprecated void shouldThrowExceptionWhenGetTargetFieldReturnEmpty() { URI baseUrl = URI.create(SITE_ATLASSIAN_NET); String token = "token"; @@ -850,6 +862,7 @@ void shouldThrowExceptionWhenGetBoardInfoAndGetTargetFieldReturnEmpty() { } @Test + @Deprecated void shouldThrowCustomExceptionWhenGetJiraBoardConfig() { when(urlGenerator.getUri(any())).thenReturn(URI.create(SITE_ATLASSIAN_NET)); @@ -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)); @@ -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); @@ -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();