mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-12 23:18:48 +00:00
NVV: Migrate to Hafas client interface.
This commit is contained in:
parent
f1641c5fa3
commit
389cd53bbf
3 changed files with 28 additions and 114 deletions
|
@ -19,26 +19,24 @@ package de.schildbach.pte;
|
|||
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
import de.schildbach.pte.dto.Product;
|
||||
import de.schildbach.pte.util.StringReplaceReader;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class NvvProvider extends AbstractHafasLegacyProvider {
|
||||
private static final HttpUrl API_BASE = HttpUrl.parse("https://auskunft.nvv.de/auskunft/bin/jp/");
|
||||
public class NvvProvider extends AbstractHafasClientInterfaceProvider {
|
||||
private static final HttpUrl API_BASE = HttpUrl.parse("https://auskunft.nvv.de/auskunft/bin/app/");
|
||||
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.SUBWAY, Product.TRAM, Product.BUS, Product.BUS,
|
||||
Product.FERRY, Product.ON_DEMAND, Product.REGIONAL_TRAIN, Product.REGIONAL_TRAIN };
|
||||
|
||||
public NvvProvider() {
|
||||
super(NetworkId.NVV, API_BASE, "dn", PRODUCTS_MAP);
|
||||
setRequestUrlEncoding(Charsets.UTF_8);
|
||||
setJsonNearbyLocationsEncoding(Charsets.UTF_8);
|
||||
public NvvProvider(final String apiAuthorization) {
|
||||
super(NetworkId.NVV, API_BASE, PRODUCTS_MAP);
|
||||
setApiVersion("1.14");
|
||||
setApiClient("{\"id\":\"NVV\",\"type\":\"AND\"}");
|
||||
setApiAuthorization(apiAuthorization);
|
||||
httpClient.setTrustAllCertificates(true);
|
||||
}
|
||||
|
||||
|
@ -69,40 +67,6 @@ public class NvvProvider extends AbstractHafasLegacyProvider {
|
|||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addCustomReplaces(final StringReplaceReader reader) {
|
||||
reader.replace("<ul>", " ");
|
||||
reader.replace("</ul>", " ");
|
||||
reader.replace("<li>", " ");
|
||||
reader.replace("</li>", " ");
|
||||
reader.replace("Park&Ride", "Park&Ride");
|
||||
reader.replace("C&A", "C&A");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Product normalizeType(final String type) {
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if ("U-BAHN".equals(ucType))
|
||||
return Product.SUBWAY;
|
||||
|
||||
if ("AT".equals(ucType)) // Anschluß Sammel Taxi, Anmeldung nicht erforderlich
|
||||
return Product.BUS;
|
||||
if ("LTAXI".equals(ucType))
|
||||
return Product.BUS;
|
||||
|
||||
if ("MOFA".equals(ucType)) // Mobilfalt-Fahrt
|
||||
return Product.ON_DEMAND;
|
||||
|
||||
if ("64".equals(ucType))
|
||||
return null;
|
||||
if ("65".equals(ucType))
|
||||
return null;
|
||||
|
||||
return super.normalizeType(type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,13 +43,7 @@ import de.schildbach.pte.dto.TripOptions;
|
|||
*/
|
||||
public class NvvProviderLiveTest extends AbstractProviderLiveTest {
|
||||
public NvvProviderLiveTest() {
|
||||
super(new NvvProvider());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearbyStations() throws Exception {
|
||||
final NearbyLocationsResult result = queryNearbyStations(new Location(LocationType.STATION, "3000001"));
|
||||
print(result);
|
||||
super(new NvvProvider(secretProperty("nvv.api_authorization")));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -111,80 +105,39 @@ public class NvvProviderLiveTest extends AbstractProviderLiveTest {
|
|||
|
||||
@Test
|
||||
public void shortTrip() throws Exception {
|
||||
|
||||
final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "3000001", null, "Hauptwache"),
|
||||
null, new Location(LocationType.STATION, "3000912", null, "Südbahnhof"), new Date(), true, null);
|
||||
final Location from = new Location(LocationType.STATION, "3000001", null, "Hauptwache");
|
||||
final Location to = new Location(LocationType.STATION, "3000912", null, "Südbahnhof");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
assertEquals(QueryTripsResult.Status.OK, result.status);
|
||||
assertTrue(result.trips.size() > 0);
|
||||
|
||||
if (!result.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
|
||||
if (!laterResult.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult later2Result = queryMoreTrips(laterResult.context, true);
|
||||
print(later2Result);
|
||||
|
||||
if (!later2Result.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult later3Result = queryMoreTrips(later2Result.context, true);
|
||||
print(later3Result);
|
||||
|
||||
if (!later3Result.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult later4Result = queryMoreTrips(later3Result.context, true);
|
||||
print(later4Result);
|
||||
|
||||
if (!later4Result.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult later5Result = queryMoreTrips(later4Result.context, true);
|
||||
print(later5Result);
|
||||
|
||||
if (!later5Result.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult later6Result = queryMoreTrips(later5Result.context, true);
|
||||
print(later6Result);
|
||||
|
||||
if (!result.context.canQueryEarlier())
|
||||
return;
|
||||
|
||||
final QueryTripsResult earlierResult = queryMoreTrips(result.context, false);
|
||||
print(earlierResult);
|
||||
|
||||
if (!earlierResult.context.canQueryEarlier())
|
||||
return;
|
||||
|
||||
final QueryTripsResult earlier2Result = queryMoreTrips(earlierResult.context, false);
|
||||
print(earlier2Result);
|
||||
|
||||
if (!earlier2Result.context.canQueryEarlier())
|
||||
return;
|
||||
|
||||
final QueryTripsResult earlier3Result = queryMoreTrips(earlier2Result.context, false);
|
||||
print(earlier3Result);
|
||||
|
||||
if (!earlier3Result.context.canQueryEarlier())
|
||||
return;
|
||||
|
||||
final QueryTripsResult earlier4Result = queryMoreTrips(earlier3Result.context, false);
|
||||
print(earlier4Result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortTripKassel() throws Exception {
|
||||
final QueryTripsResult result = queryTrips(
|
||||
new Location(LocationType.STATION, "2200007", null, "Kassel Wilhelmshöhe"), null,
|
||||
new Location(LocationType.STATION, "2200278", null, "Kassel Wilhelmshöher Weg"), new Date(), true,
|
||||
null);
|
||||
final Location from = new Location(LocationType.STATION, "2200007", null, "Kassel Wilhelmshöhe");
|
||||
final Location to = new Location(LocationType.STATION, "2200278", null, "Kassel Wilhelmshöher Weg");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
|
@ -192,29 +145,25 @@ public class NvvProviderLiveTest extends AbstractProviderLiveTest {
|
|||
|
||||
@Test
|
||||
public void slowTrip() throws Exception {
|
||||
final TripOptions options = new TripOptions(Product.ALL, null, WalkSpeed.NORMAL, Accessibility.BARRIER_FREE,
|
||||
null);
|
||||
final Location from = new Location(LocationType.STATION, "3029079", Point.from1E6(50017679, 8229480), "Mainz",
|
||||
"An den Dünen");
|
||||
final Location to = new Location(LocationType.STATION, "3013508", Point.from1E6(50142890, 8895203), "Hanau",
|
||||
"Beethovenplatz");
|
||||
final TripOptions options = new TripOptions(Product.ALL, null, WalkSpeed.NORMAL, Accessibility.BARRIER_FREE,
|
||||
null);
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, options);
|
||||
print(result);
|
||||
assertEquals(QueryTripsResult.Status.OK, result.status);
|
||||
assertTrue(result.trips.size() > 0);
|
||||
|
||||
if (!result.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortTripByName() throws Exception {
|
||||
final QueryTripsResult result = queryTrips(
|
||||
new Location(LocationType.ANY, null, null, "Frankfurt Bockenheimer Warte!"), null,
|
||||
new Location(LocationType.ANY, null, null, "Frankfurt Hauptbahnhof!"), new Date(), true, null);
|
||||
final Location from = new Location(LocationType.ANY, null, null, "Frankfurt Bockenheimer Warte!");
|
||||
final Location to = new Location(LocationType.ANY, null, null, "Frankfurt Hauptbahnhof!");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
}
|
||||
|
||||
|
@ -226,10 +175,6 @@ public class NvvProviderLiveTest extends AbstractProviderLiveTest {
|
|||
"Mainzer Landstrasse, Frankfurt");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(1378368840000l), true, null);
|
||||
print(result);
|
||||
|
||||
if (!result.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
}
|
||||
|
@ -242,11 +187,15 @@ public class NvvProviderLiveTest extends AbstractProviderLiveTest {
|
|||
"F Bockenheimer Warte");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(1378368840000l), true, null);
|
||||
print(result);
|
||||
|
||||
if (!result.context.canQueryLater())
|
||||
return;
|
||||
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tripBetweenCoordinates() throws Exception {
|
||||
final Location from = Location.coord(Point.fromDouble(51.3183386, 9.4896007)); // Kassel Hauptbahnhof
|
||||
final Location to = Location.coord(Point.fromDouble(51.3245728, 9.4521398)); // Kassel-Kirchditmold
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# Secrets are needed to run some of the live tests.
|
||||
navitia.authorization =
|
||||
bvg.api_authorization =
|
||||
nvv.api_authorization =
|
||||
vbn.api_authorization =
|
||||
sh.api_authorization =
|
||||
vmt.api_authorization =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue