From 20aeebe16c522b7ce0ca26a577678151ab189eb8 Mon Sep 17 00:00:00 2001 From: Jingsi Lu Date: Mon, 21 Oct 2024 14:24:39 -0400 Subject: [PATCH] feat: included network_id as part of the primary key for fare_leg_rules.txt (#1894) * included network_id as part of the primary key for fare_leg_rules.txt * rewrote noDuplicateKeyNoticeWithNetworkIdAsPrimaryKey test and wrote duplicateKeyNoticeWithNetworkIdAsPrimaryKey test --- .../table/GtfsFareLegRuleSchema.java | 1 + .../GtfsFareLegRuleDuplicateKeyTest.java | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 main/src/test/java/org/mobilitydata/gtfsvalidator/table/GtfsFareLegRuleDuplicateKeyTest.java diff --git a/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsFareLegRuleSchema.java b/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsFareLegRuleSchema.java index 72b949b840..346888a81a 100644 --- a/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsFareLegRuleSchema.java +++ b/main/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsFareLegRuleSchema.java @@ -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) diff --git a/main/src/test/java/org/mobilitydata/gtfsvalidator/table/GtfsFareLegRuleDuplicateKeyTest.java b/main/src/test/java/org/mobilitydata/gtfsvalidator/table/GtfsFareLegRuleDuplicateKeyTest.java new file mode 100644 index 0000000000..52556d8589 --- /dev/null +++ b/main/src/test/java/org/mobilitydata/gtfsvalidator/table/GtfsFareLegRuleDuplicateKeyTest.java @@ -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"); + } +}