-
Notifications
You must be signed in to change notification settings - Fork 260
/
TestDescriptor.java
387 lines (330 loc) · 14.7 KB
/
TestDescriptor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
package com.cronutils.utils.descriptor;
import java.util.Locale;
import java.util.ResourceBundle;
import org.junit.Ignore;
import org.junit.Test;
import com.cronutils.descriptor.CronDescriptor;
import com.cronutils.descriptor.refactor.TimeDescriptor;
import com.cronutils.model.Cron;
import com.cronutils.model.CronType;
import com.cronutils.model.definition.CronDefinition;
import com.cronutils.model.definition.CronDefinitionBuilder;
import com.cronutils.parser.CronParser;
import static org.junit.Assert.assertEquals;
//FIXME https://github.com/jmrozanec/cron-utils/issues/3
public class TestDescriptor {
private final CronDescriptor descriptor = CronDescriptor.instance();
// SoM MoH HoD D0M MoY DoW Year
// 3/4 5/6 7/8 9/2 10/2 ? 2017/2
//Every 4 seconds starting at second 03,
//every 6 minutes starting at minute :05,
//every 8 hours starting at 07am,
//every 2 days starting on the 9th,
//every 2 months starting in October,
//every 2 years starting in 2017
@Ignore
@Test
public void testFull() {
final Cron cron = getCron("3/4 5/6 7/8 9/2 10/2 ? 2017");
assertEquals("every 4 seconds starting at second 03, every 6 minutes starting at minute 05, every 8 hours starting at 07am, "
+ "every 2 days startint on the 9th, every 2 months starting in October, in 2017", descriptor.describe(cron));
}
private Cron getCron(final String quartzExpression) {
final CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
final CronParser parser = new CronParser(cronDefinition);
return parser.parse(quartzExpression);
}
@Test
public void testEverySecond() {
final Cron cron = getCron("* * * * * ? *");
final TimeDescriptor t = new TimeDescriptor(ResourceBundle.getBundle("CronUtilsI18N", Locale.UK));
assertEquals("every second", t.describe(cron));
}
@Test
public void testEvery1Second() {
final Cron cron = getCron("*/1 * * * * ? *");
final TimeDescriptor t = new TimeDescriptor(ResourceBundle.getBundle("CronUtilsI18N", Locale.UK));
assertEquals("every second", t.describe(cron));
}
@Test
public void testEvery2Seconds() {
final Cron cron = getCron("*/2 * * * * ? *");
final TimeDescriptor t = new TimeDescriptor(ResourceBundle.getBundle("CronUtilsI18N", Locale.UK));
assertEquals("every 2 seconds", t.describe(cron));
}
@Test
public void testEverySecondGerman() {
final Cron cron = getCron("* * * * * ? *");
final TimeDescriptor t = new TimeDescriptor(ResourceBundle.getBundle("CronUtilsI18N", Locale.GERMAN));
assertEquals("jede sekunde", t.describe(cron));
}
@Test
public void testEvery1SecondGerman() {
final Cron cron = getCron("*/1 * * * * ? *");
final TimeDescriptor t = new TimeDescriptor(ResourceBundle.getBundle("CronUtilsI18N", Locale.GERMAN));
assertEquals("jede sekunde", t.describe(cron));
}
@Test
public void testEvery2SecondsGerman() {
final Cron cron = getCron("*/2 * * * * ? *");
final TimeDescriptor t = new TimeDescriptor(ResourceBundle.getBundle("CronUtilsI18N", Locale.GERMAN));
assertEquals("alle 2 sekunden", t.describe(cron));
}
@Test
public void testEverySecondWithoutYear() {
final Cron cron = getCron("* * * * * ?");
assertEquals("every second", descriptor.describe(cron));
}
@Test
public void testEverySecond2() {
final Cron cron = getCron("* * * ? * * *");
final Cron otherCron = getCron("* * * * * ? *");
assertEquals("every second", descriptor.describe(cron));
assertEquals(descriptor.describe(cron), descriptor.describe(otherCron));
}
@Test
public void testEverySecond2WithoutYear() {
final Cron cron = getCron("* * * ? * * *");
final Cron otherCron = getCron("* * * * * ? *");
assertEquals("every second", descriptor.describe(cron));
assertEquals(descriptor.describe(cron), descriptor.describe(otherCron));
}
@Ignore
@Test
public void testAtSecondEveryMinute() {
final Cron cron = getCron("1 * * * * ? *");
final Cron otherCron = getCron("15 * * * * ? *");
assertEquals("at second 01 of every minute", descriptor.describe(cron));
assertEquals("at second 15 of every minute", descriptor.describe(otherCron));
}
@Ignore
@Test
public void testAtSecondEveryMinuteWithoutYear() {
final Cron cron = getCron("1 * * * * ?");
final Cron otherCron = getCron("15 * * * * ?");
assertEquals("at second 01 of every minute", descriptor.describe(cron));
assertEquals("at second 15 of every minute", descriptor.describe(otherCron));
}
@Ignore
@Test
public void testEverySecondDuringMinuteOfEveryHour() {
final Cron cron = getCron("* 1 * * * ? *");
final Cron otherCron = getCron("* 15 * * * ? *");
assertEquals("every second during minute 01 of every hour", descriptor.describe(cron));
assertEquals("every second during minute 15 of every hour", descriptor.describe(otherCron));
}
@Ignore
@Test
public void testEverySecondDuringMinuteOfEveryHourWithoutYear() {
final Cron cron = getCron("* 1 * * * ?");
final Cron otherCron = getCron("* 15 * * * ?");
assertEquals("every second during minute 01 of every hour", descriptor.describe(cron));
assertEquals("every second during minute 15 of every hour", descriptor.describe(otherCron));
}
@Ignore
@Test
public void testEverySecondOnTheDayEveryMonth() {
final Cron first = getCron("* * * 1 * ? *");
final Cron second = getCron("* * * 1 * ? *");
final Cron third = getCron("* * * 1 * ? *");
final Cron otherCron = getCron("* * * 15 * ? *");
assertEquals("every second, on the 1st day, every month", descriptor.describe(first));
assertEquals("every second, on the 2nd day, every month", descriptor.describe(second));
assertEquals("every second, on the 3rd day, every month", descriptor.describe(third));
assertEquals("every second, on the 15th day, every month", descriptor.describe(otherCron));
}
@Ignore
@Test
public void testEverySecondOnTheDayEveryMonthWithoutYear() {
final Cron first = getCron("* * * 1 * ?");
final Cron second = getCron("* * * 1 * ?");
final Cron third = getCron("* * * 1 * ?");
final Cron otherCron = getCron("* * * 15 * ?");
assertEquals("every second, on the 1st day, every month", descriptor.describe(first));
assertEquals("every second, on the 2nd day, every month", descriptor.describe(second));
assertEquals("every second, on the 3rd day, every month", descriptor.describe(third));
assertEquals("every second, on the 15th day, every month", descriptor.describe(otherCron));
}
@Ignore
@Test
public void testEverySecondEveryDayInMonth() {
final Cron cron = getCron("* * * * 1 ? *");
final Cron otherCron = getCron("* * 12 * * ? *");
assertEquals("every second, every day, in January", descriptor.describe(cron));
assertEquals("every second, every day, in December", descriptor.describe(otherCron));
}
@Ignore
@Test
public void testEverySecondEveryDayInMonthWithoutYear() {
final Cron cron = getCron("* * * * 1 ?");
final Cron otherCron = getCron("* * 12 * * ?");
assertEquals("every second, every day, in January", descriptor.describe(cron));
assertEquals("every second, every day, in December", descriptor.describe(otherCron));
}
@Ignore
@Test
public void testEverySecondEveryDayInYear() {
final Cron cron = getCron("* * * * * ? 2017");
final Cron otherCron = getCron("* * * * * ? 2018");
//maybe we could assert only "every second in 2017"
assertEquals("every second, every day, in 2017", descriptor.describe(cron));
assertEquals("every second, every day, in 2018", descriptor.describe(otherCron));
}
@Ignore
@Test
public void testAtTimeEveryDay() {
final Cron cron = getCron("0 0 0 * * ? *");
assertEquals("at 00:00:00am every day", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeEveryDay2() {
final Cron cron = getCron("00 00 16 * * ? *");
assertEquals("at 16:00:00pm every day", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtMultipleTimesEveryDay() {
final Cron cron = getCron("00 00 8,16 * * ? *");
assertEquals("at second 00, at minute 00, at 08am and 16pm, of every day", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeOfDayEveryMonth() {
final Cron cron = getCron("0 0 16 1 * ? *");
assertEquals("at 16:00:00pm, on the first day, every month", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeOfMultipleDaysEveryMonth() {
final Cron cron = getCron("0 0 16 1,5,26 * ? *");
assertEquals("at 16:00:00pm on the 1st, 5th and 26th day, every month", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeOfEveryDayInMonth() {
final Cron cron = getCron("0 0 16 * 3 ? *");
assertEquals("at 16:00:00pm, every day, in March", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeOfEveryDayInMultipleMonth() {
final Cron cron = getCron("0 0 16 * 1,5,12 ? *");
assertEquals("at 16:00:00pm, every day in January, May and December", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeOfEveryDayBetweenMonths() {
final Cron cron = getCron("0 0 16 * 3-7 ? *");
assertEquals("at 16:00:00pm, every day between March and July", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeOfEveryDayBetweenMultipleMonths() {
final Cron cron = getCron("0 0 16 * 3-7,10-12 ? *");
assertEquals("at 16:00:00pm, every day between march and July and every month between October and December", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeOfFirstInMultipleMonths() {
final Cron cron = getCron("0 0 16 1 3,5,12 ? *");
assertEquals("at 16:00:00pm, on the 1st day in March, May and December", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeOfSecondInMultipleMonths() {
final Cron cron = getCron("0 0 16 2 3,5,12 ? *");
assertEquals("at 16:00:00pm, on the 2nd day in March, May and December", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeOfThirdInMultipleMonths() {
final Cron cron = getCron("0 0 16 3 3,5,12 ? *");
assertEquals("at 16:00:00pm, on the 3rd day in March, May and December", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeOfSpecificDayInMultipleMonths() {
final Cron cron = getCron("0 0 16 15 3,5,12 ? *");
assertEquals("at 16:00:00pm, on the 15th day in March, May and December", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeOfSpecificDayBetweenMonths() {
final Cron cron = getCron("0 0 16 15 3-7 ? *");
assertEquals("at 16:00:00pm, on the 15th day every month between March and July", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeOfSpecificDayBetweenMultipleMonths() {
final Cron cron = getCron("0 0 16 15 3-7,10-12 ? *");
assertEquals("at 16:00:00pm, on the 15th day every month between March and July and every month between October and December",
descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeOnLastDayOfMonth() {
final Cron cron = getCron("0 0 16 L * ? *");
assertEquals("at 16:00:00pm, on the last day of the month, every month", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeOnLastDayOfSpecificMonth() {
final Cron cron = getCron("0 0 16 L 3 ? *");
assertEquals("at 16:00:00pm, on the last day of the month, in March", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeOnThirdLastDayOfMonth() {
final Cron cron = getCron("0 0 16 L-3 * ? *");
assertEquals("at 16:00:00pm, 3 days before the end of the month, every month", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeOnNthSpecificWeekdayOfMonth() {
final Cron cron = getCron("0 0 16 ? * 5#2 *");
assertEquals("at 16:00:00pm, on the 2nd Thursday of the month, every month", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeOnLastSpecificWeekdayOfMonth() {
final Cron cron = getCron("0 0 16 ? * 2L *");
assertEquals("at 16:00:00pm, on the last Monday of the month, every month", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeEverySpecificWeekdayOfMonth() {
final Cron cron = getCron("0 0 16 ? * 2 *");
assertEquals("at 16:00:00pm, every Monday of the month, every month", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeEverySpecificWeekdayOfSpecificMonth() {
final Cron cron = getCron("0 0 16 ? 5 3 *");
assertEquals("at 16:00:00pm, every Tuesday of the month, in May", descriptor.describe(cron));
}
@Ignore
@Test
public void testAtTimeMultipleWeekdaysOfMultipleSpecificMonths() {
final Cron cron = getCron("0 0 16 ? 1,5,12 2,5,7 *");
assertEquals("at 16:00:00pm, every Monday, Thursday and Saturday of the month, in January, May and December", descriptor.describe(cron));
}
@Test
public void testTwoDaysBeforeLastDayOfMonth(){
CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
CronParser parser = new CronParser(cronDefinition);
Cron quartzCron = parser.parse("0 0 11 L-2 * ?");
CronDescriptor descriptor = CronDescriptor.instance(Locale.ENGLISH);
String description = descriptor.describe(quartzCron);
assertEquals( "at 11:00 2 days before the last day of the month", description);
}
@Test
public void testOneDayBeforeLastDayOfMonth(){
CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
CronParser parser = new CronParser(cronDefinition);
Cron quartzCron = parser.parse("0 0 11 L-1 * ?");
CronDescriptor descriptor = CronDescriptor.instance(Locale.ENGLISH);
String description = descriptor.describe(quartzCron);
assertEquals( "at 11:00 one day before the last day of the month", description);
}
}