Search in sources :

Example 36 with GHResponse

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"));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GHRequest(com.graphhopper.GHRequest) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test)

Example 37 with GHResponse

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());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GHRequest(com.graphhopper.GHRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 38 with GHResponse

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);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GHRequest(com.graphhopper.GHRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test)

Example 39 with GHResponse

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());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GHRequest(com.graphhopper.GHRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test)

Example 40 with GHResponse

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);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GHRequest(com.graphhopper.GHRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test)

Aggregations

GHResponse (com.graphhopper.GHResponse)100 GHRequest (com.graphhopper.GHRequest)86 GHPoint (com.graphhopper.util.shapes.GHPoint)52 Test (org.junit.Test)31 Test (org.junit.jupiter.api.Test)31 GraphHopperWeb (com.graphhopper.api.GraphHopperWeb)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 ResponsePath (com.graphhopper.ResponsePath)15 EnumSource (org.junit.jupiter.params.provider.EnumSource)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 PathWrapper (com.graphhopper.PathWrapper)9 GraphHopper (com.graphhopper.GraphHopper)7 InstructionList (com.graphhopper.util.InstructionList)7 PathDetail (com.graphhopper.util.details.PathDetail)7 GraphHopperAPI (com.graphhopper.GraphHopperAPI)6 Profile (com.graphhopper.config.Profile)5 Graph (com.graphhopper.storage.Graph)5 NodeAccess (com.graphhopper.storage.NodeAccess)5 PointNotFoundException (com.graphhopper.util.exceptions.PointNotFoundException)5