Search in sources :

Example 1 with GTFS

use of org.opentripplanner.datastore.FileType.GTFS in project OpenTripPlanner by opentripplanner.

the class ZipFileDataSourceTest method testIO.

@Test
public void testIO() throws IOException {
    // Given:
    File target = new File(FILENAME);
    CompositeDataSource subject = new ZipFileDataSource(target, GTFS);
    Collection<DataSource> content = subject.content();
    Collection<String> names = content.stream().map(it -> it.name()).collect(Collectors.toList());
    // System.out.println(names);
    assertTrue(names.toString(), names.containsAll(List.of("agency.txt", "stops.txt", "trips.txt")));
    DataSource entry = subject.entry("agency.txt");
    List<String> lines = IOUtils.readLines(entry.asInputStream(), StandardCharsets.UTF_8);
    assertEquals("agency_id,agency_name,agency_url,agency_timezone", lines.get(0));
    assertEquals("Caltrain,Caltrain,http://www.caltrain.com,America/Los_Angeles", lines.get(1));
    // Close zip
    subject.close();
}
Also used : Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) GTFS(org.opentripplanner.datastore.FileType.GTFS) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) DataSource(org.opentripplanner.datastore.DataSource) ConstantsForTests(org.opentripplanner.ConstantsForTests) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) Assert.fail(org.junit.Assert.fail) Assert.assertEquals(org.junit.Assert.assertEquals) File(java.io.File) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) DataSource(org.opentripplanner.datastore.DataSource) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) Test(org.junit.Test)

Example 2 with GTFS

use of org.opentripplanner.datastore.FileType.GTFS in project OpenTripPlanner by opentripplanner.

the class ZipStreamDataSourceDecoratorTest method testIO.

@Test
public void testIO() throws IOException {
    // Given:
    File target = new File(FILENAME);
    CompositeDataSource subject = new ZipStreamDataSourceDecorator(new FileDataSource(target, GTFS));
    Collection<DataSource> content = subject.content();
    Collection<String> names = content.stream().map(it -> it.name()).collect(Collectors.toList());
    System.out.println(names);
    assertTrue(names.toString(), names.containsAll(List.of("trips.txt", "agency.txt", "calendar.txt", "calendar_dates.txt", "fare_attributes.txt", "fare_rules.txt", "routes.txt", "shapes.txt", "stop_times.txt", "stops.txt")));
    DataSource entry = subject.entry("agency.txt");
    List<String> lines = IOUtils.readLines(entry.asInputStream(), StandardCharsets.UTF_8);
    assertEquals("agency_id,agency_name,agency_url,agency_timezone", lines.get(0));
    // Close zip
    subject.close();
}
Also used : Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) FileDataSource(org.opentripplanner.datastore.file.FileDataSource) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) GTFS(org.opentripplanner.datastore.FileType.GTFS) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) DataSource(org.opentripplanner.datastore.DataSource) ConstantsForTests(org.opentripplanner.ConstantsForTests) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) Assert.assertEquals(org.junit.Assert.assertEquals) FileDataSource(org.opentripplanner.datastore.file.FileDataSource) File(java.io.File) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) FileDataSource(org.opentripplanner.datastore.file.FileDataSource) DataSource(org.opentripplanner.datastore.DataSource) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) Test(org.junit.Test)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Collection (java.util.Collection)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 IOUtils (org.apache.commons.io.IOUtils)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Test (org.junit.Test)2 ConstantsForTests (org.opentripplanner.ConstantsForTests)2 CompositeDataSource (org.opentripplanner.datastore.CompositeDataSource)2 DataSource (org.opentripplanner.datastore.DataSource)2 GTFS (org.opentripplanner.datastore.FileType.GTFS)2 Assert.fail (org.junit.Assert.fail)1 FileDataSource (org.opentripplanner.datastore.file.FileDataSource)1