Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0fcaf9e
push for diff
cswilson252 Mar 2, 2026
ee49572
add to own file
cswilson252 Mar 2, 2026
ffbcca5
add validator functionality
cswilson252 Mar 3, 2026
d078d3b
half baked test +some lint
cswilson252 Mar 4, 2026
abadac7
push up actual notice tests
cswilson252 Mar 4, 2026
5caa4e8
fix to asserttrue?
cswilson252 Mar 8, 2026
e457ddc
assertThat?
cswilson252 Mar 8, 2026
4ca9741
make the non-errors assertFalse
cswilson252 Mar 9, 2026
13e3475
assertThat
cswilson252 Mar 9, 2026
32a2cfd
add import
cswilson252 Mar 9, 2026
4d5f495
other assertThat import
cswilson252 Mar 9, 2026
95a83c6
get rid of assertFalse
cswilson252 Mar 9, 2026
337b917
isFalse
cswilson252 Mar 9, 2026
0e93ab1
Merge branch 'master' into noShapesNoDrt
cswilson252 Mar 9, 2026
6923baf
Merge branch 'master' into noShapesNoDrt
cswilson252 Mar 23, 2026
a1c4524
copilot feedback
cswilson252 Mar 24, 2026
19a3143
missing import
cswilson252 Mar 27, 2026
f5e6311
comparisonfailure
cswilson252 Mar 27, 2026
d5196e4
we have to pass another arg, luckily its nullable
cswilson252 Mar 27, 2026
98c14d0
remove 1f check in favour of 1
cswilson252 Mar 27, 2026
ce9c224
isAtLeast assertation check
cswilson252 Mar 27, 2026
2447088
not 1l?
cswilson252 Mar 27, 2026
528b409
fix semicolon
cswilson252 Mar 27, 2026
8329286
Merge branch 'master' into noShapesNoDrt
cswilson252 Apr 22, 2026
dfe1600
correct tests and validator loop logic
cswilson252 May 4, 2026
22b978b
return, don't break
cswilson252 May 4, 2026
69af53e
lint
cswilson252 May 4, 2026
04c0638
fully remove arguments
cswilson252 May 4, 2026
3763437
0 rows
cswilson252 May 4, 2026
6962ced
-1 rows
cswilson252 May 4, 2026
516dab9
break if rows are -1
cswilson252 May 4, 2026
b86fa31
try returning
cswilson252 May 4, 2026
d7de502
[Skip CI] push method signature WIP
cswilson252 May 4, 2026
e4e72a8
rely on FeedMetadata in validator method
cswilson252 Jun 3, 2026
7d7564d
stringify filename
cswilson252 Jun 3, 2026
86e77ef
pass single feedContainer
cswilson252 Jun 3, 2026
ccaedfd
lint
cswilson252 Jun 3, 2026
52b330e
add createFeedContainer()
cswilson252 Jun 3, 2026
049e820
lint
cswilson252 Jun 3, 2026
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 @@ -183,7 +183,7 @@ private <E extends GtfsEntity> int loadUniqueCount(
* "Zone-Based Demand Responsive Transit" feature.
* @return true if at least one trip with only location_id is found, false otherwise.
*/
private boolean hasAtLeastOneTripWithOnlyLocationId(GtfsFeedContainer feedContainer) {
public static boolean hasAtLeastOneTripWithOnlyLocationId(GtfsFeedContainer feedContainer) {
var optionalStopTimeTable = feedContainer.getTableForFilename(GtfsStopTime.FILENAME);
if (optionalStopTimeTable.isPresent()) {
for (GtfsEntity entity : optionalStopTimeTable.get().getEntities()) {
Expand All @@ -206,7 +206,7 @@ private boolean hasAtLeastOneTripWithOnlyLocationId(GtfsFeedContainer feedContai
* "Fixed-Stops Demand Responsive Transit" feature.
* @return true if at least one trip with only location_group_id is found, false otherwise.
*/
private boolean hasAtLeastOneTripWithOnlyLocationGroupId(GtfsFeedContainer feedContainer) {
public static boolean hasAtLeastOneTripWithOnlyLocationGroupId(GtfsFeedContainer feedContainer) {
var optionalStopTimeTable = feedContainer.getTableForFilename(GtfsStopTime.FILENAME);
if (optionalStopTimeTable.isPresent()) {
for (GtfsEntity entity : optionalStopTimeTable.get().getEntities()) {
Expand Down Expand Up @@ -791,7 +791,7 @@ public void loadServiceWindow(
}
}

private boolean hasAtLeastOneRecordInFile(
public static boolean hasAtLeastOneRecordInFile(
GtfsFeedContainer feedContainer, String featureFilename) {
var table = feedContainer.getTableForFilename(featureFilename);
return table.isPresent() && table.get().entityCount() > 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.mobilitydata.gtfsvalidator.validator;

import javax.inject.Inject;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator;
import org.mobilitydata.gtfsvalidator.notice.MissingRecommendedFileNotice;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
import org.mobilitydata.gtfsvalidator.reportsummary.model.FeedMetadata;
import org.mobilitydata.gtfsvalidator.table.GtfsFeedContainer;
import org.mobilitydata.gtfsvalidator.table.GtfsLocationGroupsTableContainer;
import org.mobilitydata.gtfsvalidator.table.GtfsShapeTableContainer;

/**
* Validates that the feed has either a `shapes.txt` file, or uses zone-based DRT or fixed-stops
* DRT.
*
* <p>Generated notice: {@link MissingRecommendedFileNotice}.
*/
@GtfsValidator
public class MissingShapesFileValidator extends FileValidator {
private final GtfsShapeTableContainer shapeTable;
private final GtfsLocationGroupsTableContainer locationGroups;
private final GtfsFeedContainer feedContainer;

@Inject
MissingShapesFileValidator(
GtfsShapeTableContainer shapeTable,
GtfsLocationGroupsTableContainer locationGroups,
GtfsFeedContainer feedContainer) {
this.shapeTable = shapeTable;
this.locationGroups = locationGroups;
this.feedContainer = feedContainer;
}

@Override
public void validate(NoticeContainer noticeContainer) {
Comment thread
cswilson252 marked this conversation as resolved.

Boolean missingShapes = shapeTable == null || shapeTable.isMissingFile();
boolean hasZoneBasedDrt = FeedMetadata.hasAtLeastOneTripWithOnlyLocationId(feedContainer);
boolean hasFixedStopsDrt =
FeedMetadata.hasAtLeastOneRecordInFile(feedContainer, "location_groups.txt")
&& FeedMetadata.hasAtLeastOneTripWithOnlyLocationGroupId(feedContainer);

// Do we NOT have: a shapes.txt file and the required fields for Zone-Based DRT,
// and also the required fields for Fixed-Stop DRT?
if (missingShapes && !hasZoneBasedDrt && !hasFixedStopsDrt) {
noticeContainer.addValidationNotice(new MissingRecommendedFileNotice("shapes.txt"));
// This is a feed-level warning; emit it at most once.
return;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package org.mobilitydata.gtfsvalidator.validator;

import static com.google.common.truth.Truth.assertThat;

import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.mobilitydata.gtfsvalidator.notice.MissingRecommendedFileNotice;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
import org.mobilitydata.gtfsvalidator.notice.ValidationNotice;
import org.mobilitydata.gtfsvalidator.table.GtfsFeedContainer;
import org.mobilitydata.gtfsvalidator.table.GtfsLocationGroups;
import org.mobilitydata.gtfsvalidator.table.GtfsLocationGroupsTableContainer;
import org.mobilitydata.gtfsvalidator.table.GtfsShape;
import org.mobilitydata.gtfsvalidator.table.GtfsShapeTableContainer;

public class MissingShapesFileValidatorTest {

private static GtfsFeedContainer createFeedContainer(
List<GtfsShape> shapes, List<GtfsLocationGroups> locationGroups) {
NoticeContainer noticeContainer = new NoticeContainer();
return new GtfsFeedContainer(
ImmutableList.of(
GtfsShapeTableContainer.forEntities(shapes, noticeContainer),
GtfsLocationGroupsTableContainer.forEntities(locationGroups, noticeContainer)));
}

private static List<GtfsShape> createShapeTable(int rows) {
ArrayList<GtfsShape> shapes = new ArrayList<>();
for (int i = 0; i < rows; i++) {
if (rows == -1) {
return null;
}
shapes.add(new GtfsShape.Builder().setCsvRowNumber(i + 1).setShapeId("s" + i).build());
}
return shapes;
}

private static List<GtfsLocationGroups> createLocationGroupsTable(
int rows, String groupId, String groupName) {
ArrayList<GtfsLocationGroups> locationGroups = new ArrayList<>();
for (int i = 0; i < rows; i++) {
locationGroups.add(
new GtfsLocationGroups.Builder()
.setCsvRowNumber(i + 1)
.setLocationGroupId(groupId)
.setLocationGroupName(groupName)
.build());
}
return locationGroups;
}

@Test
public void testShapesFileAndFixedDrtPresent() {
List<ValidationNotice> notices =
generateNotices(
createShapeTable(1),
createLocationGroupsTable(1, "b", "testgroup"),
createFeedContainer(
createShapeTable(1), createLocationGroupsTable(1, "b", "testgroup")));
boolean found =
notices.stream().anyMatch(notice -> notice instanceof MissingRecommendedFileNotice);
assertThat(found).isFalse();
}

@Test
public void testShapesFileAndZoneBasedDrtPresent() {
List<ValidationNotice> notices =
generateNotices(
createShapeTable(1),
createLocationGroupsTable(1, "d", "t3stgroup"),
createFeedContainer(
createShapeTable(1), createLocationGroupsTable(1, "d", "t3stgroup")));
boolean found =
notices.stream().anyMatch(notice -> notice instanceof MissingRecommendedFileNotice);
assertThat(found).isFalse();
}

@Test
public void testNoShapesFileAndNoDrtPresent() {
List<ValidationNotice> notices =
generateNotices(
createShapeTable(-1),
createLocationGroupsTable(0, null, null),
createFeedContainer(createShapeTable(-1), createLocationGroupsTable(0, null, null)));
long missingRecommendedFileNoticesCount =
notices.stream().filter(notice -> notice instanceof MissingRecommendedFileNotice).count();
assertThat(missingRecommendedFileNoticesCount).isAtLeast(1);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is now an assertion error here :( probably related to my implementation of createFeedContainer()

}

private static List<ValidationNotice> generateNotices(
Comment thread
cswilson252 marked this conversation as resolved.
List<GtfsShape> shapes,
List<GtfsLocationGroups> locationGroups,
GtfsFeedContainer feedContainer) {
NoticeContainer noticeContainer = new NoticeContainer();
new MissingShapesFileValidator(
GtfsShapeTableContainer.forEntities(shapes, noticeContainer),
GtfsLocationGroupsTableContainer.forEntities(locationGroups, noticeContainer),
feedContainer)
.validate(noticeContainer);
return noticeContainer.getValidationNotices();
}
}
Loading