001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.gl.service;
017:
018: import java.text.DateFormat;
019: import java.text.SimpleDateFormat;
020: import java.util.Date;
021: import java.util.LinkedHashMap;
022: import java.util.Map;
023: import java.util.Map.Entry;
024:
025: import org.kuali.kfs.context.KualiTestBase;
026: import org.kuali.kfs.context.SpringContext;
027: import org.kuali.kfs.context.TestUtils;
028: import org.kuali.module.gl.GLConstants;
029: import org.kuali.module.gl.batch.ScrubberStep;
030: import org.kuali.test.ConfigureContext;
031:
032: /**
033: * Tests the cutoff time functionality of RunDateService
034: */
035: @ConfigureContext
036: public class RunDateServiceTest extends KualiTestBase {
037:
038: protected static final String DATE_FORMAT = "MM/dd/yyyy HH:mm:ss";
039:
040: protected RunDateService runDateService;
041:
042: /**
043: * Initializes the RunDateService implementation to test
044: * @see junit.framework.TestCase#setUp()
045: */
046: @Override
047: protected void setUp() throws Exception {
048: super .setUp();
049:
050: runDateService = SpringContext.getBean(RunDateService.class);
051: }
052:
053: /**
054: * Tests that the cutoff time is parsed correct and tests several times to see where they lie
055: * against the cut off time
056: *
057: * @throws Exception thrown if any exception is encountered for any reason
058: */
059: public void testCalculateCutoff() throws Exception {
060: // cutoff time should be set to 10am in the master data source, see FS_PARM_T, script name GL.SCRUBBER, param name
061: // SCRUBBER_CUTOFF_TIME
062: // KFSP1/Scrubber+cutoff+time+configuration
063:
064: Map<String, String> expectedCurrentToRunTimeMappings = new LinkedHashMap<String, String>();
065:
066: // assuming cutoff time of 10am in this code
067: expectedCurrentToRunTimeMappings.put("6/1/2006 10:35:00",
068: "6/1/2006 10:35:00");
069: expectedCurrentToRunTimeMappings.put("3/1/2006 9:59:00",
070: "2/28/2006 23:59:59");
071: expectedCurrentToRunTimeMappings.put("3/1/2004 9:59:00",
072: "2/29/2004 23:59:59");
073: expectedCurrentToRunTimeMappings.put("4/1/2004 1:59:00",
074: "3/31/2004 23:59:59");
075: expectedCurrentToRunTimeMappings.put("9/21/2005 19:13:14",
076: "9/21/2005 19:13:14");
077: expectedCurrentToRunTimeMappings.put("1/1/2009 9:59:14",
078: "12/31/2008 23:59:59");
079: expectedCurrentToRunTimeMappings.put("5/12/2009 21:59:14",
080: "5/12/2009 21:59:14");
081: expectedCurrentToRunTimeMappings.put("5/12/2050 21:59:14",
082: "5/12/2050 21:59:14");
083: // 2100 is not a leap year
084: expectedCurrentToRunTimeMappings.put("3/1/2100 9:59:00",
085: "2/28/2100 23:59:59");
086: expectedCurrentToRunTimeMappings.put("3/1/2104 9:59:00",
087: "2/29/2104 23:59:59");
088:
089: DateFormat parser = new SimpleDateFormat(DATE_FORMAT);
090: for (Entry<String, String> entry : expectedCurrentToRunTimeMappings
091: .entrySet()) {
092: Date calculatedRunTime = runDateService
093: .calculateRunDate(parser.parse(entry.getKey()));
094: assertTrue(entry.getKey() + " " + entry.getValue() + " "
095: + calculatedRunTime, parser.parse(entry.getValue())
096: .equals(calculatedRunTime));
097: }
098: }
099:
100: /**
101: * Tests an edge case where the cutoff time is at midnight
102: *
103: * @throws Exception thrown if any exception is encountered for any reason
104: */
105: public void testCalculateCutoffDuringMidnightHour()
106: throws Exception {
107: TestUtils
108: .setSystemParameter(
109: ScrubberStep.class,
110: GLConstants.GlScrubberGroupParameters.SCRUBBER_CUTOFF_TIME,
111: "0:05:00");
112: Map<String, String> expectedCurrentToRunTimeMappings = new LinkedHashMap<String, String>();
113:
114: expectedCurrentToRunTimeMappings.put("6/1/2006 0:05:00",
115: "6/1/2006 0:05:00");
116: expectedCurrentToRunTimeMappings.put("3/1/2006 0:02:33",
117: "2/28/2006 23:59:59");
118:
119: DateFormat parser = new SimpleDateFormat(DATE_FORMAT);
120: for (Entry<String, String> entry : expectedCurrentToRunTimeMappings
121: .entrySet()) {
122: Date calculatedRunTime = runDateService
123: .calculateRunDate(parser.parse(entry.getKey()));
124: assertTrue(entry.getKey() + " " + entry.getValue() + " "
125: + calculatedRunTime, parser.parse(entry.getValue())
126: .equals(calculatedRunTime));
127: }
128: }
129: }
|