use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class NavigateResponseConverterTest method testError.
@Test
public void testError() {
GHResponse rsp = hopper.route(new GHRequest(42.554851, 111.536198, 42.510071, 1.548128).setProfile(profile));
ObjectNode json = NavigateResponseConverter.convertFromGHResponseError(rsp);
assertEquals("InvalidInput", json.get("code").asText());
assertTrue(json.get("message").asText().startsWith("Point 0 is out of bounds: 42.554851,111.536198"));
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class NavigateResponseConverterTest method alternativeRoutesTest.
@Test
@Disabled
public void alternativeRoutesTest() {
GHResponse rsp = hopper.route(new GHRequest(42.554851, 1.536198, 42.510071, 1.548128).setProfile(profile).setAlgorithm(Parameters.Algorithms.ALT_ROUTE));
assertEquals(2, rsp.getAll().size());
ObjectNode json = NavigateResponseConverter.convertFromGHResponse(rsp, trMap, Locale.ENGLISH, distanceConfig);
JsonNode routes = json.get("routes");
assertEquals(2, routes.size());
assertEquals("GraphHopper Route 0", routes.get(0).get("legs").get(0).get("summary").asText());
assertEquals("Avinguda Sant Antoni, CG-3", routes.get(1).get("legs").get(0).get("summary").asText());
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class NavigateResponseConverterTest method basicTest.
@Test
public void basicTest() {
GHResponse rsp = hopper.route(new GHRequest(42.554851, 1.536198, 42.510071, 1.548128).setProfile(profile));
ObjectNode json = NavigateResponseConverter.convertFromGHResponse(rsp, trMap, Locale.ENGLISH, distanceConfig);
JsonNode route = json.get("routes").get(0);
double routeDistance = route.get("distance").asDouble();
assertTrue(routeDistance > 9000, "distance wasn't correct:" + routeDistance);
assertTrue(routeDistance < 9500, "distance wasn't correct:" + routeDistance);
double routeDuration = route.get("duration").asDouble();
assertTrue(routeDuration > 500, "duration wasn't correct:" + routeDuration);
assertTrue(routeDuration < 600, "duration wasn't correct:" + routeDuration);
assertEquals("en", route.get("voiceLocale").asText());
JsonNode leg = route.get("legs").get(0);
assertEquals(routeDistance, leg.get("distance").asDouble(), .000001);
JsonNode steps = leg.get("steps");
JsonNode step = steps.get(0);
JsonNode maneuver = step.get("maneuver");
// Intersection coordinates should be equal to maneuver coordinates
assertEquals(maneuver.get("location").get(0).asDouble(), step.get("intersections").get(0).get("location").get(0).asDouble(), .00001);
assertEquals("depart", maneuver.get("type").asText());
assertEquals("straight", maneuver.get("modifier").asText());
assertEquals("la Callisa", step.get("name").asText());
double instructionDistance = step.get("distance").asDouble();
assertTrue(instructionDistance < routeDistance);
JsonNode voiceInstructions = step.get("voiceInstructions");
assertEquals(1, voiceInstructions.size());
JsonNode voiceInstruction = voiceInstructions.get(0);
assertTrue(voiceInstruction.get("distanceAlongGeometry").asDouble() <= instructionDistance);
assertEquals("turn sharp left onto la Callisa, then keep left", voiceInstruction.get("announcement").asText());
JsonNode bannerInstructions = step.get("bannerInstructions");
assertEquals(1, bannerInstructions.size());
JsonNode bannerInstruction = bannerInstructions.get(0).get("primary");
assertEquals("la Callisa", bannerInstruction.get("text").asText());
assertEquals("turn", bannerInstruction.get("type").asText());
assertEquals("sharp left", bannerInstruction.get("modifier").asText());
JsonNode bannerInstructionComponent = bannerInstruction.get("components").get(0);
assertEquals("la Callisa", bannerInstructionComponent.get("text").asText());
// Get the second last step (and the last banner/voice instruction)
step = steps.get(steps.size() - 2);
voiceInstructions = step.get("voiceInstructions");
assertEquals(1, voiceInstructions.size());
voiceInstruction = voiceInstructions.get(0);
assertTrue(voiceInstruction.get("distanceAlongGeometry").asDouble() < instructionDistance);
bannerInstructions = step.get("bannerInstructions");
assertEquals(1, bannerInstructions.size());
bannerInstruction = bannerInstructions.get(0).get("primary");
assertEquals("Arrive at destination", bannerInstruction.get("text").asText());
JsonNode waypointsJson = json.get("waypoints");
assertEquals(2, waypointsJson.size());
JsonNode waypointLoc = waypointsJson.get(0).get("location");
assertEquals(1.536198, waypointLoc.get(0).asDouble(), .001);
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class NavigateResponseConverterTest method voiceInstructionsImperialTest.
@Test
public void voiceInstructionsImperialTest() {
GHResponse rsp = hopper.route(new GHRequest(42.554851, 1.536198, 42.510071, 1.548128).setProfile(profile));
ObjectNode json = NavigateResponseConverter.convertFromGHResponse(rsp, trMap, Locale.ENGLISH, new DistanceConfig(DistanceUtils.Unit.IMPERIAL, trMap, Locale.ENGLISH));
JsonNode steps = json.get("routes").get(0).get("legs").get(0).get("steps");
// Step 4 is about 240m long
JsonNode step = steps.get(4);
JsonNode maneuver = step.get("maneuver");
JsonNode voiceInstructions = step.get("voiceInstructions");
assertEquals(2, voiceInstructions.size());
JsonNode voiceInstruction = voiceInstructions.get(0);
assertEquals(200, voiceInstruction.get("distanceAlongGeometry").asDouble(), 1);
assertEquals("In 600 feet At roundabout, take exit 2 onto CS-340, then At roundabout, take exit 2 onto CG-3", voiceInstruction.get("announcement").asText());
// Step 14 is over 3km long
step = steps.get(14);
maneuver = step.get("maneuver");
voiceInstructions = step.get("voiceInstructions");
assertEquals(4, voiceInstructions.size());
voiceInstruction = voiceInstructions.get(0);
assertEquals(3220, voiceInstruction.get("distanceAlongGeometry").asDouble(), 1);
assertEquals("In 2 miles keep right", voiceInstruction.get("announcement").asText());
voiceInstruction = voiceInstructions.get(3);
assertEquals("keep right", voiceInstruction.get("announcement").asText());
}
use of com.graphhopper.GHResponse in project graphhopper by graphhopper.
the class NavigateResponseConverterTest method roundaboutDegreesTest.
@Test
public void roundaboutDegreesTest() {
GHResponse rsp = hopper.route(new GHRequest(42.554851, 1.536198, 42.510071, 1.548128).setProfile(profile));
ObjectNode json = NavigateResponseConverter.convertFromGHResponse(rsp, trMap, Locale.ENGLISH, distanceConfig);
JsonNode steps = json.get("routes").get(0).get("legs").get(0).get("steps");
JsonNode step = steps.get(5);
JsonNode bannerInstructions = step.get("bannerInstructions");
JsonNode primary = bannerInstructions.get(0).get("primary");
assertEquals("roundabout", primary.get("type").asText());
assertEquals("right", primary.get("modifier").asText());
assertEquals(222, primary.get("degrees").asDouble(), 1);
}
Aggregations