From 4b6b09ce52a5cd597af789237ddb7674624243c0 Mon Sep 17 00:00:00 2001 From: Stefan Kalscheuer Date: Tue, 27 Dec 2016 16:07:35 +0100 Subject: [PATCH] getTrips() tested --- pom.xml | 2 +- .../de/stklcode/pubtrans/ura/model/Trip.java | 40 +++++++++ .../stklcode/pubtrans/ura/UraClientTest.java | 88 +++++++++++++++++++ .../pubtrans/ura/instant_trips_all.txt | 11 +++ .../pubtrans/ura/instant_trips_line.txt | 11 +++ .../pubtrans/ura/instant_trips_stop.txt | 11 +++ .../pubtrans/ura/instant_trips_stop_line.txt | 11 +++ 7 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/de/stklcode/pubtrans/ura/instant_trips_all.txt create mode 100644 src/test/resources/de/stklcode/pubtrans/ura/instant_trips_line.txt create mode 100644 src/test/resources/de/stklcode/pubtrans/ura/instant_trips_stop.txt create mode 100644 src/test/resources/de/stklcode/pubtrans/ura/instant_trips_stop_line.txt diff --git a/pom.xml b/pom.xml index ec4defa..c6adc3c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 de.stklcode.pubtrans - ura-connector + juraclien 1.0.0-SNAPSHOT diff --git a/src/main/java/de/stklcode/pubtrans/ura/model/Trip.java b/src/main/java/de/stklcode/pubtrans/ura/model/Trip.java index 9b2df24..45e59d9 100644 --- a/src/main/java/de/stklcode/pubtrans/ura/model/Trip.java +++ b/src/main/java/de/stklcode/pubtrans/ura/model/Trip.java @@ -82,4 +82,44 @@ public class Trip { else throw new IOException("Field 15 not of expected type Long, found " + raw.get(15).getClass().getSimpleName()); } + + public Stop getStop() { + return stop; + } + + public String getId() { + return id; + } + + public Integer getVisitID() { + return visitID; + } + + public String getLineID() { + return lineID; + } + + public String getLineName() { + return lineName; + } + + public Integer getDirectionID() { + return directionID; + } + + public String getDestinationName() { + return destinationName; + } + + public String getDestinationText() { + return destinationText; + } + + public Long getEstimatedTime() { + return estimatedTime; + } + + public String getVehicleID() { + return vehicleID; + } } diff --git a/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java b/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java index 3541077..56a446a 100644 --- a/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java +++ b/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java @@ -1,6 +1,7 @@ package de.stklcode.pubtrans.ura; import de.stklcode.pubtrans.ura.model.Stop; +import de.stklcode.pubtrans.ura.model.Trip; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; @@ -9,11 +10,17 @@ import org.powermock.modules.junit4.PowerMockRunner; import java.net.URL; import java.util.List; +import java.util.Optional; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.core.Is.is; +/** + * Unit test for the URA Client. + * Tests run against mocked data collected from hte ASEAG API (http://ivu.aseag.de/) + * + */ @RunWith(PowerMockRunner.class) @PrepareForTest({ UraClient.class, URL.class }) public class UraClientTest { @@ -35,4 +42,85 @@ public class UraClientTest { assertThat(stops.get(3).getLatitude(), is(50.7578775)); assertThat(stops.get(4).getLongitude(), is(6.0708663)); } + + @Test + public void getTripsTest() 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_trips_all.txt")); + + /* Get trips without filters and verify some values */ + List trips = new UraClient("mocked").getTrips(); + assertThat(trips, hasSize(10)); + assertThat(trips.get(0).getId(), is("27000165015001")); + assertThat(trips.get(1).getLineID(), is("55")); + assertThat(trips.get(2).getLineName(), is("28"));; + assertThat(trips.get(3).getDirectionID(), is(1)); + assertThat(trips.get(4).getDestinationName(), is("Verlautenheide Endstr.")); + assertThat(trips.get(5).getDestinationText(), is("Aachen Bushof")); + assertThat(trips.get(6).getVehicleID(), is("247")); + assertThat(trips.get(7).getEstimatedTime(), is(1482854580000L)); + assertThat(trips.get(8).getVisitID(), is(30)); + assertThat(trips.get(9).getStop().getId(), is("100002")); + } + + @Test + public void getTripsForStopTest() 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_trips_stop.txt")); + + /* Get trips for stop ID 100000 (Aachen Bushof) and verify some values */ + List trips = new UraClient("mocked") + .forStops("100000") + .getTrips(); + assertThat(trips, hasSize(10)); + assertThat(trips.stream().filter(t -> !t.getStop().getId().equals("100000")).findAny(), is(Optional.empty())); + assertThat(trips.get(0).getId(), is("27000158010001")); + assertThat(trips.get(1).getLineID(), is("7")); + assertThat(trips.get(2).getLineName(), is("25"));; + assertThat(trips.get(3).getStop().getIndicator(), is("H.15")); + } + + @Test + public void getTripsForLine() 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_trips_line.txt")); + + /* Get trips for line ID 3 and verify some values */ + List trips = new UraClient("mocked") + .forLines("3") + .getTrips(); + assertThat(trips, hasSize(10)); + assertThat(trips.stream().filter(t -> !t.getLineID().equals("3")).findAny(), is(Optional.empty())); + assertThat(trips.get(0).getId(), is("27000154004001")); + assertThat(trips.get(1).getLineID(), is("3")); + assertThat(trips.get(2).getLineName(), is("3.A"));; + assertThat(trips.get(3).getStop().getIndicator(), is("H.4 (Pontwall)")); + } + + @Test + public void getTripsForStopAndLine() 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_trips_stop_line.txt")); + + /* Get trips for line ID 25 and 25 at stop 100000 and verify some values */ + List trips = new UraClient("mocked") + .forLines("25", "35") + .forStops("100000") + .getTrips(); + assertThat(trips, hasSize(10)); + assertThat(trips.stream().filter(t -> !t.getLineID().equals("25") && !t.getLineID().equals("35")).findAny(), is(Optional.empty())); + assertThat(trips.stream().filter(t -> !t.getStop().getId().equals("100000")).findAny(), is(Optional.empty())); + assertThat(trips.get(0).getId(), is("27000078014001")); + assertThat(trips.get(1).getLineID(), is("25")); + assertThat(trips.get(3).getLineName(), is("35"));; + assertThat(trips.get(5).getStop().getIndicator(), is("H.12")); + } } diff --git a/src/test/resources/de/stklcode/pubtrans/ura/instant_trips_all.txt b/src/test/resources/de/stklcode/pubtrans/ura/instant_trips_all.txt new file mode 100644 index 0000000..4ecbea0 --- /dev/null +++ b/src/test/resources/de/stklcode/pubtrans/ura/instant_trips_all.txt @@ -0,0 +1,11 @@ +[4,"2.0",1482850556146] +[1,"Fischbachstraße","215812","",0,50.73893,6.2666311,6,"8","8",1,"Eschweiler Bushof","Eschweiler Bushof","0","27000165015001",1482856620000] +[1,"Wolferskaul","100322","",0,50.7439086,6.1594241,19,"55","55",1,"Aachen Elisenbrunnen","Aachen Elisenbrunnen","619","27000229015001",1482852180000] +[1,"Lindenallee","213227","",0,50.8271524,6.3194636,8,"28","28",1,"Alsdorf Annapark","Alsdorf Annapark","519","27000190012001",1482853140000] +[1,"Karlsgraben","100024","",0,50.7728605,6.0766513,6,"5","5",1,"Driescher Hof-Brand","Driescher Hof-Brand","0","27000283012001",1482855960000] +[1,"Eilendorf Bahnhof","100246","",0,50.7855477,6.1521783,61,"57","57",1,"Verlautenheide Endstr.","Verlautenheide Endstr.","528","27000200015001",1482855908000] +[1,"Elisenbrunnen","100001","H.1",0,50.7747372,6.0879925,24,"34","34",1,"Aachen Bushof","Aachen Bushof","670","27000237013001",1482854520000] +[1,"Schneidmühle","215602","",0,50.7847038,6.2190627,42,"22","22",1,"Stolberg Mühlener Bf.","Stolberg Mühlener Bf.","247","27000118005001",1482855180000] +[1,"Dechant-Brock-Str.","215824","",0,50.7592927,6.2735355,22,"1","1",1,"Lintert Friedhof","Lintert Friedhof","268","27000102007001",1482854580000] +[1,"Am Tiergarten","100382","",0,50.755833,6.1689597,30,"34","34",1,"Brand","Brand","0","27000224012001",1482854040000] +[1,"Hansemannplatz","100002","H.1",0,50.7784794,6.0959816,26,"51","51",1,"Aachen Bushof","Aachen Bushof","603","27000230015001",1482854400000] diff --git a/src/test/resources/de/stklcode/pubtrans/ura/instant_trips_line.txt b/src/test/resources/de/stklcode/pubtrans/ura/instant_trips_line.txt new file mode 100644 index 0000000..d10daaa --- /dev/null +++ b/src/test/resources/de/stklcode/pubtrans/ura/instant_trips_line.txt @@ -0,0 +1,11 @@ +[4,"2.0",1482854839773] +[1,"Seffenter Weg","100643","",0,50.7820069,6.0644119,19,"3","3.A",1,"Uniklinik-Schanz-Hbf.","Uniklinik-Schanz-Hbf.","317","27000154004001",1482855824000] +[1,"Normaluhr","100009","H.5 (Wilhelmstr.)",0,50.7680616,6.094883,9,"3","3.A",1,"Ponttor-Unikl.-Schanz","Ponttor-Unikl.-Schanz","226","27000134003001",1482855960000] +[1,"Uniklinik","100600","H.1",0,50.7756388,6.04425,5,"3","3.A",1,"Uniklinik-Schanz-Hbf.","Uniklinik-Schanz-Hbf.","226","27000134002001",1482854820000] +[1,"Ponttor","100005","H.4 (Pontwall)",0,50.7808611,6.0779722,15,"3","3.A",1,"Uniklinik-Schanz-Hbf.","Uniklinik-Schanz-Hbf.","226","27000134003001",1482856500000] +[1,"Stiewistraße","100630","",0,50.78029,6.05058,25,"3","3.A",1,"Uniklinik-Schanz-Hbf.","Uniklinik-Schanz-Hbf.","226","27000134004001",1482859800000] +[1,"Misereor","100010","",0,50.7685583,6.0833027,7,"3","3.A",1,"Hbf.-Ponttor-Uniklinik","Hbf.-Ponttor-Uniklinik","0","27000134005001",1482861060000] +[1,"Wendlingweg","100646","",0,50.7773216,6.0504405,26,"3","3.A",1,"Uniklinik-Schanz-Hbf.","Uniklinik-Schanz-Hbf.","338","27000128004001",1482858060000] +[1,"Hörn Brücke","100627","",0,50.7871194,6.051875,22,"3","3.A",1,"Uniklinik-Schanz-Hbf.","Uniklinik-Schanz-Hbf.","0","27000141015001",1482861420000] +[1,"Forckenbeckstraße","100628","",0,50.78534,6.05054,23,"3","3.A",1,"Uniklinik-Schanz-Hbf.","Uniklinik-Schanz-Hbf.","338","27000128003001",1482855127000] +[1,"Hörn Brücke","100627","",0,50.7871194,6.051875,22,"3","3.A",1,"Uniklinik-Schanz-Hbf.","Uniklinik-Schanz-Hbf.","338","27000128003001",1482855067000] diff --git a/src/test/resources/de/stklcode/pubtrans/ura/instant_trips_stop.txt b/src/test/resources/de/stklcode/pubtrans/ura/instant_trips_stop.txt new file mode 100644 index 0000000..0068950 --- /dev/null +++ b/src/test/resources/de/stklcode/pubtrans/ura/instant_trips_stop.txt @@ -0,0 +1,11 @@ +[4,"2.0",1482854457011] +[1,"Aachen Bushof","100000","H.13",0,50.7775936,6.0908191,20,"1","1",1,"Schevenhütte","Schevenhütte","565","27000158010001",1482854446000] +[1,"Aachen Bushof","100000","H.2",0,50.7775936,6.0908191,8,"7","7",1,"Aachen Bushof","Aachen Bushof","514","27000210017001",1482854400000] +[1,"Aachen Bushof","100000","H.11",0,50.7775936,6.0908191,30,"25","25",1,"Vaals Busstation","Vaals Busstation","0","27000171010001",1482854460000] +[1,"Aachen Bushof","100000","H.15",0,50.7775936,6.0908191,17,"47","47",1,"Aachen Bushof","Aachen Bushof","258","27000139003001",1482854460000] +[1,"Aachen Bushof","100000","H.15",0,50.7775936,6.0908191,1,"7","7",1,"Aachen Diepenbenden","Aachen Diepenbenden","257","27000089026001",1482854454000] +[1,"Aachen Bushof","100000","H.12",0,50.7775936,6.0908191,17,"2","2",1,"Eilendorf Schubertstr.","Eilendorf Schubertstr.","221","27000039021001",1482854445000] +[1,"Aachen Bushof","100000","H.11",0,50.7775936,6.0908191,28,"12","12",1,"Campus Melaten","Campus Melaten","298","27000062010001",1482854451000] +[1,"Aachen Bushof","100000","H.1",0,50.7775936,6.0908191,27,"51","51",1,"Aachen Bushof","Aachen Bushof","603","27000230015001",1482854801000] +[1,"Aachen Bushof","100000","H.15",0,50.7775936,6.0908191,1,"43","43",1,"Hüls Schulz+Elleter F.","Hüls Schulz+Elleter F.","258","27000139004001",1482854520000] +[1,"Aachen Bushof","100000","H.15",0,50.7775936,6.0908191,25,"33","33",1,"Aachen Fuchserde","Aachen Fuchserde","286","27000033017001",1482854459000] diff --git a/src/test/resources/de/stklcode/pubtrans/ura/instant_trips_stop_line.txt b/src/test/resources/de/stklcode/pubtrans/ura/instant_trips_stop_line.txt new file mode 100644 index 0000000..5e1c3e5 --- /dev/null +++ b/src/test/resources/de/stklcode/pubtrans/ura/instant_trips_stop_line.txt @@ -0,0 +1,11 @@ +[4,"2.0",1482855134910] +[1,"Aachen Bushof","100000","H.11",0,50.7775936,6.0908191,32,"35","35",1,"Vaals Grenze","Vaals Grenze","346","27000078014001",1482855350000] +[1,"Aachen Bushof","100000","H.12",0,50.7775936,6.0908191,15,"25","25",1,"Stolberg Mühlener Bf.","Stolberg Mühlener Bf.","334","27000268014001",1482856194000] +[1,"Aachen Bushof","100000","H.11",0,50.7775936,6.0908191,30,"25","25",1,"Vaals Busstation","Vaals Busstation","242","27000270010001",1482856248000] +[1,"Aachen Bushof","100000","H.12",0,50.7775936,6.0908191,14,"35","35",1,"Breinig Entengasse","Breinig Entengasse","248","27000074012001",1482856740000] +[1,"Aachen Bushof","100000","H.11",0,50.7775936,6.0908191,32,"35","35",1,"Vaals Grenze","Vaals Grenze","294","27000076010001",1482857507000] +[1,"Aachen Bushof","100000","H.12",0,50.7775936,6.0908191,15,"25","25",1,"Stolberg Mühlener Bf.","Stolberg Mühlener Bf.","0","27000171011001",1482857640000] +[1,"Aachen Bushof","100000","H.11",0,50.7775936,6.0908191,30,"25","25",1,"Vaals Busstation","Vaals Busstation","191","27000032012001",1482858057000] +[1,"Aachen Bushof","100000","H.12",0,50.7775936,6.0908191,14,"35","35",1,"Breinig Entengasse","Breinig Entengasse","346","27000078015001",1482858540000] +[1,"Aachen Bushof","100000","H.12",0,50.7775936,6.0908191,15,"25","25",1,"Stolberg Mühlener Bf.","Stolberg Mühlener Bf.","242","27000270011001",1482859440000] +[1,"Aachen Bushof","100000","H.11",0,50.7775936,6.0908191,30,"25","25",1,"Vaals Busstation","Vaals Busstation","187","27000060013001",1482859860000]