Skip to content

Commit

Permalink
Remove dependency on org.json-simple
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Apr 4, 2024
1 parent b0d28ff commit b41f286
Show file tree
Hide file tree
Showing 10 changed files with 255 additions and 146 deletions.
14 changes: 0 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -586,20 +586,6 @@
<version>${google.dagger.version}</version>
</dependency>

<!-- JSON AST, not used much and is a good candidate for removal -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<exclusions>
<!-- This includes a dependency on an ancient version of Junit which we want to exclude -->
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- GEOTOOLS AND JTS TOPOLOGY: geometry, rasters and projections. -->
<!-- GEOTOOLS includes JTS as a transitive dependency. -->

Expand Down
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()
);
}
}
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"));
}
}
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"));
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
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.Instant;
import java.time.LocalDate;
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.ext.vectortiles.layers.TestTransitService;
import org.opentripplanner.framework.i18n.TranslatedString;
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;
Expand All @@ -35,7 +19,6 @@
public class StopsLayerTest {

private RegularStop stop;
private RegularStop stop2;

@BeforeEach
public void setUp() {
Expand Down Expand Up @@ -67,22 +50,14 @@ public void setUp() {
.withDescription(descTranslations)
.withCoordinate(50, 10)
.build();
stop2 =
StopModel
.of()
.regularStop(new FeedScopedId("F", "name"))
.withName(nameTranslations)
.withDescription(descTranslations)
.withCoordinate(51, 10)
.build();
}

@Test
public void digitransitStopPropertyMapperTest() {
var deduplicator = new Deduplicator();
var transitModel = new TransitModel(new StopModel(), deduplicator);
transitModel.index();
var transitService = new DefaultTransitService(transitModel);
var transitService = new TestTransitService(transitModel);

DigitransitStopPropertyMapper mapper = DigitransitStopPropertyMapper.create(
transitService,
Expand All @@ -95,6 +70,7 @@ public void digitransitStopPropertyMapperTest() {
assertEquals("F:name", map.get("gtfsId"));
assertEquals("name", map.get("name"));
assertEquals("desc", map.get("desc"));
assertEquals("[{\"gtfsType\":100}]", map.get("routes"));
}

@Test
Expand All @@ -115,49 +91,4 @@ public void digitransitStopPropertyMapperTranslationTest() {
assertEquals("nameDE", map.get("name"));
assertEquals("descDE", map.get("desc"));
}

@Test
public void digitransitRealtimeStopPropertyMapperTest() {
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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void digitransitVehicleParkingGroupPropertyMapperTest() {
assertEquals("groupName", map.get("name").toString());

assertEquals(
"[{\"bicyclePlaces\":false,\"carPlaces\":true,\"name\":\"name\",\"id\":\"F:id\"}]",
"[{\"carPlaces\":true,\"bicyclePlaces\":false,\"id\":\"F:id\",\"name\":\"name\"}]",
map.get("vehicleParking")
);
}
Expand All @@ -162,7 +162,7 @@ public void digitransitVehicleParkingGroupPropertyMapperTranslationTest() {
assertEquals("groupDE", map.get("name").toString());

assertEquals(
"[{\"bicyclePlaces\":false,\"carPlaces\":true,\"name\":\"DE\",\"id\":\"F:id\"}]",
"[{\"carPlaces\":true,\"bicyclePlaces\":false,\"id\":\"F:id\",\"name\":\"DE\"}]",
map.get("vehicleParking")
);
}
Expand Down
Loading

0 comments on commit b41f286

Please sign in to comment.