From 5fb878ae07d0831141ce6bca5f2457899dd31115 Mon Sep 17 00:00:00 2001 From: Leonard Ehrenfried Date: Tue, 5 Nov 2024 14:28:03 +0100 Subject: [PATCH] Add test for parking processor --- .../apis/vectortiles/model/StyleBuilder.java | 3 + .../module/osm/ParkingProcessor.java | 2 +- .../module/osm/ParkingProcessorTest.java | 60 +++++++++++++++++++ .../wayproperty/specifier/WayTestData.java | 8 +++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 application/src/test/java/org/opentripplanner/graph_builder/module/osm/ParkingProcessorTest.java diff --git a/application/src/main/java/org/opentripplanner/apis/vectortiles/model/StyleBuilder.java b/application/src/main/java/org/opentripplanner/apis/vectortiles/model/StyleBuilder.java index deef5ac22bb..1d261bed75f 100644 --- a/application/src/main/java/org/opentripplanner/apis/vectortiles/model/StyleBuilder.java +++ b/application/src/main/java/org/opentripplanner/apis/vectortiles/model/StyleBuilder.java @@ -228,6 +228,9 @@ public final StyleBuilder permissionsFilter(StreetTraversalPermission p) { return this; } + /** + * Filter the entities by a boolean property. + */ public final StyleBuilder booleanFilter(String propertyName, boolean value) { filter = List.of("==", propertyName, value); return this; diff --git a/application/src/main/java/org/opentripplanner/graph_builder/module/osm/ParkingProcessor.java b/application/src/main/java/org/opentripplanner/graph_builder/module/osm/ParkingProcessor.java index 8a169b1157d..d2bbbe7e27f 100644 --- a/application/src/main/java/org/opentripplanner/graph_builder/module/osm/ParkingProcessor.java +++ b/application/src/main/java/org/opentripplanner/graph_builder/module/osm/ParkingProcessor.java @@ -312,7 +312,7 @@ private List createArtificialEntra ); } - private VehicleParking createVehicleParkingObjectFromOsmEntity( + VehicleParking createVehicleParkingObjectFromOsmEntity( boolean isCarParkAndRide, Coordinate coordinate, OsmWithTags entity, diff --git a/application/src/test/java/org/opentripplanner/graph_builder/module/osm/ParkingProcessorTest.java b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/ParkingProcessorTest.java new file mode 100644 index 00000000000..bfe5992399b --- /dev/null +++ b/application/src/test/java/org/opentripplanner/graph_builder/module/osm/ParkingProcessorTest.java @@ -0,0 +1,60 @@ +package org.opentripplanner.graph_builder.module.osm; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; +import org.junit.jupiter.api.Test; +import org.opentripplanner._support.geometry.Coordinates; +import org.opentripplanner.framework.i18n.I18NString; +import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore; +import org.opentripplanner.osm.wayproperty.specifier.WayTestData; +import org.opentripplanner.routing.graph.Graph; +import org.opentripplanner.street.model._data.StreetModelForTest; +import org.opentripplanner.street.model.vertex.IntersectionVertex; + +class ParkingProcessorTest { + + private static final IntersectionVertex INTERSECTION_VERTEX = StreetModelForTest.intersectionVertex( + 1, + 1 + ); + private static final ParkingProcessor PROCESSOR = new ParkingProcessor( + new Graph(), + DataImportIssueStore.NOOP, + (n, w) -> INTERSECTION_VERTEX + ); + + @Test + void noWheelchairParking() { + var entity = WayTestData.parkAndRide(); + var parking = PROCESSOR.createVehicleParkingObjectFromOsmEntity( + true, + Coordinates.BERLIN, + entity, + I18NString.of("parking"), + List.of() + ); + + assertFalse(parking.hasWheelchairAccessibleCarPlaces()); + assertNull(parking.getCapacity().getWheelchairAccessibleCarSpaces()); + } + + @Test + void wheelchairParking() { + var entity = WayTestData.parkAndRide(); + entity.addTag("capacity:disabled", "yes"); + var parking = PROCESSOR.createVehicleParkingObjectFromOsmEntity( + true, + Coordinates.BERLIN, + entity, + I18NString.of("parking"), + List.of() + ); + + assertTrue(parking.hasWheelchairAccessibleCarPlaces()); + assertEquals(1, parking.getCapacity().getWheelchairAccessibleCarSpaces()); + } +} diff --git a/application/src/test/java/org/opentripplanner/osm/wayproperty/specifier/WayTestData.java b/application/src/test/java/org/opentripplanner/osm/wayproperty/specifier/WayTestData.java index e075955f6c4..6d468b42db0 100644 --- a/application/src/test/java/org/opentripplanner/osm/wayproperty/specifier/WayTestData.java +++ b/application/src/test/java/org/opentripplanner/osm/wayproperty/specifier/WayTestData.java @@ -224,4 +224,12 @@ public static OsmWithTags indoor(String value) { way.addTag("indoor", value); return way; } + + public static OsmWithTags parkAndRide() { + var way = new OsmWithTags(); + way.addTag("amenity", "parking"); + way.addTag("park_ride", "yes"); + way.addTag("capacity", "10"); + return way; + } }