Skip to content

Commit

Permalink
feat: modify stops.txt to be conditionally required (#1868)
Browse files Browse the repository at this point in the history
  • Loading branch information
cka-y authored Oct 7, 2024
1 parent f89774a commit 2a02346
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
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();
}
}

0 comments on commit 2a02346

Please sign in to comment.