1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.validation.tests;
|
---|
3 |
|
---|
4 | import org.junit.Before;
|
---|
5 | import org.junit.Test;
|
---|
6 | import org.openstreetmap.josm.Main;
|
---|
7 | import org.openstreetmap.josm.data.validation.Severity;
|
---|
8 |
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | import static org.CustomMatchers.hasSize;
|
---|
12 | import static org.CustomMatchers.isEmpty;
|
---|
13 | import static org.hamcrest.CoreMatchers.is;
|
---|
14 | import static org.hamcrest.CoreMatchers.not;
|
---|
15 | import static org.junit.Assert.assertThat;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * JUnit Test of "Opening hours" validation test.
|
---|
19 | */
|
---|
20 | public class OpeningHourTestTest {
|
---|
21 |
|
---|
22 | private static final OpeningHourTest OPENING_HOUR_TEST = new OpeningHourTest();
|
---|
23 |
|
---|
24 | @Before
|
---|
25 | public void setUp() throws Exception {
|
---|
26 | Main.initApplicationPreferences();
|
---|
27 | OPENING_HOUR_TEST.initialize();
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Test
|
---|
31 | public void testCheckOpeningHourSyntax1() throws Exception {
|
---|
32 | final String key = "opening_hours";
|
---|
33 | // frequently used tags according to http://taginfo.openstreetmap.org/keys/opening_hours#values
|
---|
34 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "24/7"), isEmpty());
|
---|
35 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 08:30-20:00"), isEmpty());
|
---|
36 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "09:00-21:00"), isEmpty());
|
---|
37 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise"), isEmpty());
|
---|
38 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise"), hasSize(1));
|
---|
39 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise").get(0).getSeverity(), is(Severity.OTHER));
|
---|
40 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise").get(0).getPrettifiedValue(), is("Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise"));
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Test
|
---|
44 | public void testCheckOpeningHourSyntax2() throws Exception {
|
---|
45 | final String key = "opening_hours";
|
---|
46 | final List<OpeningHourTest.OpeningHoursTestError> errors = OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Tue");
|
---|
47 | assertThat(errors, hasSize(1));
|
---|
48 | assertThat(errors.get(0).getMessage(), is("Mo-Tue <--- (Please use the abbreviation \"Tu\" for \"tue\".)"));
|
---|
49 | assertThat(errors.get(0).getSeverity(), is(Severity.WARNING));
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Test
|
---|
53 | public void testCheckOpeningHourSyntax3() throws Exception {
|
---|
54 | final String key = "opening_hours";
|
---|
55 | final List<OpeningHourTest.OpeningHoursTestError> errors = OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Sa-Su 10.00-20.00");
|
---|
56 | assertThat(errors, hasSize(2));
|
---|
57 | assertThat(errors.get(0).getMessage(), is("Sa-Su 10. <--- (Please use \":\" as hour/minute-separator)"));
|
---|
58 | assertThat(errors.get(0).getSeverity(), is(Severity.WARNING));
|
---|
59 | assertThat(errors.get(0).getPrettifiedValue(), is("Sa-Su 10:00-20:00"));
|
---|
60 | assertThat(errors.get(1).getMessage(), is("Sa-Su 10.00-20. <--- (Please use \":\" as hour/minute-separator)"));
|
---|
61 | assertThat(errors.get(1).getSeverity(), is(Severity.WARNING));
|
---|
62 | }
|
---|
63 |
|
---|
64 | @Test
|
---|
65 | public void testCheckOpeningHourSyntax4() throws Exception {
|
---|
66 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(null, null), isEmpty());
|
---|
67 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(null, ""), isEmpty());
|
---|
68 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(null, " "), isEmpty());
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Test
|
---|
72 | public void testCheckOpeningHourSyntax5() throws Exception {
|
---|
73 | final String key = "opening_hours";
|
---|
74 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "badtext"), hasSize(1));
|
---|
75 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "badtext").get(0).getMessage(),
|
---|
76 | is("opening_hours - ba <--- (Unexpected token: \"b\" This means that the syntax is not valid at that point or it is currently not supported.)"));
|
---|
77 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m"), hasSize(1));
|
---|
78 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m").get(0).getMessage(),
|
---|
79 | is("opening_hours - 5.00 p <--- (hyphen (-) or open end (+) in time range expected. For working with points in time, the mode for opening_hours.js has to be altered. Maybe wrong tag?)"));
|
---|
80 | }
|
---|
81 |
|
---|
82 | @Test
|
---|
83 | public void testCheckOpeningHourSyntax6() throws Exception {
|
---|
84 | final String key = "opening_hours";
|
---|
85 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "PH open \"always open on public holidays\""), isEmpty());
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Test
|
---|
89 | public void testCheckOpeningHourSyntax7() throws Exception {
|
---|
90 | final String key = "opening_hours";
|
---|
91 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00"), hasSize(1));
|
---|
92 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getSeverity(), is(Severity.OTHER));
|
---|
93 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getPrettifiedValue(), is("09:00-18:00"));
|
---|
94 | }
|
---|
95 |
|
---|
96 | @Test
|
---|
97 | public void testCheckOpeningHourSyntaxTicket9367() throws Exception {
|
---|
98 | final String key = "opening_hours";
|
---|
99 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getSeverity(), is(Severity.WARNING));
|
---|
100 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getMessage(), is("Mo,Tu 04-17 <--- (Time range without minutes specified. Not very explicit! Please use this syntax instead e.g. \"12:00-14:00\".)"));
|
---|
101 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getPrettifiedValue(), is("Mo,Tu 04:00-17:00"));
|
---|
102 | }
|
---|
103 |
|
---|
104 | @Test
|
---|
105 | public void testCheckServiceTimeSyntax1() throws Exception {
|
---|
106 | final String key = "service_times";
|
---|
107 | // frequently used tags according to http://taginfo.openstreetmap.org/keys/service_times#values
|
---|
108 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su 10:00", OpeningHourTest.CheckMode.BOTH), isEmpty());
|
---|
109 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "automatic", OpeningHourTest.CheckMode.BOTH), not(isEmpty()));
|
---|
110 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Sa 09:00-18:00", OpeningHourTest.CheckMode.BOTH), isEmpty());
|
---|
111 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su 09:30; We 19:30", OpeningHourTest.CheckMode.BOTH), isEmpty());
|
---|
112 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00", OpeningHourTest.CheckMode.BOTH), isEmpty());
|
---|
113 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00", OpeningHourTest.CheckMode.BOTH), hasSize(1));
|
---|
114 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00", OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue(), is("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00"));
|
---|
115 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00", OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue(), is("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00"));
|
---|
116 | }
|
---|
117 |
|
---|
118 | @Test
|
---|
119 | public void testCheckCollectionTimeSyntax1() throws Exception {
|
---|
120 | final String key = "collection_times";
|
---|
121 | // frequently used tags according to http://taginfo.openstreetmap.org/keys/collection_times#values
|
---|
122 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Sa 09:00", OpeningHourTest.CheckMode.BOTH), isEmpty());
|
---|
123 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "fixme", OpeningHourTest.CheckMode.BOTH), not(isEmpty()));
|
---|
124 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "daily", OpeningHourTest.CheckMode.BOTH), not(isEmpty()));
|
---|
125 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30,17:45,19:00; Sa 15:00; Su 11:00", OpeningHourTest.CheckMode.BOTH), isEmpty());
|
---|
126 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00", OpeningHourTest.CheckMode.BOTH), hasSize(1));
|
---|
127 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00", OpeningHourTest.CheckMode.BOTH).get(0).getSeverity(), is(Severity.OTHER));
|
---|
128 | assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00", OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue(), is("Mo-Fr 13:30,17:45,19:00; Sa 15:00; Su 11:00"));
|
---|
129 | }
|
---|
130 | }
|
---|