Skip to content

Commit

Permalink
fixing defect of empty history results
Browse files Browse the repository at this point in the history
  • Loading branch information
larrydiamond committed Sep 29, 2023
1 parent 63e80e1 commit d71d013
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/ldiamond/sqgraph/SqgraphApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
config.getExpandedApplications().add(app);
} else {
if (app.getQuery() != null) {
final String uri = config.getUrl() + "/api/project/search?qualifiers=TRK&q=" + app.getQuery();
final String uri = config.getUrl() + "/api/projects/search?qualifiers=TRK&q=" + app.getQuery();
ResponseEntity<ApiProjectsSearchResults> response = restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity<String>(headers), ApiProjectsSearchResults.class);
ApiProjectsSearchResults result = response.getBody();
if ((result != null) && (result.getComponents() != null)) {
Expand Down Expand Up @@ -198,7 +198,7 @@ public static AssembledSearchHistory getHistory (final Config config, final Stri
ResponseEntity<SearchHistory> response = restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity<String>(headers), SearchHistory.class);
SearchHistory result = response.getBody();
if (result != null) {
if ((result.getPaging() != null) && (result.getPaging().total == page)) {
if ((result.getPaging() != null) && (result.getPaging().total <= page)) {
notYetLastPage = false;
try {
Thread.sleep(1); // SonarCloud implemented rate limiting, https://docs.github.com/en/rest/rate-limit?apiVersion=2022-11-28, sorry for contributing to the problem. I guess we all got popular :)
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/com/ldiamond/sqgraph/SqgraphApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,26 @@ void getHistory() {
assertEquals(1, ash.getMeasures().get(2).history.length);
assertEquals(1, ash.getMeasures().get(3).history.length);
}

@Test
void getHistoryEmpty() {

final Config config = new Config();
config.setUrl("prefix");

SearchHistory sh = new SearchHistory();
Paging paging = new Paging();
paging.setTotal(0);
sh.setPaging(paging);
Measures[] measuresArray = new Measures[0];
sh.setMeasures(measuresArray);

ResponseEntity<SearchHistory> rsh = new ResponseEntity<>(sh, null, HttpStatus.OK);
HttpHeaders httpHeaders = new HttpHeaders();
HttpEntity<String> hes = new HttpEntity<>(httpHeaders);
when (restTemplate.exchange("prefix/api/measures/search_history?from=blah&p=1&ps=999&component=blah&metrics=blah",HttpMethod.GET,hes,SearchHistory.class)).thenReturn(rsh);
AssembledSearchHistory ash = SqgraphApplication.getHistory(config, "blah", "blah", "blah", httpHeaders, restTemplate);

assertEquals(0, ash.getMeasures().size());
}
}

0 comments on commit d71d013

Please sign in to comment.