From 170d7eef615c974814f3410c9aca491738b456bc Mon Sep 17 00:00:00 2001 From: Filip Date: Mon, 29 Jul 2019 21:44:02 +0200 Subject: [PATCH] Navitia: Add provider for the Czech Republic, currently covering Prague. --- .../schildbach/pte/CzechRepublicProvider.java | 42 +++++ src/de/schildbach/pte/NetworkId.java | 3 + .../live/CzechRepublicProviderLiveTest.java | 175 ++++++++++++++++++ 3 files changed, 220 insertions(+) create mode 100644 src/de/schildbach/pte/CzechRepublicProvider.java create mode 100644 test/de/schildbach/pte/live/CzechRepublicProviderLiveTest.java diff --git a/src/de/schildbach/pte/CzechRepublicProvider.java b/src/de/schildbach/pte/CzechRepublicProvider.java new file mode 100644 index 000000000..c56231727 --- /dev/null +++ b/src/de/schildbach/pte/CzechRepublicProvider.java @@ -0,0 +1,42 @@ +/* + * Copyright 2019 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 okhttp3.HttpUrl; + +/** + * @author Filip Hejsek + */ +public class CzechRepublicProvider extends AbstractNavitiaProvider { + private static final String API_REGION = "cz"; + + public CzechRepublicProvider(final HttpUrl apiBase, final String authorization) { + super(NetworkId.CZECH_REPUBLIC, apiBase, authorization); + setTimeZone("Europe/Prague"); + } + + public CzechRepublicProvider(final String authorization) { + super(NetworkId.CZECH_REPUBLIC, authorization); + setTimeZone("Europe/Prague"); + } + + @Override + public String region() { + return API_REGION; + } +} diff --git a/src/de/schildbach/pte/NetworkId.java b/src/de/schildbach/pte/NetworkId.java index c9091f187..ca7b6b045 100644 --- a/src/de/schildbach/pte/NetworkId.java +++ b/src/de/schildbach/pte/NetworkId.java @@ -30,6 +30,9 @@ public enum NetworkId { // Austria OEBB, VAO, VOR, WIEN, OOEVV, LINZ, SVV, VVT, STV, VMOBIL, + // Czech Republic + CZECH_REPUBLIC, + // Switzerland SBB, VBL, ZVV, diff --git a/test/de/schildbach/pte/live/CzechRepublicProviderLiveTest.java b/test/de/schildbach/pte/live/CzechRepublicProviderLiveTest.java new file mode 100644 index 000000000..c389957ec --- /dev/null +++ b/test/de/schildbach/pte/live/CzechRepublicProviderLiveTest.java @@ -0,0 +1,175 @@ +/* + * Copyright 2019 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.CzechRepublicProvider; +import de.schildbach.pte.dto.Location; +import de.schildbach.pte.dto.LocationType; +import de.schildbach.pte.dto.Point; + +/** + * @author Filip Hejsek + */ +public class CzechRepublicProviderLiveTest extends AbstractNavitiaProviderLiveTest { + public CzechRepublicProviderLiveTest() { + super(new CzechRepublicProvider(secretProperty("navitia.authorization"))); + } + + @Test + public void nearbyStationsAddress() throws Exception { + nearbyStationsAddress(50062956, 14430641); + } + + @Test + public void nearbyStationsAddress2() throws Exception { + nearbyStationsAddress(50083373, 14423001); + } + + @Test + public void nearbyStationsStation() throws Exception { + nearbyStationsStation("stop_point:OCZPRA:U527Z102P"); + } + + @Test + public void nearbyStationsPoi() throws Exception { + nearbyStationsPoi("poi:osm:way:141756627"); + } + + @Test + public void nearbyStationsAny() throws Exception { + nearbyStationsAny(50062956, 14430641); + } + + @Test + public void nearbyStationsDistance() throws Exception { + nearbyStationsStationDistance("stop_point:OCZPRA:U527Z102P"); + } + + @Test + public void nearbyStationsInvalidStation() throws Exception { + nearbyStationsInvalidStation("stop_point:RTP:SP:392"); + } + + @Test + public void queryDeparturesEquivsFalse() throws Exception { + queryDeparturesEquivsFalse("stop_point:OCZPRA:U1072Z121P"); + } + + @Test + public void queryDeparturesStopArea() throws Exception { + queryDeparturesStopArea("stop_area:OCZPRA:U527S1"); + } + + @Test + public void queryDeparturesEquivsTrue() throws Exception { + queryDeparturesEquivsTrue("stop_point:OCZPRA:U527Z101P"); + } + + @Test + public void queryDeparturesInvalidStation() throws Exception { + queryDeparturesInvalidStation("stop_point:RTP:SP:999999"); + } + + @Test + public void suggestLocations() throws Exception { + suggestLocationsFromName("Vyšehr"); + } + + @Test + public void suggestLocationsFromAddress() throws Exception { + suggestLocationsFromAddress("This doesn't work"); + // Address search doesn't work for Czech Republic in Navitia + } + + @Test + public void suggestLocationsNoLocation() throws Exception { + suggestLocationsNoLocation("bellevilleadasdjkaskd"); + } + + @Test + public void queryTripAddresses() throws Exception { + queryTrip("This doesn't work", "This doesn't work"); + // Address search doesn't work for Czech Republic in Navitia + } + + @Test + public void queryTripAddressStation() throws Exception { + queryTrip("This doesn't work", "Muzeum"); + // Address search doesn't work for Czech Republic in Navitia + } + + @Test + public void queryTripStations() throws Exception { + queryTrip("Vyšehrad", "Muzeum"); + } + + @Test + public void queryTripStations2() throws Exception { + queryTrip("Sídliště Písnice", "Modřanská rokle"); + } + + @Test + public void queryTripStations3() throws Exception { + queryTrip("Modřanská rokle", "Českomoravská"); + } + + @Test + public void queryTripUnknownFrom() throws Exception { + queryTripUnknownFrom("Muzeum"); + } + + @Test + public void queryTripUnknownTo() throws Exception { + queryTripUnknownTo("Vyšehrad"); + } + + @Test + public void queryTripAmbiguousFrom() throws Exception { + queryTripAmbiguousFrom(new Location(LocationType.ANY, null, null, "Sídliště"), "Muzeum"); + } + + @Test + public void queryTripAmbiguousTo() throws Exception { + queryTripAmbiguousTo("Vyšehrad", new Location(LocationType.ANY, null, null, "Sídliště")); + } + + @Test + public void queryTripSlowWalk() throws Exception { + queryTripSlowWalk("Nemocnice Krč", "Budějovická"); + } + + @Test + public void queryTripFastWalk() throws Exception { + queryTripFastWalk("Nemocnice Krč", "Budějovická"); + } + + @Test + public void queryMoreTrips() throws Exception { + queryMoreTrips("Nemocnice Krč", "Budějovická"); + } + + @Test + public void getArea() throws Exception { + final Point[] polygon = provider.getArea(); + assertTrue(polygon.length > 0); + } +}