Search in sources :

Example 6 with DataSource

use of org.opentripplanner.datastore.DataSource 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)

Example 7 with DataSource

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

the class GsIntegrationTest method testGsDataSource.

@Test
public void testGsDataSource() throws IOException {
    String tempDir = "temp-dir";
    // Make sure we start with an empty folder
    cleanUpDir(tempDir);
    // Create on new file
    URI dsUri = toUri(BUCKET_NAME, tempDir + "/ds.txt");
    DataSource ds = repo.findSource(dsUri, FileType.UNKNOWN);
    // assertFalse(ds.exists());
    assertEquals(tempDir + "/ds.txt", ds.name());
    assertEquals(GsHelper.toUriString(BUCKET_NAME, tempDir + "/ds.txt"), ds.path());
    assertEquals(FileType.UNKNOWN, ds.type());
    assertTrue(ds.isWritable());
    assertFalse(ds.exists());
    // Create a new file
    writeDataToDataSource(ds);
    // Retrieve the new created file
    ds = repo.findSource(dsUri, FileType.UNKNOWN);
    // Validate the file
    assertTrue(ds.exists());
    assertEquals("temp-dir/ds.txt", ds.name());
    assertEquals("gs://" + BUCKET_NAME + "/temp-dir/ds.txt", ds.path());
    assertEquals(FileType.UNKNOWN, ds.type());
    assertTrue("LastModified: " + ds.lastModified(), ds.lastModified() > 0);
    assertTrue("Size: " + ds.size(), ds.size() > 0);
    assertTrue(ds.isWritable());
    assertEquals(DATA, IOUtils.toString(ds.asInputStream(), UTF_8));
    // Cleanup
    cleanUpDir(tempDir);
}
Also used : URI(java.net.URI) DataSource(org.opentripplanner.datastore.DataSource) CompositeDataSource(org.opentripplanner.datastore.CompositeDataSource) Test(org.junit.Test)

Example 8 with DataSource

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

the class ByteArrayDataSourceTest method verifyAReadOnlyInstanceIsNotWritable.

@Test(expected = UnsupportedOperationException.class)
public void verifyAReadOnlyInstanceIsNotWritable() {
    DataSource subject = new ByteArrayDataSource(PATH, NAME, TYPE, SIZE, LAST_MODIFIED, false).withBytes(BYTES);
    assertFalse(subject.isWritable());
    subject.asOutputStream();
}
Also used : DataSource(org.opentripplanner.datastore.DataSource) Test(org.junit.Test)

Example 9 with DataSource

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

the class ByteArrayDataSourceTest method testAccessors.

@Test
public void testAccessors() {
    DataSource subject = new ByteArrayDataSource(PATH, NAME, TYPE, SIZE, LAST_MODIFIED, true);
    assertEquals(PATH, subject.path());
    assertEquals(NAME, subject.name());
    assertEquals(TYPE, subject.type());
    assertTrue(subject.isWritable());
    assertTrue(subject.exists());
    assertEquals(SIZE, subject.size());
    assertEquals(LAST_MODIFIED, subject.lastModified());
    assertEquals(TYPE + " " + PATH, subject.toString());
}
Also used : DataSource(org.opentripplanner.datastore.DataSource) Test(org.junit.Test)

Example 10 with DataSource

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

the class ByteArrayDataSourceTest method asOutputStream.

@Test
public void asOutputStream() throws IOException {
    DataSource subject = new ByteArrayDataSource(PATH, NAME, TYPE, SIZE, LAST_MODIFIED, true);
    try (OutputStream out = subject.asOutputStream()) {
        out.write(BYTES);
    }
    assertArrayEquals(BYTES, subject.asBytes());
}
Also used : OutputStream(java.io.OutputStream) DataSource(org.opentripplanner.datastore.DataSource) Test(org.junit.Test)

Aggregations

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