Skip to content

Commit

Permalink
add test for fetching alert
Browse files Browse the repository at this point in the history
  • Loading branch information
miklcct committed Nov 5, 2024
1 parent 6f7d957 commit 48c2bf9
Showing 1 changed file with 31 additions and 0 deletions.
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
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)));
}
}

0 comments on commit 48c2bf9

Please sign in to comment.