Search in sources :

Example 6 with GraphHopperWeb

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

the class RouteResourceTest method testInitInstructionsWithTurnDescription.

@Test
public void testInitInstructionsWithTurnDescription() {
    GraphHopperWeb hopper = new GraphHopperWeb(clientUrl(app, "/route"));
    GHRequest request = new GHRequest(42.554851, 1.536198, 42.510071, 1.548128);
    request.setProfile("my_car");
    GHResponse rsp = hopper.route(request);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals("Continue onto Carrer Antoni Fiter i Rossell", rsp.getBest().getInstructions().get(3).getName());
    request.getHints().putObject("turn_description", false);
    rsp = hopper.route(request);
    assertFalse(rsp.hasErrors());
    assertEquals("Carrer Antoni Fiter i Rossell", rsp.getBest().getInstructions().get(3).getName());
}
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 7 with GraphHopperWeb

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

the class RouteResourceTest method testGPXExport.

@Test
public void testGPXExport() {
    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("gpx.millis", "300000000");
    req.putHint("type", "gpx");
    GraphHopperWeb gh = new GraphHopperWeb(clientUrl(app, "/route")).setPostRequest(false);
    String res = gh.export(req);
    assertTrue(res.contains("<gpx"));
    assertTrue(res.contains("<rtept lat="));
    assertTrue(res.contains("<trk><name>GraphHopper Track</name><trkseg>"));
    assertTrue(res.endsWith("</gpx>"));
    // this is due to `gpx.millis` we set (dates are shifted by the given (ms!) value from 1970-01-01)
    assertTrue(res.contains("1970-01-04"));
}
Also used : GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with GraphHopperWeb

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

the class RouteResourceTest method testGraphHopperWeb.

@Test
public void testGraphHopperWeb() {
    GraphHopperWeb hopper = new GraphHopperWeb(clientUrl(app, "/route"));
    GHResponse rsp = hopper.route(new GHRequest(42.554851, 1.536198, 42.510071, 1.548128).setProfile("my_car"));
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertTrue(rsp.getErrors().isEmpty(), rsp.getErrors().toString());
    ResponsePath res = rsp.getBest();
    assertTrue(res.getDistance() > 9000, "distance wasn't correct:" + res.getDistance());
    assertTrue(res.getDistance() < 9500, "distance wasn't correct:" + res.getDistance());
    rsp = hopper.route(new GHRequest().setProfile("my_car").addPoint(new GHPoint(42.554851, 1.536198)).addPoint(new GHPoint(42.531896, 1.553278)).addPoint(new GHPoint(42.510071, 1.548128)));
    assertTrue(rsp.getErrors().isEmpty(), rsp.getErrors().toString());
    res = rsp.getBest();
    assertTrue(res.getDistance() > 20000, "distance wasn't correct:" + res.getDistance());
    assertTrue(res.getDistance() < 21000, "distance wasn't correct:" + res.getDistance());
    InstructionList instructions = res.getInstructions();
    assertEquals(24, instructions.size());
    assertEquals("Continue onto la Callisa", instructions.get(0).getTurnDescription(null));
    assertEquals("At roundabout, take exit 2", instructions.get(4).getTurnDescription(null));
    assertEquals(true, instructions.get(4).getExtraInfoJSON().get("exited"));
    assertEquals(false, instructions.get(22).getExtraInfoJSON().get("exited"));
}
Also used : ResponsePath(com.graphhopper.ResponsePath) InstructionList(com.graphhopper.util.InstructionList) GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHResponse(com.graphhopper.GHResponse) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with GraphHopperWeb

use of com.graphhopper.api.GraphHopperWeb 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 10 with GraphHopperWeb

use of com.graphhopper.api.GraphHopperWeb 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)

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