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