Skip to content

Commit

Permalink
feat: included network_id as part of the primary key for fare_leg_rul…
Browse files Browse the repository at this point in the history
…es.txt (#1894)

* included network_id as part of the primary key for fare_leg_rules.txt

* rewrote noDuplicateKeyNoticeWithNetworkIdAsPrimaryKey test and wrote duplicateKeyNoticeWithNetworkIdAsPrimaryKey test
  • Loading branch information
qcdyx authored Oct 21, 2024
1 parent 457cfc5 commit 20aeebe
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public interface GtfsFareLegRuleSchema extends GtfsEntity {
* org.mobilitydata.gtfsvalidator.validator.GtfsFareLegRuleNetworkIdForeignKeyValidator}.
*/
@FieldType(FieldTypeEnum.ID)
@PrimaryKey(translationRecordIdType = UNSUPPORTED)
String networkId();

@FieldType(FieldTypeEnum.ID)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.mobilitydata.gtfsvalidator.table;

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

import org.junit.Before;
import org.junit.Test;
import org.mobilitydata.gtfsvalidator.testing.LoadingHelper;
import org.mobilitydata.gtfsvalidator.validator.ValidatorLoaderException;

public class GtfsFareLegRuleDuplicateKeyTest {
private LoadingHelper helper;
private GtfsFareLegRuleTableDescriptor tableDescriptor;

@Before
public void setup() {
tableDescriptor = new GtfsFareLegRuleTableDescriptor();
helper = new LoadingHelper();
}

@Test
public void noDuplicateKeyNoticeWithNetworkIdAsPrimaryKey() throws ValidatorLoaderException {
GtfsFareLegRuleTableContainer tableContainer =
helper.load(
tableDescriptor,
"network_id,from_area_id,to_area_id,from_timeframe_group_id,to_timeframe_group_id,fare_product_id",
"network1,area1,area2,timeframe1,timeframe2,fare1",
"network2,area1,area2,timeframe1,timeframe2,fare1");
assertThat(helper.getValidationNotices()).isEmpty();
}

@Test
public void duplicateKeyNoticeWithNetworkIdAsPrimaryKey() throws ValidatorLoaderException {
GtfsFareLegRuleTableContainer tableContainer =
helper.load(
tableDescriptor,
"network_id,from_area_id,to_area_id,from_timeframe_group_id,to_timeframe_group_id,fare_product_id",
"network1,area1,area2,timeframe1,timeframe2,fare1",
"network1,area1,area2,timeframe1,timeframe2,fare1");
assertThat(helper.getValidationNotices()).hasSize(1);
assertThat(helper.getValidationNotices().get(0).getCode()).isEqualTo("duplicate_key");
}
}

0 comments on commit 20aeebe

Please sign in to comment.