001: /*
002: * Copyright 2005-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.document;
017:
018: import static org.kuali.module.financial.document.AccountingDocumentTestUtils.testGetNewDocument_byDocumentClass;
019: import static org.kuali.module.purap.fixtures.PurchaseOrderItemAccountsFixture.WITH_DESC_WITH_UOM_WITH_PRICE_WITH_ACCOUNT;
020: import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
021: import static org.kuali.test.fixtures.UserNameFixture.RJWEISS;
022: import static org.kuali.test.fixtures.UserNameFixture.RORENFRO;
023: import static org.kuali.test.fixtures.UserNameFixture.PARKE;
024:
025: import java.sql.Date;
026: import java.util.ArrayList;
027: import java.util.List;
028:
029: import junit.framework.Assert;
030:
031: import org.apache.commons.lang.StringUtils;
032: import org.kuali.core.document.Document;
033: import org.kuali.core.service.DataDictionaryService;
034: import org.kuali.core.service.DocumentService;
035: import org.kuali.core.service.TransactionalDocumentDictionaryService;
036: import org.kuali.core.util.KualiDecimal;
037: import org.kuali.kfs.context.KualiTestBase;
038: import org.kuali.kfs.context.SpringContext;
039: import org.kuali.kfs.document.AccountingDocument;
040: import org.kuali.module.financial.document.AccountingDocumentTestUtils;
041: import org.kuali.module.purap.bo.PurchasingItem;
042: import org.kuali.module.purap.bo.PurchaseOrderItem;
043: import org.kuali.module.purap.document.WorkflowXmlPurchaseOrderDocument.DummyContractManager;
044: import org.kuali.module.purap.document.WorkflowXmlPurchaseOrderDocument.DummyStatus;
045: import org.kuali.module.purap.document.WorkflowXmlPurchaseOrderDocument.DummyVendorContract;
046: import org.kuali.module.purap.fixtures.PurchaseOrderDocumentFixture;
047: import org.kuali.module.purap.fixtures.PurchaseOrderItemAccountsFixture;
048: import org.kuali.test.ConfigureContext;
049: import org.kuali.test.DocumentTestUtils;
050: import org.kuali.test.fixtures.UserNameFixture;
051: import org.kuali.test.monitor.ChangeMonitor;
052: import org.kuali.test.monitor.DocumentWorkflowStatusMonitor;
053: import org.kuali.workflow.WorkflowTestUtils;
054:
055: import edu.iu.uis.eden.EdenConstants;
056:
057: /**
058: * Used to create and test populated Purchase Order Documents of various kinds.
059: */
060: @ConfigureContext(session=KHUNTLEY)
061: public class PurchaseOrderDocumentTest extends KualiTestBase {
062: public static final Class<PurchaseOrderDocument> DOCUMENT_CLASS = PurchaseOrderDocument.class;
063:
064: private List<PurchaseOrderItemAccountsFixture> getItemParametersFromFixtures() {
065: List<PurchaseOrderItemAccountsFixture> list = new ArrayList<PurchaseOrderItemAccountsFixture>();
066: list.add(WITH_DESC_WITH_UOM_WITH_PRICE_WITH_ACCOUNT);
067: return list;
068: }
069:
070: private int getExpectedPrePeCount() {
071: return 0;
072: }
073:
074: public final void testAddItem() throws Exception {
075: List<PurchasingItem> items = new ArrayList<PurchasingItem>();
076: for (PurchaseOrderItem item : generateItems()) {
077: items.add(item);
078: }
079: int expectedItemTotal = items.size();
080: PurchasingDocumentTestUtils.testAddItem(
081: (PurchasingDocument) DocumentTestUtils.createDocument(
082: SpringContext.getBean(DocumentService.class),
083: DOCUMENT_CLASS), items, expectedItemTotal);
084: }
085:
086: public final void testGetNewDocument() throws Exception {
087: testGetNewDocument_byDocumentClass(DOCUMENT_CLASS,
088: SpringContext.getBean(DocumentService.class));
089: }
090:
091: public final void testConvertIntoErrorCorrection_documentAlreadyCorrected()
092: throws Exception {
093: AccountingDocumentTestUtils
094: .testConvertIntoErrorCorrection_documentAlreadyCorrected(
095: buildSimpleDocument(),
096: SpringContext
097: .getBean(TransactionalDocumentDictionaryService.class));
098: }
099:
100: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
101: public final void testConvertIntoErrorCorrection() throws Exception {
102: AccountingDocumentTestUtils
103: .testConvertIntoErrorCorrection(
104: buildSimpleDocument(),
105: getExpectedPrePeCount(),
106: SpringContext.getBean(DocumentService.class),
107: SpringContext
108: .getBean(TransactionalDocumentDictionaryService.class));
109: }
110:
111: @ConfigureContext(session=PARKE,shouldCommitTransactions=true)
112: public final void testRouteDocument() throws Exception {
113: PurchaseOrderDocument poDocument = buildSimpleDocument();
114: DocumentService documentService = SpringContext
115: .getBean(DocumentService.class);
116: poDocument.prepareForSave();
117: assertFalse("R".equals(poDocument.getDocumentHeader()
118: .getWorkflowDocument().getRouteHeader()
119: .getDocRouteStatus()));
120: AccountingDocumentTestUtils.routeDocument(poDocument,
121: "saving copy source document", null, documentService);
122: WorkflowTestUtils.waitForStatusChange(poDocument
123: .getDocumentHeader().getWorkflowDocument(), "F");
124: //WorkflowTestUtils.waitForNodeChange(poDocument.getDocumentHeader().getWorkflowDocument(), "Open");
125: assertTrue("Document should now be final.", poDocument
126: .getDocumentHeader().getWorkflowDocument()
127: .stateIsFinal());
128: }
129:
130: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
131: public final void testSaveDocument() throws Exception {
132: PurchaseOrderDocument poDocument = buildSimpleDocument();
133: DocumentService documentService = SpringContext
134: .getBean(DocumentService.class);
135: poDocument.prepareForSave();
136: AccountingDocumentTestUtils.saveDocument(poDocument,
137: documentService);
138: PurchaseOrderDocument result = (PurchaseOrderDocument) documentService
139: .getByDocumentHeaderId(poDocument.getDocumentNumber());
140: assertMatch(poDocument, result);
141: }
142:
143: // test util methods
144:
145: public static void assertMatch(PurchaseOrderDocument doc1,
146: PurchaseOrderDocument doc2) {
147: // match header
148: Assert.assertEquals(doc1.getDocumentNumber(), doc2
149: .getDocumentNumber());
150: Assert.assertEquals(doc1.getDocumentHeader()
151: .getWorkflowDocument().getDocumentType(), doc2
152: .getDocumentHeader().getWorkflowDocument()
153: .getDocumentType());
154:
155: // match posting year
156: if (StringUtils.isNotBlank(doc1.getPostingPeriodCode())
157: && StringUtils.isNotBlank(doc2.getPostingPeriodCode())) {
158: Assert.assertEquals(doc1.getPostingPeriodCode(), doc2
159: .getPostingPeriodCode());
160: }
161: Assert.assertEquals(doc1.getPostingYear(), doc2
162: .getPostingYear());
163:
164: // match important fields in PO
165:
166: Assert.assertEquals(doc1.getVendorHeaderGeneratedIdentifier(),
167: doc2.getVendorHeaderGeneratedIdentifier());
168: Assert.assertEquals(doc1.getVendorDetailAssignedIdentifier(),
169: doc2.getVendorDetailAssignedIdentifier());
170: Assert.assertEquals(doc1.getVendorName(), doc2.getVendorName());
171: Assert.assertEquals(doc1.getVendorNumber(), doc2
172: .getVendorNumber());
173: Assert.assertEquals(doc1.getStatusCode(), doc2.getStatusCode());
174:
175: Assert.assertEquals(doc1.getChartOfAccountsCode(), doc2
176: .getChartOfAccountsCode());
177: Assert.assertEquals(doc1.getOrganizationCode(), doc2
178: .getOrganizationCode());
179: Assert.assertEquals(doc1.getDeliveryCampusCode(), doc2
180: .getDeliveryCampusCode());
181: Assert.assertEquals(doc1.getDeliveryRequiredDate(), doc2
182: .getDeliveryRequiredDate());
183: Assert.assertEquals(doc1.getRequestorPersonName(), doc2
184: .getRequestorPersonName());
185: Assert.assertEquals(doc1.getContractManagerCode(), doc2
186: .getContractManagerCode());
187: Assert.assertEquals(doc1.getVendorContractName(), doc2
188: .getVendorContractName());
189: Assert.assertEquals(doc1.getPurchaseOrderAutomaticIndicator(),
190: doc2.getPurchaseOrderAutomaticIndicator());
191: Assert.assertEquals(doc1
192: .getPurchaseOrderTransmissionMethodCode(), doc2
193: .getPurchaseOrderTransmissionMethodCode());
194:
195: Assert.assertEquals(doc1.getRequisitionIdentifier(), doc2
196: .getRequisitionIdentifier());
197: Assert.assertEquals(doc1.getPurchaseOrderPreviousIdentifier(),
198: doc2.getPurchaseOrderPreviousIdentifier());
199: Assert.assertEquals(doc1.isPurchaseOrderCurrentIndicator(),
200: doc2.isPurchaseOrderCurrentIndicator());
201: Assert.assertEquals(doc1.getPurchaseOrderCreateDate(), doc2
202: .getPurchaseOrderCreateDate());
203: Assert.assertEquals(doc1.getPurchaseOrderLastTransmitDate(),
204: doc2.getPurchaseOrderLastTransmitDate());
205: }
206:
207: private List<PurchaseOrderItem> generateItems() throws Exception {
208: List<PurchaseOrderItem> items = new ArrayList<PurchaseOrderItem>();
209: // set items to document
210: for (PurchaseOrderItemAccountsFixture itemFixture : getItemParametersFromFixtures()) {
211: items.add(itemFixture.populateItem());
212: }
213:
214: return items;
215: }
216:
217: private PurchaseOrderDocument buildSimpleDocument()
218: throws Exception {
219: return PurchaseOrderDocumentFixture.PO_ONLY_REQUIRED_FIELDS
220: .createPurchaseOrderDocument();
221: }
222:
223: private UserNameFixture getInitialUserName() {
224: return RJWEISS;
225: }
226:
227: protected UserNameFixture getTestUserName() {
228: return RORENFRO;
229: }
230: }
|