7
7
import com .graphhopper .GraphHopper ;
8
8
import com .graphhopper .jackson .ResponsePathSerializer ;
9
9
import com .graphhopper .routing .TestProfiles ;
10
+ import com .graphhopper .routing .util .TransportationMode ;
10
11
import com .graphhopper .util .Helper ;
11
12
import com .graphhopper .util .Parameters ;
12
13
import com .graphhopper .util .PointList ;
@@ -29,9 +30,8 @@ public class NavigateResponseConverterTest {
29
30
private static final String osmFile = "../core/files/andorra.osm.gz" ;
30
31
private static GraphHopper hopper ;
31
32
private static final String profile = "my_car" ;
32
-
33
33
private final TranslationMap trMap = hopper .getTranslationMap ();
34
- private final DistanceConfig distanceConfig = new DistanceConfig (DistanceUtils .Unit .METRIC , trMap , Locale .ENGLISH );
34
+ private final DistanceConfig distanceConfig = new DistanceConfig (DistanceUtils .Unit .METRIC , trMap , Locale .ENGLISH , TransportationMode . CAR );
35
35
36
36
@ BeforeAll
37
37
public static void beforeClass () {
@@ -183,7 +183,7 @@ public void voiceInstructionsImperialTest() {
183
183
GHResponse rsp = hopper .route (new GHRequest (42.554851 , 1.536198 , 42.510071 , 1.548128 ).setProfile (profile ));
184
184
185
185
ObjectNode json = NavigateResponseConverter .convertFromGHResponse (rsp , trMap , Locale .ENGLISH ,
186
- new DistanceConfig (DistanceUtils .Unit .IMPERIAL , trMap , Locale .ENGLISH ));
186
+ new DistanceConfig (DistanceUtils .Unit .IMPERIAL , trMap , Locale .ENGLISH , TransportationMode . CAR ));
187
187
188
188
JsonNode steps = json .get ("routes" ).get (0 ).get ("legs" ).get (0 ).get ("steps" );
189
189
@@ -212,6 +212,146 @@ public void voiceInstructionsImperialTest() {
212
212
assertEquals ("keep right" , voiceInstruction .get ("announcement" ).asText ());
213
213
}
214
214
215
+ @ Test
216
+ public void voiceInstructionsWalkingMetricTest () {
217
+
218
+ GHResponse rsp = hopper .route (new GHRequest (42.554851 , 1.536198 , 42.510071 , 1.548128 ).setProfile (profile ));
219
+
220
+ ObjectNode json = NavigateResponseConverter .convertFromGHResponse (rsp , trMap , Locale .ENGLISH ,
221
+ new DistanceConfig (DistanceUtils .Unit .METRIC , trMap , Locale .ENGLISH , TransportationMode .FOOT ));
222
+
223
+ JsonNode steps = json .get ("routes" ).get (0 ).get ("legs" ).get (0 ).get ("steps" );
224
+
225
+ // Step 4 is about 240m long
226
+ JsonNode step = steps .get (4 );
227
+ JsonNode maneuver = step .get ("maneuver" );
228
+
229
+ JsonNode voiceInstructions = step .get ("voiceInstructions" );
230
+ assertEquals (2 , voiceInstructions .size ());
231
+ JsonNode voiceInstruction = voiceInstructions .get (0 );
232
+ assertEquals (50 , voiceInstruction .get ("distanceAlongGeometry" ).asDouble (), 1 );
233
+ assertEquals ("In 50 meters At roundabout, take exit 2 onto CS-340, then At roundabout, take exit 2 onto CG-3" ,
234
+ voiceInstruction .get ("announcement" ).asText ());
235
+
236
+ // Step 14 is over 3km long
237
+ step = steps .get (14 );
238
+ maneuver = step .get ("maneuver" );
239
+
240
+ voiceInstructions = step .get ("voiceInstructions" );
241
+ assertEquals (2 , voiceInstructions .size ());
242
+ voiceInstruction = voiceInstructions .get (0 );
243
+ assertEquals (50 , voiceInstruction .get ("distanceAlongGeometry" ).asDouble (), 1 );
244
+ assertEquals ("In 50 meters keep right" , voiceInstruction .get ("announcement" ).asText ());
245
+
246
+ voiceInstruction = voiceInstructions .get (1 );
247
+ assertEquals ("keep right" , voiceInstruction .get ("announcement" ).asText ());
248
+ }
249
+
250
+ @ Test
251
+ public void voiceInstructionsWalkingImperialTest () {
252
+
253
+ GHResponse rsp = hopper .route (new GHRequest (42.554851 , 1.536198 , 42.510071 , 1.548128 ).setProfile (profile ));
254
+
255
+ ObjectNode json = NavigateResponseConverter .convertFromGHResponse (rsp , trMap , Locale .ENGLISH ,
256
+ new DistanceConfig (DistanceUtils .Unit .IMPERIAL , trMap , Locale .ENGLISH , TransportationMode .FOOT ));
257
+
258
+ JsonNode steps = json .get ("routes" ).get (0 ).get ("legs" ).get (0 ).get ("steps" );
259
+
260
+ // Step 4 is about 240m long
261
+ JsonNode step = steps .get (4 );
262
+ JsonNode maneuver = step .get ("maneuver" );
263
+
264
+ JsonNode voiceInstructions = step .get ("voiceInstructions" );
265
+ assertEquals (2 , voiceInstructions .size ());
266
+ JsonNode voiceInstruction = voiceInstructions .get (0 );
267
+ assertEquals (50 , voiceInstruction .get ("distanceAlongGeometry" ).asDouble (), 1 );
268
+ assertEquals ("In 150 feet At roundabout, take exit 2 onto CS-340, then At roundabout, take exit 2 onto CG-3" ,
269
+ voiceInstruction .get ("announcement" ).asText ());
270
+
271
+ // Step 14 is over 3km long
272
+ step = steps .get (14 );
273
+ maneuver = step .get ("maneuver" );
274
+
275
+ voiceInstructions = step .get ("voiceInstructions" );
276
+ assertEquals (2 , voiceInstructions .size ());
277
+ voiceInstruction = voiceInstructions .get (0 );
278
+ assertEquals (50 , voiceInstruction .get ("distanceAlongGeometry" ).asDouble (), 1 );
279
+ assertEquals ("In 150 feet keep right" , voiceInstruction .get ("announcement" ).asText ());
280
+
281
+ voiceInstruction = voiceInstructions .get (1 );
282
+ assertEquals ("keep right" , voiceInstruction .get ("announcement" ).asText ());
283
+ }
284
+
285
+ @ Test
286
+ public void voiceInstructionsCyclingMetricTest () {
287
+
288
+ GHResponse rsp = hopper .route (new GHRequest (42.554851 , 1.536198 , 42.510071 , 1.548128 ).setProfile (profile ));
289
+
290
+ ObjectNode json = NavigateResponseConverter .convertFromGHResponse (rsp , trMap , Locale .ENGLISH ,
291
+ new DistanceConfig (DistanceUtils .Unit .METRIC , trMap , Locale .ENGLISH , TransportationMode .BIKE ));
292
+
293
+ JsonNode steps = json .get ("routes" ).get (0 ).get ("legs" ).get (0 ).get ("steps" );
294
+
295
+ // Step 4 is about 240m long
296
+ JsonNode step = steps .get (4 );
297
+ JsonNode maneuver = step .get ("maneuver" );
298
+
299
+ JsonNode voiceInstructions = step .get ("voiceInstructions" );
300
+ assertEquals (2 , voiceInstructions .size ());
301
+ JsonNode voiceInstruction = voiceInstructions .get (0 );
302
+ assertEquals (150 , voiceInstruction .get ("distanceAlongGeometry" ).asDouble (), 1 );
303
+ assertEquals ("In 150 meters At roundabout, take exit 2 onto CS-340, then At roundabout, take exit 2 onto CG-3" ,
304
+ voiceInstruction .get ("announcement" ).asText ());
305
+
306
+ // Step 14 is over 3km long
307
+ step = steps .get (14 );
308
+ maneuver = step .get ("maneuver" );
309
+
310
+ voiceInstructions = step .get ("voiceInstructions" );
311
+ assertEquals (2 , voiceInstructions .size ());
312
+ voiceInstruction = voiceInstructions .get (0 );
313
+ assertEquals (150 , voiceInstruction .get ("distanceAlongGeometry" ).asDouble (), 1 );
314
+ assertEquals ("In 150 meters keep right" , voiceInstruction .get ("announcement" ).asText ());
315
+
316
+ voiceInstruction = voiceInstructions .get (1 );
317
+ assertEquals ("keep right" , voiceInstruction .get ("announcement" ).asText ());
318
+ }
319
+
320
+ @ Test
321
+ public void voiceInstructionsCyclingImperialTest () {
322
+
323
+ GHResponse rsp = hopper .route (new GHRequest (42.554851 , 1.536198 , 42.510071 , 1.548128 ).setProfile (profile ));
324
+
325
+ ObjectNode json = NavigateResponseConverter .convertFromGHResponse (rsp , trMap , Locale .ENGLISH ,
326
+ new DistanceConfig (DistanceUtils .Unit .IMPERIAL , trMap , Locale .ENGLISH , TransportationMode .BIKE ));
327
+
328
+ JsonNode steps = json .get ("routes" ).get (0 ).get ("legs" ).get (0 ).get ("steps" );
329
+
330
+ // Step 4 is about 240m long
331
+ JsonNode step = steps .get (4 );
332
+ JsonNode maneuver = step .get ("maneuver" );
333
+
334
+ JsonNode voiceInstructions = step .get ("voiceInstructions" );
335
+ assertEquals (2 , voiceInstructions .size ());
336
+ JsonNode voiceInstruction = voiceInstructions .get (0 );
337
+ assertEquals (150 , voiceInstruction .get ("distanceAlongGeometry" ).asDouble (), 1 );
338
+ assertEquals ("In 500 feet At roundabout, take exit 2 onto CS-340, then At roundabout, take exit 2 onto CG-3" ,
339
+ voiceInstruction .get ("announcement" ).asText ());
340
+
341
+ // Step 14 is over 3km long
342
+ step = steps .get (14 );
343
+ maneuver = step .get ("maneuver" );
344
+
345
+ voiceInstructions = step .get ("voiceInstructions" );
346
+ assertEquals (2 , voiceInstructions .size ());
347
+ voiceInstruction = voiceInstructions .get (0 );
348
+ assertEquals (150 , voiceInstruction .get ("distanceAlongGeometry" ).asDouble (), 1 );
349
+ assertEquals ("In 500 feet keep right" , voiceInstruction .get ("announcement" ).asText ());
350
+
351
+ voiceInstruction = voiceInstructions .get (1 );
352
+ assertEquals ("keep right" , voiceInstruction .get ("announcement" ).asText ());
353
+ }
354
+
215
355
@ Test
216
356
@ Disabled
217
357
public void alternativeRoutesTest () {
@@ -244,7 +384,7 @@ public void voiceInstructionTranslationTest() {
244
384
rsp = hopper .route (
245
385
new GHRequest (42.554851 , 1.536198 , 42.510071 , 1.548128 ).setProfile (profile ).setLocale (Locale .GERMAN ));
246
386
247
- DistanceConfig distanceConfigGerman = new DistanceConfig (DistanceUtils .Unit .METRIC , trMap , Locale .GERMAN );
387
+ DistanceConfig distanceConfigGerman = new DistanceConfig (DistanceUtils .Unit .METRIC , trMap , Locale .GERMAN , TransportationMode . CAR );
248
388
249
389
json = NavigateResponseConverter .convertFromGHResponse (rsp , trMap , Locale .GERMAN , distanceConfigGerman );
250
390
0 commit comments