ReleaseGraphManager { public List<UpgradeInfo> getUpgradeInfos( String fromVersionString, String toVersionString) { if (!_directedGraph.containsVertex(fromVersionString)) { return Collections.emptyList(); } if (!_directedGraph.containsVertex(toVersionString)) { return Collections.emptyList(); } DijkstraShortestPath<String, UpgradeProcessEdge> dijkstraShortestPath = new DijkstraShortestPath<>( _directedGraph, fromVersionString, toVersionString); List<UpgradeProcessEdge> upgradeProcessEdges = dijkstraShortestPath.getPathEdgeList(); if (upgradeProcessEdges == null) { return Collections.emptyList(); } return ListUtil.toList( upgradeProcessEdges, new Function<UpgradeProcessEdge, UpgradeInfo>() { @Override public UpgradeInfo apply( UpgradeProcessEdge upgradeProcessEdge) { return upgradeProcessEdge.getUpgradeInfo(); } }); } ReleaseGraphManager(final List<UpgradeInfo> upgradeInfos); List<UpgradeInfo> getUpgradeInfos(
		String fromVersionString, String toVersionString); List<List<UpgradeInfo>> getUpgradeInfosList(
		String fromVersionString);  }
@Test public void testGetUpgradePath() { UpgradeInfo upgradeInfo1 = createUpgradeInfo("0.0.0", "0.1.0"); UpgradeInfo upgradeInfo2 = createUpgradeInfo("0.1.0", "0.2.0"); UpgradeInfo upgradeInfo3 = createUpgradeInfo("0.2.0", "1.0.0"); UpgradeInfo upgradeInfo4 = createUpgradeInfo("1.0.0", "2.0.0"); ReleaseGraphManager releaseGraphManager = new ReleaseGraphManager( Arrays.asList( upgradeInfo1, upgradeInfo2, upgradeInfo3, upgradeInfo4)); List<UpgradeInfo> upgradePath = releaseGraphManager.getUpgradeInfos( "0.0.0", "2.0.0"); Assert.assertEquals( Arrays.asList( upgradeInfo1, upgradeInfo2, upgradeInfo3, upgradeInfo4), upgradePath); }
@Test public void testGetUpgradePathNotInOrder() { UpgradeInfo upgradeInfo1 = createUpgradeInfo("0.0.0", "0.1.0"); UpgradeInfo upgradeInfo2 = createUpgradeInfo("0.1.0", "0.2.0"); UpgradeInfo upgradeInfo3 = createUpgradeInfo("0.2.0", "1.0.0"); UpgradeInfo upgradeInfo4 = createUpgradeInfo("1.0.0", "2.0.0"); ReleaseGraphManager releaseGraphManager = new ReleaseGraphManager( Arrays.asList( upgradeInfo4, upgradeInfo2, upgradeInfo1, upgradeInfo3)); List<UpgradeInfo> upgradePath = releaseGraphManager.getUpgradeInfos( "0.0.0", "2.0.0"); Assert.assertEquals( Arrays.asList( upgradeInfo1, upgradeInfo2, upgradeInfo3, upgradeInfo4), upgradePath); }
@Test public void testGetUpgradePathWithCyclesReturnsShortestPath() { UpgradeInfo upgradeInfo1 = createUpgradeInfo("0.0.0", "0.1.0"); UpgradeInfo upgradeInfo2 = createUpgradeInfo("0.1.0", "0.2.0"); UpgradeInfo upgradeInfo3 = createUpgradeInfo("0.2.0", "1.0.0"); UpgradeInfo upgradeInfo4 = createUpgradeInfo("1.0.0", "2.0.0"); UpgradeInfo upgradeInfo5 = createUpgradeInfo("0.0.0", "2.0.0"); ReleaseGraphManager releaseGraphManager = new ReleaseGraphManager( Arrays.asList( upgradeInfo1, upgradeInfo2, upgradeInfo3, upgradeInfo4, upgradeInfo5)); List<UpgradeInfo> upgradePath = releaseGraphManager.getUpgradeInfos( "0.0.0", "2.0.0"); Assert.assertEquals(Arrays.asList(upgradeInfo5), upgradePath); }
@Test public void testGetUpgradePathWithCyclesReturnsShortestPathWhenNotZero() { UpgradeInfo upgradeInfo1 = createUpgradeInfo("0.0.0", "0.1.0"); UpgradeInfo upgradeInfo2 = createUpgradeInfo("0.1.0", "0.2.0"); UpgradeInfo upgradeInfo3 = createUpgradeInfo("0.2.0", "1.0.0"); UpgradeInfo upgradeInfo4 = createUpgradeInfo("1.0.0", "2.0.0"); UpgradeInfo upgradeInfo5 = createUpgradeInfo("0.0.0", "2.0.0"); ReleaseGraphManager releaseGraphManager = new ReleaseGraphManager( Arrays.asList( upgradeInfo1, upgradeInfo2, upgradeInfo3, upgradeInfo4, upgradeInfo5)); List<UpgradeInfo> upgradePath = releaseGraphManager.getUpgradeInfos( "0.1.0", "2.0.0"); Assert.assertEquals( Arrays.asList(upgradeInfo2, upgradeInfo3, upgradeInfo4), upgradePath); }
@Test public void testGetUpgradePathWithIllegalArguments() { UpgradeInfo upgradeInfo1 = createUpgradeInfo("0.0.0", "0.1.0"); UpgradeInfo upgradeInfo2 = createUpgradeInfo("0.1.0", "0.2.0"); UpgradeInfo upgradeInfo3 = createUpgradeInfo("0.2.0", "1.0.0"); UpgradeInfo upgradeInfo4 = createUpgradeInfo("1.0.0", "2.0.0"); ReleaseGraphManager releaseGraphManager = new ReleaseGraphManager( Arrays.asList( upgradeInfo4, upgradeInfo2, upgradeInfo1, upgradeInfo3)); List<UpgradeInfo> upgradeInfos = releaseGraphManager.getUpgradeInfos( "0.0.0", "2.0.1"); Assert.assertEquals(upgradeInfos.toString(), 0, upgradeInfos.size()); }