CommunicationSummaryTreeBuilder { public static Collection<CommunicationSummaryStatistics> buildCommunicationSummaryTree( Collection<CommunicationSummaryStatistics> nodes, Set<String> endpoints) { Map<String, CommunicationSummaryStatistics> nodeMap = new HashMap<String, CommunicationSummaryStatistics>(); for (CommunicationSummaryStatistics css : nodes) { nodeMap.put(css.getId(), css); } List<CommunicationSummaryStatistics> ret = new ArrayList<>(); for (String endpoint : endpoints) { CommunicationSummaryStatistics n = nodeMap.get(EndpointUtil.encodeClientURI(endpoint)); if (n == null) { n = nodeMap.get(endpoint); } if (n != null) { CommunicationSummaryStatistics rootNode = new CommunicationSummaryStatistics(n); initCommunicationSummaryTreeNode(rootNode, nodeMap, new HashSet<>(Collections.singleton(rootNode.getId()))); ret.add(rootNode); } } return ret; }  static Collection<CommunicationSummaryStatistics> buildCommunicationSummaryTree(
            Collection<CommunicationSummaryStatistics> nodes, Set<String> endpoints);  }
@Test public void testBuildCommunicationSummaryTree() { List<CommunicationSummaryStatistics> nodes = new ArrayList<CommunicationSummaryStatistics>(); CommunicationSummaryStatistics css1 = new CommunicationSummaryStatistics(); css1.setId("css1"); nodes.add(css1); CommunicationSummaryStatistics.ConnectionStatistics con1 = new CommunicationSummaryStatistics.ConnectionStatistics(); css1.getOutbound().put("css2", con1); CommunicationSummaryStatistics css2 = new CommunicationSummaryStatistics(); css2.setId("css2"); css2.setCount(1); nodes.add(css2); CommunicationSummaryStatistics css3 = new CommunicationSummaryStatistics(); css3.setId("css3"); nodes.add(css3); Collection<CommunicationSummaryStatistics> result = CommunicationSummaryTreeBuilder.buildCommunicationSummaryTree(nodes, new HashSet<>(Arrays.asList("css1", "css3"))); assertNotNull(result); assertEquals(2, result.size()); CommunicationSummaryStatistics css1a = null; CommunicationSummaryStatistics css3a = null; for (CommunicationSummaryStatistics css : result) { if (css.getId().equals("css1")) { css1a = css; } else if (css.getId().equals("css3")) { css3a = css; } else { fail("Unexpected id: " + css.getId()); } } assertEquals(1, css1a.getOutbound().size()); assertTrue(css1a.getOutbound().containsKey("css2")); assertTrue(css3a.getOutbound().isEmpty()); assertNotNull(css1a.getOutbound().get("css2").getNode()); assertEquals("css2", css1a.getOutbound().get("css2").getNode().getId()); assertEquals(1, css1a.getOutbound().get("css2").getNode().getCount()); }
@Test public void testBuildCommunicationSummaryTreeMissingTarget() { List<CommunicationSummaryStatistics> nodes = new ArrayList<CommunicationSummaryStatistics>(); CommunicationSummaryStatistics css1 = new CommunicationSummaryStatistics(); css1.setId("css1"); nodes.add(css1); CommunicationSummaryStatistics.ConnectionStatistics con1 = new CommunicationSummaryStatistics.ConnectionStatistics(); css1.getOutbound().put("css2", con1); Collection<CommunicationSummaryStatistics> result = CommunicationSummaryTreeBuilder.buildCommunicationSummaryTree(nodes, new HashSet<>(Collections.singletonList("css1"))); assertNotNull(result); assertEquals(1, result.size()); CommunicationSummaryStatistics css1result = result.iterator().next(); assertEquals(css1.getId(), css1result.getId()); assertEquals(1, css1.getOutbound().size()); assertTrue(css1result.getOutbound().containsKey("css2")); assertNotNull(css1result.getOutbound().get("css2").getNode()); assertEquals("css2", css1result.getOutbound().get("css2").getNode().getId()); assertEquals(0, css1result.getOutbound().get("css2").getNode().getCount()); }