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.purap.rules;
017:
018: import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
019:
020: import java.sql.Date;
021: import java.util.Calendar;
022:
023: import org.kuali.core.service.DateTimeService;
024: import org.kuali.kfs.context.SpringContext;
025: import org.kuali.module.purap.document.PaymentRequestDocument;
026: import org.kuali.module.purap.fixtures.PaymentRequestInvoiceTabFixture;
027: import org.kuali.test.ConfigureContext;
028:
029: @ConfigureContext(session=KHUNTLEY)
030: public class PaymentRequestDocumentRuleTest extends PurapRuleTestBase {
031:
032: PaymentRequestDocumentRule rule;
033: PaymentRequestDocument preq;
034:
035: @Override
036: protected void setUp() throws Exception {
037: super .setUp();
038: preq = new PaymentRequestDocument();
039: rule = new PaymentRequestDocumentRule();
040: }
041:
042: @Override
043: protected void tearDown() throws Exception {
044: rule = null;
045: preq = null;
046: super .tearDown();
047: }
048:
049: /*
050: * Tests of processInvoiceValidation
051: */
052: public void testProcessInvoiceValidation_With_All() {
053: preq = PaymentRequestInvoiceTabFixture.WITH_POID_WITH_DATE_WITH_NUMBER_WITH_AMOUNT
054: .populate(preq);
055: assertTrue(rule.processInvoiceValidation(preq));
056: }
057:
058: public void testProcessInvoiceValidation_Without_PO_ID() {
059: preq = PaymentRequestInvoiceTabFixture.NO_POID_WITH_DATE_WITH_NUMBER_WITH_AMOUNT
060: .populate(preq);
061: assertFalse(rule.processInvoiceValidation(preq));
062: }
063:
064: public void testProcessInvoiceValidation_Without_Date() {
065: preq = PaymentRequestInvoiceTabFixture.WITH_POID_NO_DATE_WITH_NUMBER_WITH_AMOUNT
066: .populate(preq);
067: assertFalse(rule.processInvoiceValidation(preq));
068: }
069:
070: public void testProcessInvoiceValidation_Without_Number() {
071: preq = PaymentRequestInvoiceTabFixture.WITH_POID_WITH_DATE_NO_NUMBER_WITH_AMOUNT
072: .populate(preq);
073: assertFalse(rule.processInvoiceValidation(preq));
074: }
075:
076: public void testProcessInvoiceValidation_Without_Amount() {
077: preq = PaymentRequestInvoiceTabFixture.WITH_POID_WITH_DATE_WITH_NUMBER_NO_AMOUNT
078: .populate(preq);
079: assertFalse(rule.processInvoiceValidation(preq));
080: }
081:
082: /*
083: * Tests of processPurchaseOrderIDValidation
084: */
085:
086: /*
087: * Tests of encumberedItemExistsForInvoicing
088: */
089:
090: /*
091: * Tests of processPaymentRequestDateValidationForContinue
092: */
093: private Date getDateFromOffsetFromToday(int offsetDays) {
094: Calendar calendar = SpringContext
095: .getBean(DateTimeService.class).getCurrentCalendar();
096: calendar.add(Calendar.DATE, offsetDays);
097: return new Date(calendar.getTimeInMillis());
098: }
099:
100: public void testProcessPaymentRequestDateValidationForContinue_BeforeToday() {
101: preq = PaymentRequestInvoiceTabFixture.WITH_POID_WITH_DATE_WITH_NUMBER_WITH_AMOUNT
102: .populate(preq);
103: Date yesterday = getDateFromOffsetFromToday(-1);
104: preq.setInvoiceDate(yesterday);
105: assertTrue(rule
106: .processPaymentRequestDateValidationForContinue(preq));
107: }
108:
109: public void testProcessPaymentRequestDateValidationForContinue_AfterToday() {
110: preq = PaymentRequestInvoiceTabFixture.WITH_POID_WITH_DATE_WITH_NUMBER_WITH_AMOUNT
111: .populate(preq);
112: Date tomorrow = getDateFromOffsetFromToday(1);
113: preq.setInvoiceDate(tomorrow);
114: assertFalse(rule
115: .processPaymentRequestDateValidationForContinue(preq));
116: }
117:
118: public void testProcessPaymentRequestDateValidationForContinue_Today() {
119: preq = PaymentRequestInvoiceTabFixture.WITH_POID_WITH_DATE_WITH_NUMBER_WITH_AMOUNT
120: .populate(preq);
121: Date today = SpringContext.getBean(DateTimeService.class)
122: .getCurrentSqlDate();
123: preq.setInvoiceDate(today);
124: assertTrue(rule
125: .processPaymentRequestDateValidationForContinue(preq));
126: }
127:
128: /*
129: * Tests of validatePaymentRequestDates
130: */
131: public void testValidatePaymentRequestDates_Yesterday() {
132: Date yesterday = getDateFromOffsetFromToday(-1);
133: preq.setPaymentRequestPayDate(yesterday);
134: assertFalse(rule.validatePaymentRequestDates(preq));
135: }
136:
137: public void testValidatePaymentRequestDates_Today() {
138: Date today = SpringContext.getBean(DateTimeService.class)
139: .getCurrentSqlDate();
140: preq.setPaymentRequestPayDate(today);
141: assertTrue(rule.validatePaymentRequestDates(preq));
142: }
143:
144: public void testValidatePaymentRequestDates_Tomorrow() {
145: Date tomorrow = getDateFromOffsetFromToday(1);
146: preq.setPaymentRequestPayDate(tomorrow);
147: assertTrue(rule.validatePaymentRequestDates(preq));
148: }
149:
150: /*
151: * Tests of validateItem
152: */
153:
154: /*
155: * Tests of validateItemAccounts
156: */
157:
158: /*
159: * Tests of validateCancel
160: */
161:
162: /*
163: * Tests of validatePaymentRequestReview
164: */
165:
166: }
|