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