Skip to content

Commit 43ff5cb

Browse files
authored
Merge e7fdce3 into d9c1ecb
2 parents d9c1ecb + e7fdce3 commit 43ff5cb

File tree

3 files changed

+233
-2
lines changed

3 files changed

+233
-2
lines changed

main/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsFeedInfoSchema.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,9 @@ public interface GtfsFeedInfoSchema extends GtfsEntity {
5050
@Recommended
5151
String feedVersion();
5252

53-
@Recommended
5453
@FieldType(FieldTypeEnum.EMAIL)
5554
String feedContactEmail();
5655

57-
@Recommended
5856
@FieldType(FieldTypeEnum.URL)
5957
String feedContactUrl();
6058
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.mobilitydata.gtfsvalidator.validator;
2+
3+
import static org.mobilitydata.gtfsvalidator.notice.SeverityLevel.WARNING;
4+
5+
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidationNotice;
6+
import org.mobilitydata.gtfsvalidator.annotation.GtfsValidator;
7+
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
8+
import org.mobilitydata.gtfsvalidator.notice.ValidationNotice;
9+
import org.mobilitydata.gtfsvalidator.table.GtfsFeedInfo;
10+
11+
@GtfsValidator
12+
public class FeedContactValidator extends SingleEntityValidator<GtfsFeedInfo> {
13+
14+
@Override
15+
public void validate(GtfsFeedInfo entity, NoticeContainer noticeContainer) {
16+
if (!entity.hasFeedContactEmail() && !entity.hasFeedContactUrl()
17+
|| entity.feedContactEmail().isBlank() && entity.feedContactUrl().isBlank()) {
18+
noticeContainer.addValidationNotice(
19+
new FeedContactNotice(
20+
entity.csvRowNumber(), entity.feedContactEmail(), entity.feedContactUrl()));
21+
}
22+
}
23+
24+
@GtfsValidationNotice(
25+
severity = WARNING,
26+
files = @GtfsValidationNotice.FileRefs(GtfsFeedInfo.class),
27+
urls = {
28+
@GtfsValidationNotice.UrlRef(
29+
label = "Original Python validator implementation",
30+
url = "https://github.com/google/transitfeed")
31+
})
32+
static class FeedContactNotice extends ValidationNotice {
33+
/** The row number of the faulty record. */
34+
private final int rowNumber;
35+
36+
private final String feedContactEmail;
37+
38+
private final String feedContactUrl;
39+
40+
FeedContactNotice(int rowNumber, String feedContactEmail, String feedContactUrl) {
41+
this.rowNumber = rowNumber;
42+
this.feedContactEmail = feedContactEmail;
43+
this.feedContactUrl = feedContactUrl;
44+
}
45+
}
46+
}
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
package org.mobilitydata.gtfsvalidator.validator;
2+
3+
import static com.google.common.truth.Truth.assertThat;
4+
5+
import java.util.Locale;
6+
import org.junit.Test;
7+
import org.mobilitydata.gtfsvalidator.notice.NoticeContainer;
8+
import org.mobilitydata.gtfsvalidator.table.GtfsFeedInfo;
9+
import org.mobilitydata.gtfsvalidator.type.GtfsDate;
10+
11+
public class FeedContactValidatorTest {
12+
public static GtfsFeedInfo createFeedInfo(
13+
int csvRowNumber,
14+
String feedPublisherName,
15+
String feedPublisherUrl,
16+
Locale feedLang,
17+
Locale defaultLang,
18+
GtfsDate feedStartDate,
19+
GtfsDate feedEndDate,
20+
String feedVersion,
21+
String feedContactEmail,
22+
String feedContactUrl) {
23+
return new GtfsFeedInfo.Builder()
24+
.setCsvRowNumber(csvRowNumber)
25+
.setFeedPublisherName(feedPublisherName)
26+
.setFeedPublisherUrl(feedPublisherUrl)
27+
.setFeedLang(feedLang)
28+
.setDefaultLang(defaultLang)
29+
.setFeedStartDate(feedStartDate)
30+
.setFeedEndDate(feedEndDate)
31+
.setFeedVersion(feedVersion)
32+
.setFeedContactEmail(feedContactEmail)
33+
.setFeedContactUrl(feedContactUrl)
34+
.build();
35+
}
36+
37+
/**
38+
* This method is to test the case that a feed has both email and url contact information No
39+
* FeedContactNotice should be generated
40+
*/
41+
@Test
42+
public void hasFeedContactEmailAndUrlShouldNotGenerateNotice() {
43+
NoticeContainer noticeContainer = new NoticeContainer();
44+
GtfsFeedInfo entity =
45+
createFeedInfo(
46+
2,
47+
"feed publisher name value",
48+
"feed publisher url value",
49+
GtfsFeedInfo.DEFAULT_FEED_LANG,
50+
GtfsFeedInfo.DEFAULT_DEFAULT_LANG,
51+
GtfsFeedInfo.DEFAULT_FEED_START_DATE,
52+
GtfsFeedInfo.DEFAULT_FEED_END_DATE,
53+
GtfsFeedInfo.DEFAULT_FEED_VERSION,
54+
55+
"https://github.com/MobilityData/gtfs-validator");
56+
57+
FeedContactValidator underTest = new FeedContactValidator();
58+
underTest.validate(entity, noticeContainer);
59+
assertThat(noticeContainer.getValidationNotices()).isEmpty();
60+
}
61+
62+
/**
63+
* This method is to test the case that a feed has email contact information but no contact url
64+
* information No FeedContactNotice should be generated
65+
*/
66+
@Test
67+
public void hasFeedContactEmailNoUrlShouldNotGenerateNotice1() {
68+
NoticeContainer noticeContainer = new NoticeContainer();
69+
GtfsFeedInfo entity =
70+
createFeedInfo(
71+
2,
72+
"feed publisher name value",
73+
"feed publisher url value",
74+
GtfsFeedInfo.DEFAULT_FEED_LANG,
75+
GtfsFeedInfo.DEFAULT_DEFAULT_LANG,
76+
GtfsFeedInfo.DEFAULT_FEED_START_DATE,
77+
GtfsFeedInfo.DEFAULT_FEED_END_DATE,
78+
GtfsFeedInfo.DEFAULT_FEED_VERSION,
79+
80+
"");
81+
82+
FeedContactValidator underTest = new FeedContactValidator();
83+
underTest.validate(entity, noticeContainer);
84+
assertThat(noticeContainer.getValidationNotices()).isEmpty();
85+
}
86+
87+
/**
88+
* This method is to test the case that a feed has email contact information but no contact url
89+
* information No FeedContactNotice should be generated
90+
*/
91+
@Test
92+
public void hasFeedContactEmailNoUrlShouldNotGenerateNotice2() {
93+
NoticeContainer noticeContainer = new NoticeContainer();
94+
GtfsFeedInfo entity =
95+
createFeedInfo(
96+
2,
97+
"feed publisher name value",
98+
"feed publisher url value",
99+
GtfsFeedInfo.DEFAULT_FEED_LANG,
100+
GtfsFeedInfo.DEFAULT_DEFAULT_LANG,
101+
GtfsFeedInfo.DEFAULT_FEED_START_DATE,
102+
GtfsFeedInfo.DEFAULT_FEED_END_DATE,
103+
GtfsFeedInfo.DEFAULT_FEED_VERSION,
104+
105+
null);
106+
107+
FeedContactValidator underTest = new FeedContactValidator();
108+
underTest.validate(entity, noticeContainer);
109+
assertThat(noticeContainer.getValidationNotices()).isEmpty();
110+
}
111+
112+
/**
113+
* This method is to test the case that a feed has contact url but no contact email No
114+
* FeedContactNotice should be generated
115+
*/
116+
@Test
117+
public void hasFeedContactUrlNoEmailShouldNotGenerateNotice1() {
118+
NoticeContainer noticeContainer = new NoticeContainer();
119+
GtfsFeedInfo entity =
120+
createFeedInfo(
121+
2,
122+
"feed publisher name value",
123+
"feed publisher url value",
124+
GtfsFeedInfo.DEFAULT_FEED_LANG,
125+
GtfsFeedInfo.DEFAULT_DEFAULT_LANG,
126+
GtfsFeedInfo.DEFAULT_FEED_START_DATE,
127+
GtfsFeedInfo.DEFAULT_FEED_END_DATE,
128+
GtfsFeedInfo.DEFAULT_FEED_VERSION,
129+
"",
130+
"https://github.com/MobilityData/gtfs-validator");
131+
132+
FeedContactValidator underTest = new FeedContactValidator();
133+
underTest.validate(entity, noticeContainer);
134+
assertThat(noticeContainer.getValidationNotices()).isEmpty();
135+
}
136+
137+
/**
138+
* This method is to test the case that a feed has contact url but no contact email No
139+
* FeedContactNotice should be generated
140+
*/
141+
@Test
142+
public void hasFeedContactUrlNoEmailShouldNotGenerateNotice2() {
143+
NoticeContainer noticeContainer = new NoticeContainer();
144+
GtfsFeedInfo entity =
145+
createFeedInfo(
146+
2,
147+
"feed publisher name value",
148+
"feed publisher url value",
149+
GtfsFeedInfo.DEFAULT_FEED_LANG,
150+
GtfsFeedInfo.DEFAULT_DEFAULT_LANG,
151+
GtfsFeedInfo.DEFAULT_FEED_START_DATE,
152+
GtfsFeedInfo.DEFAULT_FEED_END_DATE,
153+
GtfsFeedInfo.DEFAULT_FEED_VERSION,
154+
null,
155+
"https://github.com/MobilityData/gtfs-validator");
156+
157+
FeedContactValidator underTest = new FeedContactValidator();
158+
underTest.validate(entity, noticeContainer);
159+
assertThat(noticeContainer.getValidationNotices()).isEmpty();
160+
}
161+
162+
/**
163+
* This method is to test the case that a feed has neither contact url nor contact email
164+
* FeedContactNotice should be generated
165+
*/
166+
@Test
167+
public void nonFeedContactEmailAndUrlShouldGenerateNotice() {
168+
NoticeContainer noticeContainer = new NoticeContainer();
169+
GtfsFeedInfo entity =
170+
createFeedInfo(
171+
2,
172+
"feed publisher name value",
173+
"feed publisher url value",
174+
GtfsFeedInfo.DEFAULT_FEED_LANG,
175+
GtfsFeedInfo.DEFAULT_DEFAULT_LANG,
176+
GtfsFeedInfo.DEFAULT_FEED_START_DATE,
177+
GtfsFeedInfo.DEFAULT_FEED_END_DATE,
178+
GtfsFeedInfo.DEFAULT_FEED_VERSION,
179+
"",
180+
"");
181+
182+
FeedContactValidator underTest = new FeedContactValidator();
183+
underTest.validate(entity, noticeContainer);
184+
assertThat(noticeContainer.getValidationNotices())
185+
.containsExactly(new FeedContactValidator.FeedContactNotice(2, "", ""));
186+
}
187+
}

0 commit comments

Comments
 (0)