Skip to content

Commit 011ac03

Browse files
authored
Merge f640f58 into ede7e0c
2 parents ede7e0c + f640f58 commit 011ac03

File tree

2 files changed

+113
-1
lines changed

2 files changed

+113
-1
lines changed

main/src/main/java/org/mobilitydata/gtfsvalidator/report/model/FeedMetadata.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ private void loadSpecFeatures(GtfsFeedContainer feedContainer) {
9595
boolean faresV2 = fareProductsTable.isPresent() && fareProductsTable.get().entityCount() > 0;
9696
specFeatures.put("Fares V2", faresV2 ? "Yes" : "No");
9797
specFeatures.put("Route Names", hasRouteNamesComponent(feedContainer) ? "Yes" : "No");
98+
specFeatures.put("Route Colors", hasRouteColorsComponent(feedContainer) ? "Yes" : "No");
9899
specFeatures.put(
99100
"Shapes", hasOneRecordOfComponent(feedContainer, GtfsShape.FILENAME) ? "Yes" : "No");
100101
var stopTimesTable = feedContainer.getTableForFilename(GtfsStopTime.FILENAME);
@@ -123,6 +124,18 @@ private void loadFeedInfo(GtfsTableContainer<GtfsFeedInfo> feedTable) {
123124
}
124125
}
125126

127+
private boolean hasRouteColorsComponent(GtfsFeedContainer feedContainer) {
128+
var routeContainer = feedContainer.getTableForFilename(GtfsRoute.FILENAME);
129+
if (routeContainer.isPresent()) {
130+
GtfsRouteTableContainer routeTable = (GtfsRouteTableContainer) routeContainer.get();
131+
if (routeTable.hasColumn(GtfsRoute.ROUTE_COLOR_FIELD_NAME)
132+
&& routeTable.hasColumn(GtfsRoute.ROUTE_TEXT_COLOR_FIELD_NAME))
133+
return routeTable.getEntities().stream()
134+
.anyMatch(route -> route.hasRouteColor() || route.hasRouteTextColor());
135+
}
136+
return false;
137+
}
138+
126139
private boolean hasRouteNamesComponent(GtfsFeedContainer feedContainer) {
127140
var routeContainer = feedContainer.getTableForFilename(GtfsRoute.FILENAME);
128141
if (routeContainer.isPresent()) {

main/src/test/java/org/mobilitydata/gtfsvalidator/report/model/FeedMetadataTest.java

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class FeedMetadataTest {
3232
ValidatorLoader validatorLoader;
3333
File rootDir;
3434

35-
private void createDataFile(String filename, String content) throws IOException {
35+
public void createDataFile(String filename, String content) throws IOException {
3636
File dataFile = tmpDir.newFile("data/" + filename);
3737
try (BufferedWriter writer = new BufferedWriter(new FileWriter(dataFile))) {
3838
writer.write(content);
@@ -120,6 +120,105 @@ public void omitsRouteNamesComponentTest3() throws IOException, InterruptedExcep
120120
ImmutableList.of(GtfsRouteTableDescriptor.class, GtfsAgencyTableDescriptor.class));
121121
}
122122

123+
@Test
124+
/**
125+
* This method is to test when both route_color and route_text_color are present in routes.txt,
126+
* and they each have two records
127+
*/
128+
public void containsRouteColorsComponentTest() throws IOException, InterruptedException {
129+
String routesContent =
130+
"route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color\n"
131+
+ "01,LTC -2023 Spring Schedules,01,Route 1,,3,,70C2DA,000000\n"
132+
+ "02,LTC -2023 Spring Schedules,02,Route 2,,3,,0080C0,000000\n";
133+
createDataFile("routes.txt", routesContent);
134+
validateSpecFeature(
135+
"Route Colors",
136+
"Yes",
137+
ImmutableList.of(GtfsRouteTableDescriptor.class, GtfsAgencyTableDescriptor.class));
138+
}
139+
140+
/**
141+
* This method is to test when both route_color and route_text_color are present in routes.txt,
142+
* and none of them has records
143+
*/
144+
@Test
145+
public void omitsRouteColorsComponentTest1() throws IOException, InterruptedException {
146+
String routesContent =
147+
"route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color\n"
148+
+ "01,LTC -2023 Spring Schedules,01,Route 1,,3,,,\n"
149+
+ "02,LTC -2023 Spring Schedules,02,Route 2,,3,,,\n";
150+
createDataFile("routes.txt", routesContent);
151+
validateSpecFeature(
152+
"Route Colors",
153+
"No",
154+
ImmutableList.of(GtfsRouteTableDescriptor.class, GtfsAgencyTableDescriptor.class));
155+
}
156+
157+
/**
158+
* This method is to test when both route_color and route_text_color are present in routes.txt,
159+
* and they each have one record
160+
*/
161+
@Test
162+
public void omitsRouteColorsComponentTest2() throws IOException, InterruptedException {
163+
String routesContent =
164+
"route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color\n"
165+
+ "01,LTC -2023 Spring Schedules,01,Route 1,,3,,,70C2DA\n"
166+
+ "02,LTC -2023 Spring Schedules,02,Route 2,,3,,0080C0,\n";
167+
createDataFile("routes.txt", routesContent);
168+
validateSpecFeature(
169+
"Route Colors",
170+
"Yes",
171+
ImmutableList.of(GtfsRouteTableDescriptor.class, GtfsAgencyTableDescriptor.class));
172+
}
173+
174+
/**
175+
* This method is to test when both route_color and route_text_color are present in routes.txt,
176+
* and one has two records, one has none
177+
*/
178+
@Test
179+
public void omitsRouteColorsComponentTest3() throws IOException, InterruptedException {
180+
String routesContent =
181+
"route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color\n"
182+
+ "01,LTC -2023 Spring Schedules,01,Route 1,,3,,0080C0,000000\n"
183+
+ "02,LTC -2023 Spring Schedules,02,Route 2,,3,,,\n";
184+
createDataFile("routes.txt", routesContent);
185+
validateSpecFeature(
186+
"Route Colors",
187+
"Yes",
188+
ImmutableList.of(GtfsRouteTableDescriptor.class, GtfsAgencyTableDescriptor.class));
189+
}
190+
191+
/**
192+
* This method is to test when route_color is present and route_text_color is missing in
193+
* routes.txt
194+
*/
195+
@Test
196+
public void omitsRouteColorsComponentTest4() throws IOException, InterruptedException {
197+
String routesContent =
198+
"route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color\n"
199+
+ "01,LTC -2023 Spring Schedules,01,Route 1,,3,,,\n"
200+
+ "02,LTC -2023 Spring Schedules,02,Route 2,,3,,70C2DA\n";
201+
createDataFile("routes.txt", routesContent);
202+
validateSpecFeature(
203+
"Route Colors",
204+
"No",
205+
ImmutableList.of(GtfsRouteTableDescriptor.class, GtfsAgencyTableDescriptor.class));
206+
}
207+
208+
/** This method is to test when both route_color and route_text_color are missing in routes.txt */
209+
@Test
210+
public void omitsRouteColorsComponentTest5() throws IOException, InterruptedException {
211+
String routesContent =
212+
"route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url\n"
213+
+ "01,LTC -2023 Spring Schedules,01,Route 1,,3,\n"
214+
+ "02,LTC -2023 Spring Schedules,02,Route 2,,3,\n";
215+
createDataFile("routes.txt", routesContent);
216+
validateSpecFeature(
217+
"Route Colors",
218+
"No",
219+
ImmutableList.of(GtfsRouteTableDescriptor.class, GtfsAgencyTableDescriptor.class));
220+
}
221+
123222
@Test
124223
public void containsPathwaysComponentTest() throws IOException, InterruptedException {
125224
String pathwayContent =

0 commit comments

Comments
 (0)