Search in sources :

Example 1 with GraphHopperWeb

use of com.graphhopper.api.GraphHopperWeb in project graphhopper by graphhopper.

the class RouteResourceClientHCTest method testCannotFindPointException.

@ParameterizedTest
@EnumSource(value = TestParam.class)
public void testCannotFindPointException(TestParam p) {
    GraphHopperWeb gh = createGH(p);
    GHRequest req = new GHRequest().addPoint(new GHPoint(42.49058, 1.602974)).addPoint(new GHPoint(42.510383, 1.533392)).putHint("vehicle", "car");
    GHResponse res = gh.route(req);
    assertTrue(res.hasErrors(), "no errors found?");
    assertTrue(res.getErrors().get(0) instanceof PointNotFoundException);
}
Also used : PointNotFoundException(com.graphhopper.util.exceptions.PointNotFoundException) 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 2 with GraphHopperWeb

use of com.graphhopper.api.GraphHopperWeb in project graphhopper by graphhopper.

the class RouteResourceClientHCTest method testNoPoints.

@ParameterizedTest
@EnumSource(value = TestParam.class)
public void testNoPoints(TestParam p) {
    GraphHopperWeb gh = createGH(p);
    GHRequest req = new GHRequest().addPoint(new GHPoint(42.509225, 1.534728)).addPoint(new GHPoint(42.512602, 1.551558)).putHint("vehicle", "car");
    req.putHint("instructions", false);
    req.putHint("calc_points", false);
    GHResponse rsp = gh.route(req);
    assertFalse(rsp.hasErrors(), "errors:" + rsp.getErrors().toString());
    ResponsePath res = rsp.getBest();
    assertEquals(0, res.getPoints().size());
    isBetween(1750, 1800, res.getDistance());
}
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 3 with GraphHopperWeb

use of com.graphhopper.api.GraphHopperWeb in project graphhopper by graphhopper.

the class RouteResourceClientHCTest method readRoundabout.

@ParameterizedTest
@EnumSource(value = TestParam.class)
public void readRoundabout(TestParam p) {
    GraphHopperWeb gh = createGH(p);
    GHRequest req = new GHRequest().addPoint(new GHPoint(42.509644, 1.532958)).addPoint(new GHPoint(42.510383, 1.533392)).putHint("vehicle", "car");
    GHResponse res = gh.route(req);
    int counter = 0;
    for (Instruction i : res.getBest().getInstructions()) {
        if (i instanceof RoundaboutInstruction) {
            counter++;
            RoundaboutInstruction ri = (RoundaboutInstruction) i;
            assertEquals(-5, ri.getTurnAngle(), 0.1, "turn_angle was incorrect:" + ri.getTurnAngle());
            // This route contains only one roundabout and no (via) point in a roundabout
            assertTrue(ri.isExited(), "exited was incorrect:" + ri.isExited());
        }
    }
    assertTrue(counter > 0, "no roundabout in route?");
}
Also used : GHRequest(com.graphhopper.GHRequest) RoundaboutInstruction(com.graphhopper.util.RoundaboutInstruction) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) Instruction(com.graphhopper.util.Instruction) RoundaboutInstruction(com.graphhopper.util.RoundaboutInstruction) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) GHPoint(com.graphhopper.util.shapes.GHPoint) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with GraphHopperWeb

use of com.graphhopper.api.GraphHopperWeb in project graphhopper by graphhopper.

the class RouteResourceClientHCTest method testAlternativeRoute.

@ParameterizedTest
@EnumSource(value = TestParam.class)
public void testAlternativeRoute(TestParam p) {
    GraphHopperWeb gh = createGH(p);
    GHRequest req = new GHRequest().addPoint(new GHPoint(42.505041, 1.521864)).addPoint(new GHPoint(42.509074, 1.537936)).putHint("vehicle", "car").setAlgorithm("alternative_route").putHint("instructions", true).putHint("calc_points", true).putHint("ch.disable", true);
    GHResponse res = gh.route(req);
    assertFalse(res.hasErrors(), "errors:" + res.getErrors().toString());
    List<ResponsePath> paths = res.getAll();
    assertEquals(2, paths.size());
    ResponsePath path = paths.get(0);
    assertEquals(35, path.getPoints().size());
    assertEquals(1689, path.getDistance(), 1);
    assertTrue(path.getInstructions().toString().contains("Avinguda de Tarragona"), path.getInstructions().toString());
    path = paths.get(1);
    assertEquals(30, path.getPoints().size());
    assertEquals(1759, path.getDistance(), 1);
    assertTrue(path.getInstructions().toString().contains("Avinguda Prat de la Creu"), path.getInstructions().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 5 with GraphHopperWeb

use of com.graphhopper.api.GraphHopperWeb in project graphhopper by graphhopper.

the class RouteResourceTest method testExportWithoutTrack.

@Test
public void testExportWithoutTrack() {
    GHRequest req = new GHRequest(42.554851, 1.536198, 42.510071, 1.548128);
    req.putHint("elevation", false);
    req.putHint("instructions", true);
    req.putHint("calc_points", true);
    req.putHint("type", "gpx");
    req.putHint("gpx.track", false);
    GraphHopperWeb gh = new GraphHopperWeb(clientUrl(app, "/route")).setPostRequest(false);
    String res = gh.export(req);
    assertTrue(res.contains("<gpx"));
    assertTrue(res.contains("<rtept lat="));
    assertFalse(res.contains("<trk><name>GraphHopper Track</name><trkseg>"));
    assertTrue(res.endsWith("</gpx>"));
}
Also used : GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

GHRequest (com.graphhopper.GHRequest)22 GraphHopperWeb (com.graphhopper.api.GraphHopperWeb)22 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)22 GHResponse (com.graphhopper.GHResponse)20 GHPoint (com.graphhopper.util.shapes.GHPoint)13 EnumSource (org.junit.jupiter.params.provider.EnumSource)11 Test (org.junit.jupiter.api.Test)10 ResponsePath (com.graphhopper.ResponsePath)5 InstructionList (com.graphhopper.util.InstructionList)4 PathDetail (com.graphhopper.util.details.PathDetail)3 Instruction (com.graphhopper.util.Instruction)1 RoundaboutInstruction (com.graphhopper.util.RoundaboutInstruction)1 PointNotFoundException (com.graphhopper.util.exceptions.PointNotFoundException)1 PointOutOfBoundsException (com.graphhopper.util.exceptions.PointOutOfBoundsException)1 Response (javax.ws.rs.core.Response)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1