forked from opentripplanner/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dependency on org.json-simple
- Loading branch information
1 parent
b0d28ff
commit b41f286
Showing
10 changed files
with
255 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/ext-test/java/org/opentripplanner/ext/vectortiles/layers/TestTransitService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.opentripplanner.ext.vectortiles.layers; | ||
|
||
import java.util.Set; | ||
import org.opentripplanner.transit.model._data.TransitModelForTest; | ||
import org.opentripplanner.transit.model.basic.TransitMode; | ||
import org.opentripplanner.transit.model.network.Route; | ||
import org.opentripplanner.transit.model.site.StopLocation; | ||
import org.opentripplanner.transit.service.DefaultTransitService; | ||
import org.opentripplanner.transit.service.TransitModel; | ||
|
||
public class TestTransitService extends DefaultTransitService { | ||
|
||
public TestTransitService(TransitModel transitModel) { | ||
super(transitModel); | ||
} | ||
|
||
@Override | ||
public Set<Route> getRoutesForStop(StopLocation stop) { | ||
return Set.of( | ||
TransitModelForTest.route("1").withMode(TransitMode.RAIL).withGtfsType(100).build() | ||
); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...opentripplanner/ext/vectortiles/layers/stations/DigitransitStationPropertyMapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.opentripplanner.ext.vectortiles.layers.stations; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.opentripplanner.transit.model._data.TransitModelForTest.id; | ||
|
||
import java.util.HashMap; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
import org.opentripplanner.ext.vectortiles.layers.TestTransitService; | ||
import org.opentripplanner.framework.i18n.I18NString; | ||
import org.opentripplanner.transit.model._data.TransitModelForTest; | ||
import org.opentripplanner.transit.model.framework.Deduplicator; | ||
import org.opentripplanner.transit.model.site.Station; | ||
import org.opentripplanner.transit.service.StopModel; | ||
import org.opentripplanner.transit.service.TransitModel; | ||
|
||
public class DigitransitStationPropertyMapperTest { | ||
|
||
@Test | ||
void map() { | ||
var deduplicator = new Deduplicator(); | ||
var transitModel = new TransitModel(new StopModel(), deduplicator); | ||
transitModel.index(); | ||
var transitService = new TestTransitService(transitModel); | ||
|
||
var mapper = DigitransitStationPropertyMapper.create(transitService, Locale.US); | ||
|
||
var station = Station | ||
.of(id("a-station")) | ||
.withCoordinate(1, 1) | ||
.withName(I18NString.of("A station")) | ||
.build(); | ||
|
||
TransitModelForTest.of().stop("stop-1").withParentStation(station).build(); | ||
|
||
Map<String, Object> map = new HashMap<>(); | ||
mapper.map(station).forEach(o -> map.put(o.key(), o.value())); | ||
|
||
assertEquals("F:a-station", map.get("gtfsId")); | ||
assertEquals("A station", map.get("name")); | ||
assertEquals("", map.get("type")); | ||
assertEquals("[{\"mode\":\"RAIL\",\"shortName\":\"R1\"}]", map.get("routes")); | ||
assertEquals("[\"F:stop-1\"]", map.get("stops")); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
...xt-test/java/org/opentripplanner/ext/vectortiles/layers/stops/RealtimeStopsLayerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package org.opentripplanner.ext.vectortiles.layers.stops; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.opentripplanner.framework.time.TimeUtils.time; | ||
import static org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary; | ||
|
||
import java.time.ZonedDateTime; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.opentripplanner._support.time.ZoneIds; | ||
import org.opentripplanner.ext.realtimeresolver.RealtimeResolver; | ||
import org.opentripplanner.framework.i18n.I18NString; | ||
import org.opentripplanner.model.plan.Place; | ||
import org.opentripplanner.routing.alertpatch.AlertEffect; | ||
import org.opentripplanner.routing.alertpatch.EntitySelector; | ||
import org.opentripplanner.routing.alertpatch.TimePeriod; | ||
import org.opentripplanner.routing.alertpatch.TransitAlert; | ||
import org.opentripplanner.routing.impl.TransitAlertServiceImpl; | ||
import org.opentripplanner.routing.services.TransitAlertService; | ||
import org.opentripplanner.transit.model._data.TransitModelForTest; | ||
import org.opentripplanner.transit.model.framework.Deduplicator; | ||
import org.opentripplanner.transit.model.framework.FeedScopedId; | ||
import org.opentripplanner.transit.model.network.Route; | ||
import org.opentripplanner.transit.model.site.RegularStop; | ||
import org.opentripplanner.transit.service.DefaultTransitService; | ||
import org.opentripplanner.transit.service.StopModel; | ||
import org.opentripplanner.transit.service.TransitModel; | ||
|
||
public class RealtimeStopsLayerTest { | ||
|
||
private RegularStop stop; | ||
private RegularStop stop2; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
var name = I18NString.of("name"); | ||
var desc = I18NString.of("desc"); | ||
stop = | ||
StopModel | ||
.of() | ||
.regularStop(new FeedScopedId("F", "name")) | ||
.withName(name) | ||
.withDescription(desc) | ||
.withCoordinate(50, 10) | ||
.build(); | ||
stop2 = | ||
StopModel | ||
.of() | ||
.regularStop(new FeedScopedId("F", "name")) | ||
.withName(name) | ||
.withDescription(desc) | ||
.withCoordinate(51, 10) | ||
.build(); | ||
} | ||
|
||
@Test | ||
void realtimeStopLayer() { | ||
var deduplicator = new Deduplicator(); | ||
var transitModel = new TransitModel(new StopModel(), deduplicator); | ||
transitModel.initTimeZone(ZoneIds.HELSINKI); | ||
transitModel.index(); | ||
var alertService = new TransitAlertServiceImpl(transitModel); | ||
var transitService = new DefaultTransitService(transitModel) { | ||
@Override | ||
public TransitAlertService getTransitAlertService() { | ||
return alertService; | ||
} | ||
}; | ||
|
||
Route route = TransitModelForTest.route("route").build(); | ||
var itinerary = newItinerary(Place.forStop(stop), time("11:00")) | ||
.bus(route, 1, time("11:05"), time("11:20"), Place.forStop(stop2)) | ||
.build(); | ||
var startDate = ZonedDateTime.now(ZoneIds.HELSINKI).minusDays(1).toEpochSecond(); | ||
var endDate = ZonedDateTime.now(ZoneIds.HELSINKI).plusDays(1).toEpochSecond(); | ||
var alert = TransitAlert | ||
.of(stop.getId()) | ||
.addEntity(new EntitySelector.Stop(stop.getId())) | ||
.addTimePeriod(new TimePeriod(startDate, endDate)) | ||
.withEffect(AlertEffect.NO_SERVICE) | ||
.build(); | ||
transitService.getTransitAlertService().setAlerts(List.of(alert)); | ||
|
||
var itineraries = List.of(itinerary); | ||
RealtimeResolver.populateLegsWithRealtime(itineraries, transitService); | ||
|
||
DigitransitRealtimeStopPropertyMapper mapper = new DigitransitRealtimeStopPropertyMapper( | ||
transitService, | ||
new Locale("en-US") | ||
); | ||
|
||
Map<String, Object> map = new HashMap<>(); | ||
mapper.map(stop).forEach(o -> map.put(o.key(), o.value())); | ||
|
||
assertEquals("F:name", map.get("gtfsId")); | ||
assertEquals("name", map.get("name")); | ||
assertEquals("desc", map.get("desc")); | ||
assertEquals(true, map.get("closedByServiceAlert")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.