1 4 package org.oddjob.schedules.schedules; 5 6 import java.text.DateFormat ; 7 import java.text.ParseException ; 8 import java.text.SimpleDateFormat ; 9 import java.util.Date ; 10 11 import org.oddjob.schedules.ScheduleContext; 12 13 import junit.framework.TestCase; 14 15 19 public class MonthScheduleTest extends TestCase { 20 21 static DateFormat checkFormat = new SimpleDateFormat ("dd-MMM-yy HH:mm:ss:SSS"); 22 static DateFormat inputFormat = new SimpleDateFormat ("dd-MMM-yy HH:mm"); 23 24 public void testFromAndTo() throws ParseException { 25 MonthSchedule schedule = new MonthSchedule(); 26 schedule.setFrom("FEB"); 27 schedule.setTo("APR"); 28 29 Date now1 = inputFormat.parse("10-feb-2003 12:30"); 30 Date expectedStart 31 = checkFormat.parse("01-feb-2003 00:00:00:000"); 32 Date actualStart1 = schedule.getStartDate( 33 new ScheduleContext(now1)); 34 assertTrue("Start [" + actualStart1 + "] wrong.", 35 expectedStart.equals(actualStart1)); 36 Date expectedEnd 37 = checkFormat.parse("30-apr-2003 23:59:59:999"); 38 Date actualEnd1 = schedule.getEndDate( 39 new ScheduleContext(now1)); 40 assertTrue("End [" + actualEnd1 + "] wrong.", 41 expectedEnd.equals(actualEnd1)); 42 } 43 44 public void testAfter() throws ParseException { 45 MonthSchedule schedule = new MonthSchedule(); 46 schedule.setFrom("FEB"); 47 schedule.setTo("APR"); 48 49 Date now1 = inputFormat.parse("21-jun-2003 12:30"); 50 Date expectedStart 51 = checkFormat.parse("01-feb-2004 00:00:00:000"); 52 Date actualStart1 = schedule.getStartDate( 53 new ScheduleContext(now1)); 54 assertTrue("Start [" + actualStart1 + "] wrong.", 55 expectedStart.equals(actualStart1)); 56 Date expectedEnd 57 = checkFormat.parse("30-apr-2004 23:59:59:999"); 58 Date actualEnd1 = schedule.getEndDate( 59 new ScheduleContext(now1)); 60 assertTrue("End [" + actualEnd1 + "] wrong.", 61 expectedEnd.equals(actualEnd1)); 62 } 63 64 public void testOverBoundry() throws ParseException { 65 MonthSchedule schedule = new MonthSchedule(); 66 schedule.setFrom("NOV"); 67 schedule.setTo("FEB"); 68 69 Date now1 = inputFormat.parse("25-dec-2003 12:30"); 70 Date expectedStart 71 = checkFormat.parse("01-nov-2003 00:00:00:000"); 72 Date actualStart1 = schedule.getStartDate( 73 new ScheduleContext(now1)); 74 assertEquals(expectedStart, actualStart1); 75 Date expectedEnd 76 = checkFormat.parse("29-feb-2004 23:59:59:999"); 77 Date actualEnd1 = schedule.getEndDate( 78 new ScheduleContext(now1)); 79 assertEquals(expectedEnd, actualEnd1); 80 81 Date now2 = inputFormat.parse("21-sep-2003 12:30"); 82 Date actualStart2 = schedule.getStartDate( 83 new ScheduleContext(now2)); 84 assertTrue("Start [" + actualStart2 + "] wrong.", 85 expectedStart.equals(actualStart2)); 86 Date actualEnd2 = schedule.getEndDate( 87 new ScheduleContext(now2)); 88 assertTrue("End [" + actualEnd2 + "] wrong.", 89 expectedEnd.equals(actualEnd2)); 90 91 Date now3 = inputFormat.parse("01-feb-2004 12:30"); 92 Date actualStart3 = schedule.getStartDate( 93 new ScheduleContext(now3)); 94 assertTrue("Start [" + actualStart3 + "] wrong.", 95 expectedStart.equals(actualStart3)); 96 Date actualEnd3 = schedule.getEndDate( 97 new ScheduleContext(now3)); 98 assertTrue("End [" + expectedEnd + "] wrong.", 99 expectedEnd.equals(actualEnd3)); 100 } 101 102 } 103 | Popular Tags |