Skip to content

Commit

Permalink
feat: modify stops.txt to be conditionnally required
Browse files Browse the repository at this point in the history
  • Loading branch information
cka-y committed Oct 3, 2024
1 parent b03bc03 commit a108ba7
Show file tree
Hide file tree
Showing 3 changed files with 71 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,30 @@
package org.mobilitydata.gtfsvalidator.validator;

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

import javax.inject.Inject;


@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,40 @@
package org.mobilitydata.gtfsvalidator.validator;

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;

import java.util.ArrayList;

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

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 a108ba7

Please sign in to comment.