diff --git a/.github/workflows/mta_ci.yml b/.github/workflows/mta_ci.yml index ad0909d..c70468c 100644 --- a/.github/workflows/mta_ci.yml +++ b/.github/workflows/mta_ci.yml @@ -29,21 +29,18 @@ jobs: distribution: temurin java-version: ${{ matrix.java }} - - name: Create Folder + - name: Install resources shell: bash - run: mkdir -p "src/test/java/resources" + run: ./install.sh - name: Load Client ID - run: |- - echo ${{ secrets.BUS_TOKEN }} > src/test/java/resources/bus.txt + run: echo ${{ secrets.BUS_TOKEN }} > src/test/java/resources/bus.txt - name: Load OAuth Token - run: |- - echo ${{ secrets.SUBWAY_TOKEN }} > src/test/java/resources/subway.txt + run: echo ${{ secrets.SUBWAY_TOKEN }} > src/test/java/resources/subway.txt - name: Load Test Group - run: |- - echo ${{ matrix.group }} > src/test/java/resources/TEST_GROUP + run: echo ${{ matrix.group }} > src/test/java/resources/TEST_GROUP - name: Test with Maven continue-on-error: true diff --git a/README.md b/README.md index e2baad0..1908c55 100644 --- a/README.md +++ b/README.md @@ -150,12 +150,13 @@ Sample response data available on the [`reference`](https://github.com/KatsuteDe 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. + - You must run `install.sh` to initialize test resources. - (Bus) Run tests locally by adding a text file named `bus.txt` that contains the bus token in the `src/test/java/resources` directory. - (Subway) Run tests locally by adding a text file named `subway.txt` that contains the subway in the `src/test/java/resources` directory. #### Running Tests using GitHub Actions -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. +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.
diff --git a/install.sh b/install.sh index e4c5083..21c25b9 100755 --- a/install.sh +++ b/install.sh @@ -2,10 +2,6 @@ version=25.0 -if [ -d protobuf ]; then - exit 0 -fi - mkdir protobuf 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 cp "onebusaway-gtfs-realtime-api/src/main/proto/com/google/transit/realtime/gtfs-realtime-OneBusAway.proto" "protobuf/gtfs-realtime-OneBusAway.proto" cp "onebusaway-gtfs-realtime-api/src/main/proto/com/google/transit/realtime/gtfs-realtime-crowding.proto" "protobuf/gtfs-realtime-crowding.proto" cp "onebusaway-gtfs-realtime-api/src/main/proto/com/google/transit/realtime/gtfs-realtime-service-status.proto" "protobuf/gtfs-realtime-service-status.proto" -cp "onebusaway-gtfs-realtime-api/src/main/proto/com/google/transit/realtime/gtfs-realtime.proto" "protobuf/gtfs-realtime.proto" \ No newline at end of file +cp "onebusaway-gtfs-realtime-api/src/main/proto/com/google/transit/realtime/gtfs-realtime.proto" "protobuf/gtfs-realtime.proto" + +# test resources + +mkdir src/test/java/resources + +curl -L -k -o "src/test/java/resources/resource_subway.zip" "http://web.mta.info/developers/data/nyct/subway/google_transit.zip" +curl -L -k -o "src/test/java/resources/resource_bus_bronx.zip" "http://web.mta.info/developers/data/nyct/bus/google_transit_bronx.zip" +curl -L -k -o "src/test/java/resources/resource_bus_brooklyn.zip" "http://web.mta.info/developers/data/nyct/bus/google_transit_brooklyn.zip" +curl -L -k -o "src/test/java/resources/resource_bus_manhattan.zip" "http://web.mta.info/developers/data/nyct/bus/google_transit_manhattan.zip" +curl -L -k -o "src/test/java/resources/resource_bus_queens.zip" "http://web.mta.info/developers/data/nyct/bus/google_transit_queens.zip" +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" +curl -L -k -o "src/test/java/resources/resource_longislandrailroad.zip" "http://web.mta.info/developers/data/lirr/google_transit.zip" +curl -L -k -o "src/test/java/resources/resource_metronorthrailroad.zip" "http://web.mta.info/developers/data/mnr/google_transit.zip" +curl -L -k -o "src/test/java/resources/resource_bus_company.zip" "http://web.mta.info/developers/data/busco/google_transit.zip" \ No newline at end of file diff --git a/src/test/java/dev/katsute/onemta/TestProvider.java b/src/test/java/dev/katsute/onemta/TestProvider.java index 4689812..7e5d4e1 100644 --- a/src/test/java/dev/katsute/onemta/TestProvider.java +++ b/src/test/java/dev/katsute/onemta/TestProvider.java @@ -80,17 +80,17 @@ public static void acquireTestLock(){ private static final boolean hasBus = bus.exists(); private static final boolean hasSubway = subway.exists(); - private static final Map resources = new HashMap(){{ - put(DataResourceType.Subway , "http://web.mta.info/developers/data/nyct/subway/google_transit.zip"); - put(DataResourceType.Bus_Bronx , "http://web.mta.info/developers/data/nyct/bus/google_transit_bronx.zip"); - put(DataResourceType.Bus_Brooklyn , "http://web.mta.info/developers/data/nyct/bus/google_transit_brooklyn.zip"); - put(DataResourceType.Bus_Manhattan , "http://web.mta.info/developers/data/nyct/bus/google_transit_manhattan.zip"); - put(DataResourceType.Bus_Queens , "http://web.mta.info/developers/data/nyct/bus/google_transit_queens.zip"); - put(DataResourceType.Bus_StatenIsland , "http://web.mta.info/developers/data/nyct/bus/google_transit_staten_island.zip"); - put(DataResourceType.LongIslandRailroad , "http://web.mta.info/developers/data/lirr/google_transit.zip"); - put(DataResourceType.MetroNorthRailroad , "http://web.mta.info/developers/data/mnr/google_transit.zip"); - put(DataResourceType.Bus_Company , "http://web.mta.info/developers/data/busco/google_transit.zip"); - }}; + private static final List resources = Arrays.asList( + DataResourceType.Subway, + DataResourceType.Bus_Bronx, + DataResourceType.Bus_Brooklyn, + DataResourceType.Bus_Manhattan, + DataResourceType.Bus_Queens, + DataResourceType.Bus_StatenIsland, + DataResourceType.LongIslandRailroad, + DataResourceType.MetroNorthRailroad, + DataResourceType.Bus_Company + ); public static MTA mta; @@ -101,24 +101,8 @@ public static MTA getOneMTA(){ acquireTestLock(); - for(final Map.Entry entry : resources.entrySet()) - try(final BufferedInputStream IN = new BufferedInputStream(new URL(entry.getValue()).openStream())){ - final File file = new File(test_resources, "resource_" + entry.getKey().name().toLowerCase() + ".zip"); - System.out.println("[↻] Checking for data resource " + file.getName()); - if(!file.exists()){ - System.out.println("[⚠] " + file.getName() + " not found, downloading from the MTA..."); - try(final FileOutputStream OUT = new FileOutputStream(file)){ - byte[] buffer = new byte[1024]; - int bytesReads; - while((bytesReads = IN.read(buffer, 0, 1024)) != -1) - OUT.write(buffer, 0, bytesReads); - } - } - System.out.println("[✔] Added " + file.getName() + " as " + entry.getKey().name()); - } - final List resources = new ArrayList<>(); - for(final DataResourceType type : TestProvider.resources.keySet()) + for(final DataResourceType type : TestProvider.resources) resources.add(DataResource.create(type, new File(test_resources, "resource_" + type.name().toLowerCase() + ".zip"))); return mta = MTA.create(strip(readFile(bus)), strip(readFile(subway)), resources.toArray(new DataResource[0]));