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));
}
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());
}
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();
}
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();
}
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);
}
Aggregations