Skip to content

Commit

Permalink
feat: 1791 feed infotxt should be added to missing required file when…
Browse files Browse the repository at this point in the history
… translationstxt exists (#1803)

* added logic: feed_info.txt should be added to missing_required_file when translations.txt exists

* removed sout

* have one loop that checks for the presence of translations, then the original loop that processes the files.

* added MissingFeedInfoValidator

* changed GtfsFeedInfoSchema to ConditionallyRequired

* formatted code

* added MissingFeedInfoValidatorTest

* formatted code

* added class comments

* added test: feedInfoPresentShouldGenerateNoNotice

* added blank line back

* formatted code
  • Loading branch information
qcdyx authored Aug 28, 2024
1 parent eb0d40a commit ada0b25
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,11 @@
package org.mobilitydata.gtfsvalidator.table;

import java.util.Locale;
import org.mobilitydata.gtfsvalidator.annotation.EndRange;
import org.mobilitydata.gtfsvalidator.annotation.FieldType;
import org.mobilitydata.gtfsvalidator.annotation.FieldTypeEnum;
import org.mobilitydata.gtfsvalidator.annotation.GtfsTable;
import org.mobilitydata.gtfsvalidator.annotation.Recommended;
import org.mobilitydata.gtfsvalidator.annotation.Required;
import org.mobilitydata.gtfsvalidator.annotation.*;
import org.mobilitydata.gtfsvalidator.type.GtfsDate;

@GtfsTable(value = "feed_info.txt", singleRow = true)
@Recommended
@ConditionallyRequired
public interface GtfsFeedInfoSchema extends GtfsEntity {
@Required
String feedPublisherName();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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.MissingRequiredFileNotice;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
import org.mobilitydata.gtfsvalidator.table.GtfsFeedInfo;
import org.mobilitydata.gtfsvalidator.table.GtfsFeedInfoTableContainer;
import org.mobilitydata.gtfsvalidator.table.GtfsTranslationTableContainer;

/**
* The `MissingFeedInfoValidator` class is responsible for validating the presence of the
* `feed_info.txt` file in a GTFS feed. If the `feed_info.txt` file is missing, it generates
* appropriate validation notices.
*
* <p>The validation logic is as follows: - If the `feed_info.txt` file is missing and the
* `translations.txt` file is also missing, a `MissingRecommendedFileNotice` is generated. - If the
* `feed_info.txt` file is missing but the `translations.txt` file is present, a
* `MissingRequiredFileNotice` is generated.
*
* <p>This validator is part of the GTFS validation framework and is annotated with `@GtfsValidator`
* to indicate its role.
*
* <p>Dependencies: - `GtfsFeedInfoTableContainer`: Provides access to the `feed_info.txt` file
* data. - `GtfsTranslationTableContainer`: Provides access to the `translations.txt` file data. -
* `NoticeContainer`: Collects validation notices generated during the validation process.
*/
@GtfsValidator
public class MissingFeedInfoValidator extends FileValidator {

private final GtfsFeedInfoTableContainer feedInfoTable;
private final GtfsTranslationTableContainer translationTable;

@Inject
public MissingFeedInfoValidator(
GtfsFeedInfoTableContainer feedInfoTable, GtfsTranslationTableContainer translationTable) {
this.feedInfoTable = feedInfoTable;
this.translationTable = translationTable;
}

@Override
public void validate(NoticeContainer noticeContainer) {
if (feedInfoTable.isMissingFile()) {
if (translationTable.isMissingFile()) {
noticeContainer.addValidationNotice(
new MissingRecommendedFileNotice(GtfsFeedInfo.FILENAME));
} else {
noticeContainer.addValidationNotice(new MissingRequiredFileNotice(GtfsFeedInfo.FILENAME));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.mobilitydata.gtfsvalidator.validator;

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

import java.util.List;
import org.junit.Test;
import org.mobilitydata.gtfsvalidator.notice.MissingRecommendedFileNotice;
import org.mobilitydata.gtfsvalidator.notice.MissingRequiredFileNotice;
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
import org.mobilitydata.gtfsvalidator.notice.ValidationNotice;
import org.mobilitydata.gtfsvalidator.table.*;

public class MissingFeedInfoValidatorTest {

private static List<ValidationNotice> generateNotices(
GtfsFeedInfoTableContainer feedInfoTableContainer,
GtfsTranslationTableContainer translationTableContainer) {
NoticeContainer noticeContainer = new NoticeContainer();
new MissingFeedInfoValidator(feedInfoTableContainer, translationTableContainer)
.validate(noticeContainer);
return noticeContainer.getValidationNotices();
}

@Test
public void missingFeedInfoTranslationTableNotPresent() {
assertThat(
generateNotices(
GtfsFeedInfoTableContainer.forStatus(GtfsTableContainer.TableStatus.MISSING_FILE),
GtfsTranslationTableContainer.forStatus(
GtfsTableContainer.TableStatus.MISSING_FILE)))
.containsExactly(new MissingRecommendedFileNotice(GtfsFeedInfo.FILENAME));
}

@Test
public void missingFeedInfoWhenTranslationTableIsPresent() {
assertThat(
generateNotices(
GtfsFeedInfoTableContainer.forStatus(GtfsTableContainer.TableStatus.MISSING_FILE),
GtfsTranslationTableContainer.forStatus(
GtfsTableContainer.TableStatus.PARSABLE_HEADERS_AND_ROWS)))
.contains(new MissingRequiredFileNotice(GtfsFeedInfo.FILENAME));
}

@Test
public void feedInfoPresentShouldGenerateNoNotice() {
assertThat(
generateNotices(
GtfsFeedInfoTableContainer.forStatus(
GtfsTableContainer.TableStatus.PARSABLE_HEADERS_AND_ROWS),
GtfsTranslationTableContainer.forStatus(
GtfsTableContainer.TableStatus.PARSABLE_HEADERS_AND_ROWS)))
.isEmpty();
}
}

0 comments on commit ada0b25

Please sign in to comment.