Skip to content

Commit 93fc266

Browse files
authored
fix test resources
1 parent 07f48c3 commit 93fc266

File tree

4 files changed

+34
-42
lines changed

4 files changed

+34
-42
lines changed

.github/workflows/mta_ci.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,18 @@ jobs:
2929
distribution: temurin
3030
java-version: ${{ matrix.java }}
3131

32-
- name: Create Folder
32+
- name: Install resources
3333
shell: bash
34-
run: mkdir -p "src/test/java/resources"
34+
run: ./install.sh
3535

3636
- name: Load Client ID
37-
run: |-
38-
echo ${{ secrets.BUS_TOKEN }} > src/test/java/resources/bus.txt
37+
run: echo ${{ secrets.BUS_TOKEN }} > src/test/java/resources/bus.txt
3938

4039
- name: Load OAuth Token
41-
run: |-
42-
echo ${{ secrets.SUBWAY_TOKEN }} > src/test/java/resources/subway.txt
40+
run: echo ${{ secrets.SUBWAY_TOKEN }} > src/test/java/resources/subway.txt
4341

4442
- name: Load Test Group
45-
run: |-
46-
echo ${{ matrix.group }} > src/test/java/resources/TEST_GROUP
43+
run: echo ${{ matrix.group }} > src/test/java/resources/TEST_GROUP
4744

4845
- name: Test with Maven
4946
continue-on-error: true

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,13 @@ Sample response data available on the [`reference`](https://github.com/KatsuteDe
150150

151151
For local tests you can use Java 8+, however only methods in the Java 8 API may be used. The `src/main/java9` folder should not be marked as a source root.
152152

153+
- You must run `install.sh` to initialize test resources.
153154
- (Bus) Run tests locally by adding a text file named `bus.txt` that contains the bus token in the `src/test/java/resources` directory.
154155
- (Subway) Run tests locally by adding a text file named `subway.txt` that contains the subway in the `src/test/java/resources` directory.
155156

156157
#### Running Tests using GitHub Actions
157158

158-
Devs running remote tests through GitHub Actions may do so by running the `MTA CI` workflow manually in the actions tab of your fork. Note that this requires two secrets, a `BUS_TOKEN` which contains the bus token, and a `SUBWAY_TOKEN` which contains the subway token.
159+
Developers running remote tests through GitHub Actions may do so by running the `MTA CI` workflow manually in the actions tab of your fork. Note that this requires two secrets, a `BUS_TOKEN` which contains the bus token, and a `SUBWAY_TOKEN` which contains the subway token.
159160

160161
<div align="right"><a href="#top"><code>▲</code></a></div>
161162

install.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
version=25.0
44

5-
if [ -d protobuf ]; then
6-
exit 0
7-
fi
8-
95
mkdir protobuf
106

117
if [ "$(expr substr $(uname -s) 1 10)" == "MINGW64_NT" ]; then
@@ -32,4 +28,18 @@ cp "onebusaway-gtfs-realtime-api/src/main/proto/com/google/transit/realtime/gtfs
3228
cp "onebusaway-gtfs-realtime-api/src/main/proto/com/google/transit/realtime/gtfs-realtime-OneBusAway.proto" "protobuf/gtfs-realtime-OneBusAway.proto"
3329
cp "onebusaway-gtfs-realtime-api/src/main/proto/com/google/transit/realtime/gtfs-realtime-crowding.proto" "protobuf/gtfs-realtime-crowding.proto"
3430
cp "onebusaway-gtfs-realtime-api/src/main/proto/com/google/transit/realtime/gtfs-realtime-service-status.proto" "protobuf/gtfs-realtime-service-status.proto"
35-
cp "onebusaway-gtfs-realtime-api/src/main/proto/com/google/transit/realtime/gtfs-realtime.proto" "protobuf/gtfs-realtime.proto"
31+
cp "onebusaway-gtfs-realtime-api/src/main/proto/com/google/transit/realtime/gtfs-realtime.proto" "protobuf/gtfs-realtime.proto"
32+
33+
# test resources
34+
35+
mkdir src/test/java/resources
36+
37+
curl -L -k -o "src/test/java/resources/resource_subway.zip" "http://web.mta.info/developers/data/nyct/subway/google_transit.zip"
38+
curl -L -k -o "src/test/java/resources/resource_bus_bronx.zip" "http://web.mta.info/developers/data/nyct/bus/google_transit_bronx.zip"
39+
curl -L -k -o "src/test/java/resources/resource_bus_brooklyn.zip" "http://web.mta.info/developers/data/nyct/bus/google_transit_brooklyn.zip"
40+
curl -L -k -o "src/test/java/resources/resource_bus_manhattan.zip" "http://web.mta.info/developers/data/nyct/bus/google_transit_manhattan.zip"
41+
curl -L -k -o "src/test/java/resources/resource_bus_queens.zip" "http://web.mta.info/developers/data/nyct/bus/google_transit_queens.zip"
42+
curl -L -k -o "src/test/java/resources/resource_bus_statenisland.zip" "http://web.mta.info/developers/data/nyct/bus/google_transit_staten_island.zip"
43+
curl -L -k -o "src/test/java/resources/resource_longislandrailroad.zip" "http://web.mta.info/developers/data/lirr/google_transit.zip"
44+
curl -L -k -o "src/test/java/resources/resource_metronorthrailroad.zip" "http://web.mta.info/developers/data/mnr/google_transit.zip"
45+
curl -L -k -o "src/test/java/resources/resource_bus_company.zip" "http://web.mta.info/developers/data/busco/google_transit.zip"

src/test/java/dev/katsute/onemta/TestProvider.java

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ public static void acquireTestLock(){
8080
private static final boolean hasBus = bus.exists();
8181
private static final boolean hasSubway = subway.exists();
8282

83-
private static final Map<DataResourceType,String> resources = new HashMap<DataResourceType,String>(){{
84-
put(DataResourceType.Subway , "http://web.mta.info/developers/data/nyct/subway/google_transit.zip");
85-
put(DataResourceType.Bus_Bronx , "http://web.mta.info/developers/data/nyct/bus/google_transit_bronx.zip");
86-
put(DataResourceType.Bus_Brooklyn , "http://web.mta.info/developers/data/nyct/bus/google_transit_brooklyn.zip");
87-
put(DataResourceType.Bus_Manhattan , "http://web.mta.info/developers/data/nyct/bus/google_transit_manhattan.zip");
88-
put(DataResourceType.Bus_Queens , "http://web.mta.info/developers/data/nyct/bus/google_transit_queens.zip");
89-
put(DataResourceType.Bus_StatenIsland , "http://web.mta.info/developers/data/nyct/bus/google_transit_staten_island.zip");
90-
put(DataResourceType.LongIslandRailroad , "http://web.mta.info/developers/data/lirr/google_transit.zip");
91-
put(DataResourceType.MetroNorthRailroad , "http://web.mta.info/developers/data/mnr/google_transit.zip");
92-
put(DataResourceType.Bus_Company , "http://web.mta.info/developers/data/busco/google_transit.zip");
93-
}};
83+
private static final List<DataResourceType> resources = Arrays.asList(
84+
DataResourceType.Subway,
85+
DataResourceType.Bus_Bronx,
86+
DataResourceType.Bus_Brooklyn,
87+
DataResourceType.Bus_Manhattan,
88+
DataResourceType.Bus_Queens,
89+
DataResourceType.Bus_StatenIsland,
90+
DataResourceType.LongIslandRailroad,
91+
DataResourceType.MetroNorthRailroad,
92+
DataResourceType.Bus_Company
93+
);
9494

9595
public static MTA mta;
9696

@@ -101,24 +101,8 @@ public static MTA getOneMTA(){
101101

102102
acquireTestLock();
103103

104-
for(final Map.Entry<DataResourceType,String> entry : resources.entrySet())
105-
try(final BufferedInputStream IN = new BufferedInputStream(new URL(entry.getValue()).openStream())){
106-
final File file = new File(test_resources, "resource_" + entry.getKey().name().toLowerCase() + ".zip");
107-
System.out.println("[↻] Checking for data resource " + file.getName());
108-
if(!file.exists()){
109-
System.out.println("[⚠] " + file.getName() + " not found, downloading from the MTA...");
110-
try(final FileOutputStream OUT = new FileOutputStream(file)){
111-
byte[] buffer = new byte[1024];
112-
int bytesReads;
113-
while((bytesReads = IN.read(buffer, 0, 1024)) != -1)
114-
OUT.write(buffer, 0, bytesReads);
115-
}
116-
}
117-
System.out.println("[✔] Added " + file.getName() + " as " + entry.getKey().name());
118-
}
119-
120104
final List<DataResource> resources = new ArrayList<>();
121-
for(final DataResourceType type : TestProvider.resources.keySet())
105+
for(final DataResourceType type : TestProvider.resources)
122106
resources.add(DataResource.create(type, new File(test_resources, "resource_" + type.name().toLowerCase() + ".zip")));
123107

124108
return mta = MTA.create(strip(readFile(bus)), strip(readFile(subway)), resources.toArray(new DataResource[0]));

0 commit comments

Comments
 (0)