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