Search in sources :

Example 86 with GHRequest

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

the class RouteResourceClientHCTest method doNotReadFinishInstruction.

@ParameterizedTest
@EnumSource(value = TestParam.class)
public void doNotReadFinishInstruction(TestParam p) {
    GraphHopperWeb gh = createGH(p);
    GHRequest req = new GHRequest().addPoint(new GHPoint(42.507065, 1.529846)).addPoint(new GHPoint(42.510383, 1.533392)).putHint("vehicle", "car").putHint("turn_description", false);
    GHResponse res = gh.route(req);
    InstructionList instructions = res.getBest().getInstructions();
    String finishInstructionName = instructions.get(instructions.size() - 1).getName();
    assertEquals("", finishInstructionName);
}
Also used : InstructionList(com.graphhopper.util.InstructionList) GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 87 with GHRequest

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

the class RouteResourceClientHCTest method testOutOfBoundsException.

@ParameterizedTest
@EnumSource(value = TestParam.class)
public void testOutOfBoundsException(TestParam p) {
    GraphHopperWeb gh = createGH(p);
    GHRequest req = new GHRequest().addPoint(new GHPoint(-400.214943, -130.078125)).addPoint(new GHPoint(39.909736, -91.054687)).putHint("vehicle", "car");
    GHResponse res = gh.route(req);
    assertTrue(res.hasErrors(), "no errors found?");
    assertTrue(res.getErrors().get(0) instanceof PointOutOfBoundsException);
}
Also used : GHRequest(com.graphhopper.GHRequest) PointOutOfBoundsException(com.graphhopper.util.exceptions.PointOutOfBoundsException) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 88 with GHRequest

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

the class RouteResourceClientHCTest method testPathDetails.

@ParameterizedTest
@EnumSource(value = TestParam.class)
public void testPathDetails(TestParam p) {
    GraphHopperWeb gh = createGH(p);
    GHRequest req = new GHRequest().addPoint(new GHPoint(42.507065, 1.529846)).addPoint(new GHPoint(42.510383, 1.533392)).setProfile("my_car");
    req.getPathDetails().add("average_speed");
    GHResponse res = gh.route(req);
    assertFalse(res.hasErrors(), "errors:" + res.getErrors().toString());
    ResponsePath alt = res.getBest();
    assertEquals(1, alt.getPathDetails().size());
    List<PathDetail> details = alt.getPathDetails().get("average_speed");
    assertFalse(details.isEmpty());
    assertTrue((Double) details.get(0).getValue() > 20);
    assertTrue((Double) details.get(0).getValue() < 70);
}
Also used : ResponsePath(com.graphhopper.ResponsePath) PathDetail(com.graphhopper.util.details.PathDetail) GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 89 with GHRequest

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

the class RouteResourceClientHCTest method testSimpleRoute.

@ParameterizedTest
@EnumSource(value = TestParam.class)
public void testSimpleRoute(TestParam p) {
    GraphHopperWeb gh = createGH(p);
    GHRequest req = new GHRequest().addPoint(new GHPoint(42.5093, 1.5274)).addPoint(new GHPoint(42.5126, 1.5410)).putHint("vehicle", "car").putHint("elevation", false).putHint("instructions", true).putHint("calc_points", true);
    GHResponse rsp = gh.route(req);
    assertFalse(rsp.hasErrors(), "errors:" + rsp.getErrors().toString());
    ResponsePath res = rsp.getBest();
    isBetween(60, 70, res.getPoints().size());
    isBetween(2900, 3000, res.getDistance());
    isBetween(110, 120, res.getAscend());
    isBetween(70, 80, res.getDescend());
    isBetween(190, 200, res.getRouteWeight());
    // change vehicle
    rsp = gh.route(new GHRequest(42.5093, 1.5274, 42.5126, 1.5410).putHint("vehicle", "bike"));
    res = rsp.getBest();
    assertFalse(rsp.hasErrors(), "errors:" + rsp.getErrors().toString());
    isBetween(2500, 2600, res.getDistance());
    assertEquals("[0, 1]", res.getPointsOrder().toString());
}
Also used : ResponsePath(com.graphhopper.ResponsePath) GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 90 with GHRequest

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

the class RouteResourceClientHCTest method testRetrieveOnlyStreetname.

@ParameterizedTest
@EnumSource(value = TestParam.class)
public void testRetrieveOnlyStreetname(TestParam p) {
    GraphHopperWeb gh = createGH(p);
    GHRequest req = new GHRequest().addPoint(new GHPoint(42.507065, 1.529846)).addPoint(new GHPoint(42.510383, 1.533392)).putHint("vehicle", "car");
    GHResponse res = gh.route(req);
    List<String> given = extractInstructionNames(res.getBest(), 5);
    assertEquals(Arrays.asList("Continue onto Carrer de l'Aigüeta", "Turn right onto Carrer Pere d'Urg", "Turn right onto Carrer Bonaventura Armengol", "Keep right onto Avinguda Consell d'Europa", "At roundabout, take exit 4"), given);
    req.putHint("turn_description", false);
    res = gh.route(req);
    given = extractInstructionNames(res.getBest(), 5);
    assertEquals(Arrays.asList("Carrer de l'Aigüeta", "Carrer Pere d'Urg", "Carrer Bonaventura Armengol", "Avinguda Consell d'Europa", ""), given);
}
Also used : GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

GHRequest (com.graphhopper.GHRequest)106 GHResponse (com.graphhopper.GHResponse)86 GHPoint (com.graphhopper.util.shapes.GHPoint)59 Test (org.junit.Test)35 Test (org.junit.jupiter.api.Test)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 GraphHopperWeb (com.graphhopper.api.GraphHopperWeb)22 ResponsePath (com.graphhopper.ResponsePath)13 EnumSource (org.junit.jupiter.params.provider.EnumSource)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 PathWrapper (com.graphhopper.PathWrapper)8 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 LMProfile (com.graphhopper.config.LMProfile)4