diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraServiceTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraServiceTest.java index c4cc6cab31..4ecb6cb054 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraServiceTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraServiceTest.java @@ -101,7 +101,8 @@ private static Stream provideHttpStatusCodesWithExceptionClass() { return Stream.of( Arguments.of(HttpStatus.valueOf(AUTHORIZATION_ERROR_CODE), UnAuthorizedException.class), Arguments.of(HttpStatus.valueOf(TOKEN_EXPIRED), RuntimeException.class), - Arguments.of(HttpStatus.TOO_MANY_REQUESTS, RuntimeException.class) + Arguments.of(HttpStatus.TOO_MANY_REQUESTS, RuntimeException.class), + Arguments.of(HttpStatus.INSUFFICIENT_STORAGE, RuntimeException.class) ); } @@ -264,7 +265,7 @@ void testInvokeRestApiTokenExpiredInterruptException() throws JsonProcessingExce JiraSourceConfig jiraSourceConfig = createJiraConfiguration(BASIC, issueType, issueStatus, projectKey); JiraService jiraService = new JiraService(restTemplate, jiraSourceConfig, authConfig); when(authConfig.getUrl()).thenReturn("https://example.com/rest/api/2/issue/key"); - doReturn(new ResponseEntity<>("", HttpStatus.UNAUTHORIZED)).when(restTemplate).getForEntity(any(URI.class), any(Class.class)); + when(restTemplate.getForEntity(any(URI.class), any(Class.class))).thenThrow(new HttpClientErrorException(HttpStatus.TOO_MANY_REQUESTS)); jiraService.setSleepTimeMultiplier(100000); Thread testThread = new Thread(() -> { diff --git a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraSourceConfigTest.java b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraSourceConfigTest.java index 94f718cf61..9da7011d0d 100644 --- a/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraSourceConfigTest.java +++ b/data-prepper-plugins/saas-source-plugins/jira-source/src/test/java/org/opensearch/dataprepper/plugins/source/jira/JiraSourceConfigTest.java @@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; -import java.util.Arrays; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -14,6 +14,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.BASIC; import static org.opensearch.dataprepper.plugins.source.jira.utils.Constants.OAUTH2; +import static org.opensearch.dataprepper.plugins.source.source_crawler.base.CrawlerSourceConfig.DEFAULT_NUMBER_OF_WORKERS; public class JiraSourceConfigTest { private final String accessToken = "access token test"; @@ -22,13 +23,19 @@ public class JiraSourceConfigTest { private final String clientSecret = "client secret test"; private final String jiraCredential = "test Jira Credential"; private final String jiraId = "test Jira Id"; + private final String accountUrl = "https://example.atlassian.net"; + private List projectList = new ArrayList<>(); + private List issueTypeList = new ArrayList<>(); + private List inclusionPatternList = new ArrayList<>(); + private List exclusionPatternList = new ArrayList<>(); + private List statusList = new ArrayList<>(); + private Map connectorCredentialMap = new HashMap<>(); private JiraSourceConfig jiraSourceConfig; private JiraSourceConfig createJiraSourceConfig(String authtype, boolean hasToken) throws JsonProcessingException { Map configMap = new HashMap<>(); - configMap.put("account_url", "https://example.atlassian.net"); + configMap.put("account_url", accountUrl); - Map connectorCredentialMap = new HashMap<>(); connectorCredentialMap.put("auth_type", authtype); if (hasToken) { connectorCredentialMap.put("access_token", accessToken); @@ -43,19 +50,24 @@ private JiraSourceConfig createJiraSourceConfig(String authtype, boolean hasToke configMap.put("connector_credentials", connectorCredentialMap); - List projectList = Arrays.asList("project1", "project2"); + projectList.add("project1"); + projectList.add("project2"); configMap.put("projects", projectList); - List issueTypeList = Arrays.asList("issue type 1", "issue type 2"); + issueTypeList.add("issue type 1"); + issueTypeList.add("issue type 2"); configMap.put("issue_types", issueTypeList); - List inclusionPatternList = Arrays.asList("pattern 1", "pattern 2"); + inclusionPatternList.add("pattern 1"); + inclusionPatternList.add("pattern 2"); configMap.put("inclusion_patterns", inclusionPatternList); - List exclusionPatternList = Arrays.asList("pattern 3", "pattern 4"); + exclusionPatternList.add("pattern 3"); + exclusionPatternList.add("pattern 4"); configMap.put("exclusion_patterns", exclusionPatternList); - List statusList = Arrays.asList("status 1", "status 2"); + statusList.add("status 1"); + statusList.add("status 2"); configMap.put("statuses", statusList); ObjectMapper objectMapper = new ObjectMapper(); @@ -67,15 +79,14 @@ private JiraSourceConfig createJiraSourceConfig(String authtype, boolean hasToke @Test void testGetters() throws JsonProcessingException { jiraSourceConfig = createJiraSourceConfig(BASIC, false); - assertNotNull(jiraSourceConfig.getInclusionPatterns()); - assertNotNull(jiraSourceConfig.getIssueType()); - assertNotNull(jiraSourceConfig.getExclusionPatterns()); - assertNotNull(jiraSourceConfig.getNumWorkers()); - assertNotNull(jiraSourceConfig.getIssueType()); - assertNotNull(jiraSourceConfig.getProject()); - assertNotNull(jiraSourceConfig.getStatus()); - assertNotNull(jiraSourceConfig.getConnectorCredentials()); - assertNotNull(jiraSourceConfig.getAccountUrl()); + assertEquals(jiraSourceConfig.getInclusionPatterns(), inclusionPatternList); + assertEquals(jiraSourceConfig.getIssueType(), issueTypeList); + assertEquals(jiraSourceConfig.getExclusionPatterns(), exclusionPatternList); + assertEquals(jiraSourceConfig.getNumWorkers(), DEFAULT_NUMBER_OF_WORKERS); + assertEquals(jiraSourceConfig.getProject(), projectList); + assertEquals(jiraSourceConfig.getStatus(), statusList); + assertEquals(jiraSourceConfig.getConnectorCredentials(), connectorCredentialMap); + assertEquals(jiraSourceConfig.getAccountUrl(), accountUrl); assertNotNull(jiraSourceConfig.getBackOff()); assertEquals(jiraSourceConfig.getJiraCredential(), jiraCredential); assertEquals(jiraSourceConfig.getJiraId(), jiraId);