From 6fe713bbc62b04d21e954e51419cf154db0f0142 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Sat, 17 Nov 2012 17:48:12 +0100 Subject: [PATCH] =?UTF-8?q?VMT:=20New=20provider=20for=20Mittelth=C3=BCrin?= =?UTF-8?q?gen.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- enabler/src/de/schildbach/pte/NetworkId.java | 2 +- .../src/de/schildbach/pte/VmtProvider.java | 64 ++++++++++++ .../pte/live/VmtProviderLiveTest.java | 98 +++++++++++++++++++ .../pte/live/secrets.properties.template | 1 + 4 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 enabler/src/de/schildbach/pte/VmtProvider.java create mode 100644 enabler/test/de/schildbach/pte/live/VmtProviderLiveTest.java diff --git a/enabler/src/de/schildbach/pte/NetworkId.java b/enabler/src/de/schildbach/pte/NetworkId.java index 00ebe6a7..11873e41 100644 --- a/enabler/src/de/schildbach/pte/NetworkId.java +++ b/enabler/src/de/schildbach/pte/NetworkId.java @@ -25,7 +25,7 @@ public enum NetworkId { RT, // Germany - DB, BVG, VBB, NVV, BAYERN, MVV, INVG, AVV, VGN, VVM, VMV, SH, GVH, BSVAG, VBN, NASA, VVO, VMS, VGS, VRR, VRS, MVG, VRN, VVS, DING, KVV, VAGFR, NVBW, VVV, + DB, BVG, VBB, NVV, BAYERN, MVV, INVG, AVV, VGN, VVM, VMV, SH, GVH, BSVAG, VBN, NASA, VMT, VVO, VMS, VGS, VRR, VRS, MVG, VRN, VVS, DING, KVV, VAGFR, NVBW, VVV, // Austria OEBB, VAO, VOR, WIEN, OOEVV, LINZ, SVV, VVT, IVB, STV, VMOBIL, diff --git a/enabler/src/de/schildbach/pte/VmtProvider.java b/enabler/src/de/schildbach/pte/VmtProvider.java new file mode 100644 index 00000000..abde8b71 --- /dev/null +++ b/enabler/src/de/schildbach/pte/VmtProvider.java @@ -0,0 +1,64 @@ +/* + * Copyright 2017 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 java.util.regex.Matcher; + +import de.schildbach.pte.dto.Product; + +import okhttp3.HttpUrl; + +/** + * @author Andreas Schildbach + */ +public class VmtProvider extends AbstractHafasMobileProvider { + private static final HttpUrl API_BASE = HttpUrl.parse("https://vmt.hafas.de/bin/"); + // http://www.routenplaner.nahverkehr-jena.de/bin/ + private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN, + Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.TRAM, Product.FERRY, + Product.BUS /* guessing */, Product.BUS }; + + public VmtProvider(final String jsonApiAuthorization) { + super(NetworkId.VMT, API_BASE, PRODUCTS_MAP); + setApiVersion("1.10"); + setApiClient("{\"name\":\"VMT\"}"); + setApiAuthorization(jsonApiAuthorization); + } + + private static final String[] PLACES = { "Erfurt", "Jena", "Gera", "Weimar", "Gotha" }; + + @Override + protected String[] splitStationName(final String name) { + for (final String place : PLACES) { + if (name.startsWith(place + ", ")) + return new String[] { place, name.substring(place.length() + 2) }; + if (name.startsWith(place + " ") || name.startsWith(place + "-")) + return new String[] { place, name.substring(place.length() + 1) }; + } + return super.splitStationName(name); + } + + @Override + protected String[] splitAddress(final String address) { + final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address); + if (m.matches()) + return new String[] { m.group(1), m.group(2) }; + + return super.splitStationName(address); + } +} diff --git a/enabler/test/de/schildbach/pte/live/VmtProviderLiveTest.java b/enabler/test/de/schildbach/pte/live/VmtProviderLiveTest.java new file mode 100644 index 00000000..1065fe27 --- /dev/null +++ b/enabler/test/de/schildbach/pte/live/VmtProviderLiveTest.java @@ -0,0 +1,98 @@ +/* + * Copyright 2017 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.assertEquals; + +import java.util.Date; + +import org.junit.Test; + +import de.schildbach.pte.NetworkProvider.Accessibility; +import de.schildbach.pte.NetworkProvider.WalkSpeed; +import de.schildbach.pte.VmtProvider; +import de.schildbach.pte.dto.Location; +import de.schildbach.pte.dto.LocationType; +import de.schildbach.pte.dto.NearbyLocationsResult; +import de.schildbach.pte.dto.Product; +import de.schildbach.pte.dto.QueryDeparturesResult; +import de.schildbach.pte.dto.QueryTripsResult; +import de.schildbach.pte.dto.SuggestLocationsResult; + +/** + * @author Andreas Schildbach + */ +public class VmtProviderLiveTest extends AbstractProviderLiveTest { + public VmtProviderLiveTest() { + super(new VmtProvider(secretProperty("vmt.api_authorization"))); + } + + @Test + public void nearbyStations() throws Exception { + final NearbyLocationsResult result = queryNearbyStations(new Location(LocationType.STATION, "153166")); + print(result); + } + + @Test + public void nearbyStationsByCoordinate() throws Exception { + final NearbyLocationsResult result = queryNearbyStations(Location.coord(50972622, 11037283)); + print(result); + } + + @Test + public void queryDepartures() throws Exception { + final QueryDeparturesResult result = queryDepartures("153166", false); + print(result); + } + + @Test + public void queryDeparturesInvalidStation() throws Exception { + final QueryDeparturesResult result = queryDepartures("999999", false); + assertEquals(QueryDeparturesResult.Status.INVALID_STATION, result.status); + } + + @Test + public void suggestLocationsIncomplete() throws Exception { + final SuggestLocationsResult result = suggestLocations("Jena Stadtzentrum"); + print(result); + + final SuggestLocationsResult result2 = suggestLocations("Spittelplatz"); + print(result2); + } + + @Test + public void suggestLocationsUmlaut() throws Exception { + final SuggestLocationsResult result = suggestLocations("Höhle"); + print(result); + } + + @Test + public void shortTrip() throws Exception { + final QueryTripsResult result = queryTrips( + new Location(LocationType.STATION, "153166", 50926947, 11586987, null, "Jena, Stadtzentrum"), null, + new Location(LocationType.STATION, "153014", 50933887, 11590592, null, "Jena, Spittelpl."), new Date(), + true, Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL); + System.out.println(result); + + if (!result.context.canQueryLater()) + return; + + final QueryTripsResult laterResult = queryMoreTrips(result.context, true); + System.out.println(laterResult); + } +} diff --git a/enabler/test/de/schildbach/pte/live/secrets.properties.template b/enabler/test/de/schildbach/pte/live/secrets.properties.template index 3a3b7002..62ecdb8b 100644 --- a/enabler/test/de/schildbach/pte/live/secrets.properties.template +++ b/enabler/test/de/schildbach/pte/live/secrets.properties.template @@ -3,6 +3,7 @@ vgn.api_base = navitia.authorization = vbn.api_authorization = sh.api_authorization = +vmt.api_authorization = vor.api_authorization = ooevv.api_authorization = svv.api_authorization =