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.service;
017:
018: import java.sql.Date;
019:
020: import org.kuali.core.document.Document;
021: import org.kuali.core.service.DateTimeService;
022: import org.kuali.core.service.DocumentService;
023: import org.kuali.core.util.KualiDecimal;
024: import org.kuali.kfs.context.KualiTestBase;
025: import org.kuali.kfs.context.SpringContext;
026: import org.kuali.kfs.service.ParameterService;
027: import org.kuali.module.purap.PurapConstants;
028: import org.kuali.module.purap.PurapParameterConstants;
029: import org.kuali.module.purap.document.PaymentRequestDocument;
030: import org.kuali.module.purap.document.PurchaseOrderDocument;
031: import org.kuali.module.purap.document.RequisitionDocument;
032: import org.kuali.test.ConfigureContext;
033: import org.kuali.test.fixtures.UserNameFixture;
034:
035: import edu.iu.uis.eden.exception.WorkflowException;
036:
037: @ConfigureContext(session=UserNameFixture.APPLETON)
038: public class PaymentRequestServiceTest extends KualiTestBase {
039: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
040: .getLogger(PaymentRequestServiceTest.class);
041:
042: private DocumentService documentService;
043: // private PaymentRequestDocument document;
044: private KualiDecimal defaultMinimumLimit;
045: private ParameterService parameterService;
046: private NegativePaymentRequestApprovalLimitService npras;
047: private PaymentRequestService paymentRequestService;
048:
049: @Override
050: public void setUp() throws Exception {
051: super .setUp();
052: if (null == documentService) {
053: documentService = SpringContext
054: .getBean(DocumentService.class);
055: }
056: if (null == parameterService) {
057: parameterService = SpringContext
058: .getBean(ParameterService.class);
059: String samt = parameterService
060: .getParameterValue(
061: PaymentRequestDocument.class,
062: PurapParameterConstants.PURAP_DEFAULT_NEGATIVE_PAYMENT_REQUEST_APPROVAL_LIMIT);
063: defaultMinimumLimit = new KualiDecimal(samt);
064: }
065: if (null == npras) {
066: npras = SpringContext
067: .getBean(NegativePaymentRequestApprovalLimitService.class);
068: }
069: if (null == paymentRequestService) {
070: paymentRequestService = SpringContext
071: .getBean(PaymentRequestService.class);
072: }
073: }
074:
075: private void cancelDocument(Document document)
076: throws WorkflowException {
077: documentService.cancelDocument(document, "testing complete");
078: }
079:
080: private void header(Document document) {
081: document.getDocumentHeader().setFinancialDocumentDescription(
082: "test");
083: }
084:
085: private PaymentRequestDocument createBasicDocument()
086: throws WorkflowException {
087:
088: RequisitionDocument requisitionDocument = (RequisitionDocument) documentService
089: .getNewDocument(RequisitionDocument.class);
090: requisitionDocument.initiateDocument();
091: header(requisitionDocument);
092: documentService.saveDocument(requisitionDocument);
093: requisitionDocument.refreshNonUpdateableReferences();
094:
095: PurchaseOrderDocument purchaseOrderDocument = (PurchaseOrderDocument) documentService
096: .getNewDocument(PurchaseOrderDocument.class);
097: purchaseOrderDocument
098: .populatePurchaseOrderFromRequisition(requisitionDocument);
099: header(purchaseOrderDocument);
100: documentService.saveDocument(purchaseOrderDocument);
101: purchaseOrderDocument.refreshNonUpdateableReferences();
102:
103: PaymentRequestDocument paymentRequestDocument = (PaymentRequestDocument) documentService
104: .getNewDocument(PaymentRequestDocument.class);
105: Date today = SpringContext.getBean(DateTimeService.class)
106: .getCurrentSqlDate();
107: // paymentRequestDocument.initiateDocument();
108: paymentRequestDocument.setInvoiceDate(today);
109: paymentRequestDocument
110: .setStatusCode(PurapConstants.PaymentRequestStatuses.AWAITING_ACCOUNTS_PAYABLE_REVIEW);// IN_PROCESS);
111: paymentRequestDocument
112: .setPaymentRequestCostSourceCode(PurapConstants.POCostSources.ESTIMATE);
113: purchaseOrderDocument.setPurchaseOrderCreateDate(today);
114: // purchaseOrderDocument.setDefaultValuesForAPO();
115: // purchaseOrderDocument.setP
116:
117: paymentRequestDocument
118: .populatePaymentRequestFromPurchaseOrder(purchaseOrderDocument);
119: header(paymentRequestDocument);
120: documentService.saveDocument(paymentRequestDocument);
121: paymentRequestDocument.refreshNonUpdateableReferences();
122:
123: // paymentRequestDocument.setPurchaseOrderIdentifier(1);
124: // paymentRequestDocument.setInvoiceDate(today);
125: // UniversalUser currentUser = (UniversalUser)GlobalVariables.getUserSession().getUniversalUser();
126: // paymentRequestDocument.setAccountsPayableProcessorIdentifier(currentUser.getPersonUniversalIdentifier());
127: // paymentRequestDocument.getDocumentHeader().setFinancialDocumentDescription("test description");
128:
129: // PurchaseOrderDocument purchaseOrderDocument =
130: // SpringContext.getBean(DocumentService.class).getNewDocument(PurchaseOrderDocument.class);
131: // purchaseOrderDocument.getDocumentHeader().setFinancialDocumentDescription("test");
132: // documentService.saveDocument(purchaseOrderDocument);
133: //
134: // paymentRequestDocument.setPurchaseOrderDocument(purchaseOrderDocument);
135: // Integer poid = purchaseOrderDocument.getPurapDocumentIdentifier();
136: // paymentRequestDocument.setPurchaseOrderIdentifier(poid);
137: // documentService.saveDocument(paymentRequestDocument);
138: return paymentRequestDocument;
139: }
140:
141: @ConfigureContext(session=UserNameFixture.APPLETON)
142: public void testFoo() throws Exception {
143: // PaymentRequestDocument document = createBasicDocument();
144: // boolean isApprovalRequested = document.getDocumentHeader().getWorkflowDocument().isApprovalRequested();
145: // documentService.routeDocument(document, "", new ArrayList());
146: // document.setChartOfAccountsCode("BA");
147: // //changeCurrentUser(UserNameFixture.KHUNTLEY);
148: // boolean approved = SpringContext.getBean(PaymentRequestService.class).autoApprovePaymentRequest(document,
149: // defaultMinimumLimit);
150: // Map map = GlobalVariables.getErrorMap();
151: // boolean breakonme = approved;
152: }
153:
154: /**
155: * Payment requests with a negative payment request approval limit higher than the default limit should be auto-approved.
156: *
157: * @throws Exception
158: */
159: public void testAutoApprovePaymentRequests_defaultLimit()
160: throws Exception {
161:
162: // (laran) This is just sample code that doesn't really do anything.
163: // I was trying to come up with a good testing strategy. This code
164: // probably shouldn't be used for real tests. But it may be helpful to
165: // look at.
166: /*
167: * Collection<NegativePaymentRequestApprovalLimit> notOverriddenByChart = new HashSet<NegativePaymentRequestApprovalLimit>();
168: * Collection<NegativePaymentRequestApprovalLimit> limits = npras.findAboveLimit(defaultMinimumLimit);
169: * for(NegativePaymentRequestApprovalLimit limit : limits) { LOG.info("Creating PayReq for limit."); PaymentRequestDocument
170: * document = createBasicDocument(); PurchasingApItem item = new PaymentRequestItem(); item.setItemQuantity(new
171: * KualiDecimal(1)); // Set the total for this document below the default minimum. // item.setItemUnitPrice(new
172: * BigDecimal(defaultMinimumLimit.intValue() - 1)); document.addItem(item); String preSaveStatusCode =
173: * document.getStatusCode(); paymentRequestService.autoApprovePaymentRequests(); // Status should have changed if document
174: * was approved. LOG.info("Pre-save status code is " + preSaveStatusCode + ". Post-save status code is " +
175: * document.getStatusCode()); assertNotSame(preSaveStatusCode, document.getStatusCode()); cancelDocument(document); }
176: */
177: }
178:
179: /**
180: * When the chart negative payment request approval limit is lower than the default limit, and lower than the limit according to
181: * (chart + account) and the limit according to (chart and org) the payreq should be auto-approved.
182: *
183: * @throws Exception
184: */
185: public void testAutoApprovePaymentRequests_chartLimit()
186: throws Exception {
187: }
188:
189: /**
190: * When the (chart+account) negative payment request approval limit is lower than the default limit, and lower than the limit
191: * according to chart and the limit according to (chart and org) the payreq should be auto-approved.
192: *
193: * @throws Exception
194: */
195: public void testAutoApprovePaymentRequests_chartAndAccountLimit()
196: throws Exception {
197: }
198:
199: public void testAutoApprovePaymentRequests_chartAndOrganizationLimit()
200: throws Exception {
201: }
202:
203: public void testAutoApprovePaymentRequests_held() throws Exception {
204: }
205:
206: public void testAutoApprovePaymentRequests_cancelled()
207: throws Exception {
208: }
209:
210: public void testAutoApprovePaymentRequests_futurePayDate()
211: throws Exception {
212: }
213:
214: }
|