Search in sources :

Example 1 with CompositeDataSource

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

the class ZipFileDataSourceTest method testAccessorsForNoneExistingFile.

@Test
public void testAccessorsForNoneExistingFile() throws IOException {
    // Given:
    File target = new File(FILENAME);
    File copyTarget = new File(FILENAME);
    CompositeDataSource subject = new ZipFileDataSource(target, GTFS);
    CompositeDataSource copySubject = new ZipFileDataSource(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("GTFS " + expectedPath, subject.toString());
    assertEquals(copySubject, subject);
    assertEquals(copySubject.hashCode(), subject.hashCode());
    subject.close();
    copySubject.close();
}
Also used : File(java.io.File) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) Test(org.junit.Test)

Example 2 with CompositeDataSource

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

the class ZipFileDataSourceTest method testUnsupportedDelete.

@Test
public void testUnsupportedDelete() {
    // Given:
    File target = new File(FILENAME);
    CompositeDataSource subject = new ZipFileDataSource(target, GTFS);
    // delete entry is not implemented
    try {
        // When:
        subject.delete();
        // Then:
        fail("Expected delete to throw an exception.");
    } catch (Exception e) {
        assertTrue(e.getMessage().contains("ZipFileDataSource"));
    }
}
Also used : File(java.io.File) IOException(java.io.IOException) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) Test(org.junit.Test)

Example 3 with CompositeDataSource

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

the class ZipFileDataSourceTest method testEntryProperties.

@Test
public void testEntryProperties() {
    // Given:
    File target = new File(FILENAME);
    CompositeDataSource subject = new ZipFileDataSource(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 : File(java.io.File) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) DataSource(org.opentripplanner.datastore.DataSource) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) Test(org.junit.Test)

Example 4 with CompositeDataSource

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

the class GsIntegrationTest method testReadingZipFile.

@Test
public // @Ignore("This test is a manual test, because it require an Google Cloud Store to run.")
void testReadingZipFile() throws Exception {
    CompositeDataSource ds = repo.findCompositeSource(GTFS_URI, FileType.GTFS);
    DataSource stops = ds.entry("stops.txt");
    String text = IOUtils.toString(stops.asInputStream(), UTF_8);
    assertTrue(text, text.contains("stop"));
}
Also used : CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) DataSource(org.opentripplanner.datastore.DataSource) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) Test(org.junit.Test)

Example 5 with CompositeDataSource

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

the class GsIntegrationTest method testGsDirectory.

@Test
public void testGsDirectory() throws Exception {
    // Get a virtual directory
    URI dirUri = toUri(BUCKET_NAME, "my-test-dir");
    CompositeDataSource dir = repo.findCompositeSource(dirUri, FileType.REPORT);
    assertEquals(dirUri.toString(), dir.path());
    assertEquals(FileType.REPORT, dir.type());
    assertEquals("my-test-dir", dir.name());
    assertTrue(dir.isWritable());
    Collection<DataSource> content;
    // Add at least one file
    writeDataToDataSource(dir.entry("a.txt"));
    // Assert content have at least one file
    content = dir.content();
    assertTrue(dir.exists());
    assertTrue(content.toString(), content.size() > 0);
    // And the new file have the expected content
    assertEquals(DATA, IOUtils.toString(dir.entry("a.txt").asInputStream(), UTF_8));
    // Delete all files in dir
    dir.delete();
    // Verify there is no data
    assertFalse(dir.exists());
    content = dir.content();
    assertEquals(content.toString(), 0, content.size());
    // Write a file
    writeDataToDataSource(dir.entry("b.txt"));
    content = dir.content();
    // Assert file is moved
    assertEquals(content.toString(), 1, content.size());
    assertTrue(content.toString(), content.toString().contains("my-test-dir/b.txt"));
    // Cleanup
    dir.delete();
    dir.close();
}
Also used : URI(java.net.URI) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) DataSource(org.opentripplanner.datastore.DataSource) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) Test(org.junit.Test)

Aggregations

CompositeDataSource (org.opentripplanner.datastore.CompositeDataSource)15 Test (org.junit.Test)11 File (java.io.File)10 DataSource (org.opentripplanner.datastore.DataSource)9 IOException (java.io.IOException)3 FileDataSource (org.opentripplanner.datastore.file.FileDataSource)3 StandardCharsets (java.nio.charset.StandardCharsets)2 ArrayList (java.util.ArrayList)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 Blob (com.google.cloud.storage.Blob)1 URI (java.net.URI)1 Assert.fail (org.junit.Assert.fail)1