getStops() with filters

This commit is contained in:
Stefan Kalscheuer 2017-01-02 15:24:35 +01:00
parent ef7423e4ca
commit 3bc11bdee5
3 changed files with 87 additions and 2 deletions
src
main/java/de/stklcode/pubtrans/ura
test
java/de/stklcode/pubtrans/ura
resources/de/stklcode/pubtrans/ura

@ -193,13 +193,23 @@ public class UraClient {
}
/**
* List available stopIDs.
* Get list of stops without filters.
*
* @return the list
*/
public List<Stop> getStops() {
return getStops(new Query());
}
/**
* List available stopIDs.
* If forStops() and/or forLines() has been called, those will be used as filter.
*
* @return the list
*/
public List<Stop> getStops(Query query) {
List<Stop> stops = new ArrayList<>();
try (InputStream is = requestInstant(REQUEST_STOP, null, null, null, null, null);
try (InputStream is = requestInstant(REQUEST_STOP, query.stopIDs, query.stopNames, query.lineIDs, query.lineNames, query.direction);
BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
String line;
while ((line = br.readLine()) != null) {
@ -302,6 +312,15 @@ public class UraClient {
return this;
}
/**
* Get stops for set filters.
*
* @return List of matching trips
*/
public List<Stop> getStops() {
return UraClient.this.getStops(this);
}
/**
* Get trips for set filters.
*

@ -70,6 +70,24 @@ public class UraClientTest {
assertThat(new UraClient("mocked").getStops(), hasSize(0));
}
@Test
public void getStopsForLineTest() throws Exception {
/* Mock the HTTP call */
URL mockURL = PowerMockito.mock(URL.class);
PowerMockito.whenNew(URL.class).withAnyArguments().thenReturn(mockURL);
PowerMockito.when(mockURL.openStream()).thenReturn(getClass().getResourceAsStream("instant_stops_line.txt"));
/* List stops and verify some values */
List<Stop> stops = new UraClient("mocked").forLines("33").getStops();
assertThat(stops, hasSize(47));
assertThat(stops.get(0).getId(), is("100000"));
assertThat(stops.get(1).getName(), is("Kuckelkorn"));
assertThat(stops.get(2).getState(), is(0));;
assertThat(stops.get(3).getLatitude(), is(50.7690688));
assertThat(stops.get(4).getIndicator(), is("H.1"));
assertThat(stops.get(5).getLongitude(), is(6.2314072));
}
@Test
public void getTripsTest() throws Exception {
/* Mock the HTTP call */

@ -0,0 +1,48 @@
[4,"2.0",1483366286728]
[0,"Aachen Bushof","100000","H.1",0,50.7775936,6.0908191]
[0,"Kuckelkorn","100602","",0,50.7700072,6.0626944]
[0,"Scheibenstraße","100051","",0,50.7744208,6.10152]
[0,"Püngelerstraße","100609","",0,50.7690688,6.0247316]
[0,"Elisenbrunnen","100001","H.1",0,50.7747372,6.0879925]
[0,"Finkensief","215508","",0,50.7605258,6.2314072]
[0,"Bahnhof Rothe Erde","100302","",0,50.7699361,6.1178416]
[0,"Aachen Gartenstraße","100601","",0,50.7704169,6.0695841]
[0,"Kolpingstraße","100311","",0,50.7506691,6.1715483]
[0,"Adenauerallee","100304","",0,50.766538,6.127538]
[0,"Büsbach Aachener Straße","215923","",0,50.758498,6.2153119]
[0,"Westfriedhof","100604","",0,50.7692586,6.0497513]
[0,"Mühlener Bahnhof","215500","H.1",0,50.7734847,6.2240144]
[0,"Hansemannplatz","100002","H.4",0,50.7784794,6.0959816]
[0,"Zeppelinstraße","100303","",0,50.7677477,6.1228494]
[0,"Brand","100310","",0,50.7494283,6.16572]
[0,"Venskyhäuschen","100603","",0,50.7689588,6.0560022]
[0,"Bischofstraße","215922","",0,50.7575197,6.2193038]
[0,"Brand Ringstraße","100309","",0,50.7519583,6.160035]
[0,"Kaiserplatz","100003","H.1",0,50.77451,6.09563]
[0,"Josefskirche","100052","",0,50.7746669,6.1074288]
[0,"Eilendorfer Straße","100312","",0,50.7518747,6.1769938]
[0,"Reutershag","100606","",0,50.7698647,6.0396447]
[0,"Stolberg Rathaus","215506","",0,50.7695202,6.2287016]
[0,"Büsbach Kirche","215925","",0,50.7514783,6.2147552]
[0,"Schönforst","100305","",0,50.7626019,6.1345288]
[0,"Schanz","100012","H.2 (Boxgraben)",0,50.76891,6.074498]
[0,"Büsbach Markt","215924","",0,50.7557252,6.2174675]
[0,"Trierer Platz","100306","",0,50.7602225,6.1398791]
[0,"Steppenberg","100605","",0,50.7696838,6.0427633]
[0,"Vaals Busstation","725000","Hst. A",0,50.772108,6.0210191]
[0,"Keltenstraße","100608","",0,50.7690502,6.0276094]
[0,"Goertzbrunnstraße","100313","",0,50.7526244,6.1804261]
[0,"Elgermühle","215927","",0,50.75483,6.2004438]
[0,"Stolberg Altstadt","215507","",0,50.7654055,6.2320975]
[0,"Freund","100314","",0,50.7531063,6.1826952]
[0,"Königsberger Str.","100307","",0,50.7569527,6.1472138]
[0,"Annastraße","100027","",0,50.7725855,6.0800072]
[0,"Elsassstraße","100053","",0,50.7723686,6.1136894]
[0,"Schmiedgasse","100607","",0,50.7686708,6.0338744]
[0,"Alter Posthof","100026","",0,50.7722052,6.0837347]
[0,"Büsbach Friedhof","215926","",0,50.7512988,6.2096533]
[0,"Eckenerstraße","100308","",0,50.7539658,6.1541161]
[0,"Rosental","215504","",0,50.7722116,6.2268719]
[0,"Vaals Grenze","100610","",0,50.7706958,6.0255975]
[0,"Büsbacher Berg","215921","",0,50.758643,6.2242836]
[0,"Karlsgraben","100024","",0,50.7728605,6.0766513]