0001: /*
0002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
0003: * Distributed under the terms of either:
0004: * - the common development and distribution license (CDDL), v1.0; or
0005: * - the GNU Lesser General Public License, v2.1 or later
0006: * $Id: TestFrequency.java 3714 2007-04-08 02:57:38Z gbevin $
0007: */
0008: package com.uwyn.rife.scheduler;
0009:
0010: import com.uwyn.rife.config.RifeConfig;
0011: import com.uwyn.rife.scheduler.exceptions.FrequencyException;
0012: import com.uwyn.rife.tools.ExceptionUtils;
0013: import com.uwyn.rife.tools.Localization;
0014: import java.util.Arrays;
0015: import java.util.Calendar;
0016: import java.util.Locale;
0017: import java.util.TimeZone;
0018: import junit.framework.TestCase;
0019:
0020: public class TestFrequency extends TestCase {
0021: final static private byte[] ALL_MINUTES = new byte[] { 0, 1, 2, 3,
0022: 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
0023: 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
0024: 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
0025: 50, 51, 52, 53, 54, 55, 56, 57, 58, 59 };
0026: final static private byte[] ALL_HOURS = new byte[] { 0, 1, 2, 3, 4,
0027: 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
0028: 21, 22, 23 };
0029: final static private byte[] ALL_DATES = new byte[] { 1, 2, 3, 4, 5,
0030: 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
0031: 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
0032: final static private byte[] ALL_MONTHS = new byte[] { 1, 2, 3, 4,
0033: 5, 6, 7, 8, 9, 10, 11, 12 };
0034: final static private byte[] ALL_WEEKDAYS = new byte[] { 1, 2, 3, 4,
0035: 5, 6, 7 };
0036:
0037: public TestFrequency(String name) {
0038: super (name);
0039: }
0040:
0041: public void testAllWildcards() {
0042: try {
0043: Frequency frequency = new Frequency("* * * * *");
0044: assertNotNull(frequency);
0045:
0046: assertTrue(frequency.isParsed());
0047: assertEquals(frequency.getFrequency(), "* * * * *");
0048: assertTrue(Arrays.equals(frequency.getMinutes(),
0049: ALL_MINUTES));
0050: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0051: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0052: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0053: assertTrue(Arrays.equals(frequency.getWeekdays(),
0054: ALL_WEEKDAYS));
0055: } catch (FrequencyException e) {
0056: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0057: }
0058: }
0059:
0060: public void testInvalidSpacing() {
0061: try {
0062: Frequency frequency = new Frequency("* * * * *");
0063: fail();
0064: assertNotNull(frequency);
0065: } catch (FrequencyException e) {
0066: assertTrue(true);
0067: }
0068: }
0069:
0070: public void testTooManyParts() {
0071: try {
0072: Frequency frequency = new Frequency("* * * * * *");
0073: fail();
0074: assertNotNull(frequency);
0075: } catch (FrequencyException e) {
0076: assertTrue(true);
0077: }
0078: }
0079:
0080: public void testTooLittleParts() {
0081: try {
0082: Frequency frequency = new Frequency("* * * *");
0083: fail();
0084: assertNotNull(frequency);
0085: } catch (FrequencyException e) {
0086: assertTrue(true);
0087: }
0088: }
0089:
0090: public void testInvalidNumberMinute() {
0091: try {
0092: Frequency frequency = new Frequency("d * * * *");
0093: fail();
0094: assertNotNull(frequency);
0095: } catch (FrequencyException e) {
0096: assertTrue(true);
0097: }
0098: }
0099:
0100: public void testInvalidDividerMinute() {
0101: try {
0102: Frequency frequency = new Frequency("2/4 * * * *");
0103: fail();
0104: assertNotNull(frequency);
0105: } catch (FrequencyException e) {
0106: assertTrue(true);
0107: }
0108: }
0109:
0110: public void testInvalidEmptyPartMinute() {
0111: try {
0112: Frequency frequency = new Frequency("2, * * * *");
0113: assertNotNull(frequency);
0114: fail();
0115: } catch (FrequencyException e) {
0116: assertTrue(true);
0117: }
0118: }
0119:
0120: public void testSingleMinute() {
0121: try {
0122: Frequency frequency = new Frequency("2 * * * *");
0123: assertNotNull(frequency);
0124:
0125: assertTrue(frequency.isParsed());
0126: assertEquals(frequency.getFrequency(), "2 * * * *");
0127: assertTrue(Arrays.equals(frequency.getMinutes(),
0128: new byte[] { -1, -1, 2, -1, -1, -1, -1, -1, -1, -1,
0129: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0130: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0131: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0132: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0133: -1, -1, -1, -1, -1, -1 }));
0134: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0135: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0136: assertNull(frequency.getDatesUnderflow());
0137: assertNull(frequency.getDatesOverflow());
0138: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0139: assertTrue(Arrays.equals(frequency.getWeekdays(),
0140: ALL_WEEKDAYS));
0141: } catch (FrequencyException e) {
0142: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0143: }
0144: }
0145:
0146: public void testRangedMinutes() {
0147: try {
0148: Frequency frequency = null;
0149:
0150: frequency = new Frequency("10-22 * * * *");
0151: assertNotNull(frequency);
0152:
0153: assertTrue(frequency.isParsed());
0154: assertEquals(frequency.getFrequency(), "10-22 * * * *");
0155: assertTrue(Arrays.equals(frequency.getMinutes(),
0156: new byte[] { -1, -1, -1, -1, -1, -1, -1, -1, -1,
0157: -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
0158: 20, 21, 22, -1, -1, -1, -1, -1, -1, -1, -1,
0159: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0160: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0161: -1, -1, -1, -1, -1, -1, -1 }));
0162: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0163: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0164: assertNull(frequency.getDatesUnderflow());
0165: assertNull(frequency.getDatesOverflow());
0166: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0167: assertTrue(Arrays.equals(frequency.getWeekdays(),
0168: ALL_WEEKDAYS));
0169:
0170: frequency = new Frequency("56-59 * * * *");
0171: assertNotNull(frequency);
0172:
0173: assertTrue(frequency.isParsed());
0174: assertEquals(frequency.getFrequency(), "56-59 * * * *");
0175: assertTrue(Arrays.equals(frequency.getMinutes(),
0176: new byte[] { -1, -1, -1, -1, -1, -1, -1, -1, -1,
0177: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0178: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0179: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0180: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0181: -1, -1, -1, 56, 57, 58, 59 }));
0182: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0183: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0184: assertNull(frequency.getDatesUnderflow());
0185: assertNull(frequency.getDatesOverflow());
0186: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0187: assertTrue(Arrays.equals(frequency.getWeekdays(),
0188: ALL_WEEKDAYS));
0189:
0190: frequency = new Frequency("12-12 * * * *");
0191: assertNotNull(frequency);
0192:
0193: assertTrue(frequency.isParsed());
0194: assertEquals(frequency.getFrequency(), "12-12 * * * *");
0195: assertTrue(Arrays.equals(frequency.getMinutes(),
0196: new byte[] { -1, -1, -1, -1, -1, -1, -1, -1, -1,
0197: -1, -1, -1, 12, -1, -1, -1, -1, -1, -1, -1,
0198: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0199: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0200: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0201: -1, -1, -1, -1, -1, -1, -1 }));
0202: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0203: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0204: assertNull(frequency.getDatesUnderflow());
0205: assertNull(frequency.getDatesOverflow());
0206: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0207: assertTrue(Arrays.equals(frequency.getWeekdays(),
0208: ALL_WEEKDAYS));
0209: } catch (FrequencyException e) {
0210: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0211: }
0212: }
0213:
0214: public void testReverseRangedMinutes() {
0215: try {
0216: Frequency frequency = null;
0217:
0218: frequency = new Frequency("57-5 * * * *");
0219: assertNotNull(frequency);
0220:
0221: assertTrue(frequency.isParsed());
0222: assertEquals(frequency.getFrequency(), "57-5 * * * *");
0223: assertTrue(Arrays.equals(frequency.getMinutes(),
0224: new byte[] { 0, 1, 2, 3, 4, 5, -1, -1, -1, -1, -1,
0225: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0226: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0227: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0228: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0229: -1, -1, 57, 58, 59 }));
0230: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0231: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0232: assertNull(frequency.getDatesUnderflow());
0233: assertNull(frequency.getDatesOverflow());
0234: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0235: assertTrue(Arrays.equals(frequency.getWeekdays(),
0236: ALL_WEEKDAYS));
0237:
0238: frequency = new Frequency("58-0 * * * *");
0239: assertNotNull(frequency);
0240:
0241: assertTrue(frequency.isParsed());
0242: assertEquals(frequency.getFrequency(), "58-0 * * * *");
0243: assertTrue(Arrays.equals(frequency.getMinutes(),
0244: new byte[] { 0, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0245: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0246: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0247: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0248: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0249: -1, -1, -1, -1, 58, 59 }));
0250: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0251: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0252: assertNull(frequency.getDatesUnderflow());
0253: assertNull(frequency.getDatesOverflow());
0254: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0255: assertTrue(Arrays.equals(frequency.getWeekdays(),
0256: ALL_WEEKDAYS));
0257: } catch (FrequencyException e) {
0258: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0259: }
0260: }
0261:
0262: public void testDividerMinutes() {
0263: try {
0264: Frequency frequency = new Frequency("*/17 * * * *");
0265: assertNotNull(frequency);
0266:
0267: assertTrue(frequency.isParsed());
0268: assertEquals(frequency.getFrequency(), "*/17 * * * *");
0269: assertTrue(Arrays.equals(frequency.getMinutes(),
0270: new byte[] { 0, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0271: -1, -1, -1, -1, -1, -1, -1, 17, -1, -1, -1,
0272: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0273: -1, -1, 34, -1, -1, -1, -1, -1, -1, -1, -1,
0274: -1, -1, -1, -1, -1, -1, -1, -1, 51, -1, -1,
0275: -1, -1, -1, -1, -1, -1 }));
0276: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0277: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0278: assertNull(frequency.getDatesUnderflow());
0279: assertNull(frequency.getDatesOverflow());
0280: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0281: assertTrue(Arrays.equals(frequency.getWeekdays(),
0282: ALL_WEEKDAYS));
0283: } catch (FrequencyException e) {
0284: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0285: }
0286: }
0287:
0288: public void testRangedDividerMinutes() {
0289: try {
0290: Frequency frequency = new Frequency("5-40/17 * * * *");
0291: assertNotNull(frequency);
0292:
0293: assertTrue(frequency.isParsed());
0294: assertEquals(frequency.getFrequency(), "5-40/17 * * * *");
0295: assertTrue(Arrays.equals(frequency.getMinutes(),
0296: new byte[] { -1, -1, -1, -1, -1, 5, -1, -1, -1, -1,
0297: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0298: -1, 22, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0299: -1, -1, -1, -1, -1, -1, -1, 39, -1, -1, -1,
0300: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0301: -1, -1, -1, -1, -1, -1 }));
0302: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0303: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0304: assertNull(frequency.getDatesUnderflow());
0305: assertNull(frequency.getDatesOverflow());
0306: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0307: assertTrue(Arrays.equals(frequency.getWeekdays(),
0308: ALL_WEEKDAYS));
0309: } catch (FrequencyException e) {
0310: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0311: }
0312: }
0313:
0314: public void testReverseRangedDividerMinutes() {
0315: try {
0316: Frequency frequency = new Frequency("31-20/13 * * * *");
0317: assertNotNull(frequency);
0318:
0319: assertTrue(frequency.isParsed());
0320: assertEquals(frequency.getFrequency(), "31-20/13 * * * *");
0321: assertTrue(Arrays.equals(frequency.getMinutes(),
0322: new byte[] { -1, -1, -1, -1, -1, -1, -1, -1, -1,
0323: -1, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0324: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0325: 31, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0326: -1, -1, 44, -1, -1, -1, -1, -1, -1, -1, -1,
0327: -1, -1, -1, -1, 57, -1, -1 }));
0328: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0329: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0330: assertNull(frequency.getDatesUnderflow());
0331: assertNull(frequency.getDatesOverflow());
0332: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0333: assertTrue(Arrays.equals(frequency.getWeekdays(),
0334: ALL_WEEKDAYS));
0335: } catch (FrequencyException e) {
0336: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0337: }
0338: }
0339:
0340: public void testMixedMinutes() {
0341: try {
0342: Frequency frequency = new Frequency(
0343: "10,12-18/2,30-40,45,48-5/3 * * * *");
0344: assertNotNull(frequency);
0345:
0346: assertTrue(frequency.isParsed());
0347: assertEquals(frequency.getFrequency(),
0348: "10,12-18/2,30-40,45,48-5/3 * * * *");
0349: assertTrue(Arrays.equals(frequency.getMinutes(),
0350: new byte[] { 0, -1, -1, 3, -1, -1, -1, -1, -1, -1,
0351: 10, -1, 12, -1, 14, -1, 16, -1, 18, -1, -1,
0352: -1, -1, -1, -1, -1, -1, -1, -1, -1, 30, 31,
0353: 32, 33, 34, 35, 36, 37, 38, 39, 40, -1, -1,
0354: -1, -1, 45, -1, -1, 48, -1, -1, 51, -1, -1,
0355: 54, -1, -1, 57, -1, -1 }));
0356: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0357: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0358: assertNull(frequency.getDatesUnderflow());
0359: assertNull(frequency.getDatesOverflow());
0360: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0361: assertTrue(Arrays.equals(frequency.getWeekdays(),
0362: ALL_WEEKDAYS));
0363: } catch (FrequencyException e) {
0364: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0365: }
0366: }
0367:
0368: public void testInvalidNumberHour() {
0369: try {
0370: Frequency frequency = new Frequency("* d * * *");
0371: fail();
0372: assertNotNull(frequency);
0373: } catch (FrequencyException e) {
0374: assertTrue(true);
0375: }
0376: }
0377:
0378: public void testInvalidDividerHour() {
0379: try {
0380: Frequency frequency = new Frequency("* 2/4 * * *");
0381: fail();
0382: assertNotNull(frequency);
0383: } catch (FrequencyException e) {
0384: assertTrue(true);
0385: }
0386: }
0387:
0388: public void testInvalidEmptyPartHour() {
0389: try {
0390: Frequency frequency = new Frequency("* 2, * * *");
0391: fail();
0392: assertNotNull(frequency);
0393: } catch (FrequencyException e) {
0394: assertTrue(true);
0395: }
0396: }
0397:
0398: public void testSingleHour() {
0399: try {
0400: Frequency frequency = new Frequency("* 12 * * *");
0401: assertNotNull(frequency);
0402:
0403: assertTrue(frequency.isParsed());
0404: assertEquals(frequency.getFrequency(), "* 12 * * *");
0405: assertTrue(Arrays.equals(frequency.getMinutes(),
0406: ALL_MINUTES));
0407: assertTrue(Arrays.equals(frequency.getHours(), new byte[] {
0408: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 12,
0409: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }));
0410: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0411: assertNull(frequency.getDatesUnderflow());
0412: assertNull(frequency.getDatesOverflow());
0413: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0414: assertTrue(Arrays.equals(frequency.getWeekdays(),
0415: ALL_WEEKDAYS));
0416: } catch (FrequencyException e) {
0417: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0418: }
0419: }
0420:
0421: public void testRangedHours() {
0422: try {
0423: Frequency frequency = null;
0424:
0425: frequency = new Frequency("* 7-13 * * *");
0426: assertNotNull(frequency);
0427:
0428: assertTrue(frequency.isParsed());
0429: assertEquals(frequency.getFrequency(), "* 7-13 * * *");
0430: assertTrue(Arrays.equals(frequency.getMinutes(),
0431: ALL_MINUTES));
0432: assertTrue(Arrays.equals(frequency.getHours(), new byte[] {
0433: -1, -1, -1, -1, -1, -1, -1, 7, 8, 9, 10, 11, 12,
0434: 13, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }));
0435: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0436: assertNull(frequency.getDatesUnderflow());
0437: assertNull(frequency.getDatesOverflow());
0438: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0439: assertTrue(Arrays.equals(frequency.getWeekdays(),
0440: ALL_WEEKDAYS));
0441:
0442: frequency = new Frequency("* 22-23 * * *");
0443: assertNotNull(frequency);
0444:
0445: assertTrue(frequency.isParsed());
0446: assertEquals(frequency.getFrequency(), "* 22-23 * * *");
0447: assertTrue(Arrays.equals(frequency.getMinutes(),
0448: ALL_MINUTES));
0449: assertTrue(Arrays.equals(frequency.getHours(), new byte[] {
0450: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0451: -1, -1, -1, -1, -1, -1, -1, -1, -1, 22, 23 }));
0452: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0453: assertNull(frequency.getDatesUnderflow());
0454: assertNull(frequency.getDatesOverflow());
0455: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0456: assertTrue(Arrays.equals(frequency.getWeekdays(),
0457: ALL_WEEKDAYS));
0458:
0459: frequency = new Frequency("* 19-19 * * *");
0460: assertNotNull(frequency);
0461:
0462: assertTrue(frequency.isParsed());
0463: assertEquals(frequency.getFrequency(), "* 19-19 * * *");
0464: assertTrue(Arrays.equals(frequency.getMinutes(),
0465: ALL_MINUTES));
0466: assertTrue(Arrays.equals(frequency.getHours(), new byte[] {
0467: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0468: -1, -1, -1, -1, -1, -1, 19, -1, -1, -1, -1 }));
0469: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0470: assertNull(frequency.getDatesUnderflow());
0471: assertNull(frequency.getDatesOverflow());
0472: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0473: assertTrue(Arrays.equals(frequency.getWeekdays(),
0474: ALL_WEEKDAYS));
0475: } catch (FrequencyException e) {
0476: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0477: }
0478: }
0479:
0480: public void testReverseRangedHours() {
0481: try {
0482: Frequency frequency = null;
0483:
0484: frequency = new Frequency("* 17-3 * * *");
0485: assertNotNull(frequency);
0486:
0487: assertTrue(frequency.isParsed());
0488: assertEquals(frequency.getFrequency(), "* 17-3 * * *");
0489: assertTrue(Arrays.equals(frequency.getMinutes(),
0490: ALL_MINUTES));
0491: assertTrue(Arrays.equals(frequency.getHours(), new byte[] {
0492: 0, 1, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0493: -1, -1, -1, 17, 18, 19, 20, 21, 22, 23 }));
0494: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0495: assertNull(frequency.getDatesUnderflow());
0496: assertNull(frequency.getDatesOverflow());
0497: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0498: assertTrue(Arrays.equals(frequency.getWeekdays(),
0499: ALL_WEEKDAYS));
0500:
0501: frequency = new Frequency("* 21-0 * * *");
0502: assertNotNull(frequency);
0503:
0504: assertTrue(frequency.isParsed());
0505: assertEquals(frequency.getFrequency(), "* 21-0 * * *");
0506: assertTrue(Arrays.equals(frequency.getMinutes(),
0507: ALL_MINUTES));
0508: assertTrue(Arrays.equals(frequency.getHours(), new byte[] {
0509: 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0510: -1, -1, -1, -1, -1, -1, -1, -1, 21, 22, 23 }));
0511: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0512: assertNull(frequency.getDatesUnderflow());
0513: assertNull(frequency.getDatesOverflow());
0514: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0515: assertTrue(Arrays.equals(frequency.getWeekdays(),
0516: ALL_WEEKDAYS));
0517: } catch (FrequencyException e) {
0518: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0519: }
0520: }
0521:
0522: public void testDividerHours() {
0523: try {
0524: Frequency frequency = new Frequency("* */6 * * *");
0525: assertNotNull(frequency);
0526:
0527: assertTrue(frequency.isParsed());
0528: assertEquals(frequency.getFrequency(), "* */6 * * *");
0529: assertTrue(Arrays.equals(frequency.getMinutes(),
0530: ALL_MINUTES));
0531: assertTrue(Arrays.equals(frequency.getHours(), new byte[] {
0532: 0, -1, -1, -1, -1, -1, 6, -1, -1, -1, -1, -1, 12,
0533: -1, -1, -1, -1, -1, 18, -1, -1, -1, -1, -1 }));
0534: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0535: assertNull(frequency.getDatesUnderflow());
0536: assertNull(frequency.getDatesOverflow());
0537: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0538: assertTrue(Arrays.equals(frequency.getWeekdays(),
0539: ALL_WEEKDAYS));
0540: } catch (FrequencyException e) {
0541: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0542: }
0543: }
0544:
0545: public void testRangedDividerHours() {
0546: try {
0547: Frequency frequency = new Frequency("* 4-17/5 * * *");
0548: assertNotNull(frequency);
0549:
0550: assertTrue(frequency.isParsed());
0551: assertEquals(frequency.getFrequency(), "* 4-17/5 * * *");
0552: assertTrue(Arrays.equals(frequency.getMinutes(),
0553: ALL_MINUTES));
0554: assertTrue(Arrays.equals(frequency.getHours(), new byte[] {
0555: -1, -1, -1, -1, 4, -1, -1, -1, -1, 9, -1, -1, -1,
0556: -1, 14, -1, -1, -1, -1, -1, -1, -1, -1, -1 }));
0557: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0558: assertNull(frequency.getDatesUnderflow());
0559: assertNull(frequency.getDatesOverflow());
0560: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0561: assertTrue(Arrays.equals(frequency.getWeekdays(),
0562: ALL_WEEKDAYS));
0563: } catch (FrequencyException e) {
0564: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0565: }
0566: }
0567:
0568: public void testReverseRangedDividerHours() {
0569: try {
0570: Frequency frequency = new Frequency("* 18-5/4 * * *");
0571: assertNotNull(frequency);
0572:
0573: assertTrue(frequency.isParsed());
0574: assertEquals(frequency.getFrequency(), "* 18-5/4 * * *");
0575: assertTrue(Arrays.equals(frequency.getMinutes(),
0576: ALL_MINUTES));
0577: assertTrue(Arrays.equals(frequency.getHours(), new byte[] {
0578: -1, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0579: -1, -1, -1, -1, -1, 18, -1, -1, -1, 22, -1 }));
0580: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0581: assertNull(frequency.getDatesUnderflow());
0582: assertNull(frequency.getDatesOverflow());
0583: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0584: assertTrue(Arrays.equals(frequency.getWeekdays(),
0585: ALL_WEEKDAYS));
0586: } catch (FrequencyException e) {
0587: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0588: }
0589: }
0590:
0591: public void testMixedHours() {
0592: try {
0593: Frequency frequency = new Frequency(
0594: "* 4,8-10/3,12,15-18,20-3/3 * * *");
0595: assertNotNull(frequency);
0596:
0597: assertTrue(frequency.isParsed());
0598: assertEquals(frequency.getFrequency(),
0599: "* 4,8-10/3,12,15-18,20-3/3 * * *");
0600: assertTrue(Arrays.equals(frequency.getMinutes(),
0601: ALL_MINUTES));
0602: assertTrue(Arrays.equals(frequency.getHours(), new byte[] {
0603: -1, -1, 2, -1, 4, -1, -1, -1, 8, -1, -1, -1, 12,
0604: -1, -1, 15, 16, 17, 18, -1, 20, -1, -1, 23 }));
0605: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
0606: assertNull(frequency.getDatesUnderflow());
0607: assertNull(frequency.getDatesOverflow());
0608: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0609: assertTrue(Arrays.equals(frequency.getWeekdays(),
0610: ALL_WEEKDAYS));
0611: } catch (FrequencyException e) {
0612: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0613: }
0614: }
0615:
0616: public void testInvalidNumberDate() {
0617: try {
0618: Frequency frequency = new Frequency("* * d * *");
0619: fail();
0620: assertNotNull(frequency);
0621: } catch (FrequencyException e) {
0622: assertTrue(true);
0623: }
0624: }
0625:
0626: public void testInvalidDividerDate() {
0627: try {
0628: Frequency frequency = new Frequency("* * 2/4 * *");
0629: fail();
0630: assertNotNull(frequency);
0631: } catch (FrequencyException e) {
0632: assertTrue(true);
0633: }
0634: }
0635:
0636: public void testInvalidEmptyPartDate() {
0637: try {
0638: Frequency frequency = new Frequency("* * 2, * *");
0639: fail();
0640: assertNotNull(frequency);
0641: } catch (FrequencyException e) {
0642: assertTrue(true);
0643: }
0644: }
0645:
0646: public void testSingleDate() {
0647: try {
0648: Frequency frequency = new Frequency("* * 14 * *");
0649: assertNotNull(frequency);
0650:
0651: assertTrue(frequency.isParsed());
0652: assertEquals(frequency.getFrequency(), "* * 14 * *");
0653: assertTrue(Arrays.equals(frequency.getMinutes(),
0654: ALL_MINUTES));
0655: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0656: assertTrue(Arrays.equals(frequency.getDates(), new byte[] {
0657: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0658: 14, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0659: -1, -1, -1, -1, -1 }));
0660: assertNull(frequency.getDatesUnderflow());
0661: assertNull(frequency.getDatesOverflow());
0662: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0663: assertTrue(Arrays.equals(frequency.getWeekdays(),
0664: ALL_WEEKDAYS));
0665: } catch (FrequencyException e) {
0666: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0667: }
0668: }
0669:
0670: public void testRangedDates() {
0671: try {
0672: Frequency frequency = null;
0673:
0674: frequency = new Frequency("* * 13-17 * *");
0675: assertNotNull(frequency);
0676:
0677: assertTrue(frequency.isParsed());
0678: assertEquals(frequency.getFrequency(), "* * 13-17 * *");
0679: assertTrue(Arrays.equals(frequency.getMinutes(),
0680: ALL_MINUTES));
0681: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0682: assertTrue(Arrays.equals(frequency.getDates(), new byte[] {
0683: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 13,
0684: 14, 15, 16, 17, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0685: -1, -1, -1, -1, -1 }));
0686: assertNull(frequency.getDatesUnderflow());
0687: assertNull(frequency.getDatesOverflow());
0688: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0689: assertTrue(Arrays.equals(frequency.getWeekdays(),
0690: ALL_WEEKDAYS));
0691:
0692: frequency = new Frequency("* * 29-31 * *");
0693: assertNotNull(frequency);
0694:
0695: assertTrue(frequency.isParsed());
0696: assertEquals(frequency.getFrequency(), "* * 29-31 * *");
0697: assertTrue(Arrays.equals(frequency.getMinutes(),
0698: ALL_MINUTES));
0699: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0700: assertTrue(Arrays.equals(frequency.getDates(), new byte[] {
0701: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0702: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0703: -1, -1, 29, 30, 31 }));
0704: assertNull(frequency.getDatesUnderflow());
0705: assertNull(frequency.getDatesOverflow());
0706: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0707: assertTrue(Arrays.equals(frequency.getWeekdays(),
0708: ALL_WEEKDAYS));
0709:
0710: frequency = new Frequency("* * 7-7 * *");
0711: assertNotNull(frequency);
0712:
0713: assertTrue(frequency.isParsed());
0714: assertEquals(frequency.getFrequency(), "* * 7-7 * *");
0715: assertTrue(Arrays.equals(frequency.getMinutes(),
0716: ALL_MINUTES));
0717: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0718: assertTrue(Arrays.equals(frequency.getDates(), new byte[] {
0719: -1, -1, -1, -1, -1, -1, 7, -1, -1, -1, -1, -1, -1,
0720: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0721: -1, -1, -1, -1, -1 }));
0722: assertNull(frequency.getDatesUnderflow());
0723: assertNull(frequency.getDatesOverflow());
0724: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0725: assertTrue(Arrays.equals(frequency.getWeekdays(),
0726: ALL_WEEKDAYS));
0727: } catch (FrequencyException e) {
0728: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0729: }
0730: }
0731:
0732: public void testReverseRangedDates() {
0733: try {
0734: Frequency frequency = null;
0735:
0736: frequency = new Frequency("* * 26-4 * *");
0737: assertNotNull(frequency);
0738:
0739: assertTrue(frequency.isParsed());
0740: assertEquals(frequency.getFrequency(), "* * 26-4 * *");
0741: assertTrue(Arrays.equals(frequency.getMinutes(),
0742: ALL_MINUTES));
0743: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0744: assertTrue(Arrays.equals(frequency.getDates(), new byte[] {
0745: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0746: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26,
0747: 27, 28, 29, 30, 31 }));
0748: assertTrue(Arrays.equals(frequency.getDatesUnderflow(),
0749: new byte[] { -1, -1, -1, -1, -1, -1, -1, -1, -1,
0750: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0751: -1, -1, -1, -1, -1, 4, 4, 4, 4, 4, 4 }));
0752: assertTrue(Arrays.equals(frequency.getDatesOverflow(),
0753: new byte[] { 4, 4, 4, 4, -1, -1, -1, -1, -1, -1,
0754: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0755: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }));
0756: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0757: assertTrue(Arrays.equals(frequency.getWeekdays(),
0758: ALL_WEEKDAYS));
0759:
0760: frequency = new Frequency("* * 26-2,30-5 * *");
0761: assertNotNull(frequency);
0762:
0763: assertTrue(frequency.isParsed());
0764: assertEquals(frequency.getFrequency(), "* * 26-2,30-5 * *");
0765: assertTrue(Arrays.equals(frequency.getMinutes(),
0766: ALL_MINUTES));
0767: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0768: assertTrue(Arrays.equals(frequency.getDates(), new byte[] {
0769: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0770: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26,
0771: 27, 28, 29, 30, 31 }));
0772: assertTrue(Arrays.equals(frequency.getDatesUnderflow(),
0773: new byte[] { -1, -1, -1, -1, -1, -1, -1, -1, -1,
0774: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0775: -1, -1, -1, -1, -1, 2, 2, 2, 2, 5, 5 }));
0776: assertTrue(Arrays.equals(frequency.getDatesOverflow(),
0777: new byte[] { 5, 5, 5, 5, 5, -1, -1, -1, -1, -1, -1,
0778: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0779: -1, -1, -1, -1, -1, -1, -1, -1, -1 }));
0780: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0781: assertTrue(Arrays.equals(frequency.getWeekdays(),
0782: ALL_WEEKDAYS));
0783:
0784: frequency = new Frequency("* * 26-5,30-2 * *");
0785: assertNotNull(frequency);
0786:
0787: assertTrue(frequency.isParsed());
0788: assertEquals(frequency.getFrequency(), "* * 26-5,30-2 * *");
0789: assertTrue(Arrays.equals(frequency.getMinutes(),
0790: ALL_MINUTES));
0791: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0792: assertTrue(Arrays.equals(frequency.getDates(), new byte[] {
0793: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0794: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26,
0795: 27, 28, 29, 30, 31 }));
0796: assertTrue(Arrays.equals(frequency.getDatesUnderflow(),
0797: new byte[] { -1, -1, -1, -1, -1, -1, -1, -1, -1,
0798: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0799: -1, -1, -1, -1, -1, 5, 5, 5, 5, 5, 5 }));
0800: assertTrue(Arrays.equals(frequency.getDatesOverflow(),
0801: new byte[] { 5, 5, 5, 5, 5, -1, -1, -1, -1, -1, -1,
0802: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0803: -1, -1, -1, -1, -1, -1, -1, -1, -1 }));
0804: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0805: assertTrue(Arrays.equals(frequency.getWeekdays(),
0806: ALL_WEEKDAYS));
0807:
0808: frequency = new Frequency("* * 26-2,31-30 * *");
0809: assertNotNull(frequency);
0810:
0811: assertTrue(frequency.isParsed());
0812: assertEquals(frequency.getFrequency(), "* * 26-2,31-30 * *");
0813: assertTrue(Arrays.equals(frequency.getMinutes(),
0814: ALL_MINUTES));
0815: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0816: assertTrue(Arrays.equals(frequency.getDates(), new byte[] {
0817: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0818: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26,
0819: 27, 28, 29, 30, 31 }));
0820: assertTrue(Arrays.equals(frequency.getDatesUnderflow(),
0821: new byte[] { -1, -1, -1, -1, -1, -1, -1, -1, -1,
0822: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0823: -1, -1, -1, -1, -1, 2, 2, 2, 2, 2, 30 }));
0824: assertTrue(Arrays
0825: .equals(frequency.getDatesOverflow(), new byte[] {
0826: 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
0827: 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
0828: 30, 30, 30, 30, 30, 30, 30, 30, -1 }));
0829: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0830: assertTrue(Arrays.equals(frequency.getWeekdays(),
0831: ALL_WEEKDAYS));
0832:
0833: frequency = new Frequency("* * 27-1 * *");
0834: assertNotNull(frequency);
0835:
0836: assertTrue(frequency.isParsed());
0837: assertEquals(frequency.getFrequency(), "* * 27-1 * *");
0838: assertTrue(Arrays.equals(frequency.getMinutes(),
0839: ALL_MINUTES));
0840: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0841: assertTrue(Arrays.equals(frequency.getDates(), new byte[] {
0842: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0843: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0844: 27, 28, 29, 30, 31 }));
0845: assertTrue(Arrays.equals(frequency.getDatesUnderflow(),
0846: new byte[] { -1, -1, -1, -1, -1, -1, -1, -1, -1,
0847: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0848: -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1 }));
0849: assertTrue(Arrays.equals(frequency.getDatesOverflow(),
0850: new byte[] { 1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0851: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0852: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }));
0853: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0854: assertTrue(Arrays.equals(frequency.getWeekdays(),
0855: ALL_WEEKDAYS));
0856: } catch (FrequencyException e) {
0857: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0858: }
0859: }
0860:
0861: public void testDividerDates() {
0862: try {
0863: Frequency frequency = new Frequency("* * */8 * *");
0864: assertNotNull(frequency);
0865:
0866: assertTrue(frequency.isParsed());
0867: assertEquals(frequency.getFrequency(), "* * */8 * *");
0868: assertTrue(Arrays.equals(frequency.getMinutes(),
0869: ALL_MINUTES));
0870: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0871: assertTrue(Arrays.equals(frequency.getDates(), new byte[] {
0872: 1, -1, -1, -1, -1, -1, -1, -1, 9, -1, -1, -1, -1,
0873: -1, -1, -1, 17, -1, -1, -1, -1, -1, -1, -1, 25, -1,
0874: -1, -1, -1, -1, -1 }));
0875: assertNull(frequency.getDatesUnderflow());
0876: assertNull(frequency.getDatesOverflow());
0877: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0878: assertTrue(Arrays.equals(frequency.getWeekdays(),
0879: ALL_WEEKDAYS));
0880: } catch (FrequencyException e) {
0881: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0882: }
0883: }
0884:
0885: public void testRangedDividerDates() {
0886: try {
0887: Frequency frequency = new Frequency("* * 7-23/9 * *");
0888: assertNotNull(frequency);
0889:
0890: assertTrue(frequency.isParsed());
0891: assertEquals(frequency.getFrequency(), "* * 7-23/9 * *");
0892: assertTrue(Arrays.equals(frequency.getMinutes(),
0893: ALL_MINUTES));
0894: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0895: assertTrue(Arrays.equals(frequency.getDates(), new byte[] {
0896: -1, -1, -1, -1, -1, -1, 7, -1, -1, -1, -1, -1, -1,
0897: -1, -1, 16, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0898: -1, -1, -1, -1, -1 }));
0899: assertNull(frequency.getDatesUnderflow());
0900: assertNull(frequency.getDatesOverflow());
0901: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0902: assertTrue(Arrays.equals(frequency.getWeekdays(),
0903: ALL_WEEKDAYS));
0904: } catch (FrequencyException e) {
0905: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0906: }
0907: }
0908:
0909: public void testReverseRangedDividerDates() {
0910: try {
0911: Frequency frequency = new Frequency("* * 11-7/13 * *");
0912: assertNotNull(frequency);
0913:
0914: assertTrue(frequency.isParsed());
0915: assertEquals(frequency.getFrequency(), "* * 11-7/13 * *");
0916: assertTrue(Arrays.equals(frequency.getMinutes(),
0917: ALL_MINUTES));
0918: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0919: assertTrue(Arrays.equals(frequency.getDates(), new byte[] {
0920: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 11, -1, -1,
0921: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, -1, -1,
0922: -1, -1, -1, -1, -1 }));
0923: assertTrue(Arrays
0924: .equals(frequency.getDatesUnderflow(), new byte[] {
0925: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 7,
0926: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0927: -1, 7, -1, -1, -1, -1, -1, -1, -1 }));
0928: assertTrue(Arrays.equals(frequency.getDatesOverflow(),
0929: new byte[] { -1, -1, -1, -1, -1, 7, -1, -1, -1, -1,
0930: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0931: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }));
0932: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0933: assertTrue(Arrays.equals(frequency.getWeekdays(),
0934: ALL_WEEKDAYS));
0935:
0936: frequency = new Frequency("* * 30-29/5,18-17/8 * *");
0937: assertNotNull(frequency);
0938:
0939: assertTrue(frequency.isParsed());
0940: assertEquals(frequency.getFrequency(),
0941: "* * 30-29/5,18-17/8 * *");
0942: assertTrue(Arrays.equals(frequency.getMinutes(),
0943: ALL_MINUTES));
0944: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0945: assertTrue(Arrays.equals(frequency.getDates(), new byte[] {
0946: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0947: -1, -1, -1, -1, 18, -1, -1, -1, -1, -1, -1, -1, 26,
0948: -1, -1, -1, 30, -1 }));
0949: assertTrue(Arrays
0950: .equals(frequency.getDatesUnderflow(), new byte[] {
0951: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0952: -1, -1, -1, -1, -1, -1, 17, -1, -1, -1, -1,
0953: -1, -1, -1, 17, -1, -1, -1, 29, -1 }));
0954: assertTrue(Arrays
0955: .equals(frequency.getDatesOverflow(), new byte[] {
0956: -1, -1, 17, 29, -1, -1, -1, -1, 29, -1, 17,
0957: -1, -1, 29, -1, -1, -1, -1, 29, -1, -1, -1,
0958: -1, 29, -1, -1, -1, -1, 29, -1, -1 }));
0959: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0960: assertTrue(Arrays.equals(frequency.getWeekdays(),
0961: ALL_WEEKDAYS));
0962:
0963: frequency = new Frequency("* * 27-26/3 * *");
0964: assertNotNull(frequency);
0965:
0966: assertTrue(frequency.isParsed());
0967: assertEquals(frequency.getFrequency(), "* * 27-26/3 * *");
0968: assertTrue(Arrays.equals(frequency.getMinutes(),
0969: ALL_MINUTES));
0970: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
0971: assertTrue(Arrays.equals(frequency.getDates(), new byte[] {
0972: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0973: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0974: 27, -1, -1, 30, -1 }));
0975: assertTrue(Arrays
0976: .equals(frequency.getDatesUnderflow(), new byte[] {
0977: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0978: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0979: -1, -1, -1, -1, 26, -1, -1, 26, -1 }));
0980: assertTrue(Arrays
0981: .equals(frequency.getDatesOverflow(), new byte[] {
0982: -1, 26, -1, -1, 26, -1, -1, 26, -1, -1, 26,
0983: -1, -1, 26, -1, -1, 26, -1, -1, 26, -1, -1,
0984: 26, -1, -1, 26, -1, -1, -1, -1, -1 }));
0985: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
0986: assertTrue(Arrays.equals(frequency.getWeekdays(),
0987: ALL_WEEKDAYS));
0988: } catch (FrequencyException e) {
0989: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
0990: }
0991: }
0992:
0993: public void testMixedDates() {
0994: try {
0995: Frequency frequency = new Frequency(
0996: "* * 3,5,8-18/4,19-23,27-2/2 * *");
0997: assertNotNull(frequency);
0998:
0999: assertTrue(frequency.isParsed());
1000: assertEquals(frequency.getFrequency(),
1001: "* * 3,5,8-18/4,19-23,27-2/2 * *");
1002: assertTrue(Arrays.equals(frequency.getMinutes(),
1003: ALL_MINUTES));
1004: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1005: assertTrue(Arrays.equals(frequency.getDates(), new byte[] {
1006: -1, -1, 3, -1, 5, -1, -1, 8, -1, -1, -1, 12, -1,
1007: -1, -1, 16, -1, -1, 19, 20, 21, 22, 23, -1, -1, -1,
1008: 27, -1, 29, -1, 31 }));
1009: assertTrue(Arrays.equals(frequency.getDatesUnderflow(),
1010: new byte[] { -1, -1, -1, -1, -1, -1, -1, -1, -1,
1011: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1012: -1, -1, -1, -1, -1, -1, 2, -1, 2, -1, 2 }));
1013: assertTrue(Arrays.equals(frequency.getDatesOverflow(),
1014: new byte[] { -1, 2, -1, -1, -1, -1, -1, -1, -1, -1,
1015: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1016: -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }));
1017: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
1018: assertTrue(Arrays.equals(frequency.getWeekdays(),
1019: ALL_WEEKDAYS));
1020: } catch (FrequencyException e) {
1021: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1022: }
1023: }
1024:
1025: public void testInvalidNumberMonth() {
1026: try {
1027: Frequency frequency = new Frequency("* * * d *");
1028: fail();
1029: assertNotNull(frequency);
1030: } catch (FrequencyException e) {
1031: assertTrue(true);
1032: }
1033: }
1034:
1035: public void testInvalidDividerMonth() {
1036: try {
1037: Frequency frequency = new Frequency("* * * 2/4 *");
1038: fail();
1039: assertNotNull(frequency);
1040: } catch (FrequencyException e) {
1041: assertTrue(true);
1042: }
1043: }
1044:
1045: public void testInvalidEmptyPartMonth() {
1046: try {
1047: Frequency frequency = new Frequency("* * * 2, *");
1048: fail();
1049: assertNotNull(frequency);
1050: } catch (FrequencyException e) {
1051: assertTrue(true);
1052: }
1053: }
1054:
1055: public void testSingleMonth() {
1056: try {
1057: Frequency frequency = new Frequency("* * * 3 *");
1058: assertNotNull(frequency);
1059:
1060: assertTrue(frequency.isParsed());
1061: assertEquals(frequency.getFrequency(), "* * * 3 *");
1062: assertTrue(Arrays.equals(frequency.getMinutes(),
1063: ALL_MINUTES));
1064: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1065: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1066: assertNull(frequency.getDatesUnderflow());
1067: assertNull(frequency.getDatesOverflow());
1068: assertTrue(Arrays.equals(frequency.getMonths(), new byte[] {
1069: -1, -1, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1 }));
1070: assertTrue(Arrays.equals(frequency.getWeekdays(),
1071: ALL_WEEKDAYS));
1072: } catch (FrequencyException e) {
1073: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1074: }
1075: }
1076:
1077: public void testRangedMonths() {
1078: try {
1079: Frequency frequency = null;
1080:
1081: frequency = new Frequency("* * * 7-9 *");
1082: assertNotNull(frequency);
1083:
1084: assertTrue(frequency.isParsed());
1085: assertEquals(frequency.getFrequency(), "* * * 7-9 *");
1086: assertTrue(Arrays.equals(frequency.getMinutes(),
1087: ALL_MINUTES));
1088: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1089: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1090: assertNull(frequency.getDatesUnderflow());
1091: assertNull(frequency.getDatesOverflow());
1092: assertTrue(Arrays.equals(frequency.getMonths(), new byte[] {
1093: -1, -1, -1, -1, -1, -1, 7, 8, 9, -1, -1, -1 }));
1094: assertTrue(Arrays.equals(frequency.getWeekdays(),
1095: ALL_WEEKDAYS));
1096:
1097: frequency = new Frequency("* * * 10-12 *");
1098: assertNotNull(frequency);
1099:
1100: assertTrue(frequency.isParsed());
1101: assertEquals(frequency.getFrequency(), "* * * 10-12 *");
1102: assertTrue(Arrays.equals(frequency.getMinutes(),
1103: ALL_MINUTES));
1104: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1105: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1106: assertNull(frequency.getDatesUnderflow());
1107: assertNull(frequency.getDatesOverflow());
1108: assertTrue(Arrays.equals(frequency.getMonths(), new byte[] {
1109: -1, -1, -1, -1, -1, -1, -1, -1, -1, 10, 11, 12 }));
1110: assertTrue(Arrays.equals(frequency.getWeekdays(),
1111: ALL_WEEKDAYS));
1112:
1113: frequency = new Frequency("* * * 5-5 *");
1114: assertNotNull(frequency);
1115:
1116: assertTrue(frequency.isParsed());
1117: assertEquals(frequency.getFrequency(), "* * * 5-5 *");
1118: assertTrue(Arrays.equals(frequency.getMinutes(),
1119: ALL_MINUTES));
1120: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1121: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1122: assertNull(frequency.getDatesUnderflow());
1123: assertNull(frequency.getDatesOverflow());
1124: assertTrue(Arrays.equals(frequency.getMonths(), new byte[] {
1125: -1, -1, -1, -1, 5, -1, -1, -1, -1, -1, -1, -1 }));
1126: assertTrue(Arrays.equals(frequency.getWeekdays(),
1127: ALL_WEEKDAYS));
1128: } catch (FrequencyException e) {
1129: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1130: }
1131: }
1132:
1133: public void testReverseRangedMonths() {
1134: try {
1135: Frequency frequency = null;
1136:
1137: frequency = new Frequency("* * * 9-2 *");
1138: assertNotNull(frequency);
1139:
1140: assertTrue(frequency.isParsed());
1141: assertEquals(frequency.getFrequency(), "* * * 9-2 *");
1142: assertTrue(Arrays.equals(frequency.getMinutes(),
1143: ALL_MINUTES));
1144: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1145: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1146: assertNull(frequency.getDatesUnderflow());
1147: assertNull(frequency.getDatesOverflow());
1148: assertTrue(Arrays.equals(frequency.getMonths(), new byte[] {
1149: 1, 2, -1, -1, -1, -1, -1, -1, 9, 10, 11, 12 }));
1150: assertTrue(Arrays.equals(frequency.getWeekdays(),
1151: ALL_WEEKDAYS));
1152:
1153: frequency = new Frequency("* * * 11-1 *");
1154: assertNotNull(frequency);
1155:
1156: assertTrue(frequency.isParsed());
1157: assertEquals(frequency.getFrequency(), "* * * 11-1 *");
1158: assertTrue(Arrays.equals(frequency.getMinutes(),
1159: ALL_MINUTES));
1160: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1161: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1162: assertNull(frequency.getDatesUnderflow());
1163: assertNull(frequency.getDatesOverflow());
1164: assertTrue(Arrays.equals(frequency.getMonths(), new byte[] {
1165: 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 11, 12 }));
1166: assertTrue(Arrays.equals(frequency.getWeekdays(),
1167: ALL_WEEKDAYS));
1168: } catch (FrequencyException e) {
1169: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1170: }
1171: }
1172:
1173: public void testDividerMonths() {
1174: try {
1175: Frequency frequency = new Frequency("* * * */4 *");
1176: assertNotNull(frequency);
1177:
1178: assertTrue(frequency.isParsed());
1179: assertEquals(frequency.getFrequency(), "* * * */4 *");
1180: assertTrue(Arrays.equals(frequency.getMinutes(),
1181: ALL_MINUTES));
1182: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1183: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1184: assertNull(frequency.getDatesUnderflow());
1185: assertNull(frequency.getDatesOverflow());
1186: assertTrue(Arrays.equals(frequency.getMonths(), new byte[] {
1187: 1, -1, -1, -1, 5, -1, -1, -1, 9, -1, -1, -1 }));
1188: assertTrue(Arrays.equals(frequency.getWeekdays(),
1189: ALL_WEEKDAYS));
1190: } catch (FrequencyException e) {
1191: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1192: }
1193: }
1194:
1195: public void testRangedDividerMonths() {
1196: try {
1197: Frequency frequency = new Frequency("* * * 3-11/3 *");
1198: assertNotNull(frequency);
1199:
1200: assertTrue(frequency.isParsed());
1201: assertEquals(frequency.getFrequency(), "* * * 3-11/3 *");
1202: assertTrue(Arrays.equals(frequency.getMinutes(),
1203: ALL_MINUTES));
1204: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1205: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1206: assertNull(frequency.getDatesUnderflow());
1207: assertNull(frequency.getDatesOverflow());
1208: assertTrue(Arrays.equals(frequency.getMonths(), new byte[] {
1209: -1, -1, 3, -1, -1, 6, -1, -1, 9, -1, -1, -1 }));
1210: assertTrue(Arrays.equals(frequency.getWeekdays(),
1211: ALL_WEEKDAYS));
1212: } catch (FrequencyException e) {
1213: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1214: }
1215: }
1216:
1217: public void testReverseRangedDividerMonths() {
1218: try {
1219: Frequency frequency = new Frequency("* * * 5-3/2 *");
1220: assertNotNull(frequency);
1221:
1222: assertTrue(frequency.isParsed());
1223: assertEquals(frequency.getFrequency(), "* * * 5-3/2 *");
1224: assertTrue(Arrays.equals(frequency.getMinutes(),
1225: ALL_MINUTES));
1226: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1227: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1228: assertNull(frequency.getDatesUnderflow());
1229: assertNull(frequency.getDatesOverflow());
1230: assertTrue(Arrays.equals(frequency.getMonths(), new byte[] {
1231: 1, -1, 3, -1, 5, -1, 7, -1, 9, -1, 11, -1 }));
1232: assertTrue(Arrays.equals(frequency.getWeekdays(),
1233: ALL_WEEKDAYS));
1234: } catch (FrequencyException e) {
1235: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1236: }
1237: }
1238:
1239: public void testMixedMonths() {
1240: try {
1241: Frequency frequency = new Frequency(
1242: "* * * 4,5-6,8-11/2,12-3/3 *");
1243: assertNotNull(frequency);
1244:
1245: assertTrue(frequency.isParsed());
1246: assertEquals(frequency.getFrequency(),
1247: "* * * 4,5-6,8-11/2,12-3/3 *");
1248: assertTrue(Arrays.equals(frequency.getMinutes(),
1249: ALL_MINUTES));
1250: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1251: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1252: assertNull(frequency.getDatesUnderflow());
1253: assertNull(frequency.getDatesOverflow());
1254: assertTrue(Arrays.equals(frequency.getMonths(), new byte[] {
1255: -1, -1, 3, 4, 5, 6, -1, 8, -1, 10, -1, 12 }));
1256: assertTrue(Arrays.equals(frequency.getWeekdays(),
1257: ALL_WEEKDAYS));
1258: } catch (FrequencyException e) {
1259: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1260: }
1261: }
1262:
1263: public void testInvalidNumberWeekday() {
1264: try {
1265: Frequency frequency = new Frequency("* * * * d");
1266: fail();
1267: assertNotNull(frequency);
1268: } catch (FrequencyException e) {
1269: assertTrue(true);
1270: }
1271: }
1272:
1273: public void testInvalidDividerWeekday() {
1274: try {
1275: Frequency frequency = new Frequency("* * * * 2/4");
1276: fail();
1277: assertNotNull(frequency);
1278: } catch (FrequencyException e) {
1279: assertTrue(true);
1280: }
1281: }
1282:
1283: public void testInvalidEmptyPartWeekday() {
1284: try {
1285: Frequency frequency = new Frequency("* * * * 2,");
1286: fail();
1287: assertNotNull(frequency);
1288: } catch (FrequencyException e) {
1289: assertTrue(true);
1290: }
1291: }
1292:
1293: public void testSingleWeekday() {
1294: try {
1295: Frequency frequency = new Frequency("* * * * 7");
1296: assertNotNull(frequency);
1297:
1298: assertTrue(frequency.isParsed());
1299: assertEquals(frequency.getFrequency(), "* * * * 7");
1300: assertTrue(Arrays.equals(frequency.getMinutes(),
1301: ALL_MINUTES));
1302: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1303: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1304: assertNull(frequency.getDatesUnderflow());
1305: assertNull(frequency.getDatesOverflow());
1306: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
1307: assertTrue(Arrays.equals(frequency.getWeekdays(),
1308: new byte[] { -1, -1, -1, -1, -1, -1, 7 }));
1309: } catch (FrequencyException e) {
1310: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1311: }
1312: }
1313:
1314: public void testRangedWeekdays() {
1315: try {
1316: Frequency frequency = null;
1317:
1318: frequency = new Frequency("* * * * 3-5");
1319: assertNotNull(frequency);
1320:
1321: assertTrue(frequency.isParsed());
1322: assertEquals(frequency.getFrequency(), "* * * * 3-5");
1323: assertTrue(Arrays.equals(frequency.getMinutes(),
1324: ALL_MINUTES));
1325: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1326: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1327: assertNull(frequency.getDatesUnderflow());
1328: assertNull(frequency.getDatesOverflow());
1329: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
1330: assertTrue(Arrays.equals(frequency.getWeekdays(),
1331: new byte[] { -1, -1, 3, 4, 5, -1, -1 }));
1332:
1333: frequency = new Frequency("* * * * 6-7");
1334: assertNotNull(frequency);
1335:
1336: assertTrue(frequency.isParsed());
1337: assertEquals(frequency.getFrequency(), "* * * * 6-7");
1338: assertTrue(Arrays.equals(frequency.getMinutes(),
1339: ALL_MINUTES));
1340: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1341: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1342: assertNull(frequency.getDatesUnderflow());
1343: assertNull(frequency.getDatesOverflow());
1344: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
1345: assertTrue(Arrays.equals(frequency.getWeekdays(),
1346: new byte[] { -1, -1, -1, -1, -1, 6, 7 }));
1347:
1348: frequency = new Frequency("* * * * 2-2");
1349: assertNotNull(frequency);
1350:
1351: assertTrue(frequency.isParsed());
1352: assertEquals(frequency.getFrequency(), "* * * * 2-2");
1353: assertTrue(Arrays.equals(frequency.getMinutes(),
1354: ALL_MINUTES));
1355: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1356: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1357: assertNull(frequency.getDatesUnderflow());
1358: assertNull(frequency.getDatesOverflow());
1359: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
1360: assertTrue(Arrays.equals(frequency.getWeekdays(),
1361: new byte[] { -1, 2, -1, -1, -1, -1, -1 }));
1362: } catch (FrequencyException e) {
1363: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1364: }
1365: }
1366:
1367: public void testReverseRangedWeekdays() {
1368: try {
1369: Frequency frequency = null;
1370:
1371: frequency = new Frequency("* * * * 5-2");
1372: assertNotNull(frequency);
1373:
1374: assertTrue(frequency.isParsed());
1375: assertEquals(frequency.getFrequency(), "* * * * 5-2");
1376: assertTrue(Arrays.equals(frequency.getMinutes(),
1377: ALL_MINUTES));
1378: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1379: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1380: assertNull(frequency.getDatesUnderflow());
1381: assertNull(frequency.getDatesOverflow());
1382: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
1383: assertTrue(Arrays.equals(frequency.getWeekdays(),
1384: new byte[] { 1, 2, -1, -1, 5, 6, 7 }));
1385:
1386: frequency = new Frequency("* * * * 6-1");
1387: assertNotNull(frequency);
1388:
1389: assertTrue(frequency.isParsed());
1390: assertEquals(frequency.getFrequency(), "* * * * 6-1");
1391: assertTrue(Arrays.equals(frequency.getMinutes(),
1392: ALL_MINUTES));
1393: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1394: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1395: assertNull(frequency.getDatesUnderflow());
1396: assertNull(frequency.getDatesOverflow());
1397: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
1398: assertTrue(Arrays.equals(frequency.getWeekdays(),
1399: new byte[] { 1, -1, -1, -1, -1, 6, 7 }));
1400: } catch (FrequencyException e) {
1401: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1402: }
1403: }
1404:
1405: public void testDividerWeekdays() {
1406: try {
1407: Frequency frequency = new Frequency("* * * * */3");
1408: assertNotNull(frequency);
1409:
1410: assertTrue(frequency.isParsed());
1411: assertEquals(frequency.getFrequency(), "* * * * */3");
1412: assertTrue(Arrays.equals(frequency.getMinutes(),
1413: ALL_MINUTES));
1414: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1415: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1416: assertNull(frequency.getDatesUnderflow());
1417: assertNull(frequency.getDatesOverflow());
1418: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
1419: assertTrue(Arrays.equals(frequency.getWeekdays(),
1420: new byte[] { 1, -1, -1, 4, -1, -1, 7 }));
1421: } catch (FrequencyException e) {
1422: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1423: }
1424: }
1425:
1426: public void testRangedDividerWeekdays() {
1427: try {
1428: Frequency frequency = new Frequency("* * * * 2-6/3");
1429: assertNotNull(frequency);
1430:
1431: assertTrue(frequency.isParsed());
1432: assertEquals(frequency.getFrequency(), "* * * * 2-6/3");
1433: assertTrue(Arrays.equals(frequency.getMinutes(),
1434: ALL_MINUTES));
1435: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1436: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1437: assertNull(frequency.getDatesUnderflow());
1438: assertNull(frequency.getDatesOverflow());
1439: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
1440: assertTrue(Arrays.equals(frequency.getWeekdays(),
1441: new byte[] { -1, 2, -1, -1, 5, -1, -1 }));
1442: } catch (FrequencyException e) {
1443: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1444: }
1445: }
1446:
1447: public void testReverseRangedDividerWeekdays() {
1448: try {
1449: Frequency frequency = new Frequency("* * * * 4-2/2");
1450: assertNotNull(frequency);
1451:
1452: assertTrue(frequency.isParsed());
1453: assertEquals(frequency.getFrequency(), "* * * * 4-2/2");
1454: assertTrue(Arrays.equals(frequency.getMinutes(),
1455: ALL_MINUTES));
1456: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1457: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1458: assertNull(frequency.getDatesUnderflow());
1459: assertNull(frequency.getDatesOverflow());
1460: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
1461: assertTrue(Arrays.equals(frequency.getWeekdays(),
1462: new byte[] { 1, -1, -1, 4, -1, 6, -1 }));
1463: } catch (FrequencyException e) {
1464: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1465: }
1466: }
1467:
1468: public void testMixedWeekdays() {
1469: try {
1470: Frequency frequency = new Frequency("* * * * 2,3-4,4-1/2");
1471: assertNotNull(frequency);
1472:
1473: assertTrue(frequency.isParsed());
1474: assertEquals(frequency.getFrequency(),
1475: "* * * * 2,3-4,4-1/2");
1476: assertTrue(Arrays.equals(frequency.getMinutes(),
1477: ALL_MINUTES));
1478: assertTrue(Arrays.equals(frequency.getHours(), ALL_HOURS));
1479: assertTrue(Arrays.equals(frequency.getDates(), ALL_DATES));
1480: assertNull(frequency.getDatesUnderflow());
1481: assertNull(frequency.getDatesOverflow());
1482: assertTrue(Arrays.equals(frequency.getMonths(), ALL_MONTHS));
1483: assertTrue(Arrays.equals(frequency.getWeekdays(),
1484: new byte[] { 1, 2, 3, 4, -1, 6, -1 }));
1485: } catch (FrequencyException e) {
1486: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1487: }
1488: }
1489:
1490: public void testNextDateMinutes() {
1491: try {
1492: Calendar calendar = Calendar.getInstance(RifeConfig.Tools
1493: .getDefaultTimeZone(), Localization.getLocale());
1494: calendar.set(2002, Calendar.SEPTEMBER, 1, 10, 29);
1495: long calendar_time = calendar.getTimeInMillis();
1496: long previous = 0;
1497: long next = 0;
1498: Frequency frequency = null;
1499:
1500: int minute = 60 * 1000;
1501: int hour = 60 * minute;
1502:
1503: frequency = new Frequency("* * * * *");
1504: previous = calendar_time;
1505: next = frequency.getNextDate(previous);
1506: assertEquals(1 * minute, next - previous);
1507: previous = next;
1508: next = frequency.getNextDate(previous);
1509: assertEquals(1 * minute, next - previous);
1510:
1511: frequency = new Frequency("28 * * * *"); // 2002/09/01 10:29
1512: previous = calendar_time;
1513: next = frequency.getNextDate(previous);
1514: assertEquals(59 * minute, next - previous); // 2002/09/01 11:28
1515: previous = next;
1516: next = frequency.getNextDate(previous);
1517: assertEquals(1 * hour, next - previous); // 2002/09/01 12:28
1518: previous = next;
1519: next = frequency.getNextDate(previous);
1520: assertEquals(1 * hour, next - previous); // 2002/09/01 13:28
1521:
1522: frequency = new Frequency("*/3 * * * *"); // 2002/09/01 10:29
1523: previous = calendar_time;
1524: next = frequency.getNextDate(previous);
1525: assertEquals(1 * minute, next - previous); // 2002/09/01 10:30
1526: previous = next;
1527: next = frequency.getNextDate(previous);
1528: assertEquals(3 * minute, next - previous); // 2002/09/01 10:33
1529: previous = next;
1530: next = frequency.getNextDate(previous);
1531: assertEquals(3 * minute, next - previous); // 2002/09/01 10:36
1532:
1533: frequency = new Frequency("28-56/7 * * * *"); // 2002/09/01 10:29
1534: previous = calendar_time;
1535: next = frequency.getNextDate(previous);
1536: assertEquals(6 * minute, next - previous); // 2002/09/01 10:35
1537: previous = next;
1538: next = frequency.getNextDate(previous);
1539: assertEquals(7 * minute, next - previous); // 2002/09/01 10:42
1540: previous = next;
1541: next = frequency.getNextDate(previous);
1542: assertEquals(7 * minute, next - previous); // 2002/09/01 10:49
1543: previous = next;
1544: next = frequency.getNextDate(previous);
1545: assertEquals(7 * minute, next - previous); // 2002/09/01 10:56
1546: previous = next;
1547: next = frequency.getNextDate(previous);
1548: assertEquals(32 * minute, next - previous); // 2002/09/01 11:28
1549: previous = next;
1550: next = frequency.getNextDate(previous);
1551: assertEquals(7 * minute, next - previous); // 2002/09/01 11:35
1552:
1553: frequency = new Frequency("56-40/13 * * * *"); // 2002/09/01 10:29
1554: previous = calendar_time;
1555: next = frequency.getNextDate(previous);
1556: assertEquals(6 * minute, next - previous); // 2002/09/01 10:35
1557: previous = next;
1558: next = frequency.getNextDate(previous);
1559: assertEquals(21 * minute, next - previous); // 2002/09/01 10:56
1560: previous = next;
1561: next = frequency.getNextDate(previous);
1562: assertEquals(13 * minute, next - previous); // 2002/09/01 11:09
1563: previous = next;
1564: next = frequency.getNextDate(previous);
1565: assertEquals(13 * minute, next - previous); // 2002/09/01 11:22
1566: previous = next;
1567: next = frequency.getNextDate(previous);
1568: assertEquals(13 * minute, next - previous); // 2002/09/01 11:35
1569: previous = next;
1570: next = frequency.getNextDate(previous);
1571: assertEquals(21 * minute, next - previous); // 2002/09/01 11:56
1572:
1573: frequency = new Frequency("31,37-57/4,59-4,7 * * * *"); // 2002/09/01 10:29
1574: previous = calendar_time;
1575: next = frequency.getNextDate(previous);
1576: assertEquals(2 * minute, next - previous); // 2002/09/01 10:31
1577: previous = next;
1578: next = frequency.getNextDate(previous);
1579: assertEquals(6 * minute, next - previous); // 2002/09/01 10:37
1580: previous = next;
1581: next = frequency.getNextDate(previous);
1582: assertEquals(4 * minute, next - previous); // 2002/09/01 10:41
1583: previous = next;
1584: next = frequency.getNextDate(previous);
1585: assertEquals(4 * minute, next - previous); // 2002/09/01 10:45
1586: previous = next;
1587: next = frequency.getNextDate(previous);
1588: assertEquals(4 * minute, next - previous); // 2002/09/01 10:49
1589: previous = next;
1590: next = frequency.getNextDate(previous);
1591: assertEquals(4 * minute, next - previous); // 2002/09/01 10:53
1592: previous = next;
1593: next = frequency.getNextDate(previous);
1594: assertEquals(4 * minute, next - previous); // 2002/09/01 10:57
1595: previous = next;
1596: next = frequency.getNextDate(previous);
1597: assertEquals(2 * minute, next - previous); // 2002/09/01 10:59
1598: previous = next;
1599: next = frequency.getNextDate(previous);
1600: assertEquals(1 * minute, next - previous); // 2002/09/01 11:00
1601: previous = next;
1602: next = frequency.getNextDate(previous);
1603: assertEquals(1 * minute, next - previous); // 2002/09/01 11:01
1604: previous = next;
1605: next = frequency.getNextDate(previous);
1606: assertEquals(1 * minute, next - previous); // 2002/09/01 11:02
1607: previous = next;
1608: next = frequency.getNextDate(previous);
1609: assertEquals(1 * minute, next - previous); // 2002/09/01 11:03
1610: previous = next;
1611: next = frequency.getNextDate(previous);
1612: assertEquals(1 * minute, next - previous); // 2002/09/01 11:04
1613: previous = next;
1614: next = frequency.getNextDate(previous);
1615: assertEquals(3 * minute, next - previous); // 2002/09/01 11:07
1616: previous = next;
1617: next = frequency.getNextDate(previous);
1618: assertEquals(24 * minute, next - previous); // 2002/09/01 11:31
1619: } catch (FrequencyException e) {
1620: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1621: }
1622: }
1623:
1624: public void testNextDateHours() {
1625: try {
1626: Calendar calendar = Calendar.getInstance(RifeConfig.Tools
1627: .getDefaultTimeZone(), Localization.getLocale());
1628: calendar.set(2002, Calendar.SEPTEMBER, 1, 10, 29);
1629: long calendar_time = calendar.getTimeInMillis();
1630: long previous = 0;
1631: long next = 0;
1632: Frequency frequency = null;
1633:
1634: int minute = 60 * 1000;
1635: int hour = 60 * minute;
1636: int day = 24 * hour;
1637:
1638: frequency = new Frequency("*/30 13 * * *"); // 2002/09/01 10:29
1639: previous = calendar_time;
1640: next = frequency.getNextDate(previous);
1641: assertEquals(2 * hour + 31 * minute, next - previous); // 2002/09/01 13:00
1642: previous = next;
1643: next = frequency.getNextDate(previous);
1644: assertEquals(30 * minute, next - previous); // 2002/09/01 13:30
1645: previous = next;
1646: next = frequency.getNextDate(previous);
1647: assertEquals(1 * day - (30 * minute), next - previous); // 2002/09/02 13:00
1648: previous = next;
1649: next = frequency.getNextDate(previous);
1650: assertEquals(30 * minute, next - previous); // 2002/09/02 13:30
1651:
1652: frequency = new Frequency("10 13 * * *"); // 2002/09/01 10:29
1653: previous = calendar_time;
1654: next = frequency.getNextDate(previous);
1655: assertEquals(2 * hour + 41 * minute, next - previous); // 2002/09/01 13:10
1656: previous = next;
1657: next = frequency.getNextDate(previous);
1658: assertEquals(1 * day, next - previous); // 2002/09/02 13:10
1659: previous = next;
1660: next = frequency.getNextDate(previous);
1661: assertEquals(1 * day, next - previous); // 2002/09/03 13:10
1662:
1663: frequency = new Frequency("34 */5 * * *"); // 2002/09/01 10:29
1664: previous = calendar_time;
1665: next = frequency.getNextDate(previous);
1666: assertEquals(5 * minute, next - previous); // 2002/09/01 10:34
1667: previous = next;
1668: next = frequency.getNextDate(previous);
1669: assertEquals(5 * hour, next - previous); // 2002/09/02 15:34
1670: previous = next;
1671: next = frequency.getNextDate(previous);
1672: assertEquals(5 * hour, next - previous); // 2002/09/02 20:34
1673: previous = next;
1674: next = frequency.getNextDate(previous);
1675: assertEquals(4 * hour, next - previous); // 2002/09/03 00:34
1676: previous = next;
1677: next = frequency.getNextDate(previous);
1678: assertEquals(5 * hour, next - previous); // 2002/09/03 05:34
1679: previous = next;
1680: next = frequency.getNextDate(previous);
1681: assertEquals(5 * hour, next - previous); // 2002/09/03 10:34
1682:
1683: frequency = new Frequency("13 7-23/7 * * *"); // 2002/09/01 10:29
1684: previous = calendar_time;
1685: next = frequency.getNextDate(previous);
1686: assertEquals(31 * minute + 3 * hour + 13 * minute, next
1687: - previous); // 2002/09/01 14:13
1688: previous = next;
1689: next = frequency.getNextDate(previous);
1690: assertEquals(7 * hour, next - previous); // 2002/09/02 21:13
1691: previous = next;
1692: next = frequency.getNextDate(previous);
1693: assertEquals(10 * hour, next - previous); // 2002/09/03 07:13
1694: previous = next;
1695: next = frequency.getNextDate(previous);
1696: assertEquals(7 * hour, next - previous); // 2002/09/03 14:13
1697:
1698: frequency = new Frequency("48 18-7/3 * * *"); // 2002/09/01 10:29
1699: previous = calendar_time;
1700: next = frequency.getNextDate(previous);
1701: assertEquals(31 * minute + 7 * hour + 48 * minute, next
1702: - previous); // 2002/09/01 18:48
1703: previous = next;
1704: next = frequency.getNextDate(previous);
1705: assertEquals(3 * hour, next - previous); // 2002/09/01 21:48
1706: previous = next;
1707: next = frequency.getNextDate(previous);
1708: assertEquals(3 * hour, next - previous); // 2002/09/02 00:48
1709: previous = next;
1710: next = frequency.getNextDate(previous);
1711: assertEquals(3 * hour, next - previous); // 2002/09/02 03:48
1712: previous = next;
1713: next = frequency.getNextDate(previous);
1714: assertEquals(3 * hour, next - previous); // 2002/09/02 06:48
1715: previous = next;
1716: next = frequency.getNextDate(previous);
1717: assertEquals(12 * hour, next - previous); // 2002/09/02 18:48
1718:
1719: frequency = new Frequency("14 2,4-7,10-18/3,21-0/3 * * *"); // 2002/09/01 10:29
1720: previous = calendar_time;
1721: next = frequency.getNextDate(previous);
1722: assertEquals(31 * minute + 2 * hour + 14 * minute, next
1723: - previous); // 2002/09/01 13:14
1724: previous = next;
1725: next = frequency.getNextDate(previous);
1726: assertEquals(3 * hour, next - previous); // 2002/09/01 16:14
1727: previous = next;
1728: next = frequency.getNextDate(previous);
1729: assertEquals(5 * hour, next - previous); // 2002/09/01 21:14
1730: previous = next;
1731: next = frequency.getNextDate(previous);
1732: assertEquals(3 * hour, next - previous); // 2002/09/02 00:14
1733: previous = next;
1734: next = frequency.getNextDate(previous);
1735: assertEquals(2 * hour, next - previous); // 2002/09/02 02:14
1736: previous = next;
1737: next = frequency.getNextDate(previous);
1738: assertEquals(2 * hour, next - previous); // 2002/09/02 04:14
1739: previous = next;
1740: next = frequency.getNextDate(previous);
1741: assertEquals(1 * hour, next - previous); // 2002/09/02 05:14
1742: previous = next;
1743: next = frequency.getNextDate(previous);
1744: assertEquals(1 * hour, next - previous); // 2002/09/02 06:14
1745: previous = next;
1746: next = frequency.getNextDate(previous);
1747: assertEquals(1 * hour, next - previous); // 2002/09/02 07:14
1748: previous = next;
1749: next = frequency.getNextDate(previous);
1750: assertEquals(3 * hour, next - previous); // 2002/09/02 10:14
1751: } catch (FrequencyException e) {
1752: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
1753: }
1754: }
1755:
1756: public void testNextDateDates() {
1757: try {
1758: TimeZone tz = RifeConfig.Tools.getDefaultTimeZone();
1759: Locale l = Localization.getLocale();
1760: Calendar calendar = Calendar.getInstance(RifeConfig.Tools
1761: .getDefaultTimeZone(), Localization.getLocale());
1762: calendar.set(2002, Calendar.SEPTEMBER, 1, 10, 29);
1763: long calendar_time = calendar.getTimeInMillis();
1764: long previous = 0;
1765: long next = 0;
1766: Frequency frequency = null;
1767:
1768: long minute = 60 * 1000;
1769: long hour = 60 * minute;
1770: long day = 24 * hour;
1771:
1772: frequency = new Frequency("*/30 */12 6 * *"); // 2002/09/01 10:29
1773: previous = calendar_time;
1774: next = frequency.getNextDate(previous);
1775: assertEquals(31 * minute + 13 * hour + 4 * day, next
1776: - previous); // 2002/09/06 00:00
1777: previous = next;
1778: next = frequency.getNextDate(previous);
1779: assertEquals(30 * minute, next - previous); // 2002/09/06 00:30
1780: previous = next;
1781: next = frequency.getNextDate(previous);
1782: assertEquals(30 * minute + 11 * hour, next - previous); // 2002/09/06 12:00
1783: previous = next;
1784: next = frequency.getNextDate(previous);
1785: assertEquals(30 * minute, next - previous); // 2002/09/06 12:30
1786: previous = next;
1787: next = frequency.getNextDate(previous);
1788: assertEquals(30 * minute + 11 * hour + 29 * day, next
1789: - previous); // 2002/10/06 00:00
1790: previous = next;
1791: next = frequency.getNextDate(previous);
1792: assertEquals(30 * minute, next - previous); // 2002/10/06 00:30
1793:
1794: frequency = new Frequency("19 10 */11 * *"); // 2002/09/01 10:29
1795: previous = calendar_time;
1796: next = frequency.getNextDate(previous);
1797: assertEquals(11 * day - 10 * minute, next - previous); // 2002/09/12 10:19
1798: previous = next;
1799: next = frequency.getNextDate(previous);
1800: assertEquals(11 * day, next - previous); // 2002/09/23 10:19
1801: previous = next;
1802: next = frequency.getNextDate(previous);
1803: assertEquals(8 * day, next - previous); // 2002/10/01 10:19
1804: previous = next;
1805: next = frequency.getNextDate(previous);
1806: assertEquals(11 * day, next - previous); // 2002/10/12 10:19
1807:
1808: frequency = new Frequency("57 10 6-18/5 * *"); // 2002/09/01 10:29
1809: previous = calendar_time;
1810: next = frequency.getNextDate(previous);
1811: assertEquals(28 * minute + 5 * day, next - previous); // 2002/09/06 10:57
1812: previous = next;
1813: next = frequency.getNextDate(previous);
1814: assertEquals(5 * day, next - previous); // 2002/09/11 10:57
1815: previous = next;
1816: next = frequency.getNextDate(previous);
1817: assertEquals(5 * day, next - previous); // 2002/09/16 10:57
1818: previous = next;
1819: next = frequency.getNextDate(previous);
1820: assertEquals(20 * day, next - previous); // 2002/10/06 10:57
1821:
1822: frequency = new Frequency("24 19 27-9/4 * *"); // 2002/09/01 10:29
1823: previous = calendar_time;
1824: next = frequency.getNextDate(previous);
1825: assertEquals(9 * hour - 5 * minute + 3 * day, next
1826: - previous); // 2002/09/04 19:24
1827: previous = next;
1828: next = frequency.getNextDate(previous);
1829: assertEquals(4 * day, next - previous); // 2002/09/08 19:24
1830: previous = next;
1831: next = frequency.getNextDate(previous);
1832: assertEquals(19 * day, next - previous); // 2002/09/27 19:24
1833: previous = next;
1834: next = frequency.getNextDate(previous);
1835: assertEquals(4 * day, next - previous); // 2002/10/01 19:24
1836: previous = next;
1837: next = frequency.getNextDate(previous);
1838: assertEquals(4 * day, next - previous); // 2002/10/05 19:24
1839: previous = next;
1840: next = frequency.getNextDate(previous);
1841: assertEquals(4 * day, next - previous); // 2002/10/09 19:24
1842: previous = next;
1843: next = frequency.getNextDate(previous);
1844: assertEquals(18 * day + 1 * hour, next - previous); // 2002/10/27 19:24 (daylight savings)
1845: previous = next;
1846: next = frequency.getNextDate(previous);
1847: assertEquals(4 * day, next - previous); // 2002/10/31 19:24
1848: previous = next;
1849: next = frequency.getNextDate(previous);
1850: assertEquals(4 * day, next - previous); // 2002/11/04 19:24
1851: previous = next;
1852: next = frequency.getNextDate(previous);
1853: assertEquals(4 * day, next - previous); // 2002/11/08 19:24
1854: previous = next;
1855: next = frequency.getNextDate(previous);
1856: assertEquals(19 * day, next - previous); // 2002/11/27 19:24
1857: previous = next;
1858: next = frequency.getNextDate(previous);
1859: assertEquals(4 * day, next - previous); // 2002/12/01 19:24
1860: previous = next;
1861: next = frequency.getNextDate(previous);
1862: assertEquals(4 * day, next - previous); // 2002/12/05 19:24
1863: previous = next;
1864: next = frequency.getNextDate(previous);
1865: assertEquals(4 * day, next - previous); // 2002/12/09 19:24
1866: previous = next;
1867: next = frequency.getNextDate(previous);
1868: assertEquals(18 * day, next - previous); // 2002/12/27 19:24
1869: previous = next;
1870: next = frequency.getNextDate(previous);
1871: assertEquals(4 * day, next - previous); // 2002/12/31 19:24
1872: previous = next;
1873: next = frequency.getNextDate(previous);
1874: assertEquals(4 * day, next - previous); // 2003/01/04 19:24
1875: previous = next;
1876: next = frequency.getNextDate(previous);
1877: assertEquals(4 * day, next - previous); // 2003/01/08 19:24
1878: previous = next;
1879: next = frequency.getNextDate(previous);
1880: assertEquals(19 * day, next - previous); // 2003/01/27 19:24
1881:
1882: calendar.set(2002, Calendar.APRIL, 28, 8, 15);
1883: calendar_time = calendar.getTimeInMillis();
1884:
1885: frequency = new Frequency("30 9 29-4/3 * *"); // 2002/04/28 08:15
1886: previous = calendar_time;
1887: next = frequency.getNextDate(previous);
1888: assertEquals(15 * minute + 1 * hour + 1 * day, next
1889: - previous); // 2002/04/29 09:30
1890: previous = next;
1891: next = frequency.getNextDate(previous);
1892: assertEquals(3 * day, next - previous); // 2002/04/02 09:30
1893: previous = next;
1894: next = frequency.getNextDate(previous);
1895: assertEquals(27 * day, next - previous); // 2002/04/29 09:30
1896: previous = next;
1897: next = frequency.getNextDate(previous);
1898: assertEquals(3 * day, next - previous); // 2002/05/01 09:30
1899: previous = next;
1900: next = frequency.getNextDate(previous);
1901: assertEquals(3 * day, next - previous); // 2002/05/04 09:30
1902:
1903: calendar.set(2002, Calendar.FEBRUARY, 1, 8, 15);
1904: calendar_time = calendar.getTimeInMillis();
1905:
1906: frequency = new Frequency("30 8 18-10/9 * *"); // 2002/02/01 08:15
1907: previous = calendar_time;
1908: next = frequency.getNextDate(previous);
1909: assertEquals(15 * minute + 4 * day, next - previous); // 2002/02/05 08:30
1910: previous = next;
1911: next = frequency.getNextDate(previous);
1912: assertEquals(13 * day, next - previous); // 2002/02/18 08:30
1913: previous = next;
1914: next = frequency.getNextDate(previous);
1915: assertEquals(9 * day, next - previous); // 2002/02/27 08:30
1916: previous = next;
1917: next = frequency.getNextDate(previous);
1918: assertEquals(9 * day, next - previous); // 2002/03/08 08:30
1919: previous = next;
1920: next = frequency.getNextDate(previous);
1921: assertEquals(10 * day, next - previous); // 2002/03/18 08:30
1922: previous = next;
1923: next = frequency.getNextDate(previous);
1924: assertEquals(9 * day, next - previous); // 2002/03/27 08:30
1925: previous = next;
1926: next = frequency.getNextDate(previous);
1927: assertEquals(9 * day - 1 * hour, next - previous); // 2002/04/05 08:30 (daylight savings)
1928: previous = next;
1929: next = frequency.getNextDate(previous);
1930: assertEquals(13 * day, next - previous); // 2002/04/18 08:30
1931:
1932: calendar.set(2004, Calendar.FEBRUARY, 1, 8, 15);
1933: calendar_time = calendar.getTimeInMillis();
1934:
1935: frequency = new Frequency("30 8 18-10/9 * *"); // 2004/02/01 08:15
1936: previous = calendar_time;
1937: next = frequency.getNextDate(previous);
1938: assertEquals(15 * minute + 4 * day, next - previous); // 2004/02/05 08:30
1939: previous = next;
1940: next = frequency.getNextDate(previous);
1941: assertEquals(13 * day, next - previous); // 2004/02/18 08:30
1942: previous = next;
1943: next = frequency.getNextDate(previous);
1944: assertEquals(9 * day, next - previous); // 2004/02/27 08:30
1945: previous = next;
1946: next = frequency.getNextDate(previous);
1947: assertEquals(9 * day, next - previous); // 2004/03/07 08:30 (leap year)
1948: previous = next;
1949: next = frequency.getNextDate(previous);
1950: assertEquals(11 * day, next - previous); // 2004/03/18 08:30
1951: previous = next;
1952: next = frequency.getNextDate(previous);
1953: assertEquals(9 * day, next - previous); // 2004/03/27 08:30
1954: previous = next;
1955: next = frequency.getNextDate(previous);
1956: assertEquals(9 * day - 1 * hour, next - previous); // 2004/04/05 08:30 (daylight savings)
1957: previous = next;
1958: next = frequency.getNextDate(previous);
1959: assertEquals(13 * day, next - previous); // 2004/04/18 08:30
1960:
1961: frequency = new Frequency("15 7 6,9-12,15-27/4,26-4/3 * *"); // 2004/02/01 08:15
1962: previous = calendar_time;
1963: next = frequency.getNextDate(previous);
1964: assertEquals(3 * day - 1 * hour, next - previous); // 2004/02/04 07:15
1965: previous = next;
1966: next = frequency.getNextDate(previous);
1967: assertEquals(2 * day, next - previous); // 2004/02/06 07:15
1968: previous = next;
1969: next = frequency.getNextDate(previous);
1970: assertEquals(3 * day, next - previous); // 2004/02/09 07:15
1971: previous = next;
1972: next = frequency.getNextDate(previous);
1973: assertEquals(1 * day, next - previous); // 2004/02/10 07:15
1974: previous = next;
1975: next = frequency.getNextDate(previous);
1976: assertEquals(1 * day, next - previous); // 2004/02/11 07:15
1977: previous = next;
1978: next = frequency.getNextDate(previous);
1979: assertEquals(1 * day, next - previous); // 2004/02/12 07:15
1980: previous = next;
1981: next = frequency.getNextDate(previous);
1982: assertEquals(3 * day, next - previous); // 2004/02/15 07:15
1983: previous = next;
1984: next = frequency.getNextDate(previous);
1985: assertEquals(4 * day, next - previous); // 2004/02/19 07:15
1986: previous = next;
1987: next = frequency.getNextDate(previous);
1988: assertEquals(4 * day, next - previous); // 2004/02/23 07:15
1989: previous = next;
1990: next = frequency.getNextDate(previous);
1991: assertEquals(3 * day, next - previous); // 2004/02/26 07:15
1992: previous = next;
1993: next = frequency.getNextDate(previous);
1994: assertEquals(1 * day, next - previous); // 2004/02/27 07:15
1995: previous = next;
1996: next = frequency.getNextDate(previous);
1997: assertEquals(2 * day, next - previous); // 2004/02/29 07:15
1998: previous = next;
1999: next = frequency.getNextDate(previous);
2000: assertEquals(3 * day, next - previous); // 2004/03/03 07:15 (leap year)
2001: previous = next;
2002: next = frequency.getNextDate(previous);
2003: assertEquals(3 * day, next - previous); // 2004/03/06 07:15
2004: previous = next;
2005: next = frequency.getNextDate(previous);
2006: assertEquals(3 * day, next - previous); // 2004/03/09 07:15
2007: previous = next;
2008: next = frequency.getNextDate(previous);
2009: assertEquals(1 * day, next - previous); // 2004/03/10 07:15
2010: previous = next;
2011: next = frequency.getNextDate(previous);
2012: assertEquals(1 * day, next - previous); // 2004/03/11 07:15
2013: previous = next;
2014: next = frequency.getNextDate(previous);
2015: assertEquals(1 * day, next - previous); // 2004/03/12 07:15
2016: previous = next;
2017: next = frequency.getNextDate(previous);
2018: assertEquals(3 * day, next - previous); // 2004/03/15 07:15
2019: previous = next;
2020: next = frequency.getNextDate(previous);
2021: assertEquals(4 * day, next - previous); // 2004/03/19 07:15
2022: previous = next;
2023: next = frequency.getNextDate(previous);
2024: assertEquals(4 * day, next - previous); // 2004/03/23 07:15
2025: previous = next;
2026: next = frequency.getNextDate(previous);
2027: assertEquals(3 * day, next - previous); // 2004/03/26 07:15
2028: previous = next;
2029: next = frequency.getNextDate(previous);
2030: assertEquals(1 * day, next - previous); // 2004/03/27 07:15
2031: previous = next;
2032: next = frequency.getNextDate(previous);
2033: assertEquals(2 * day - 1 * hour, next - previous); // 2004/03/29 07:15 (daylight savings)
2034: previous = next;
2035: next = frequency.getNextDate(previous);
2036: assertEquals(3 * day, next - previous); // 2004/04/01 07:15
2037:
2038: calendar.set(2003, Calendar.DECEMBER, 20, 17, 10);
2039: calendar_time = calendar.getTimeInMillis();
2040:
2041: frequency = new Frequency("20 19 20-10/5 * *"); // 2003/12/20 17:10
2042: previous = calendar_time;
2043: next = frequency.getNextDate(previous);
2044: assertEquals(10 * minute + 2 * hour, next - previous); // 2003/12/20 19:20
2045: previous = next;
2046: next = frequency.getNextDate(previous);
2047: assertEquals(5 * day, next - previous); // 2003/12/25 19:20
2048: previous = next;
2049: next = frequency.getNextDate(previous);
2050: assertEquals(5 * day, next - previous); // 2003/12/30 19:20
2051: previous = next;
2052: next = frequency.getNextDate(previous);
2053: assertEquals(5 * day, next - previous); // 2004/01/04 19:20
2054: previous = next;
2055: next = frequency.getNextDate(previous);
2056: assertEquals(5 * day, next - previous); // 2004/01/09 19:20
2057: previous = next;
2058: next = frequency.getNextDate(previous);
2059: assertEquals(11 * day, next - previous); // 2004/01/20 19:20
2060: previous = next;
2061: next = frequency.getNextDate(previous);
2062: assertEquals(5 * day, next - previous); // 2004/01/25 19:20
2063: } catch (FrequencyException e) {
2064: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2065: }
2066: }
2067:
2068: public void testNextDateMonths() {
2069: try {
2070: Calendar calendar = Calendar.getInstance(RifeConfig.Tools
2071: .getDefaultTimeZone(), Localization.getLocale());
2072: calendar.set(2002, Calendar.SEPTEMBER, 1, 10, 29);
2073: long calendar_time = calendar.getTimeInMillis();
2074: long previous = 0;
2075: long next = 0;
2076: Frequency frequency = null;
2077:
2078: long minute = 60 * 1000;
2079: long hour = 60 * minute;
2080: long day = 24 * hour;
2081:
2082: frequency = new Frequency("*/30 */12 */20 10 *"); // 2002/09/01 10:29
2083: previous = calendar_time;
2084: next = frequency.getNextDate(previous);
2085: assertEquals(31 * minute + 13 * hour + 29 * day, next
2086: - previous); // 2002/10/01 00:00
2087: previous = next;
2088: next = frequency.getNextDate(previous);
2089: assertEquals(30 * minute, next - previous); // 2002/10/01 00:30
2090: previous = next;
2091: next = frequency.getNextDate(previous);
2092: assertEquals(30 * minute + 11 * hour, next - previous); // 2002/10/01 12:00
2093: previous = next;
2094: next = frequency.getNextDate(previous);
2095: assertEquals(30 * minute, next - previous); // 2002/10/01 12:30
2096: previous = next;
2097: next = frequency.getNextDate(previous);
2098: assertEquals(30 * minute + 11 * hour + 19 * day, next
2099: - previous); // 2002/10/21 00:00
2100: previous = next;
2101: next = frequency.getNextDate(previous);
2102: assertEquals(30 * minute, next - previous); // 2002/10/21 00:30
2103: previous = next;
2104: next = frequency.getNextDate(previous);
2105: assertEquals(30 * minute + 11 * hour, next - previous); // 2002/10/21 12:00
2106: previous = next;
2107: next = frequency.getNextDate(previous);
2108: assertEquals(30 * minute, next - previous); // 2002/10/21 12:30
2109: previous = next;
2110: next = frequency.getNextDate(previous);
2111: assertEquals(30 * minute + 11 * hour + 344 * day, next
2112: - previous); // 2003/10/01 00:00
2113:
2114: frequency = new Frequency("10 19 7 */4 *"); // 2002/09/01 10:29
2115: previous = calendar_time;
2116: next = frequency.getNextDate(previous);
2117: assertEquals(
2118: 31 * minute + 8 * hour + 6 * day + 10 * minute,
2119: next - previous); // 2002/09/07 19:10
2120: previous = next;
2121: next = frequency.getNextDate(previous);
2122: assertEquals((30 + 31 + 30 + 31) * day + 1 * hour, next
2123: - previous); // 2003/01/07 19:10 (daylight savings)
2124: previous = next;
2125: next = frequency.getNextDate(previous);
2126: assertEquals((31 + 28 + 31 + 30) * day - 1 * hour, next
2127: - previous); // 2003/05/07 19:10 (daylight savings)
2128: previous = next;
2129: next = frequency.getNextDate(previous);
2130: assertEquals((31 + 30 + 31 + 31) * day, next - previous); // 2003/09/07 19:10
2131: previous = next;
2132: next = frequency.getNextDate(previous);
2133: assertEquals((30 + 31 + 30 + 31) * day + 1 * hour, next
2134: - previous); // 2004/01/07 19:10 (daylight savings)
2135: previous = next;
2136: next = frequency.getNextDate(previous);
2137: assertEquals((31 + 29 + 31 + 30) * day - 1 * hour, next
2138: - previous); // 2004/05/07 19:10 (daylight savings)
2139: previous = next;
2140: next = frequency.getNextDate(previous);
2141: assertEquals((31 + 30 + 31 + 31) * day, next - previous); // 2003/09/07 19:10
2142:
2143: frequency = new Frequency("50 06 18 4-11/3 *"); // 2002/09/01 10:29
2144: previous = calendar_time;
2145: next = frequency.getNextDate(previous);
2146: assertEquals(31 * minute + 13 * hour + (29 + 17) * day + 6
2147: * hour + 50 * minute, next - previous); // 2002/10/18 06:50
2148: previous = next;
2149: next = frequency.getNextDate(previous);
2150: assertEquals((31 + 30 + 31 + 31 + 28 + 31) * day, next
2151: - previous); // 2003/04/18 06:50
2152: previous = next;
2153: next = frequency.getNextDate(previous);
2154: assertEquals((30 + 31 + 30) * day, next - previous); // 2003/07/18 06:50
2155: previous = next;
2156: next = frequency.getNextDate(previous);
2157: assertEquals((31 + 31 + 30) * day, next - previous); // 2003/10/18 06:50
2158: previous = next;
2159: next = frequency.getNextDate(previous);
2160: assertEquals((31 + 30 + 31 + 31 + 29 + 31) * day, next
2161: - previous); // 2004/04/18 06:50
2162:
2163: frequency = new Frequency("15 12 06 8-4/3 *"); // 2002/09/01 10:29
2164: previous = calendar_time;
2165: next = frequency.getNextDate(previous);
2166: assertEquals(31 * minute + (5 + 30 + 31) * day + 1 * hour
2167: + 15 * minute + 1 * hour, next - previous); // 2002/11/06 12:15 (daylight savings)
2168: previous = next;
2169: next = frequency.getNextDate(previous);
2170: assertEquals((30 + 31 + 31) * day, next - previous); // 2003/02/06 12:15
2171: previous = next;
2172: next = frequency.getNextDate(previous);
2173: assertEquals(
2174: (28 + 31 + 30 + 31 + 30 + 31) * day - 1 * hour,
2175: next - previous); // 2003/08/06 12:15 (daylight savings)
2176: previous = next;
2177: next = frequency.getNextDate(previous);
2178: assertEquals((31 + 30 + 31) * day + 1 * hour, next
2179: - previous); // 2003/11/06 12:15 (daylight savings)
2180:
2181: frequency = new Frequency("40 11 27 2,5-6,11-4/2 *"); // 2002/09/01 10:29
2182: previous = calendar_time;
2183: next = frequency.getNextDate(previous);
2184: assertEquals(11 * minute + 1 * hour + (26 + 30 + 31) * day
2185: + 1 * hour, next - previous); // 2002/11/27 11:40
2186: previous = next;
2187: next = frequency.getNextDate(previous);
2188: assertEquals((30 + 31) * day, next - previous); // 2003/01/27 11:40
2189: previous = next;
2190: next = frequency.getNextDate(previous);
2191: assertEquals(31 * day, next - previous); // 2003/02/27 11:40
2192: previous = next;
2193: next = frequency.getNextDate(previous);
2194: assertEquals(28 * day, next - previous); // 2003/03/27 11:40
2195: previous = next;
2196: next = frequency.getNextDate(previous);
2197: assertEquals((31 + 30) * day - 1 * hour, next - previous); // 2003/05/27 11:40 (daylight savings)
2198: previous = next;
2199: next = frequency.getNextDate(previous);
2200: assertEquals(31 * day, next - previous); // 2003/06/27 11:40
2201: previous = next;
2202: next = frequency.getNextDate(previous);
2203: assertEquals((30 + 31 + 31 + 30 + 31) * day + 1 * hour,
2204: next - previous); // 2003/11/27 11:40
2205: previous = next;
2206: next = frequency.getNextDate(previous);
2207: assertEquals((30 + 31) * day, next - previous); // 2004/01/27 11:40
2208: previous = next;
2209: next = frequency.getNextDate(previous);
2210: assertEquals(31 * day, next - previous); // 2004/02/27 11:40
2211: } catch (FrequencyException e) {
2212: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2213: }
2214: }
2215:
2216: public void testNextDateWeekdays() {
2217: try {
2218: Calendar calendar = Calendar.getInstance(RifeConfig.Tools
2219: .getDefaultTimeZone(), Localization.getLocale());
2220: calendar.set(2002, Calendar.SEPTEMBER, 1, 10, 29);
2221: long calendar_time = calendar.getTimeInMillis();
2222: long previous = 0;
2223: long next = 0;
2224: Frequency frequency = null;
2225:
2226: long minute = 60 * 1000;
2227: long hour = 60 * minute;
2228: long day = 24 * hour;
2229:
2230: frequency = new Frequency("30 12 * 10 1"); // 2002/09/01 10:29
2231: previous = calendar_time;
2232: next = frequency.getNextDate(previous);
2233: assertEquals(1 * minute + 30 * day + 6 * day + 2 * hour,
2234: next - previous); // 2002/10/07 12:30
2235: previous = next;
2236: next = frequency.getNextDate(previous);
2237: assertEquals(7 * day, next - previous); // 2002/10/14 12:30
2238: previous = next;
2239: next = frequency.getNextDate(previous);
2240: assertEquals(7 * day, next - previous); // 2002/10/21 12:30
2241: previous = next;
2242: next = frequency.getNextDate(previous);
2243: assertEquals(7 * day + 1 * hour, next - previous); // 2002/10/28 12:30 (daylight savings)
2244: previous = next;
2245: next = frequency.getNextDate(previous);
2246: assertEquals(365 * day - 22 * day - 1 * hour, next
2247: - previous); // 2003/10/06 12:30 (daylight savings)
2248: previous = next;
2249: next = frequency.getNextDate(previous);
2250: assertEquals(7 * day, next - previous); // 2003/10/13 12:30
2251: previous = next;
2252: next = frequency.getNextDate(previous);
2253: assertEquals(7 * day, next - previous); // 2003/10/20 12:30
2254: previous = next;
2255: next = frequency.getNextDate(previous);
2256: assertEquals(7 * day + 1 * hour, next - previous); // 2003/10/27 12:30 (daylight savings)
2257: } catch (FrequencyException e) {
2258: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2259: }
2260: }
2261:
2262: public void testInvalidNextDate() {
2263: try {
2264: Calendar calendar = Calendar.getInstance(RifeConfig.Tools
2265: .getDefaultTimeZone(), Localization.getLocale());
2266: calendar.set(2002, Calendar.SEPTEMBER, 1, 10, 0);
2267: long calendar_time = calendar.getTimeInMillis();
2268: Frequency frequency = null;
2269:
2270: frequency = new Frequency("* * 31 2 *");
2271: try {
2272: frequency.getNextDate(calendar_time);
2273: fail();
2274: } catch (FrequencyException e) {
2275: assertTrue(true);
2276: }
2277: } catch (FrequencyException e) {
2278: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
2279: }
2280: }
2281: }
|