Implement stream reader for trips (#1)
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2016-2018 Stefan Kalscheuer
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package de.stklcode.pubtrans.ura.reader;
|
||||
|
||||
import de.stklcode.pubtrans.ura.UraClientTest;
|
||||
import de.stklcode.pubtrans.ura.model.Trip;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
|
||||
/**
|
||||
* Unit test for the asynchronous URA Trip reader.
|
||||
*
|
||||
* @author Stefan Kalscheuer
|
||||
*/
|
||||
public class AsyncUraTripReaderTest {
|
||||
|
||||
@Test
|
||||
public void readerTest() throws InterruptedException, MalformedURLException {
|
||||
// The list which will be populated by the callback.
|
||||
List<Trip> trips = new ArrayList<>();
|
||||
|
||||
// Start with V1 data.
|
||||
AsyncUraTripReader tr = new AsyncUraTripReader(
|
||||
UraClientTest.class.getResource("stream_V1_stops_all.txt"),
|
||||
Collections.singletonList(trips::add)
|
||||
);
|
||||
|
||||
// Read for 2 seconds before closing.
|
||||
tr.open();
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
tr.close();
|
||||
|
||||
assertThat("Trips should not be empty after 1s", trips, is(not(empty())));
|
||||
assertThat("Unexpected number of trips after 1s", trips.size(), is(7));
|
||||
|
||||
// Clear trip list and repeat with V2 data.
|
||||
trips.clear();
|
||||
tr = new AsyncUraTripReader(
|
||||
UraClientTest.class.getResource("stream_V2_stops_all.txt"),
|
||||
Collections.singletonList(trips::add)
|
||||
);
|
||||
|
||||
// Read for 2 seconds before closing.
|
||||
tr.open();
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
tr.close();
|
||||
|
||||
assertThat("Trips should not be empty after 1s", trips, is(not(empty())));
|
||||
assertThat("Unexpected number of trips after 1s", trips.size(), is(7));
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
[4,"1.0",1542370828725]
|
||||
[1,"Campus Melaten","100629","",0,50.78247,6.05053,4,"764","3B","2","Ponttor-Hbf.-Schanz","Ponttor-Hbf.-Schanz","327001",16000304013001,1542375720000]
|
||||
[1,"Eckenerstraße","100308","",0,50.7539658,6.1541161,15,"65","65","2","Elisenbrunnen","Elisenbrunnen","301001",16000428004001,1542372660000]
|
||||
[1,"Talbot","100111","",0,50.7845802,6.1093236,51,"1","1","2","Süsterau-Uniklinik","Süsterau-Uniklinik","305001",16000351007001,1542372900000]
|
||||
[1,"Herz. Schulzentrum","210541","",0,50.8642111,6.1053944,1,"831","HZ1","1","Hofstadt","Hofstadt","737001",16000212021001,1542375000000]
|
||||
[1,"Weisweiler Ziegelei","213237","",0,50.8254738,6.325058,14,"96","96","1","Langerwehe Schulzentr.","Langerwehe Schulzentr.",null,16000417012001,1542373320000]
|
||||
[1,"Pongs","100233","",0,50.7725688,6.1285466,24,"7","7","2","Eilendorf Am Tunnel","Eilendorf Am Tunnel","540001",16000444014001,1542377460000]
|
||||
[1,"Velau","215624","",0,50.7893811,6.2223038,17,"8","8","2","Stolberg Mühlener Bf.","Stolberg Mühlener Bf.","568001",16000319014001,1542374400000]
|
@@ -0,0 +1,8 @@
|
||||
[4,"2.0",1542370788379]
|
||||
[1,"Campus Melaten","100629","",0,50.78247,6.05053,4,"764","3B","2","Ponttor-Hbf.-Schanz","Ponttor-Hbf.-Schanz","327001","16000304013001",1542375720000]
|
||||
[1,"Eckenerstraße","100308","",0,50.7539658,6.1541161,15,"65","65","2","Elisenbrunnen","Elisenbrunnen","301001","16000428004001",1542372660000]
|
||||
[1,"Talbot","100111","",0,50.7845802,6.1093236,51,"1","1","2","Süsterau-Uniklinik","Süsterau-Uniklinik","305001","16000351007001",1542372900000]
|
||||
[1,"Herz. Schulzentrum","210541","",0,50.8642111,6.1053944,1,"831","HZ1","1","Hofstadt","Hofstadt","737001","16000212021001",1542375000000]
|
||||
[1,"Weisweiler Ziegelei","213237","",0,50.8254738,6.325058,14,"96","96","1","Langerwehe Schulzentr.","Langerwehe Schulzentr.",null,"16000417012001",1542373320000]
|
||||
[1,"Pongs","100233","",0,50.7725688,6.1285466,24,"7","7","2","Eilendorf Am Tunnel","Eilendorf Am Tunnel","540001","16000444014001",1542377460000]
|
||||
[1,"Velau","215624","",0,50.7893811,6.2223038,17,"8","8","2","Stolberg Mühlener Bf.","Stolberg Mühlener Bf.","568001","16000319014001",1542374400000]
|
Reference in New Issue
Block a user