001: /*
002: * Copyright 2006-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.financial.service;
017:
018: import static org.kuali.test.fixtures.AccountingLineFixture.LINE18;
019: import static org.kuali.test.fixtures.UserNameFixture.MHKOZLOW;
020:
021: import java.util.Iterator;
022: import java.util.List;
023:
024: import org.kuali.core.service.DateTimeService;
025: import org.kuali.core.service.DocumentService;
026: import org.kuali.core.util.KualiDecimal;
027: import org.kuali.kfs.context.KualiTestBase;
028: import org.kuali.kfs.context.SpringContext;
029: import org.kuali.module.financial.bo.Check;
030: import org.kuali.module.financial.bo.CheckBase;
031: import org.kuali.module.financial.document.CashReceiptDocument;
032: import org.kuali.test.ConfigureContext;
033: import org.kuali.test.DocumentTestUtils;
034:
035: /**
036: * This class tests the Check service.
037: */
038: @ConfigureContext(session=MHKOZLOW)
039: public class CheckServiceTest extends KualiTestBase {
040:
041: private Check check;
042:
043: private String documentNumber;
044:
045: @Override
046: protected void setUp() throws Exception {
047: super .setUp();
048: documentNumber = createDocument();
049: // setup check
050: check = new CheckBase();
051: check.setDocumentNumber(documentNumber);
052: check.setAmount(new KualiDecimal("314.15"));
053: check.setCheckDate(SpringContext.getBean(DateTimeService.class)
054: .getCurrentSqlDate());
055: check.setCheckNumber("2112");
056: check.setDescription("test check");
057: check.setFinancialDocumentDepositLineNumber(new Integer(2001));
058: check.setSequenceId(new Integer(2001));
059: check.setFinancialDocumentTypeCode("CR");
060: check.setCashieringRecordSource("R");
061:
062: // clean up remnants of earlier tests
063: clearTestData();
064: }
065:
066: @ConfigureContext(session=MHKOZLOW,shouldCommitTransactions=true)
067: public void testLifecycle() throws Exception {
068: boolean deleteSucceeded = false;
069: List retrievedChecks = SpringContext
070: .getBean(CheckService.class).getByDocumentHeaderId(
071: documentNumber);
072: assertTrue(retrievedChecks.size() == 0);
073:
074: Check savedCheck = null;
075: Check retrievedCheck = null;
076: try {
077: // save a check
078: savedCheck = SpringContext.getBean(CheckService.class)
079: .save(check);
080:
081: // retrieve it
082: retrievedChecks = SpringContext.getBean(CheckService.class)
083: .getByDocumentHeaderId(documentNumber);
084: assertTrue(retrievedChecks.size() > 0);
085: retrievedCheck = (Check) retrievedChecks.get(0);
086:
087: // compare
088: assertTrue(check.isLike(savedCheck));
089: assertTrue(savedCheck.isLike(retrievedCheck));
090: } finally {
091: // delete it
092: SpringContext.getBean(CheckService.class).deleteCheck(
093: savedCheck);
094: }
095:
096: // verify that the delete succeeded
097: retrievedChecks = SpringContext.getBean(CheckService.class)
098: .getByDocumentHeaderId(documentNumber);
099: assertTrue(retrievedChecks.size() == 0);
100:
101: }
102:
103: private void clearTestData() {
104: List retrievedChecks = SpringContext
105: .getBean(CheckService.class).getByDocumentHeaderId(
106: documentNumber);
107: if (retrievedChecks.size() > 0) {
108: for (Iterator i = retrievedChecks.iterator(); i.hasNext();) {
109: SpringContext.getBean(CheckService.class).deleteCheck(
110: (Check) i.next());
111: }
112: }
113: }
114:
115: private String createDocument() throws Exception {
116: CashReceiptDocument document = DocumentTestUtils
117: .createDocument(SpringContext
118: .getBean(DocumentService.class),
119: CashReceiptDocument.class);
120: LINE18.addAsSourceTo(document);
121: SpringContext.getBean(DocumentService.class).saveDocument(
122: document);
123: return document.getDocumentNumber();
124: }
125: }
|