-
Notifications
You must be signed in to change notification settings - Fork 1k
/
ConstantsForTests.java
103 lines (82 loc) · 3.57 KB
/
ConstantsForTests.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* This program is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package org.opentripplanner;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import org.onebusaway.gtfs.model.calendar.CalendarServiceData;
import org.opentripplanner.graph_builder.module.TransitToStreetNetworkModule;
import org.opentripplanner.gtfs.GtfsContext;
import org.opentripplanner.gtfs.GtfsLibrary;
import org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory;
import org.opentripplanner.routing.edgetype.factory.TransferGraphLinker;
import org.opentripplanner.routing.graph.Graph;
public class ConstantsForTests {
public static final String CALTRAIN_GTFS = "src/test/resources/caltrain_gtfs.zip";
public static final String PORTLAND_GTFS = "src/test/resources/google_transit.zip";
public static final String FAKE_GTFS = "src/test/resources/testagency.zip";
private static ConstantsForTests instance = null;
private Graph portlandGraph = null;
private GtfsContext portlandContext = null;
private ConstantsForTests() {
}
public static ConstantsForTests getInstance() {
if (instance == null) {
instance = new ConstantsForTests();
}
return instance;
}
public GtfsContext getPortlandContext() {
if (portlandGraph == null) {
setupPortland();
}
return portlandContext;
}
public Graph getPortlandGraph() {
if (portlandGraph == null) {
setupPortland();
}
return portlandGraph;
}
private void setupPortland() {
try {
portlandContext = GtfsLibrary.readGtfs(new File(ConstantsForTests.PORTLAND_GTFS));
portlandGraph = new Graph();
GTFSPatternHopFactory factory = new GTFSPatternHopFactory(portlandContext);
factory.run(portlandGraph);
TransferGraphLinker linker = new TransferGraphLinker(portlandGraph);
linker.run();
// TODO: eliminate GTFSContext
// this is now making a duplicate calendarservicedata but it's oh so practical
portlandGraph.putService(CalendarServiceData.class,
GtfsLibrary.createCalendarServiceData(portlandContext.getDao()));
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
TransitToStreetNetworkModule ttsnm = new TransitToStreetNetworkModule();
ttsnm.buildGraph(portlandGraph, new HashMap<Class<?>, Object>());
}
public static Graph buildGraph(String path) {
GtfsContext context;
try {
context = GtfsLibrary.readGtfs(new File(path));
} catch (IOException e) {
e.printStackTrace();
return null;
}
Graph graph = new Graph();
GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
factory.run(graph);
graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
return graph;
}
}