From d71d0132d2fed568b8ca13ddd1481509370f9e3d Mon Sep 17 00:00:00 2001 From: Larry Diamond <1066589+larrydiamond@users.noreply.github.com> Date: Thu, 28 Sep 2023 23:10:38 -0400 Subject: [PATCH] fixing defect of empty history results --- .../ldiamond/sqgraph/SqgraphApplication.java | 4 ++-- .../sqgraph/SqgraphApplicationTests.java | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ldiamond/sqgraph/SqgraphApplication.java b/src/main/java/com/ldiamond/sqgraph/SqgraphApplication.java index 4ffc383..682d177 100644 --- a/src/main/java/com/ldiamond/sqgraph/SqgraphApplication.java +++ b/src/main/java/com/ldiamond/sqgraph/SqgraphApplication.java @@ -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 response = restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity(headers), ApiProjectsSearchResults.class); ApiProjectsSearchResults result = response.getBody(); if ((result != null) && (result.getComponents() != null)) { @@ -198,7 +198,7 @@ public static AssembledSearchHistory getHistory (final Config config, final Stri ResponseEntity response = restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity(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 :) diff --git a/src/test/java/com/ldiamond/sqgraph/SqgraphApplicationTests.java b/src/test/java/com/ldiamond/sqgraph/SqgraphApplicationTests.java index 623cdd0..6f36815 100644 --- a/src/test/java/com/ldiamond/sqgraph/SqgraphApplicationTests.java +++ b/src/test/java/com/ldiamond/sqgraph/SqgraphApplicationTests.java @@ -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 rsh = new ResponseEntity<>(sh, null, HttpStatus.OK); + HttpHeaders httpHeaders = new HttpHeaders(); + HttpEntity 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()); + } }