Skip to content

Commit

Permalink
Merge pull request #11 from Galactus22625/jira-source
Browse files Browse the repository at this point in the history
Jira source comments and test coverage
  • Loading branch information
san81 authored Nov 1, 2024
2 parents e3843d5 + a719188 commit e760d3a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ private static Stream<Arguments> 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)
);
}

Expand Down Expand Up @@ -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(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand All @@ -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<String> projectList = new ArrayList<>();
private List<String> issueTypeList = new ArrayList<>();
private List<String> inclusionPatternList = new ArrayList<>();
private List<String> exclusionPatternList = new ArrayList<>();
private List<String> statusList = new ArrayList<>();
private Map<String, String> connectorCredentialMap = new HashMap<>();
private JiraSourceConfig jiraSourceConfig;

private JiraSourceConfig createJiraSourceConfig(String authtype, boolean hasToken) throws JsonProcessingException {
Map<String, Object> configMap = new HashMap<>();
configMap.put("account_url", "https://example.atlassian.net");
configMap.put("account_url", accountUrl);

Map<String, String> connectorCredentialMap = new HashMap<>();
connectorCredentialMap.put("auth_type", authtype);
if (hasToken) {
connectorCredentialMap.put("access_token", accessToken);
Expand All @@ -43,19 +50,24 @@ private JiraSourceConfig createJiraSourceConfig(String authtype, boolean hasToke

configMap.put("connector_credentials", connectorCredentialMap);

List<String> projectList = Arrays.asList("project1", "project2");
projectList.add("project1");
projectList.add("project2");
configMap.put("projects", projectList);

List<String> 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<String> inclusionPatternList = Arrays.asList("pattern 1", "pattern 2");
inclusionPatternList.add("pattern 1");
inclusionPatternList.add("pattern 2");
configMap.put("inclusion_patterns", inclusionPatternList);

List<String> exclusionPatternList = Arrays.asList("pattern 3", "pattern 4");
exclusionPatternList.add("pattern 3");
exclusionPatternList.add("pattern 4");
configMap.put("exclusion_patterns", exclusionPatternList);

List<String> statusList = Arrays.asList("status 1", "status 2");
statusList.add("status 1");
statusList.add("status 2");
configMap.put("statuses", statusList);

ObjectMapper objectMapper = new ObjectMapper();
Expand All @@ -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);
Expand Down

0 comments on commit e760d3a

Please sign in to comment.