use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class GraphHopperServletIT method testPathDetailsSamePoint.
@Test
public void testPathDetailsSamePoint() throws Exception {
GraphHopperAPI hopper = new com.graphhopper.api.GraphHopperWeb();
assertTrue(hopper.load(getTestRouteAPIUrl()));
GHRequest request = new GHRequest(42.554851, 1.536198, 42.554851, 1.536198);
request.setPathDetails(Arrays.asList("average_speed", "edge_id", "time"));
GHResponse rsp = hopper.route(request);
assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
assertTrue(rsp.getErrors().toString(), rsp.getErrors().isEmpty());
}
use of com.graphhopper.GHRequest 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);
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testLoadOSM.
@Test
public void testLoadOSM() {
GraphHopper closableInstance = new GraphHopperOSM().setStoreOnFlush(true).setEncodingManager(new EncodingManager("car")).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm);
closableInstance.importOrLoad();
GHResponse rsp = closableInstance.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
assertFalse(rsp.hasErrors());
assertEquals(3, rsp.getBest().getPoints().getSize());
closableInstance.close();
// no encoding manager necessary
closableInstance = new GraphHopperOSM().setStoreOnFlush(true);
assertTrue(closableInstance.load(ghLoc));
rsp = closableInstance.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
assertFalse(rsp.hasErrors());
assertEquals(3, rsp.getBest().getPoints().getSize());
closableInstance.close();
try {
rsp = closableInstance.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
assertTrue(false);
} catch (Exception ex) {
assertEquals("You need to create a new GraphHopper instance as it is already closed", ex.getMessage());
}
try {
closableInstance.getLocationIndex().findClosest(51.2492152, 9.4317166, EdgeFilter.ALL_EDGES);
assertTrue(false);
} catch (Exception ex) {
assertEquals("You need to create a new LocationIndex instance as it is already closed", ex.getMessage());
}
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testCustomFactoryForNoneCH.
@Test
public void testCustomFactoryForNoneCH() {
CarFlagEncoder carEncoder = new CarFlagEncoder();
EncodingManager em = new EncodingManager(carEncoder);
// Weighting weighting = new FastestWeighting(carEncoder);
instance = new GraphHopperOSM().setStoreOnFlush(false).setCHEnabled(false).setEncodingManager(em).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm);
final RoutingAlgorithmFactory af = new RoutingAlgorithmFactorySimple();
instance.addAlgorithmFactoryDecorator(new RoutingAlgorithmFactoryDecorator() {
@Override
public void init(CmdArgs args) {
}
@Override
public RoutingAlgorithmFactory getDecoratedAlgorithmFactory(RoutingAlgorithmFactory algoFactory, HintsMap map) {
return af;
}
@Override
public boolean isEnabled() {
return true;
}
});
instance.importOrLoad();
assertTrue(af == instance.getAlgorithmFactory(null));
// test that hints are passed to algorithm opts
final AtomicInteger cnt = new AtomicInteger(0);
instance.addAlgorithmFactoryDecorator(new RoutingAlgorithmFactoryDecorator() {
@Override
public void init(CmdArgs args) {
}
public RoutingAlgorithmFactory getDecoratedAlgorithmFactory(RoutingAlgorithmFactory algoFactory, HintsMap map) {
return new RoutingAlgorithmFactorySimple() {
@Override
public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) {
cnt.addAndGet(1);
assertFalse(opts.getHints().getBool("test", true));
return super.createAlgo(g, opts);
}
};
}
@Override
public boolean isEnabled() {
return true;
}
});
GHRequest req = new GHRequest(51.2492152, 9.4317166, 51.2, 9.4);
req.getHints().put("test", false);
instance.route(req);
assertEquals(1, cnt.get());
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testNoNPE_ifLoadNotSuccessful.
@Test
public void testNoNPE_ifLoadNotSuccessful() {
instance = new GraphHopperOSM().setStoreOnFlush(true).setEncodingManager(new EncodingManager("car"));
try {
// loading from empty directory
new File(ghLoc).mkdirs();
assertFalse(instance.load(ghLoc));
instance.route(new GHRequest(10, 40, 12, 32));
assertTrue(false);
} catch (IllegalStateException ex) {
assertEquals("Do a successful call to load or importOrLoad before routing", ex.getMessage());
}
}
Aggregations