Search in sources :

Example 6 with CompositeDataSource

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

use of org.opentripplanner.datastore.CompositeDataSource 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 8 with CompositeDataSource

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

the class GsIntegrationTest method cleanUpDir.

private void cleanUpDir(String dir) {
    CompositeDataSource tempdir = repo.findCompositeSource(toUri(BUCKET_NAME, dir), FileType.REPORT);
    tempdir.delete();
}
Also used : CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource)

Example 9 with CompositeDataSource

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

the class DirectoryDataSourceTest method testIO.

@Test
public void testIO() throws IOException {
    // Given a file, yet not created
    File target = new File(tempDir, DIRNAME);
    File child = new File(target, "a.txt");
    // And then CREATE a file data source - our subject
    CompositeDataSource subject = new DirectoryDataSource(target, REPORT);
    // Verify content is empty
    assertEquals("[]", toString(subject.content()));
    // Write something to a file in the directory
    IOUtils.write("Go, go, go!", subject.entry(child.getName()).asOutputStream(), UTF_8);
    // Verify the subject directory is created and still is writable
    assertTrue(subject.exists());
    assertTrue(subject.isWritable());
    // Verify content is updated
    assertEquals("[a.txt]", toString(subject.content()));
    // Assert content can be read using the subject and file
    assertEquals("Go, go, go!", FileUtils.readFileToString(child, UTF_8));
    // Then delete subject with all content
    subject.delete();
    // Assert dir is still writable, none existing and content is gone
    assertTrue(subject.isWritable());
    assertFalse(subject.exists());
    assertFalse(target.exists());
    assertEquals("[]", toString(subject.content()));
    subject.close();
}
Also used : File(java.io.File) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) Test(org.junit.Test)

Example 10 with CompositeDataSource

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

the class DirectoryDataSourceTest method testAccessorsForNoneExistingDirectory.

@Test
public void testAccessorsForNoneExistingDirectory() throws IOException {
    File target = new File(tempDir, DIRNAME);
    File copyTarget = new File(tempDir, DIRNAME);
    CompositeDataSource subject = new DirectoryDataSource(target, REPORT);
    CompositeDataSource copySubject = new DirectoryDataSource(copyTarget, REPORT);
    String expectedPath = new File(tempDir, DIRNAME).getPath();
    assertTrue(subject.content().toString(), subject.content().isEmpty());
    assertEquals(DIRNAME, subject.name());
    assertEquals(expectedPath, subject.path());
    assertEquals(REPORT, subject.type());
    assertEquals(0L, subject.lastModified());
    assertEquals(0L, subject.size());
    assertFalse(subject.exists());
    assertTrue(subject.isWritable());
    assertEquals("REPORT " + expectedPath, subject.toString());
    assertEquals(copySubject, subject);
    assertEquals(copySubject.hashCode(), subject.hashCode());
    subject.close();
}
Also used : File(java.io.File) 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