Search in sources :

Example 1 with FileDataSource

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);
}
Also used : FileDataSource(org.opentripplanner.datastore.file.FileDataSource) JarFile(java.util.jar.JarFile) TempFile(org.jets3t.service.io.TempFile) File(java.io.File)

Example 2 with FileDataSource

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());
}
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 3 with FileDataSource

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();
}
Also used : FileDataSource(org.opentripplanner.datastore.file.FileDataSource) File(java.io.File) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) Test(org.junit.Test)

Example 4 with FileDataSource

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();
}
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 5 with FileDataSource

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

File (java.io.File)5 FileDataSource (org.opentripplanner.datastore.file.FileDataSource)5 Test (org.junit.Test)3 CompositeDataSource (org.opentripplanner.datastore.CompositeDataSource)3 DataSource (org.opentripplanner.datastore.DataSource)3 IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Collection (java.util.Collection)1 List (java.util.List)1 JarFile (java.util.jar.JarFile)1 Collectors (java.util.stream.Collectors)1 IOUtils (org.apache.commons.io.IOUtils)1 TempFile (org.jets3t.service.io.TempFile)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 BeforeClass (org.junit.BeforeClass)1 ConstantsForTests (org.opentripplanner.ConstantsForTests)1 GTFS (org.opentripplanner.datastore.FileType.GTFS)1 BinaryOpenStreetMapProvider (org.opentripplanner.openstreetmap.BinaryOpenStreetMapProvider)1