@Test public void TestCreateMergedRouteResultFromBestPaths() throws Exception { List<GHResponse> responseList = new ArrayList<>(); RoutingRequest routingRequest = new RouteRequestHandler().convertRouteRequest(request1); List<RouteExtraInfo> extrasList = new ArrayList<>(); RouteResultBuilder builder = new RouteResultBuilder(); RouteResult result = builder.createMergedRouteResultFromBestPaths(responseList, routingRequest, new List[]{extrasList}); Assert.assertEquals("Empty response list should return empty RouteResult (summary.distance = 0.0)", 0.0, result.getSummary().getDistance(), 0.0); Assert.assertEquals("Empty response list should return empty RouteResult (no segments)", 0, result.getSegments().size()); Assert.assertEquals("Empty response list should return empty RouteResult (no extra info)", 0, result.getExtraInfo().size()); Assert.assertNull("Empty response list should return empty RouteResult (no geometry)", result.getGeometry()); extrasList.add(new RouteExtraInfo(APIEnums.ExtraInfo.OSM_ID.toString())); responseList.add(constructResponse(request1)); result = builder.createMergedRouteResultFromBestPaths(responseList, routingRequest, new List[]{extrasList}); Assert.assertEquals("Single response should return valid RouteResult (summary.duration = 1452977.2)", 1452977.2, result.getSummary().getDistance(), 0.0); Assert.assertEquals("Single response should return valid RouteResult (summary.bbox = 45.6,56.7,12.3,23.4)", "45.6,56.7,12.3,23.4", result.getSummary().getBBox().toString()); Assert.assertEquals("Single response should return valid RouteResult (geometry.length = 2)", 2, result.getGeometry().length); Assert.assertEquals("Single response should return valid RouteResult (geometry[0] = 45.6,12.3,NaN)", "(45.6, 12.3, NaN)", result.getGeometry()[0].toString()); Assert.assertEquals("Single response should return valid RouteResult (geometry[1] = 56.7,23.4,NaN)", "(56.7, 23.4, NaN)", result.getGeometry()[1].toString()); Assert.assertEquals("Single response should return valid RouteResult (segments.size = 1)", 1, result.getSegments().size()); Assert.assertEquals("Single response should return valid RouteResult (segments[0].distance = 1452977.2)", 1452977.2, result.getSegments().get(0).getDistance(), 0.0); Assert.assertEquals("Single response should return valid RouteResult (segments[0].detourFactor = 2)", 0.85, result.getSegments().get(0).getDetourFactor(), 0.0); Assert.assertEquals("Single response should return valid RouteResult (segments[0].steps.size = 2)", 2, result.getSegments().get(0).getSteps().size()); Assert.assertEquals("Single response should return valid RouteResult (segments[0].steps[0].name = 'Instruction 1')", "Instruction 1", result.getSegments().get(0).getSteps().get(0).getName()); Assert.assertEquals("Single response should return valid RouteResult (segments[0].steps[0].type = 11)", 11, result.getSegments().get(0).getSteps().get(0).getType()); Assert.assertEquals("Single response should return valid RouteResult (segments[0].steps[0].maneuver.bearingAfter = 44)", 44, result.getSegments().get(0).getSteps().get(0).getManeuver().getBearingAfter()); Assert.assertEquals("Single response should return valid RouteResult (segments[0].steps[1].name = 'Instruction 2')", "Instruction 2", result.getSegments().get(0).getSteps().get(1).getName()); Assert.assertEquals("Single response should return valid RouteResult (segments[0].steps[1].type = 10)", 10, result.getSegments().get(0).getSteps().get(1).getType()); Assert.assertEquals("Single response should return valid RouteResult (segments[0].steps[1].maneuver.bearingAfter = 0)", 0, result.getSegments().get(0).getSteps().get(1).getManeuver().getBearingAfter()); Assert.assertEquals("Single response should return valid RouteResult (extrainfo.size = 1)", 1, result.getExtraInfo().size()); Assert.assertEquals("Single response should return valid RouteResult (extrainfo[0].name = 'osmid)", APIEnums.ExtraInfo.OSM_ID.toString(), result.getExtraInfo().get(0).getName()); Assert.assertEquals("Single response should return valid RouteResult (waypointindices.size = 2)", 2, result.getWayPointsIndices().size()); responseList.add(constructResponse(request2)); result = builder.createMergedRouteResultFromBestPaths(responseList, routingRequest, new List[]{extrasList}); Assert.assertEquals("Two responses should return merged RouteResult (summary.duration = 2809674.1)", 2809674.1, result.getSummary().getDistance(), 0.0); Assert.assertEquals("Two responses should return merged RouteResult (summary.bbox = 45.6,67.8,12.3,34.5)", "45.6,67.8,12.3,34.5", result.getSummary().getBBox().toString()); Assert.assertEquals("Two responses should return merged RouteResult (geometry.length = 3)", 3, result.getGeometry().length); Assert.assertEquals("Two responses should return merged RouteResult (geometry[0] = 45.6,12.3,NaN)", "(45.6, 12.3, NaN)", result.getGeometry()[0].toString()); Assert.assertEquals("Two responses should return merged RouteResult (geometry[1] = 56.7,23.4,NaN)", "(56.7, 23.4, NaN)", result.getGeometry()[1].toString()); Assert.assertEquals("Two responses should return merged RouteResult (geometry[2] = 67.8,34.5,NaN)", "(67.8, 34.5, NaN)", result.getGeometry()[2].toString()); Assert.assertEquals("Two responses should return merged RouteResult (segments.size = 2)", 2, result.getSegments().size()); Assert.assertEquals("Two responses should return merged RouteResult (segments[0].distance = 1452977.2)", 1452977.2, result.getSegments().get(0).getDistance(), 0.0); Assert.assertEquals("Two responses should return merged RouteResult (segments[0].detourFactor = 0.85)", 0.85, result.getSegments().get(0).getDetourFactor(), 0.0); Assert.assertEquals("Two responses should return merged RouteResult (segments[0].steps.size = 2)", 2, result.getSegments().get(0).getSteps().size()); Assert.assertEquals("Two responses should return merged RouteResult (segments[0].steps[0].name = 'Instruction 1')", "Instruction 1", result.getSegments().get(0).getSteps().get(0).getName()); Assert.assertEquals("Two responses should return merged RouteResult (segments[0].steps[0].type = 11)", 11, result.getSegments().get(0).getSteps().get(0).getType()); Assert.assertEquals("Two responses should return merged RouteResult (segments[0].steps[0].maneuver.bearingAfter = 44)", 44, result.getSegments().get(0).getSteps().get(0).getManeuver().getBearingAfter()); Assert.assertEquals("Two responses should return merged RouteResult (segments[0].steps[1].name = 'Instruction 2')", "Instruction 2", result.getSegments().get(0).getSteps().get(1).getName()); Assert.assertEquals("Two responses should return merged RouteResult (segments[0].steps[1].type = 10)", 10, result.getSegments().get(0).getSteps().get(1).getType()); Assert.assertEquals("Two responses should return merged RouteResult (segments[0].steps[1].maneuver.bearingAfter = 0)", 0, result.getSegments().get(0).getSteps().get(1).getManeuver().getBearingAfter()); Assert.assertEquals("Two responses should return merged RouteResult (segments[1].distance = 1356696.9)", 1356696.9, result.getSegments().get(1).getDistance(), 0.0); Assert.assertEquals("Two responses should return merged RouteResult (segments[1].detourFactor = 0.83)", 0.83, result.getSegments().get(1).getDetourFactor(), 0.0); Assert.assertEquals("Two responses should return merged RouteResult (segments[1].steps.size = 2)", 2, result.getSegments().get(1).getSteps().size()); Assert.assertEquals("Two responses should return merged RouteResult (segments[1].steps[0].name = 'Instruction 1')", "Instruction 1", result.getSegments().get(1).getSteps().get(0).getName()); Assert.assertEquals("Two responses should return merged RouteResult (segments[1].steps[0].type = 11)", 11, result.getSegments().get(1).getSteps().get(0).getType()); Assert.assertEquals("Two responses should return merged RouteResult (segments[1].steps[0].maneuver.bearingAfter = 41)", 41, result.getSegments().get(1).getSteps().get(0).getManeuver().getBearingAfter()); Assert.assertEquals("Two responses should return merged RouteResult (segments[1].steps[1].name = 'Instruction 2')", "Instruction 2", result.getSegments().get(1).getSteps().get(1).getName()); Assert.assertEquals("Two responses should return merged RouteResult (segments[1].steps[1].type = 10)", 10, result.getSegments().get(1).getSteps().get(1).getType()); Assert.assertEquals("Two responses should return merged RouteResult (segments[1].steps[1].maneuver.bearingAfter = 0)", 0, result.getSegments().get(1).getSteps().get(1).getManeuver().getBearingAfter()); Assert.assertEquals("Two responses should return merged RouteResult (extrainfo.size = 1)", 1, result.getExtraInfo().size()); Assert.assertEquals("Two responses should return merged RouteResult (extrainfo[0].name = 'osmid)", APIEnums.ExtraInfo.OSM_ID.toString(), result.getExtraInfo().get(0).getName()); Assert.assertEquals("Two responses should return merged RouteResult (waypointindices.size = 3)", 3, result.getWayPointsIndices().size()); RouteRequest modRequest = request1; List<Integer> skipSegments = new ArrayList<>(); skipSegments.add(1); modRequest.setSkipSegments(skipSegments); routingRequest = new RouteRequestHandler().convertRouteRequest(modRequest); responseList = new ArrayList<>(); responseList.add(constructResponse(modRequest)); result = builder.createMergedRouteResultFromBestPaths(responseList, routingRequest, new List[]{extrasList}); Assert.assertEquals("Response with SkipSegments should return RouteResult with warning", 1, result.getWarnings().size()); Assert.assertEquals("Response with SkipSegments should return RouteResult with warning (code 3)", 3, result.getWarnings().get(0).getWarningCode()); }
RouteResult createMergedRouteResultFromBestPaths(List<GHResponse> responses, RoutingRequest request, List<RouteExtraInfo>[] extras) throws Exception { RouteResult result = createInitialRouteResult(request, extras[0]); for (int ri = 0; ri < responses.size(); ++ri) { GHResponse response = responses.get(ri); if (response.hasErrors()) throw new InternalServerException(RoutingErrorCodes.UNKNOWN, String.format("Unable to find a route between points %d (%s) and %d (%s)", ri, FormatUtility.formatCoordinate(request.getCoordinates()[ri]), ri + 1, FormatUtility.formatCoordinate(request.getCoordinates()[ri + 1]))); handleResponseWarnings(result, response); PathWrapper path = response.getBest(); result.addPointlist(path.getPoints()); if (request.getIncludeGeometry()) { result.addPointsToGeometry(path.getPoints(), ri > 0, request.getIncludeElevation()); result.addWayPointIndex(result.getGeometry().length - 1); } result.addSegment(createRouteSegment(path, request, getNextResponseFirstStepPoints(responses, ri))); result.setGraphDate(response.getHints().get("data.date", "0000-00-00T00:00:00Z")); } result.calculateRouteSummary(request); if (!request.getIncludeInstructions()) { result.resetSegments(); } return result; }
RouteResultBuilder { RouteResult createMergedRouteResultFromBestPaths(List<GHResponse> responses, RoutingRequest request, List<RouteExtraInfo>[] extras) throws Exception { RouteResult result = createInitialRouteResult(request, extras[0]); for (int ri = 0; ri < responses.size(); ++ri) { GHResponse response = responses.get(ri); if (response.hasErrors()) throw new InternalServerException(RoutingErrorCodes.UNKNOWN, String.format("Unable to find a route between points %d (%s) and %d (%s)", ri, FormatUtility.formatCoordinate(request.getCoordinates()[ri]), ri + 1, FormatUtility.formatCoordinate(request.getCoordinates()[ri + 1]))); handleResponseWarnings(result, response); PathWrapper path = response.getBest(); result.addPointlist(path.getPoints()); if (request.getIncludeGeometry()) { result.addPointsToGeometry(path.getPoints(), ri > 0, request.getIncludeElevation()); result.addWayPointIndex(result.getGeometry().length - 1); } result.addSegment(createRouteSegment(path, request, getNextResponseFirstStepPoints(responses, ri))); result.setGraphDate(response.getHints().get("data.date", "0000-00-00T00:00:00Z")); } result.calculateRouteSummary(request); if (!request.getIncludeInstructions()) { result.resetSegments(); } return result; } }
RouteResultBuilder { RouteResult createMergedRouteResultFromBestPaths(List<GHResponse> responses, RoutingRequest request, List<RouteExtraInfo>[] extras) throws Exception { RouteResult result = createInitialRouteResult(request, extras[0]); for (int ri = 0; ri < responses.size(); ++ri) { GHResponse response = responses.get(ri); if (response.hasErrors()) throw new InternalServerException(RoutingErrorCodes.UNKNOWN, String.format("Unable to find a route between points %d (%s) and %d (%s)", ri, FormatUtility.formatCoordinate(request.getCoordinates()[ri]), ri + 1, FormatUtility.formatCoordinate(request.getCoordinates()[ri + 1]))); handleResponseWarnings(result, response); PathWrapper path = response.getBest(); result.addPointlist(path.getPoints()); if (request.getIncludeGeometry()) { result.addPointsToGeometry(path.getPoints(), ri > 0, request.getIncludeElevation()); result.addWayPointIndex(result.getGeometry().length - 1); } result.addSegment(createRouteSegment(path, request, getNextResponseFirstStepPoints(responses, ri))); result.setGraphDate(response.getHints().get("data.date", "0000-00-00T00:00:00Z")); } result.calculateRouteSummary(request); if (!request.getIncludeInstructions()) { result.resetSegments(); } return result; } RouteResultBuilder(); }
RouteResultBuilder { RouteResult createMergedRouteResultFromBestPaths(List<GHResponse> responses, RoutingRequest request, List<RouteExtraInfo>[] extras) throws Exception { RouteResult result = createInitialRouteResult(request, extras[0]); for (int ri = 0; ri < responses.size(); ++ri) { GHResponse response = responses.get(ri); if (response.hasErrors()) throw new InternalServerException(RoutingErrorCodes.UNKNOWN, String.format("Unable to find a route between points %d (%s) and %d (%s)", ri, FormatUtility.formatCoordinate(request.getCoordinates()[ri]), ri + 1, FormatUtility.formatCoordinate(request.getCoordinates()[ri + 1]))); handleResponseWarnings(result, response); PathWrapper path = response.getBest(); result.addPointlist(path.getPoints()); if (request.getIncludeGeometry()) { result.addPointsToGeometry(path.getPoints(), ri > 0, request.getIncludeElevation()); result.addWayPointIndex(result.getGeometry().length - 1); } result.addSegment(createRouteSegment(path, request, getNextResponseFirstStepPoints(responses, ri))); result.setGraphDate(response.getHints().get("data.date", "0000-00-00T00:00:00Z")); } result.calculateRouteSummary(request); if (!request.getIncludeInstructions()) { result.resetSegments(); } return result; } RouteResultBuilder();  }
RouteResultBuilder { RouteResult createMergedRouteResultFromBestPaths(List<GHResponse> responses, RoutingRequest request, List<RouteExtraInfo>[] extras) throws Exception { RouteResult result = createInitialRouteResult(request, extras[0]); for (int ri = 0; ri < responses.size(); ++ri) { GHResponse response = responses.get(ri); if (response.hasErrors()) throw new InternalServerException(RoutingErrorCodes.UNKNOWN, String.format("Unable to find a route between points %d (%s) and %d (%s)", ri, FormatUtility.formatCoordinate(request.getCoordinates()[ri]), ri + 1, FormatUtility.formatCoordinate(request.getCoordinates()[ri + 1]))); handleResponseWarnings(result, response); PathWrapper path = response.getBest(); result.addPointlist(path.getPoints()); if (request.getIncludeGeometry()) { result.addPointsToGeometry(path.getPoints(), ri > 0, request.getIncludeElevation()); result.addWayPointIndex(result.getGeometry().length - 1); } result.addSegment(createRouteSegment(path, request, getNextResponseFirstStepPoints(responses, ri))); result.setGraphDate(response.getHints().get("data.date", "0000-00-00T00:00:00Z")); } result.calculateRouteSummary(request); if (!request.getIncludeInstructions()) { result.resetSegments(); } return result; } RouteResultBuilder();   }