Search in sources :

Example 11 with DataSource

use of org.opentripplanner.datastore.DataSource in project OpenTripPlanner by opentripplanner.

the class ByteArrayDataSourceTest method asInputStream.

@Test
public void asInputStream() throws IOException {
    DataSource subject = new ByteArrayDataSource(PATH, NAME, TYPE, SIZE, LAST_MODIFIED, false).withBytes(BYTES);
    assertEquals(BYTES, subject.asBytes());
    assertEquals(DATA, IOUtils.toString(subject.asInputStream(), UTF_8));
}
Also used : DataSource(org.opentripplanner.datastore.DataSource) Test(org.junit.Test)

Example 12 with DataSource

use of org.opentripplanner.datastore.DataSource in project OpenTripPlanner by opentripplanner.

the class ZipStreamDataSourceDecoratorTest method testEntryProperties.

@Test
public void testEntryProperties() {
    // Given:
    File target = new File(FILENAME);
    CompositeDataSource subject = new ZipStreamDataSourceDecorator(new FileDataSource(target, GTFS));
    DataSource entry = subject.entry("trips.txt");
    assertEquals("trips.txt", entry.name());
    assertEquals("trips.txt (" + subject.path() + ")", entry.path());
    assertEquals(GTFS, entry.type());
    assertTrue("Last modified: " + entry.lastModified(), entry.lastModified() > TIME);
    assertTrue("Size: " + entry.size(), entry.size() > 100);
    assertTrue(entry.exists());
    // We do not support writing to zip entries
    assertFalse(entry.isWritable());
}
Also used : 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)

Example 13 with DataSource

use of org.opentripplanner.datastore.DataSource 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 14 with DataSource

use of org.opentripplanner.datastore.DataSource 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)

Example 15 with DataSource

use of org.opentripplanner.datastore.DataSource in project OpenTripPlanner by opentripplanner.

the class TriangleInequalityTest method onlyOnce.

@BeforeClass
public static void onlyOnce() {
    extra = new HashMap<>();
    graph = new Graph();
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    File file = new File(URLDecoder.decode(TriangleInequalityTest.class.getResource("NYC_small.osm.pbf").getFile(), StandardCharsets.UTF_8));
    DataSource source = new FileDataSource(file, FileType.OSM);
    BinaryOpenStreetMapProvider provider = new BinaryOpenStreetMapProvider(source, true);
    loader.setProvider(provider);
    loader.buildGraph(graph, extra);
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) FileDataSource(org.opentripplanner.datastore.file.FileDataSource) BinaryOpenStreetMapProvider(org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider) File(java.io.File) FileDataSource(org.opentripplanner.datastore.file.FileDataSource) DataSource(org.opentripplanner.datastore.DataSource) BeforeClass(org.junit.BeforeClass)

Aggregations

DataSource (org.opentripplanner.datastore.DataSource)19 CompositeDataSource (org.opentripplanner.datastore.CompositeDataSource)13 Test (org.junit.Test)11 File (java.io.File)7 ArrayList (java.util.ArrayList)3 FileDataSource (org.opentripplanner.datastore.file.FileDataSource)3 IOException (java.io.IOException)2 URI (java.net.URI)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 ConstantsForTests (org.opentripplanner.ConstantsForTests)2 GTFS (org.opentripplanner.datastore.FileType.GTFS)2 BinaryOpenStreetMapProvider (org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider)2 Blob (com.google.cloud.storage.Blob)1