Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -56,6 +56,7 @@
import org.opentripplanner.routing.graphfinder.PatternAtStop;
import org.opentripplanner.routing.graphfinder.PlaceAtDistance;
import org.opentripplanner.routing.graphfinder.PlaceType;
import org.opentripplanner.routing.services.TransitAlertService;
import org.opentripplanner.routing.vehicle_parking.VehicleParking;
import org.opentripplanner.routing.vehicle_parking.VehicleParkingService;
import org.opentripplanner.service.vehiclerental.VehicleRentalService;
Expand Down Expand Up @@ -394,7 +395,7 @@ public DataFetcher<Object> node() {
case "Agency":
return transitService.getAgencyForId(FeedScopedId.parse(id));
case "Alert":
return null; //TODO
return transitService.getTransitAlertService().getAlertById(FeedScopedId.parse(id));
case "BikePark":
var bikeParkId = FeedScopedId.parse(id);
return vehicleParkingService == null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
package org.opentripplanner.apis.gtfs.datafetchers;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import graphql.schema.DataFetchingEnvironment;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.opentripplanner.apis.gtfs.GraphQLRequestContext;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes;
import org.opentripplanner.framework.i18n.NonLocalizedString;
import org.opentripplanner.routing.alertpatch.AlertCause;
import org.opentripplanner.routing.alertpatch.AlertEffect;
import org.opentripplanner.routing.alertpatch.AlertSeverity;
import org.opentripplanner.routing.alertpatch.EntitySelector;
import org.opentripplanner.routing.alertpatch.TransitAlert;
import org.opentripplanner.routing.services.TransitAlertService;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.service.TransitService;

public class QueryTypeImplTest {

Expand Down Expand Up @@ -171,4 +179,27 @@ public void testFilterAlertsStop() {
assertEquals(1, filteredAlerts.size());
assertEquals(STOP_ID, filteredAlerts.get(0).getId());
}

@Test
Copy link
Member

@leonardehrenfried leonardehrenfried Nov 6, 2024

Choose a reason for hiding this comment

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

You can do it much simpler: just drop a file like node-alert.graphql here: https://github.com/opentripplanner/OpenTripPlanner/tree/dev-2.x/application/src/test/resources/org/opentripplanner/apis/gtfs/queries

Then run GraphQLIntegrationTest.

These tests also double up as API examples for newcomers.

public void nodeAlert() {
var subject = new QueryTypeImpl();
var id = new FeedScopedId("Feed", "Entity");
var alert = TransitAlert.of(id).build();

var transitAlertService = mock(TransitAlertService.class);
when(transitAlertService.getAlertById(id)).thenReturn(alert);

var transitService = mock(TransitService.class);
when(transitService.getTransitAlertService()).thenReturn(transitAlertService);

var environment = mock(DataFetchingEnvironment.class);
when(environment.<GraphQLRequestContext>getContext())
.thenReturn(
new GraphQLRequestContext(null, transitService, null, null, null, null, null, null)
);
when(environment.getArguments())
.thenReturn(Map.of("id", new graphql.relay.Relay.ResolvedGlobalId("Alert", id.toString())));

assertEquals(alert, assertDoesNotThrow(() -> subject.node().get(environment)));
}
}
Loading