Skip to content

Commit

Permalink
#225 Git Details & Issues Job should trigger API requests for every s…
Browse files Browse the repository at this point in the history
…cheduled job (#224)
  • Loading branch information
conorheffron authored Jan 11, 2025
1 parent ad5c4f9 commit 0d64418
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 41 deletions.
Binary file added src/main/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private ResponseEntity<List<RepositoryIssueDomain>> getIssuesByUsernameAndRepo(H
request.getHeader("host"),
request.getRequestURI(),
request.getHeader("user-agent"));
List<RepositoryIssueDto> repositoryIssueDtos = gitDetailsService.getIssues(userId, repo);
List<RepositoryIssueDto> repositoryIssueDtos = gitDetailsService.getIssues(userId, repo, false);
info("The repository issues for user={} and repo={} are: {}", userId, repo, repositoryIssueDtos);
return ResponseEntity.status(HttpStatus.OK)
.body(gitDetailsService.mapIssuesToResponse(repositoryIssueDtos));
Expand All @@ -118,7 +118,7 @@ private ResponseEntity<List<RepositoryDetailDomain>> getReposByUsername(HttpServ
request.getHeader("host"),
request.getRequestURI(),
request.getHeader("user-agent"));
List<RepositoryDetailDto> repositories = gitDetailsService.getRepoDetails(userId);
List<RepositoryDetailDto> repositories = gitDetailsService.getRepoDetails(userId, false);
info("The repository details for user={} are: {}", userId, repositories);
return ResponseEntity.status(HttpStatus.OK)
.body(gitDetailsService.mapRepositoriesToResponse(repositories));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ public void run() {
info("GitDetailsRunnable running for userIds={}", getUserIds());

for (String userId : userIds) {
List<RepositoryDetailDto> repositoryDetailDtos = gitDetails.getRepoDetails(userId);
List<RepositoryDetailDto> repositoryDetailDtos = gitDetails.getRepoDetails(userId, true);
info("Running GIT details job for userIds={}, repositoryDetailDtos={}",
userId, repositoryDetailDtos);
if (repositoryDetailDtos != null && !repositoryDetailDtos.isEmpty()) {
gitRepoCache.remove(userId);
gitRepoCache.put(userId, gitDetails.mapRepositoriesToResponse(repositoryDetailDtos));

for(String project : getProjects()) {
List<RepositoryIssueDto> issuesDtos = gitDetails.getIssues(userId, project);
List<RepositoryIssueDto> issuesDtos = gitDetails.getIssues(userId, project, true);
info("Running GIT details job for userIds={}, project={}, issuesDtos={}", userId,
project, issuesDtos);
if (issuesDtos != null && !issuesDtos.isEmpty()) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/ironoc/portfolio/service/GitDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

public interface GitDetails {

List<RepositoryDetailDto> getRepoDetails(String username);
List<RepositoryDetailDto> getRepoDetails(String username, boolean isJob);

List<RepositoryDetailDomain> mapRepositoriesToResponse(
List<RepositoryDetailDto> repositoryDetailDtos);

List<RepositoryDetailDto> mapResponseToRepositories(
List<RepositoryDetailDomain> repositoryDetailDomains);

List<RepositoryIssueDto> getIssues(String userId, String repo);
List<RepositoryIssueDto> getIssues(String userId, String repo, boolean isJob);

List<RepositoryIssueDomain> mapIssuesToResponse(List<RepositoryIssueDto> repositoryIssueDtos);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public GitDetailsService(PropertyConfigI propertyConfig,
}

@Override
public List<RepositoryDetailDto> getRepoDetails(String username) {
public List<RepositoryDetailDto> getRepoDetails(String username, boolean isJob) {
// check cache for home page user ID
if (username.equalsIgnoreCase(IRONOC_GIT_USER)) {
if (!isJob & username.equalsIgnoreCase(IRONOC_GIT_USER)) {
List<RepositoryDetailDomain> repoDetails = gitRepoCache
.get(IRONOC_GIT_USER);
if (repoDetails != null && !repoDetails.isEmpty()) {
Expand Down Expand Up @@ -110,9 +110,9 @@ public List<RepositoryDetailDto> mapResponseToRepositories(
}

@Override
public List<RepositoryIssueDto> getIssues(String userId, String repo) {
public List<RepositoryIssueDto> getIssues(String userId, String repo, boolean isJob) {
// check cache for home page user ID
if (userId.equalsIgnoreCase(IRONOC_GIT_USER)) {
if (!isJob & userId.equalsIgnoreCase(IRONOC_GIT_USER)) {
List<RepositoryIssueDomain> repositoryIssues = gitProjectCache.get(userId, repo);
if (repositoryIssues != null && !repositoryIssues.isEmpty()) {
return this.mapResponseToIssues(repositoryIssues);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void test_getReposByUsernamePathVar_success() throws Exception {
.getResourceAsStream("json" + File.separator + "test_response.json");
List<RepositoryDetailDto> dtos = List.of(objectMapper.readValue(jsonInputStream, RepositoryDetailDto[].class));

when(gitDetailsServiceMock.getRepoDetails("conorheffron")).thenReturn(dtos);
when(gitDetailsServiceMock.getRepoDetails("conorheffron", false)).thenReturn(dtos);
when(gitDetailsServiceMock.mapRepositoriesToResponse(anyList()))
.thenReturn(new GitDetailsService(null, null,
null,null,null)
Expand All @@ -95,7 +95,7 @@ public void test_getReposByUsernamePathVar_success() throws Exception {
.andReturn().getResponse();

// then
verify(gitDetailsServiceMock).getRepoDetails("conorheffron");
verify(gitDetailsServiceMock).getRepoDetails("conorheffron", false);
verify(gitDetailsServiceMock).mapRepositoriesToResponse(anyList());

assertThat(response.getStatus(), is(HttpStatus.OK.value()));
Expand All @@ -121,7 +121,7 @@ public void test_getReposByUsernameReqParam_success() throws Exception {
.getResourceAsStream("json" + File.separator + "test_response.json");
List<RepositoryDetailDto> dtos = List.of(objectMapper.readValue(jsonInputStream, RepositoryDetailDto[].class));

when(gitDetailsServiceMock.getRepoDetails("conorheffron")).thenReturn(dtos);
when(gitDetailsServiceMock.getRepoDetails("conorheffron", false)).thenReturn(dtos);
when(gitDetailsServiceMock.mapRepositoriesToResponse(anyList()))
.thenReturn(new GitDetailsService(null, null, null,
null, null)
Expand All @@ -133,7 +133,7 @@ public void test_getReposByUsernameReqParam_success() throws Exception {
.andReturn().getResponse();

// then
verify(gitDetailsServiceMock).getRepoDetails("conorheffron");
verify(gitDetailsServiceMock).getRepoDetails("conorheffron", false);
verify(gitDetailsServiceMock).mapRepositoriesToResponse(anyList());

assertThat(response.getStatus(), is(HttpStatus.OK.value()));
Expand Down Expand Up @@ -171,7 +171,7 @@ public void test_getIssuesByUsernameAndRepoPathVars_success() throws Exception {
.getResourceAsStream("json" + File.separator + "test_issues_response.json");
List<RepositoryIssueDto> dtos = List.of(objectMapper.readValue(jsonInputStream, RepositoryIssueDto[].class));

when(gitDetailsServiceMock.getIssues("test-user", "test-repo")).thenReturn(dtos);
when(gitDetailsServiceMock.getIssues("test-user", "test-repo", false)).thenReturn(dtos);
when(gitDetailsServiceMock.mapIssuesToResponse(anyList()))
.thenReturn(new GitDetailsService(null, null, null,
null, null)
Expand All @@ -183,7 +183,7 @@ public void test_getIssuesByUsernameAndRepoPathVars_success() throws Exception {
.andReturn().getResponse();

// then
verify(gitDetailsServiceMock).getIssues("test-user", "test-repo");
verify(gitDetailsServiceMock).getIssues("test-user", "test-repo", false);
verify(gitDetailsServiceMock).mapIssuesToResponse(anyList());

assertThat(response.getStatus(), is(HttpStatus.OK.value()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.emptyIterable;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.times;
Expand Down Expand Up @@ -126,7 +127,7 @@ public void test_getIssuesByUsernameAndRepoPathVars_success() {
// then
verify(httpServletRequestMock).getRequestURI();
verify(httpServletRequestMock, times(2)).getHeader(anyString());
verify(gitDetailsServiceMock).getIssues(anyString(), anyString());
verify(gitDetailsServiceMock).getIssues(anyString(), anyString(), anyBoolean());
verify(gitDetailsServiceMock).mapIssuesToResponse(anyList());

assertThat(result, is(notNullValue()));
Expand All @@ -142,7 +143,7 @@ public void test_getIssuesByUsernameAndRepoPathVars_username_invalid_fail() {
// then
verify(httpServletRequestMock, never()).getRequestURI();
verify(httpServletRequestMock, never()).getHeader(anyString());
verify(gitDetailsServiceMock, never()).getIssues(anyString(), anyString());
verify(gitDetailsServiceMock, never()).getIssues(anyString(), anyString(), anyBoolean());
verify(gitDetailsServiceMock, never()).mapIssuesToResponse(anyList());

assertThat(result, is(notNullValue()));
Expand All @@ -159,7 +160,7 @@ public void test_getIssuesByUsernameAndRepoPathVars_project_invalid_fail() {
// then
verify(httpServletRequestMock, never()).getRequestURI();
verify(httpServletRequestMock, never()).getHeader(anyString());
verify(gitDetailsServiceMock, never()).getIssues(anyString(), anyString());
verify(gitDetailsServiceMock, never()).getIssues(anyString(), anyString(), anyBoolean());
verify(gitDetailsServiceMock, never()).mapIssuesToResponse(anyList());

assertThat(result, is(notNullValue()));
Expand All @@ -176,7 +177,7 @@ public void test_getIssuesByUsernameAndRepoPathVars_missing_path_vars_fail() {
// then
verify(httpServletRequestMock, never()).getRequestURI();
verify(httpServletRequestMock, never()).getHeader(anyString());
verify(gitDetailsServiceMock, never()).getIssues(anyString(), anyString());
verify(gitDetailsServiceMock, never()).getIssues(anyString(), anyString(), anyBoolean());
verify(gitDetailsServiceMock, never()).mapIssuesToResponse(anyList());

assertThat(result, is(notNullValue()));
Expand Down
25 changes: 13 additions & 12 deletions src/test/java/net/ironoc/portfolio/job/GitDetailsJobTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Collections;
import java.util.List;

import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -53,9 +54,9 @@ public void test_triggerGitDetailsJob_success() {
when(propertyConfigMock.getGitApiEndpointUserIdsCache()).thenReturn(List.of("conorheffron"));
when(propertyConfigMock.getGitApiEndpointProjectsCache())
.thenReturn(List.of("ironoc", "booking-sys"));
when(gitDetailsMock.getRepoDetails(anyString()))
when(gitDetailsMock.getRepoDetails(anyString(), anyBoolean()))
.thenReturn(Collections.singletonList(repositoryDetailDtoMock));
when(gitDetailsMock.getIssues(anyString(), anyString()))
when(gitDetailsMock.getIssues(anyString(), anyString(), anyBoolean()))
.thenReturn(Collections.singletonList(repositoryIssueDtoMock));

// when
Expand All @@ -65,9 +66,9 @@ public void test_triggerGitDetailsJob_success() {
verify(propertyConfigMock).isCacheJobEnabled();
verify(propertyConfigMock).getGitApiEndpointProjectsCache();
verify(propertyConfigMock).getGitApiEndpointUserIdsCache();
verify(gitDetailsMock).getRepoDetails(anyString());
verify(gitDetailsMock).getRepoDetails(anyString(), anyBoolean());
verify(gitRepoCache).put(anyString(), anyList());
verify(gitDetailsMock, times(2)).getIssues(anyString(), anyString());
verify(gitDetailsMock, times(2)).getIssues(anyString(), anyString(), anyBoolean());
verify(gitProjectCache, times(2)).put(anyString(), anyString(), anyList());
}

Expand All @@ -78,9 +79,9 @@ public void test_populateCache_success() {
when(propertyConfigMock.getGitApiEndpointUserIdsCache()).thenReturn(List.of("ironoc-test-id"));
when(propertyConfigMock.getGitApiEndpointProjectsCache())
.thenReturn(List.of("ironoc", "booking-sys", "ironoc-db", "nba-stats"));
when(gitDetailsMock.getRepoDetails(anyString()))
when(gitDetailsMock.getRepoDetails(anyString(), anyBoolean()))
.thenReturn(Collections.singletonList(repositoryDetailDtoMock));
when(gitDetailsMock.getIssues(anyString(), anyString()))
when(gitDetailsMock.getIssues(anyString(), anyString(), anyBoolean()))
.thenReturn(Collections.singletonList(repositoryIssueDtoMock));

// when
Expand All @@ -90,9 +91,9 @@ public void test_populateCache_success() {
verify(propertyConfigMock).isCacheJobEnabled();
verify(propertyConfigMock).getGitApiEndpointProjectsCache();
verify(propertyConfigMock).getGitApiEndpointUserIdsCache();
verify(gitDetailsMock).getRepoDetails(anyString());
verify(gitDetailsMock).getRepoDetails(anyString(), anyBoolean());
verify(gitRepoCache).put(anyString(), anyList());
verify(gitDetailsMock, times(4)).getIssues(anyString(), anyString());
verify(gitDetailsMock, times(4)).getIssues(anyString(), anyString(), anyBoolean());
verify(gitProjectCache, times(4)).put(anyString(), anyString(), anyList());
}

Expand All @@ -108,9 +109,9 @@ public void test_triggerGitDetailsJob_fail() {
verify(propertyConfigMock).isCacheJobEnabled();
verify(propertyConfigMock, never()).getGitApiEndpointProjectsCache();
verify(propertyConfigMock, never()).getGitApiEndpointUserIdsCache();
verify(gitDetailsMock, never()).getRepoDetails(anyString());
verify(gitDetailsMock, never()).getRepoDetails(anyString(), anyBoolean());
verify(gitRepoCache, never()).put(anyString(), anyList());
verify(gitDetailsMock, never()).getIssues(anyString(), anyString());
verify(gitDetailsMock, never()).getIssues(anyString(), anyString(), anyBoolean());
verify(gitProjectCache, never()).put(anyString(), anyString(), anyList());
}

Expand All @@ -126,9 +127,9 @@ public void test_populateCache_fail() {
verify(propertyConfigMock).isCacheJobEnabled();
verify(propertyConfigMock, never()).getGitApiEndpointProjectsCache();
verify(propertyConfigMock, never()).getGitApiEndpointUserIdsCache();
verify(gitDetailsMock, never()).getRepoDetails(anyString());
verify(gitDetailsMock, never()).getRepoDetails(anyString(), anyBoolean());
verify(gitRepoCache, never()).put(anyString(), anyList());
verify(gitDetailsMock, never()).getIssues(anyString(), anyString());
verify(gitDetailsMock, never()).getIssues(anyString(), anyString(), anyBoolean());
verify(gitProjectCache, never()).put(anyString(), anyString(), anyList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static org.hamcrest.Matchers.emptyIterable;
import static org.hamcrest.Matchers.hasSize;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -59,9 +60,9 @@ public void setup() {
@Test
public void test_run_tearDown_success() {
// given
when(gitDetailsMock.getRepoDetails(anyString()))
when(gitDetailsMock.getRepoDetails(anyString(), anyBoolean()))
.thenReturn(Collections.singletonList(repositoryDetailDtoMock));
when(gitDetailsMock.getIssues(anyString(), anyString()))
when(gitDetailsMock.getIssues(anyString(), anyString(), anyBoolean()))
.thenReturn(Collections.singletonList(repositoryIssueDtoMock));

// when
Expand All @@ -70,7 +71,7 @@ public void test_run_tearDown_success() {
// then
verify(propertyConfigMock).getGitApiEndpointProjectsCache();
verify(propertyConfigMock).getGitApiEndpointUserIdsCache();
verify(gitDetailsMock).getRepoDetails(anyString());
verify(gitDetailsMock).getRepoDetails(anyString(), anyBoolean());
verify(gitRepoCacheMock).put(anyString(), anyList());
verify(gitDetailsMock).mapRepositoriesToResponse(anyList());
verify(gitProjectCacheMock, times(3)).put(anyString(), anyString(), anyList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void test_get_repos_success() throws IOException {
.thenReturn(objectMapper.readValue(jsonInputStream, listType));

// when
List<RepositoryDetailDto> results = gitDetailsService.getRepoDetails(testUserId);
List<RepositoryDetailDto> results = gitDetailsService.getRepoDetails(testUserId, false);

// then
verify(propertyConfigMock).getGitApiEndpointRepos();
Expand Down Expand Up @@ -147,7 +147,7 @@ public void test_get_issues_success() throws IOException {
.thenReturn(objectMapper.readValue(jsonInputStream, listType));

// when
List<RepositoryIssueDto> results = gitDetailsService.getIssues(testUserId, testRepo);
List<RepositoryIssueDto> results = gitDetailsService.getIssues(testUserId, testRepo, false);

// then
verify(propertyConfigMock).getGitApiEndpointIssues();
Expand Down Expand Up @@ -188,7 +188,7 @@ public void test_get_repos_parseNull_values_success() throws IOException {
.thenReturn(objectMapper.readValue(jsonInputStream, listType));

// when
List<RepositoryDetailDto> results = gitDetailsService.getRepoDetails(testUserId);
List<RepositoryDetailDto> results = gitDetailsService.getRepoDetails(testUserId, false);

// then
verify(propertyConfigMock).getGitApiEndpointRepos();
Expand All @@ -212,7 +212,7 @@ public void test_getRepoDetails_result_cached_success() {
String testUserId = "conorheffron";

// when
List<RepositoryDetailDto> results = gitDetailsService.getRepoDetails(testUserId);
List<RepositoryDetailDto> results = gitDetailsService.getRepoDetails(testUserId, false);

// then
verify(gitRepoCacheMock).get(IRONOC_GIT_USER);
Expand All @@ -228,7 +228,7 @@ public void test_getRepoDetails_url_invalid_fail() {
when(propertyConfigMock.getGitApiEndpointRepos()).thenReturn(TEST_URI);

// when
List<RepositoryDetailDto> results = gitDetailsService.getRepoDetails(testUserId);
List<RepositoryDetailDto> results = gitDetailsService.getRepoDetails(testUserId, false);

// then
verify(propertyConfigMock).getGitApiEndpointRepos();
Expand Down Expand Up @@ -360,7 +360,7 @@ public void test_getIssues_url_invalid_fail() {
when(propertyConfigMock.getGitApiEndpointIssues()).thenReturn(TEST_URI);

// when
List<RepositoryIssueDto> results = gitDetailsService.getIssues(testUserId, testProject);
List<RepositoryIssueDto> results = gitDetailsService.getIssues(testUserId, testProject, false);

// then
verify(propertyConfigMock).getGitApiEndpointIssues();
Expand Down

0 comments on commit 0d64418

Please sign in to comment.