Search in sources :

Example 96 with GHResponse

use of com.graphhopper.GHResponse in project graphhopper by graphhopper.

the class GHResponseTest method testHasNoErrorIfEmpty.

@Test
public void testHasNoErrorIfEmpty() {
    assertFalse(new GHResponse().hasErrors());
    GHResponse rsp = new GHResponse();
    rsp.add(new ResponsePath());
    assertFalse(rsp.hasErrors());
}
Also used : ResponsePath(com.graphhopper.ResponsePath) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test)

Example 97 with GHResponse

use of com.graphhopper.GHResponse in project graphhopper by graphhopper.

the class OSMReaderTest method testRoadClassInfo.

@Test
public void testRoadClassInfo() {
    GraphHopper gh = new GraphHopper() {

        @Override
        protected File _getOSMFile() {
            return new File(getClass().getResource(file2).getFile());
        }
    }.setOSMFile("dummy").setProfiles(new Profile("profile").setVehicle("car").setWeighting("fastest")).setMinNetworkSize(0).setGraphHopperLocation(dir).importOrLoad();
    GHResponse response = gh.route(new GHRequest(51.2492152, 9.4317166, 52.133, 9.1).setProfile("profile").setPathDetails(Collections.singletonList(RoadClass.KEY)));
    List<PathDetail> list = response.getBest().getPathDetails().get(RoadClass.KEY);
    assertEquals(3, list.size());
    assertEquals(RoadClass.MOTORWAY.toString(), list.get(0).getValue());
    response = gh.route(new GHRequest(51.2492152, 9.4317166, 52.133, 9.1).setProfile("profile").setPathDetails(Collections.singletonList(Toll.KEY)));
    Throwable ex = response.getErrors().get(0);
    assertTrue(ex.getMessage().contains("You requested the details [toll]"), ex.getMessage());
}
Also used : PathDetail(com.graphhopper.util.details.PathDetail) GHRequest(com.graphhopper.GHRequest) GraphHopper(com.graphhopper.GraphHopper) File(java.io.File) GHResponse(com.graphhopper.GHResponse) Profile(com.graphhopper.config.Profile) Test(org.junit.jupiter.api.Test) GraphHopperTest(com.graphhopper.GraphHopperTest)

Example 98 with GHResponse

use of com.graphhopper.GHResponse in project graphhopper by graphhopper.

the class NavigateResponseConverterTest method voiceInstructionTranslationTest.

@Test
public void voiceInstructionTranslationTest() {
    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 voiceInstruction = steps.get(14).get("voiceInstructions").get(0);
    assertEquals("In 2 kilometers keep right", voiceInstruction.get("announcement").asText());
    rsp = hopper.route(new GHRequest(42.554851, 1.536198, 42.510071, 1.548128).setProfile(profile).setLocale(Locale.GERMAN));
    DistanceConfig distanceConfigGerman = new DistanceConfig(DistanceUtils.Unit.METRIC, trMap, Locale.GERMAN);
    json = NavigateResponseConverter.convertFromGHResponse(rsp, trMap, Locale.GERMAN, distanceConfigGerman);
    steps = json.get("routes").get(0).get("legs").get(0).get("steps");
    voiceInstruction = steps.get(14).get("voiceInstructions").get(0);
    assertEquals("In 2 Kilometern rechts halten", 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 99 with GHResponse

use of com.graphhopper.GHResponse in project graphhopper by graphhopper.

the class NavigateResponseConverterTest method voiceInstructionsTest.

@Test
public void voiceInstructionsTest() {
    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");
    // Step 4 is about 240m long
    JsonNode step = steps.get(4);
    JsonNode voiceInstructions = step.get("voiceInstructions");
    assertEquals(2, voiceInstructions.size());
    JsonNode voiceInstruction = voiceInstructions.get(0);
    assertEquals(200, voiceInstruction.get("distanceAlongGeometry").asDouble(), 1);
    assertEquals("In 200 meters 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);
    voiceInstructions = step.get("voiceInstructions");
    assertEquals(4, voiceInstructions.size());
    voiceInstruction = voiceInstructions.get(0);
    assertEquals(2000, voiceInstruction.get("distanceAlongGeometry").asDouble(), 1);
    assertEquals("In 2 kilometers 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 100 with GHResponse

use of com.graphhopper.GHResponse in project graphhopper by graphhopper.

the class NavigateResponseConverterTest method testMultipleWaypoints.

@Test
public void testMultipleWaypoints() {
    GHRequest request = new GHRequest();
    request.addPoint(new GHPoint(42.504606, 1.522438));
    request.addPoint(new GHPoint(42.504776, 1.527209));
    request.addPoint(new GHPoint(42.505144, 1.526113));
    request.addPoint(new GHPoint(42.50529, 1.527218));
    request.setProfile(profile);
    GHResponse rsp = hopper.route(request);
    ObjectNode json = NavigateResponseConverter.convertFromGHResponse(rsp, trMap, Locale.ENGLISH, distanceConfig);
    // Check that all waypoints are there and in the right order
    JsonNode waypointsJson = json.get("waypoints");
    assertEquals(4, waypointsJson.size());
    JsonNode waypointLoc = waypointsJson.get(0).get("location");
    assertEquals(1.522438, waypointLoc.get(0).asDouble(), .00001);
    waypointLoc = waypointsJson.get(1).get("location");
    assertEquals(1.527209, waypointLoc.get(0).asDouble(), .00001);
    waypointLoc = waypointsJson.get(2).get("location");
    assertEquals(1.526113, waypointLoc.get(0).asDouble(), .00001);
    waypointLoc = waypointsJson.get(3).get("location");
    assertEquals(1.527218, waypointLoc.get(0).asDouble(), .00001);
    // Check that there are 3 legs
    JsonNode route = json.get("routes").get(0);
    JsonNode legs = route.get("legs");
    assertEquals(3, legs.size());
    double duration = 0;
    double distance = 0;
    for (int i = 0; i < 3; i++) {
        JsonNode leg = legs.get(i);
        duration += leg.get("duration").asDouble();
        distance += leg.get("distance").asDouble();
        JsonNode steps = leg.get("steps");
        JsonNode step = steps.get(0);
        JsonNode maneuver = step.get("maneuver");
        assertEquals("depart", maneuver.get("type").asText());
        maneuver = steps.get(steps.size() - 1).get("maneuver");
        assertEquals("arrive", maneuver.get("type").asText());
    }
    // Check if the duration and distance of the legs sum up to the overall route distance and duration
    assertEquals(route.get("duration").asDouble(), duration, 1);
    assertEquals(route.get("distance").asDouble(), distance, 1);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) GHRequest(com.graphhopper.GHRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) GHPoint(com.graphhopper.util.shapes.GHPoint) 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