Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: modify stops.txt to be conditionally required #1868

Merged
merged 4 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -20,7 +20,7 @@
import org.mobilitydata.gtfsvalidator.annotation.*;

@GtfsTable("stops.txt")
@Required
@ConditionallyRequired
public interface GtfsStopSchema extends GtfsEntity {
@FieldType(FieldTypeEnum.ID)
@PrimaryKey
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.mobilitydata.gtfsvalidator.validator;

import javax.inject.Inject;
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator;
import org.mobilitydata.gtfsvalidator.notice.MissingRequiredFileNotice;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
import org.mobilitydata.gtfsvalidator.table.*;

@GtfsValidator
public class MissingStopsFileValidator extends FileValidator {

private final GtfsStopTableContainer stopTableContainer;
private final GtfsGeojsonFeaturesContainer geojsonFeaturesContainer;

@Inject
MissingStopsFileValidator(
GtfsStopTableContainer table, GtfsGeojsonFeaturesContainer geojsonFeaturesContainer) {
this.stopTableContainer = table;
this.geojsonFeaturesContainer = geojsonFeaturesContainer;
}

@Override
public void validate(NoticeContainer noticeContainer) {
if (stopTableContainer.isMissingFile() && geojsonFeaturesContainer.isMissingFile()) {
noticeContainer.addValidationNotice(new MissingRequiredFileNotice("stops.txt"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.mobilitydata.gtfsvalidator.validator;

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

import java.util.ArrayList;
import org.junit.Test;
import org.mobilitydata.gtfsvalidator.notice.MissingRequiredFileNotice;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
import org.mobilitydata.gtfsvalidator.table.GtfsGeojsonFeaturesContainer;
import org.mobilitydata.gtfsvalidator.table.GtfsGeojsonFileDescriptor;
import org.mobilitydata.gtfsvalidator.table.GtfsStopTableContainer;
import org.mobilitydata.gtfsvalidator.table.TableStatus;

public class MissingStopsFileValidatorTest {
@Test
public void stopsTxtMissingFileShouldGenerateNotice() {
// If stops.txt is missing and locations.geojson is missing, a notice should be generated
NoticeContainer noticeContainer = new NoticeContainer();
GtfsGeojsonFileDescriptor descriptor = new GtfsGeojsonFileDescriptor();
GtfsGeojsonFeaturesContainer geoJsonFeaturesContainer =
descriptor.createContainerForInvalidStatus(TableStatus.MISSING_FILE);
GtfsStopTableContainer stopTableContainer =
GtfsStopTableContainer.forStatus(TableStatus.MISSING_FILE);
new MissingStopsFileValidator(stopTableContainer, geoJsonFeaturesContainer)
.validate(noticeContainer);
assertThat(noticeContainer.getValidationNotices())
.containsExactly(new MissingRequiredFileNotice("stops.txt"));
}

@Test
public void stopsTxtMissingFileShouldNotGenerateNotice() {
// If stops.txt is missing, but locations.geojson is present, no notice should be generated
NoticeContainer noticeContainer = new NoticeContainer();
GtfsGeojsonFileDescriptor descriptor = new GtfsGeojsonFileDescriptor();
GtfsGeojsonFeaturesContainer geoJsonFeaturesContainer =
descriptor.createContainerForEntities(new ArrayList<>(), noticeContainer);
GtfsStopTableContainer stopTableContainer =
GtfsStopTableContainer.forStatus(TableStatus.MISSING_FILE);
new MissingStopsFileValidator(stopTableContainer, geoJsonFeaturesContainer)
.validate(noticeContainer);
assertThat(noticeContainer.getValidationNotices()).isEmpty();
}
}
Loading