Search in sources :

Example 6 with GraphHopperAPI

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

the class GraphHopperServletIT method testGraphHopperWebRealExceptions.

@Test
public void testGraphHopperWebRealExceptions() {
    GraphHopperAPI hopper = new com.graphhopper.api.GraphHopperWeb();
    assertTrue(hopper.load(getTestRouteAPIUrl()));
    // IllegalArgumentException (Wrong Request)
    GHResponse rsp = hopper.route(new GHRequest());
    assertFalse("Errors expected but not found.", rsp.getErrors().isEmpty());
    Throwable ex = rsp.getErrors().get(0);
    assertTrue("Wrong exception found: " + ex.getClass().getName() + ", IllegalArgumentException expected.", ex instanceof IllegalArgumentException);
    // IllegalArgumentException (Wrong Points)
    rsp = hopper.route(new GHRequest(0.0, 0.0, 0.0, 0.0));
    assertFalse("Errors expected but not found.", rsp.getErrors().isEmpty());
    List<Throwable> errs = rsp.getErrors();
    for (int i = 0; i < errs.size(); i++) {
        assertEquals(((PointOutOfBoundsException) errs.get(i)).getPointIndex(), i);
    }
    // IllegalArgumentException (Vehicle not supported)
    rsp = hopper.route(new GHRequest(42.554851, 1.536198, 42.510071, 1.548128).setVehicle("SPACE-SHUTTLE"));
    assertFalse("Errors expected but not found.", rsp.getErrors().isEmpty());
    ex = rsp.getErrors().get(0);
    assertTrue("Wrong exception found: " + ex.getClass().getName() + ", IllegalArgumentException expected.", ex instanceof IllegalArgumentException);
}
Also used : GraphHopperAPI(com.graphhopper.GraphHopperAPI) GHRequest(com.graphhopper.GHRequest) GHResponse(com.graphhopper.GHResponse) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Aggregations

GHRequest (com.graphhopper.GHRequest)6 GHResponse (com.graphhopper.GHResponse)6 GraphHopperAPI (com.graphhopper.GraphHopperAPI)6 Test (org.junit.Test)6 GHPoint (com.graphhopper.util.shapes.GHPoint)2 PathWrapper (com.graphhopper.PathWrapper)1 PathDetail (com.graphhopper.util.details.PathDetail)1 List (java.util.List)1 Map (java.util.Map)1