Search in sources :

Example 1 with TempFile

use of org.jets3t.service.io.TempFile in project OpenTripPlanner by opentripplanner.

the class GraphSerializationTest method testRoundTrip.

/**
 * Tests that saving a Graph to disk and reloading it results in a separate but semantically identical Graph.
 */
private void testRoundTrip(Graph originalGraph) throws Exception {
    // The cached timezone in the graph is transient and lazy-initialized.
    // Previous tests may have caused a timezone to be cached.
    originalGraph.clearTimeZone();
    // Now round-trip the graph through serialization.
    File tempFile = TempFile.createTempFile("graph", "pdx");
    SerializedGraphObject serializedObj = new SerializedGraphObject(originalGraph, BuildConfig.DEFAULT, RouterConfig.DEFAULT);
    serializedObj.save(new FileDataSource(tempFile, FileType.GRAPH));
    Graph copiedGraph1 = SerializedGraphObject.load(tempFile);
    // Index both graph - we do no know if the original is indexed, because it is cached and
    // might be indexed by other tests.
    originalGraph.index();
    copiedGraph1.index();
    assertNoDifferences(originalGraph, copiedGraph1);
    Graph copiedGraph2 = SerializedGraphObject.load(tempFile);
    copiedGraph2.index();
    assertNoDifferences(copiedGraph1, copiedGraph2);
}
Also used : FileDataSource(org.opentripplanner.datastore.file.FileDataSource) JarFile(java.util.jar.JarFile) TempFile(org.jets3t.service.io.TempFile) File(java.io.File)

Aggregations

File (java.io.File)1 JarFile (java.util.jar.JarFile)1 TempFile (org.jets3t.service.io.TempFile)1 FileDataSource (org.opentripplanner.datastore.file.FileDataSource)1