Skip to content

Commit

Permalink
test(DateTimeUtils): verify configured OTP timezone equals system tim…
Browse files Browse the repository at this point in the history
…ezone
  • Loading branch information
josh-willis-arcadis committed Jan 30, 2025
1 parent a487777 commit 4d667f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -885,81 +885,6 @@ void testDuplicateNotifications() throws Exception {
Persistence.otpUsers.removeById(observer.id);
}

@Test
void testCheckMonitoredTripWhenUTCIsNextDay() throws Exception {
MonitoredTrip monitoredTrip = PersistenceTestUtils.createMonitoredTrip(
user.id,
OtpTestUtils.OTP2_DISPATCHER_PLAN_RESPONSE.clone(),
false,
OtpTestUtils.createDefaultJourneyState()
);

// monitored trip start time = 1:30AM UTC or 5:30PM PST
OtpTestUtils.updateBaseItineraryTime(
monitoredTrip.itinerary,
DateTimeUtils.makeOtpZonedDateTime(monitoredTrip.itinerary.startTime)
.withHour(17)
.withMinute(30)
.withZoneSameInstant(DateTimeUtils.getOtpZoneId())
);
monitoredTrip.itineraryExistence.monday = new ItineraryExistence.ItineraryExistenceResult();
monitoredTrip.itineraryExistence.tuesday = new ItineraryExistence.ItineraryExistenceResult();
monitoredTrip.tripTime = "17:30";
monitoredTrip.leadTimeInMinutes = 30;
Persistence.monitoredTrips.create(monitoredTrip);
LOG.info("Created trip {}", monitoredTrip.id);

// Set up an OTP mock response in order to trigger some of the monitor checks.
OtpResponse mockResponse = mockOtpPlanResponse();
Itinerary mockTuesdayJune09Itinerary = mockResponse.plan.itineraries.get(0);

// itinerary start time = 1:30AM UTC or 5:30PM PST
OtpTestUtils.updateBaseItineraryTime(
mockTuesdayJune09Itinerary,
DateTimeUtils.makeOtpZonedDateTime(mockTuesdayJune09Itinerary.startTime)
.withHour(17)
.withMinute(30)
.withZoneSameInstant(DateTimeUtils.getOtpZoneId())
);

// change "now" time to be greater than 30 min lead time
// 12:30PM UTC or 4:30PM PST
DateTimeUtils.useFixedClockAt(
noonMonday8June2020
.withDayOfMonth(9)
.withHour(16)
.withMinute(30)
.withZoneSameInstant(DateTimeUtils.getOtpZoneId())
);

// Next, run a monitor trip check from the new monitored trip using the simulated response.
CheckMonitoredTrip checkMonitoredTrip = new CheckMonitoredTrip(monitoredTrip, () -> mockResponse);
checkMonitoredTrip.run();

// trip should have been skipped
Assertions.assertEquals(0, checkMonitoredTrip.notifications.size());

// change "now" time after initial check to be within 30 min lead
// monitored trip now has previousMatchingItinerary set
// 1:00AM UTC or 5:00PM PST
DateTimeUtils.useFixedClockAt(
noonMonday8June2020
.withDayOfMonth(9)
.withHour(17)
.withMinute(0)
.withZoneSameInstant(DateTimeUtils.getOtpZoneId())
);

CheckMonitoredTrip checkMonitoredTripAgain = new CheckMonitoredTrip(monitoredTrip, () -> mockResponse);
checkMonitoredTripAgain.run();

// Assert that there is one notification generated during check.
Assertions.assertEquals(1, checkMonitoredTripAgain.notifications.size());

// Clear the created trip.
PersistenceTestUtils.deleteMonitoredTrip(monitoredTrip);
}

private void triggerCheckMonitoredTrip(MonitoredTrip monitoredTrip, TravelerPosition travelerPosition) throws CloneNotSupportedException {
CheckMonitoredTrip checkMonitoredTrip = new CheckMonitoredTrip(monitoredTrip, this::mockOtpPlanResponse);
checkMonitoredTrip.IS_TEST = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,11 @@ void canGetHoursBetween() {
);
assertEquals(expectedHours, getHoursBetween(date1, date2));
}

@Test
void testOtpZoneIdIsSameAsSystem() {

assertEquals(DateTimeUtils.getOtpZoneId(), DateTimeUtils.getSystemZoneId());

}
}

0 comments on commit 4d667f5

Please sign in to comment.