01: /* TimespanCriteriaTest
02: *
03: * $Id: TimespanCriteriaTest.java 3287 2005-03-31 03:35:18Z stack-sf $
04: *
05: * Created on Apr 8, 2004
06: *
07: * Copyright (C) 2004 Internet Archive.
08: *
09: * This file is part of the Heritrix web crawler (crawler.archive.org).
10: *
11: * Heritrix is free software; you can redistribute it and/or modify
12: * it under the terms of the GNU Lesser Public License as published by
13: * the Free Software Foundation; either version 2.1 of the License, or
14: * any later version.
15: *
16: * Heritrix is distributed in the hope that it will be useful,
17: * but WITHOUT ANY WARRANTY; without even the implied warranty of
18: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: * GNU Lesser Public License for more details.
20: *
21: * You should have received a copy of the GNU Lesser Public License
22: * along with Heritrix; if not, write to the Free Software
23: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: */
25: package org.archive.crawler.settings.refinements;
26:
27: import java.text.DateFormat;
28: import java.text.ParseException;
29: import java.text.SimpleDateFormat;
30: import java.util.Date;
31: import java.util.TimeZone;
32:
33: import junit.framework.TestCase;
34:
35: /**
36: *
37: * @author John Erik Halse
38: *
39: */
40: public class TimespanCriteriaTest extends TestCase {
41: public final void testIsWithinRefinementBounds()
42: throws ParseException {
43: DateFormat timeFormat;
44: TimeZone TZ = TimeZone.getTimeZone("GMT");
45: timeFormat = new SimpleDateFormat("HHmm");
46: timeFormat.setTimeZone(TZ);
47: Date now = timeFormat.parse(timeFormat.format(new Date()));
48:
49: String nowTime = timeFormat.format(now);
50: String beforeTime1 = timeFormat.format(new Date(
51: now.getTime() - 1000 * 60 * 2));
52: String beforeTime2 = timeFormat.format(new Date(
53: now.getTime() - 1000 * 60 * 1));
54: String afterTime1 = timeFormat.format(new Date(
55: now.getTime() + 1000 * 60 * 1));
56:
57: // now is inside and before is less than after
58: TimespanCriteria c = new TimespanCriteria(beforeTime1,
59: afterTime1);
60: assertTrue(c.isWithinRefinementBounds(null));
61:
62: // now is equal to before and less than after
63: c = new TimespanCriteria(nowTime, afterTime1);
64: assertTrue(c.isWithinRefinementBounds(null));
65:
66: // now is equal to before and less than after
67: c = new TimespanCriteria(beforeTime1, nowTime);
68: assertTrue(c.isWithinRefinementBounds(null));
69:
70: // now is outside and before is less than after
71: c = new TimespanCriteria(beforeTime1, beforeTime2);
72: assertFalse(c.isWithinRefinementBounds(null));
73:
74: // now is outside and before is greater than after
75: c = new TimespanCriteria(afterTime1, beforeTime1);
76: assertFalse(c.isWithinRefinementBounds(null));
77:
78: // now is inside and before is greater than after
79: c = new TimespanCriteria(beforeTime2, beforeTime1);
80: assertTrue(c.isWithinRefinementBounds(null));
81:
82: // now is equal to before and before is greater than after
83: c = new TimespanCriteria(nowTime, beforeTime1);
84: assertTrue(c.isWithinRefinementBounds(null));
85:
86: // now is equal to before and before is greater than after
87: c = new TimespanCriteria(afterTime1, nowTime);
88: assertTrue(c.isWithinRefinementBounds(null));
89: }
90:
91: }
|