mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-08 16:18:49 +00:00
Add AVV (Aachen) provider based on Hafas client interface.
This commit is contained in:
parent
b025ca004e
commit
eda7d37b83
4 changed files with 222 additions and 1 deletions
65
enabler/src/de/schildbach/pte/AvvAachenProvider.java
Normal file
65
enabler/src/de/schildbach/pte/AvvAachenProvider.java
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.schildbach.pte;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
import de.schildbach.pte.dto.Product;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class AvvAachenProvider extends AbstractHafasClientInterfaceProvider {
|
||||
private static final HttpUrl API_BASE = HttpUrl.parse("https://auskunft.avv.de/bin/mgate.exe");
|
||||
private static final Product[] PRODUCTS_MAP = { Product.REGIONAL_TRAIN, Product.HIGH_SPEED_TRAIN,
|
||||
Product.HIGH_SPEED_TRAIN, Product.BUS, Product.SUBURBAN_TRAIN, Product.SUBWAY, Product.TRAM, Product.BUS,
|
||||
Product.BUS, Product.ON_DEMAND, Product.FERRY };
|
||||
|
||||
public AvvAachenProvider(final String jsonApiAuthorization) {
|
||||
super(NetworkId.AVV_AACHEN, API_BASE, PRODUCTS_MAP);
|
||||
setApiVersion("1.16");
|
||||
setApiClient("{\"id\":\"AVV_AACHEN\",\"type\":\"AND\"}");
|
||||
setApiAuthorization(jsonApiAuthorization);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitStationName(final String name) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(name);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
return super.splitStationName(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] splitPOI(final String poi) {
|
||||
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(poi);
|
||||
if (m.matches())
|
||||
return new String[] { m.group(1), m.group(2) };
|
||||
return super.splitStationName(poi);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
|
@ -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, VMT, 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, AVV_AACHEN, MVG, VRN, VVS, DING, KVV, VAGFR, NVBW, VVV,
|
||||
|
||||
// Austria
|
||||
OEBB, VAO, VOR, WIEN, OOEVV, LINZ, SVV, VVT, STV, VMOBIL,
|
||||
|
|
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.schildbach.pte.live;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.hasItem;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.schildbach.pte.AvvAachenProvider;
|
||||
import de.schildbach.pte.dto.Location;
|
||||
import de.schildbach.pte.dto.LocationType;
|
||||
import de.schildbach.pte.dto.NearbyLocationsResult;
|
||||
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||
import de.schildbach.pte.dto.QueryTripsResult;
|
||||
import de.schildbach.pte.dto.SuggestLocationsResult;
|
||||
|
||||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class AvvAachenProviderLiveTest extends AbstractProviderLiveTest {
|
||||
public AvvAachenProviderLiveTest() {
|
||||
super(new AvvAachenProvider(secretProperty("avv_aachen.api_authorization")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nearbyStationsByCoordinate() throws Exception {
|
||||
final NearbyLocationsResult result = queryNearbyStations(Location.coord(50767803, 6091504));
|
||||
print(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryDepartures() throws Exception {
|
||||
final QueryDeparturesResult result = queryDepartures("1008", false);
|
||||
assertEquals(QueryDeparturesResult.Status.OK, result.status);
|
||||
print(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryDeparturesInvalidStation() throws Exception {
|
||||
final QueryDeparturesResult result = queryDepartures("999999", false);
|
||||
assertEquals(QueryDeparturesResult.Status.INVALID_STATION, result.status);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void suggestLocations() throws Exception {
|
||||
final SuggestLocationsResult result = suggestLocations("Aachen Hbf");
|
||||
print(result);
|
||||
assertThat(result.getLocations(), hasItem(new Location(LocationType.STATION, "1008", "Aachen", "Hbf")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void suggestLocationsUmlaut() throws Exception {
|
||||
final SuggestLocationsResult result = suggestLocations("Gaßmühle");
|
||||
print(result);
|
||||
assertThat(result.getLocations(), hasItem(new Location(LocationType.STATION, "1576", "Aachen", "Gaßmühle")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void suggestLocationsPOI() throws Exception {
|
||||
final SuggestLocationsResult result = suggestLocations("Suermondt-Ludwig-Museum");
|
||||
print(result);
|
||||
assertThat(result.getLocations(), hasItem(new Location(LocationType.POI,
|
||||
"A=4@O=Aachen, Suermondt Ludwig Museum@X=6095720@Y=50773376@U=105@L=009900147@B=1@p=1515630730@")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void suggestLocationsAddress() throws Exception {
|
||||
final SuggestLocationsResult result = suggestLocations("Theaterstraße 49");
|
||||
print(result);
|
||||
assertEquals("Aachen", result.getLocations().get(0).place);
|
||||
assertEquals("Theaterstraße 49", result.getLocations().get(0).name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortTrip() throws Exception {
|
||||
final Location from = new Location(LocationType.STATION, "1008", "Aachen", "Hbf");
|
||||
final Location to = new Location(LocationType.STATION, "1016", "Aachen", "Schanz");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
final QueryTripsResult later2Result = queryMoreTrips(laterResult.context, true);
|
||||
print(later2Result);
|
||||
final QueryTripsResult earlierResult = queryMoreTrips(later2Result.context, false);
|
||||
print(earlierResult);
|
||||
final QueryTripsResult later3Result = queryMoreTrips(earlierResult.context, true);
|
||||
print(later3Result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shortViaTrip() throws Exception {
|
||||
final Location from = new Location(LocationType.STATION, "1008", "Aachen", "Hbf");
|
||||
final Location via = new Location(LocationType.STATION, "1341", "Aachen", "Kellerhausstraße");
|
||||
final Location to = new Location(LocationType.STATION, "3339", "Gulpen", "Busstation");
|
||||
final QueryTripsResult result = queryTrips(from, via, to, new Date(), true, null);
|
||||
print(result);
|
||||
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||
print(laterResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tripBetweenStations() throws Exception {
|
||||
final Location from = new Location(LocationType.STATION, "1008", "Aachen", "Hbf");
|
||||
final Location to = new Location(LocationType.STATION, "3339", "Gulpen", "Busstation");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tripBetweenCoordinates() throws Exception {
|
||||
final Location from = Location.coord(50767803, 6091504); // Aachen Hbf
|
||||
final Location to = Location.coord(50769870, 6073840); // Aachen, Schanz
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
assertEquals("1008", result.from.id);
|
||||
assertEquals("1016", result.to.id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tripBetweenAddresses() throws Exception {
|
||||
final Location from = new Location(LocationType.ADDRESS, null, "Aachen", "Theaterstraße 49");
|
||||
final Location to = new Location(LocationType.ADDRESS, null, "Aachen", "Jakobstraße 109");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tripWithoutId() throws Exception {
|
||||
final Location from = new Location(LocationType.STATION, null, "Aachen", "Hbf");
|
||||
final Location to = new Location(LocationType.STATION, null, "Aachen", "Schanz");
|
||||
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
|
||||
print(result);
|
||||
assertEquals("1008", result.from.id);
|
||||
assertEquals("1016", result.to.id);
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ vbn.api_authorization =
|
|||
sh.api_authorization =
|
||||
vmt.api_authorization =
|
||||
invg.api_authorization =
|
||||
avv_aachen.api_authorization =
|
||||
vor.api_authorization =
|
||||
ooevv.api_authorization =
|
||||
svv.api_authorization =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue