SentryUpgradeOrder { public static List<String> getUpgradePath(Map<String, List<String>> upgrades, String from, String to) { List<String> upgradeListPath = new LinkedList<>(); Stack<String> upgradePaths = new Stack<>(); Set<String> visited = new HashSet<>(); searchPath(upgrades, from, to, upgradePaths, visited); while (!upgradePaths.isEmpty()) { upgradeListPath.add(upgradePaths.pop()); } return upgradeListPath; }  static Map<String, List<String>> readUpgradeGraph(Reader reader); static List<String> getUpgradePath(Map<String, List<String>> upgrades, String from, String to);  }
@Test public void testGetUpgradePathUsingSingleSourceVersions() { Map<String, List<String>> normalOrder = new HashMap<String, List<String>>() {{ put("1.7.0", Arrays.asList("1.8.0")); put("1.8.0", Arrays.asList("2.0.0")); put("2.0.0", Arrays.asList("2.1.0")); }}; List<String> upgradePath; upgradePath = SentryUpgradeOrder.getUpgradePath(normalOrder, "1.8.0", "2.1.0"); assertEquals(2, upgradePath.size()); assertEquals("1.8.0-to-2.0.0", upgradePath.get(0)); assertEquals("2.0.0-to-2.1.0", upgradePath.get(1)); upgradePath = SentryUpgradeOrder.getUpgradePath(normalOrder, "1.7.0", "2.0.0"); assertEquals(2, upgradePath.size()); assertEquals("1.7.0-to-1.8.0", upgradePath.get(0)); assertEquals("1.8.0-to-2.0.0", upgradePath.get(1)); upgradePath = SentryUpgradeOrder.getUpgradePath(normalOrder, "1.8.0", "3.1.0"); assertEquals(0, upgradePath.size()); upgradePath = SentryUpgradeOrder.getUpgradePath(normalOrder, "1.5.0", "2.1.0"); assertEquals(0, upgradePath.size()); }
@Test public void testGetUpgradePathUsingMultipleSourceTargetVersions() { Map<String, List<String>> multiVersionsOrder = new HashMap<String, List<String>>() {{ put("1.7.0", Arrays.asList("1.8.0", "2.0.0")); put("1.8.0", Arrays.asList("2.0.0")); put("1.9.0", Arrays.asList("2.1.0")); put("2.0.0", Arrays.asList("2.1.0")); }}; List<String> upgradePath; upgradePath = SentryUpgradeOrder.getUpgradePath(multiVersionsOrder, "1.8.0", "2.1.0"); assertEquals(2, upgradePath.size()); assertEquals("1.8.0-to-2.0.0", upgradePath.get(0)); assertEquals("2.0.0-to-2.1.0", upgradePath.get(1)); upgradePath = SentryUpgradeOrder.getUpgradePath(multiVersionsOrder, "1.7.0", "2.0.0"); assertEquals(2, upgradePath.size()); assertEquals("1.7.0-to-1.8.0", upgradePath.get(0)); assertEquals("1.8.0-to-2.0.0", upgradePath.get(1)); upgradePath = SentryUpgradeOrder.getUpgradePath(multiVersionsOrder, "1.9.0", "2.1.0"); assertEquals(1, upgradePath.size()); upgradePath = SentryUpgradeOrder.getUpgradePath(multiVersionsOrder, "1.7.0", "2.0.0"); assertEquals(2, upgradePath.size()); assertEquals("1.7.0-to-1.8.0", upgradePath.get(0)); assertEquals("1.8.0-to-2.0.0", upgradePath.get(1)); upgradePath = SentryUpgradeOrder.getUpgradePath(multiVersionsOrder, "1.9.0", "2.0.0"); assertEquals(0, upgradePath.size()); }