-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 1791 feed infotxt should be added to missing required file when…
… 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
Showing
3 changed files
with
109 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
main/src/main/java/org/mobilitydata/gtfsvalidator/validator/MissingFeedInfoValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
.../src/test/java/org/mobilitydata/gtfsvalidator/validator/MissingFeedInfoValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |