GraphController { @GetMapping(value = "/nodes") public Page<Node> getNodes(@RequestParam(value = "q", required = false) String query, Pageable pageable) { LOGGER.info("Get all nodes. Query: {}, Paging: {}", query, pageable); List<Node> resultList; if (query != null) { String normalizedQuery = normalizeQuery(query); resultList = new ArrayList<>(index.findNodes(normalizedQuery)); } else { resultList = new ArrayList<>(dependencyGraph.getAllNodes()); } resultList.sort(Comparator.comparing(AbstractGraphElement::getName)); int startIndex = (int) pageable.getOffset(); if (startIndex > resultList.size()) { startIndex = resultList.size(); } int stopIndex = startIndex + pageable.getPageSize(); if (stopIndex > resultList.size()) { stopIndex = resultList.size(); } List<Node> subList = resultList.subList(startIndex, stopIndex); return new PageImpl<>(subList, pageable, resultList.size()); }  @Value("${de.qaware.qav.graph.filename}") void setFilename(String filename); @PostConstruct void init(); @GetMapping(value = "/info") GraphInfoDTO getInfo(); @GetMapping(value = "/node") NodeDTO getNode(@RequestParam(value = "name") String name); @GetMapping(value = "/edge") DependencyDTO getEdge(@RequestParam("from") String from,
                                 @RequestParam("to") String to); @GetMapping(value = "/nodes") Page<Node> getNodes(@RequestParam(value = "q", required = false) String query,
                               Pageable pageable);  }
@Test public void testGetNodes() { Page<Node> resultPage = graphController.getNodes("name:v*", PageRequest.of(0, 30)); assertThat(resultPage, notNullValue()); assertThat(resultPage.getTotalElements(), is(5L)); assertThat(resultPage.getTotalPages(), is(1)); List<Node> nodes = resultPage.getContent(); assertThat(nodes, hasSize(5)); }
@Test public void testGetNodesMorePages() { Page<Node> resultPage = graphController.getNodes("name:v*", PageRequest.of(0, 3)); assertThat(resultPage, notNullValue()); assertThat(resultPage.getTotalElements(), is(5L)); assertThat(resultPage.getTotalPages(), is(2)); assertThat(resultPage.getNumber(), is(0)); List<Node> nodes = resultPage.getContent(); assertThat(nodes, hasSize(3)); resultPage = graphController.getNodes("name:v*", PageRequest.of(1, 3)); assertThat(resultPage, notNullValue()); assertThat(resultPage.getTotalElements(), is(5L)); assertThat(resultPage.getTotalPages(), is(2)); assertThat(resultPage.getNumber(), is(1)); nodes = resultPage.getContent(); assertThat(nodes, hasSize(2)); }
@Test public void testGetNodesNotFound() { Page<Node> resultPage = graphController.getNodes("name:xx*", PageRequest.of(0, 3)); assertThat(resultPage, notNullValue()); assertThat(resultPage.getTotalElements(), is(0L)); assertThat(resultPage.getTotalPages(), is(0)); List<Node> nodes = resultPage.getContent(); assertThat(nodes, hasSize(0)); }
@Test public void testGetNodesBehindLastPage() { Page<Node> resultPage = graphController.getNodes("name:v*", PageRequest.of(1, 30)); assertThat(resultPage, notNullValue()); assertThat(resultPage.getTotalElements(), is(5L)); assertThat(resultPage.getTotalPages(), is(1)); assertThat(resultPage.getNumber(), is(1)); List<Node> nodes = resultPage.getContent(); assertThat(nodes, hasSize(0)); }
@Test public void testGetNodesNoQuery() { Page<Node> resultPage = graphController.getNodes(null, PageRequest.of(0, 30)); assertThat(resultPage, notNullValue()); assertThat(resultPage.getTotalElements(), is(5L)); assertThat(resultPage.getTotalPages(), is(1)); List<Node> nodes = resultPage.getContent(); assertThat(nodes, hasSize(5)); }
@Test public void testGetNodesWithOnlyName() { Page<Node> resultPage = graphController.getNodes("v*", PageRequest.of(0, 30)); assertThat(resultPage, notNullValue()); assertThat(resultPage.getTotalElements(), is(5L)); assertThat(resultPage.getTotalPages(), is(1)); List<Node> nodes = resultPage.getContent(); assertThat(nodes, hasSize(5)); }