Search in sources :

Example 21 with GraphHopperWeb

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

the class RouteResourceTest method testPathDetailsNoConnection.

@Test
public void testPathDetailsNoConnection() {
    GraphHopperWeb hopper = new GraphHopperWeb(clientUrl(app, "/route"));
    GHRequest request = new GHRequest(42.542078, 1.45586, 42.537841, 1.439981);
    request.setPathDetails(Collections.singletonList("average_speed"));
    request.setProfile("my_car");
    GHResponse rsp = hopper.route(request);
    assertTrue(rsp.hasErrors(), rsp.getErrors().toString());
}
Also used : GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with GraphHopperWeb

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

the class RouteResourceTest method testGraphHopperWebRealExceptions.

@ParameterizedTest(name = "POST = {0}")
@ValueSource(booleans = { false, true })
public void testGraphHopperWebRealExceptions(boolean usePost) {
    GraphHopperWeb hopper = new GraphHopperWeb(clientUrl(app, "/route")).setPostRequest(usePost);
    // this one actually works
    List<GHPoint> points = Arrays.asList(new GHPoint(42.554851, 1.536198), new GHPoint(42.510071, 1.548128));
    GHResponse rsp = hopper.route(new GHRequest(points).setProfile("my_car"));
    assertEquals(9204, rsp.getBest().getDistance(), 10);
    // unknown profile
    rsp = hopper.route(new GHRequest(points).setProfile("space_shuttle"));
    assertTrue(rsp.hasErrors(), rsp.getErrors().toString());
    assertTrue(rsp.getErrors().get(0).getMessage().contains("The requested profile 'space_shuttle' does not exist"), rsp.getErrors().toString());
    // unknown profile via web api
    Response response = clientTarget(app, "/route?profile=SPACE-SHUTTLE&point=42.554851,1.536198&point=42.510071,1.548128").request().buildGet().invoke();
    assertEquals(400, response.getStatus());
    String msg = (String) response.readEntity(Map.class).get("message");
    assertTrue(msg.contains("The requested profile 'SPACE-SHUTTLE' does not exist"), msg);
    // no points
    rsp = hopper.route(new GHRequest().setProfile("my_car"));
    assertFalse(rsp.getErrors().isEmpty(), "Errors expected but not found.");
    Throwable ex = rsp.getErrors().get(0);
    assertTrue(ex instanceof IllegalArgumentException, "Wrong exception found: " + ex.getClass().getName() + ", IllegalArgumentException expected.");
    assertTrue(ex.getMessage().contains("You have to pass at least one point"), ex.getMessage());
    // no points without CH
    rsp = hopper.route(new GHRequest().setProfile("my_car").putHint(Parameters.CH.DISABLE, true));
    assertFalse(rsp.getErrors().isEmpty(), "Errors expected but not found.");
    ex = rsp.getErrors().get(0);
    assertTrue(ex instanceof IllegalArgumentException, "Wrong exception found: " + ex.getClass().getName() + ", IllegalArgumentException expected.");
    assertTrue(ex.getMessage().contains("You have to pass at least one point"), ex.getMessage());
    // points out of bounds
    rsp = hopper.route(new GHRequest(0.0, 0.0, 0.0, 0.0).setProfile("my_car"));
    assertFalse(rsp.getErrors().isEmpty(), "Errors expected but not found.");
    List<Throwable> errs = rsp.getErrors();
    for (int i = 0; i < errs.size(); i++) {
        assertEquals(((PointOutOfBoundsException) errs.get(i)).getPointIndex(), i);
        assertTrue(errs.get(i).getMessage().contains("Point 0 is out of bounds: 0.0,0.0"), errs.get(i).getMessage());
    }
    // todo: add a check with too few headings, but client-hc does not support headings, #2009
    // too many curbsides
    rsp = hopper.route(new GHRequest(points).setCurbsides(Arrays.asList("right", "left", "right")).setProfile("my_car"));
    assertFalse(rsp.getErrors().isEmpty(), "Errors expected but not found.");
    assertTrue(rsp.getErrors().toString().contains("If you pass curbside, you need to pass exactly one curbside for every point"), rsp.getErrors().toString());
    // too few point hints
    rsp = hopper.route(new GHRequest(points).setPointHints(Collections.singletonList("foo")).setProfile("my_car"));
    assertFalse(rsp.getErrors().isEmpty(), "Errors expected but not found.");
    assertTrue(rsp.getErrors().toString().contains("If you pass point_hint, you need to pass exactly one hint for every point"), rsp.getErrors().toString());
    // unknown vehicle
    rsp = hopper.route(new GHRequest(points).putHint("vehicle", "SPACE-SHUTTLE"));
    assertFalse(rsp.getErrors().isEmpty(), "Errors expected but not found.");
    ex = rsp.getErrors().get(0);
    assertTrue(ex instanceof IllegalArgumentException, "Wrong exception found: " + ex.getClass().getName() + ", IllegalArgumentException expected.");
    assertTrue(ex.getMessage().contains("Vehicle not supported: `space-shuttle`. Supported are: `car`" + "\nYou should consider using the `profile` parameter instead of specifying a vehicle." + "\nAvailable profiles: [my_car]"), ex.getMessage());
    // an IllegalArgumentException from inside the core is written as JSON, unknown profile
    response = clientTarget(app, "/route?profile=SPACE-SHUTTLE&point=42.554851,1.536198&point=42.510071,1.548128").request().buildGet().invoke();
    assertEquals(400, response.getStatus());
    msg = (String) response.readEntity(Map.class).get("message");
    assertTrue(msg.contains("The requested profile 'SPACE-SHUTTLE' does not exist"), msg);
}
Also used : GHResponse(com.graphhopper.GHResponse) Response(javax.ws.rs.core.Response) GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) GHPoint(com.graphhopper.util.shapes.GHPoint) ValueSource(org.junit.jupiter.params.provider.ValueSource) 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