From ae7146050a4036cfaadf8f7a55a297ae7570bfe1 Mon Sep 17 00:00:00 2001 From: Adrian Perez de Castro Date: Mon, 23 Jul 2018 15:22:16 +0200 Subject: [PATCH] Add Finland provider based on Navitia. --- .../de/schildbach/pte/FinlandProvider.java | 49 ++++++ enabler/src/de/schildbach/pte/NetworkId.java | 3 + .../pte/live/FinlandProviderLiveTest.java | 145 ++++++++++++++++++ 3 files changed, 197 insertions(+) create mode 100644 enabler/src/de/schildbach/pte/FinlandProvider.java create mode 100644 enabler/test/de/schildbach/pte/live/FinlandProviderLiveTest.java diff --git a/enabler/src/de/schildbach/pte/FinlandProvider.java b/enabler/src/de/schildbach/pte/FinlandProvider.java new file mode 100644 index 00000000..685e800a --- /dev/null +++ b/enabler/src/de/schildbach/pte/FinlandProvider.java @@ -0,0 +1,49 @@ +/* + * Copyright the original author or authors. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package de.schildbach.pte; + +import de.schildbach.pte.util.WordUtils; + +import okhttp3.HttpUrl; + +/** + * @author Adrian Perez de Castro + */ +public class FinlandProvider extends AbstractNavitiaProvider { + private static String API_REGION = "fi"; + + public FinlandProvider(final HttpUrl apiBase, final String authorization) { + super(NetworkId.FINLAND, apiBase, authorization); + setTimeZone("Europe/Helsinki"); + } + + public FinlandProvider(final String authorization) { + super(NetworkId.FINLAND, authorization); + setTimeZone("Europe/Helsinki"); + } + + @Override + public String region() { + return API_REGION; + } + + @Override + protected String getLocationName(final String name) { + return WordUtils.capitalizeFully(name); + } +} diff --git a/enabler/src/de/schildbach/pte/NetworkId.java b/enabler/src/de/schildbach/pte/NetworkId.java index 8750178a..e87f903c 100644 --- a/enabler/src/de/schildbach/pte/NetworkId.java +++ b/enabler/src/de/schildbach/pte/NetworkId.java @@ -51,6 +51,9 @@ public enum NetworkId { // Sweden SE, + // Finland + FINLAND, + // Luxembourg LU, diff --git a/enabler/test/de/schildbach/pte/live/FinlandProviderLiveTest.java b/enabler/test/de/schildbach/pte/live/FinlandProviderLiveTest.java new file mode 100644 index 00000000..874b5b50 --- /dev/null +++ b/enabler/test/de/schildbach/pte/live/FinlandProviderLiveTest.java @@ -0,0 +1,145 @@ +/* + * Copyright the original author or authors. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package de.schildbach.pte.live; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import de.schildbach.pte.FinlandProvider; +import de.schildbach.pte.dto.Point; + +/** + * @author Adrian Perez de Castro + */ +public class FinlandProviderLiveTest extends AbstractNavitiaProviderLiveTest { + public FinlandProviderLiveTest() { + super(new FinlandProvider(secretProperty("navitia.authorization"))); + } + + @Test + public void nearbyStationsAddress() throws Exception { + nearbyStationsAddress(60160920, 24941870); + } + + @Test + public void nearbyStationsStation() throws Exception { + nearbyStationsStation("stop_point:OFI:SP:1050412"); + } + + @Test + public void nearbyStationsPoi() throws Exception { + nearbyStationsPoi("poi:osm:way:29071686"); + } + + @Test + public void nearbyStationsAny() throws Exception { + nearbyStationsAny(60160920, 24941870); + } + + @Test + public void nearbyStationsInvalidStation() throws Exception { + nearbyStationsInvalidStation("stop_point:9999999999"); + } + + @Test + public void queryDeparturesStopArea() throws Exception { + queryDeparturesStopArea("stop_area:OFI:SA:1000201"); + } + + @Test + public void queryDeparturesEquivsFalse() throws Exception { + queryDeparturesEquivsFalse("stop_point:OFI:SP:1050412"); + } + + @Test + public void queryDeparturesEquivsTrue() throws Exception { + queryDeparturesEquivsTrue("stop_area:OFI:SA:1000201"); + } + + @Test + public void queryDeparturesInvalidStation() throws Exception { + queryDeparturesInvalidStation("stop_point:OFI:SP:999999"); + } + + @Test + public void suggestLocations() throws Exception { + suggestLocationsFromName("postitalo"); + } + + @Test + public void suggestLocationsFromAddress() throws Exception { + suggestLocationsFromAddress("10 yrjönkatu"); + } + + @Test + public void suggestLocationsNoLocation() throws Exception { + suggestLocationsNoLocation("fontana di trevi blah blah"); + } + + @Test + public void queryTripAddresses() throws Exception { + queryTrip("Yrjönkatu, 10, Helsinki", "Kolmas Linja, 5, Helsinki"); + } + + @Test + public void queryTripAddressStation() throws Exception { + queryTrip("Viides Linja, 3, Helsinki", "Kapylän asema"); + } + + @Test + public void queryTripStations() throws Exception { + queryTrip("Kapylän asema", "Päärautatieasema"); + } + + @Test + public void queryTripNoSolution() throws Exception { + queryTripNoSolution("Steissi, Helsinki", "Keskuskatu 1, Kuopio"); + } + + @Test + public void queryTripUnknownFrom() throws Exception { + queryTripUnknownFrom("Rautatieasema"); + } + + @Test + public void queryTripUnknownTo() throws Exception { + queryTripUnknownTo("Rautatieasema"); + } + + @Test + public void queryTripSlowWalk() throws Exception { + queryTripSlowWalk("Rautatieasema", "Postitalo"); + } + + @Test + public void queryTripFastWalk() throws Exception { + queryTripFastWalk("Rautatieasema", "Postitalo"); + } + + @Test + public void queryMoreTrips() throws Exception { + queryMoreTrips("Steissi", "Töölöntori"); + } + + @Test + public void getArea() throws Exception { + final Point[] polygon = provider.getArea(); + assertTrue(polygon.length > 0); + } +}