KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > archive > crawler > settings > refinements > TimespanCriteriaTest


1 /* TimespanCriteriaTest
2  *
3  * $Id: TimespanCriteriaTest.java,v 1.4 2005/03/31 03:35:17 stack-sf Exp $
4  *
5  * Created on Apr 8, 2004
6  *
7  * Copyright (C) 2004 Internet Archive.
8  *
9  * 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 JavaDoc;
28 import java.text.ParseException JavaDoc;
29 import java.text.SimpleDateFormat JavaDoc;
30 import java.util.Date JavaDoc;
31 import java.util.TimeZone JavaDoc;
32
33 import junit.framework.TestCase;
34
35
36 /**
37  *
38  * @author John Erik Halse
39  *
40  */

41 public class TimespanCriteriaTest extends TestCase {
42     public final void testIsWithinRefinementBounds() throws ParseException JavaDoc {
43         DateFormat JavaDoc timeFormat;
44         TimeZone JavaDoc TZ = TimeZone.getTimeZone("GMT");
45         timeFormat = new SimpleDateFormat JavaDoc("HHmm");
46         timeFormat.setTimeZone(TZ);
47         Date JavaDoc now = timeFormat.parse(timeFormat.format(new Date JavaDoc()));
48
49         String JavaDoc nowTime = timeFormat.format(now);
50         String JavaDoc beforeTime1 = timeFormat.format(new Date JavaDoc(now.getTime() -
51             1000 * 60 * 2));
52         String JavaDoc beforeTime2 = timeFormat.format(new Date JavaDoc(now.getTime() -
53             1000 * 60 * 1));
54         String JavaDoc afterTime1 = timeFormat.format(new Date JavaDoc(now.getTime() +
55             1000 * 60 * 1));
56
57         // now is inside and before is less than after
58
TimespanCriteria c = new TimespanCriteria(beforeTime1, afterTime1);
59         assertTrue(c.isWithinRefinementBounds(null));
60
61         // now is equal to before and less than after
62
c = new TimespanCriteria(nowTime, afterTime1);
63         assertTrue(c.isWithinRefinementBounds(null));
64
65         // now is equal to before and less than after
66
c = new TimespanCriteria(beforeTime1, nowTime);
67         assertTrue(c.isWithinRefinementBounds(null));
68
69         // now is outside and before is less than after
70
c = new TimespanCriteria(beforeTime1, beforeTime2);
71         assertFalse(c.isWithinRefinementBounds(null));
72
73         // now is outside and before is greater than after
74
c = new TimespanCriteria(afterTime1, beforeTime1);
75         assertFalse(c.isWithinRefinementBounds(null));
76
77         // now is inside and before is greater than after
78
c = new TimespanCriteria(beforeTime2, beforeTime1);
79         assertTrue(c.isWithinRefinementBounds(null));
80
81         // now is equal to before and before is greater than after
82
c = new TimespanCriteria(nowTime, beforeTime1);
83         assertTrue(c.isWithinRefinementBounds(null));
84
85         // now is equal to before and before is greater than after
86
c = new TimespanCriteria(afterTime1, nowTime);
87         assertTrue(c.isWithinRefinementBounds(null));
88 }
89
90 }
91
Popular Tags