Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,12 @@ private void copyVersionToLatest(File version, FeedSource feedSource) throws IOE
FileUtils.copyFile(version, latest, true);
}

private File createTempFile (String name, InputStream in) throws IOException {
Path path = Files.createTempFile(name, null);
protected File createTempFile (String name, InputStream in) throws IOException {
// Create temp file in such a way that filename is preserved (no tmp suffix added).
final File tempFile = new File(new File(System.getProperty("java.io.tmpdir")), name);
LOG.info("Storing temp GTFS file at {}", tempFile.getAbsolutePath());
// FIXME: Figure out how to manage temp files created here. Currently, we just call deleteOnExit, but
// this will only delete the file once the java process stops.
File tempFile = path.toFile();
tempFile.deleteOnExit();
ByteStreams.copy(in, new FileOutputStream(tempFile));
return tempFile;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/conveyal/datatools/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static FeedVersion createFeedVersionFromGtfsZip(FeedSource source, String
/**
* Helper to get a File for the given file or folder that should be in the gtfs folder of the test resources
*/
private static String getGtfsResourcePath(String gtfsFileName) {
public static String getGtfsResourcePath(String gtfsFileName) {
return TestUtils.class.getResource("gtfs/" + gtfsFileName).getFile();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.conveyal.datatools.manager.persistence;

import com.conveyal.datatools.DatatoolsTest;
import com.conveyal.datatools.UnitTest;
import com.conveyal.datatools.manager.models.FeedVersion;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import static com.conveyal.datatools.TestUtils.getGtfsResourcePath;

public class FeedStoreTest extends UnitTest {
private static final Logger LOG = LoggerFactory.getLogger(FeedStoreTest.class);

@BeforeClass
public static void setUp() throws Exception {
DatatoolsTest.setUp();
LOG.info("{} setup", FeedStoreTest.class.getSimpleName());
}

/**
* Verify that {@link FeedStore} will write a temp file with the input file name.
*/
@Test
public void canCreateTempGtfsFile() throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment for this test case?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Herzlichen Dank für die Unterstützung,

klappt leider nicht.
Sorry mein Englisch ist schlecht.
LG

final String gtfsFileName = "gtfs.zip";
File gtfsFile = new File(getGtfsResourcePath("bart_new.zip"));
FileInputStream fileInputStream = new FileInputStream(gtfsFile);
File tempFile = FeedVersion.feedStore.createTempFile(gtfsFileName, fileInputStream);
LOG.info("Feed store wrote temp file to: {}", tempFile.getAbsolutePath());
Assert.assertEquals(tempFile.getName(), gtfsFileName);
}
}