use of org.opentripplanner.datastore.file.FileDataSource in project OpenTripPlanner by opentripplanner.
the class GraphSerializationTest method testRoundTrip.
/**
* Tests that saving a Graph to disk and reloading it results in a separate but semantically identical Graph.
*/
private void testRoundTrip(Graph originalGraph) throws Exception {
// The cached timezone in the graph is transient and lazy-initialized.
// Previous tests may have caused a timezone to be cached.
originalGraph.clearTimeZone();
// Now round-trip the graph through serialization.
File tempFile = TempFile.createTempFile("graph", "pdx");
SerializedGraphObject serializedObj = new SerializedGraphObject(originalGraph, BuildConfig.DEFAULT, RouterConfig.DEFAULT);
serializedObj.save(new FileDataSource(tempFile, FileType.GRAPH));
Graph copiedGraph1 = SerializedGraphObject.load(tempFile);
// Index both graph - we do no know if the original is indexed, because it is cached and
// might be indexed by other tests.
originalGraph.index();
copiedGraph1.index();
assertNoDifferences(originalGraph, copiedGraph1);
Graph copiedGraph2 = SerializedGraphObject.load(tempFile);
copiedGraph2.index();
assertNoDifferences(copiedGraph1, copiedGraph2);
}
use of org.opentripplanner.datastore.file.FileDataSource 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.file.FileDataSource in project OpenTripPlanner by opentripplanner.
the class ZipStreamDataSourceDecoratorTest method testAccessorsForNoneExistingFile.
@Test
public void testAccessorsForNoneExistingFile() throws IOException {
// Given:
File target = new File(FILENAME);
File copyTarget = new File(FILENAME);
CompositeDataSource subject = new ZipStreamDataSourceDecorator(new FileDataSource(target, GTFS));
CompositeDataSource copySubject = new ZipStreamDataSourceDecorator(new FileDataSource(copyTarget, GTFS));
String expectedPath = target.getPath();
// Verify zip file exist before we start the test
assertTrue(target.getAbsolutePath(), target.exists());
// Then
assertEquals("caltrain_gtfs.zip", subject.name());
assertEquals(expectedPath, subject.path());
assertEquals(GTFS, subject.type());
assertTrue("Last modified: " + subject.lastModified(), subject.lastModified() > TIME);
assertTrue("Size: " + subject.size(), subject.size() > 100);
assertTrue(subject.exists());
// We do not support writing to zip files
assertFalse(subject.isWritable());
assertEquals(expectedPath, subject.toString());
subject.close();
copySubject.close();
}
use of org.opentripplanner.datastore.file.FileDataSource 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.file.FileDataSource 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