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.document;
017:
018: import static org.kuali.module.financial.document.AccountingDocumentTestUtils.testGetNewDocument_byDocumentClass;
019: import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
020: import static org.kuali.test.fixtures.UserNameFixture.RJWEISS;
021: import static org.kuali.test.fixtures.UserNameFixture.RORENFRO;
022:
023: import java.util.ArrayList;
024: import java.util.List;
025:
026: import org.kuali.core.service.DataDictionaryService;
027: import org.kuali.core.service.DocumentService;
028: import org.kuali.core.service.TransactionalDocumentDictionaryService;
029: import org.kuali.kfs.context.KualiTestBase;
030: import org.kuali.kfs.context.SpringContext;
031: import org.kuali.module.financial.document.AccountingDocumentTestUtils;
032: import org.kuali.module.purap.bo.PurchaseOrderView;
033: import org.kuali.module.purap.bo.PurchasingItem;
034: import org.kuali.module.purap.fixtures.RequisitionDocumentFixture;
035: import org.kuali.module.purap.fixtures.RequisitionItemFixture;
036: import org.kuali.module.purap.service.PurapService;
037: import org.kuali.test.ConfigureContext;
038: import org.kuali.test.DocumentTestUtils;
039: import org.kuali.test.fixtures.UserNameFixture;
040: import org.kuali.workflow.WorkflowTestUtils;
041:
042: import edu.iu.uis.eden.EdenConstants;
043:
044: /**
045: * Used to create and test populated Requisition Documents of various kinds.
046: */
047: @ConfigureContext(session=KHUNTLEY)
048: public class RequisitionDocumentTest extends KualiTestBase {
049: public static final Class<RequisitionDocument> DOCUMENT_CLASS = RequisitionDocument.class;
050: private static final String ACCOUNT_REVIEW = "Account Review";
051:
052: private RequisitionDocument requisitionDocument = null;
053:
054: protected void setUp() throws Exception {
055: super .setUp();
056: }
057:
058: protected void tearDown() throws Exception {
059: requisitionDocument = null;
060: super .tearDown();
061: }
062:
063: private List<RequisitionItemFixture> getItemParametersFromFixtures() {
064: List<RequisitionItemFixture> list = new ArrayList<RequisitionItemFixture>();
065: list.add(RequisitionItemFixture.REQ_ITEM_NO_APO);
066: return list;
067: }
068:
069: private int getExpectedPrePeCount() {
070: return 0;
071: }
072:
073: public final void testAddItem() throws Exception {
074: List<PurchasingItem> items = new ArrayList<PurchasingItem>();
075: items.add(RequisitionItemFixture.REQ_ITEM_NO_APO
076: .createRequisitionItem());
077:
078: int expectedItemTotal = items.size();
079: PurchasingDocumentTestUtils.testAddItem(
080: (PurchasingDocument) DocumentTestUtils.createDocument(
081: SpringContext.getBean(DocumentService.class),
082: DOCUMENT_CLASS), items, expectedItemTotal);
083: }
084:
085: public final void testGetNewDocument() throws Exception {
086: testGetNewDocument_byDocumentClass(DOCUMENT_CLASS,
087: SpringContext.getBean(DocumentService.class));
088: }
089:
090: public final void testConvertIntoCopy_copyDisallowed()
091: throws Exception {
092: AccountingDocumentTestUtils.testConvertIntoCopy_copyDisallowed(
093: buildSimpleDocument(), SpringContext
094: .getBean(DataDictionaryService.class));
095:
096: }
097:
098: public final void testConvertIntoErrorCorrection_documentAlreadyCorrected()
099: throws Exception {
100: AccountingDocumentTestUtils
101: .testConvertIntoErrorCorrection_documentAlreadyCorrected(
102: buildSimpleDocument(),
103: SpringContext
104: .getBean(TransactionalDocumentDictionaryService.class));
105: }
106:
107: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
108: public final void testConvertIntoErrorCorrection() throws Exception {
109: requisitionDocument = buildSimpleDocument();
110: AccountingDocumentTestUtils
111: .testConvertIntoErrorCorrection(
112: requisitionDocument,
113: getExpectedPrePeCount(),
114: SpringContext.getBean(DocumentService.class),
115: SpringContext
116: .getBean(TransactionalDocumentDictionaryService.class));
117: }
118:
119: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
120: public final void testRouteDocument() throws Exception {
121: requisitionDocument = buildSimpleDocument();
122: AccountingDocumentTestUtils.testRouteDocument(
123: requisitionDocument, SpringContext
124: .getBean(DocumentService.class));
125: }
126:
127: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
128: public final void testSaveDocument() throws Exception {
129: requisitionDocument = buildSimpleDocument();
130: AccountingDocumentTestUtils.testSaveDocument(
131: requisitionDocument, SpringContext
132: .getBean(DocumentService.class));
133: }
134:
135: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
136: public final void testConvertIntoCopy() throws Exception {
137: requisitionDocument = buildSimpleDocument();
138: AccountingDocumentTestUtils.testConvertIntoCopy(
139: requisitionDocument, SpringContext
140: .getBean(DocumentService.class),
141: getExpectedPrePeCount());
142: }
143:
144: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
145: public final void testRouteDocumentToFinal() throws Exception {
146: requisitionDocument = RequisitionDocumentFixture.REQ_NO_APO_VALID
147: .createRequisitionDocument();
148: final String docId = requisitionDocument.getDocumentNumber();
149: AccountingDocumentTestUtils.routeDocument(requisitionDocument,
150: SpringContext.getBean(DocumentService.class));
151: WorkflowTestUtils.waitForNodeChange(requisitionDocument
152: .getDocumentHeader().getWorkflowDocument(),
153: ACCOUNT_REVIEW);
154:
155: // the document should now be routed to VPUTMAN as Fiscal Officer
156: changeCurrentUser(RORENFRO);
157: requisitionDocument = (RequisitionDocument) SpringContext
158: .getBean(DocumentService.class).getByDocumentHeaderId(
159: docId);
160: assertTrue("At incorrect node.", WorkflowTestUtils.isAtNode(
161: requisitionDocument, ACCOUNT_REVIEW));
162: assertTrue("Document should be enroute.", requisitionDocument
163: .getDocumentHeader().getWorkflowDocument()
164: .stateIsEnroute());
165: assertTrue("RORENFRO should have an approve request.",
166: requisitionDocument.getDocumentHeader()
167: .getWorkflowDocument().isApprovalRequested());
168: SpringContext.getBean(DocumentService.class)
169: .approveDocument(requisitionDocument,
170: "Test approving as RORENFRO", null);
171:
172: WorkflowTestUtils.waitForStatusChange(requisitionDocument
173: .getDocumentHeader().getWorkflowDocument(),
174: EdenConstants.ROUTE_HEADER_FINAL_CD);
175:
176: changeCurrentUser(KHUNTLEY);
177: requisitionDocument = (RequisitionDocument) SpringContext
178: .getBean(DocumentService.class).getByDocumentHeaderId(
179: docId);
180: assertTrue("Document should now be final.", requisitionDocument
181: .getDocumentHeader().getWorkflowDocument()
182: .stateIsFinal());
183: }
184:
185: @ConfigureContext(session=RORENFRO,shouldCommitTransactions=true)
186: public final void testCreateAPOAlternateRequisition()
187: throws Exception {
188: RequisitionDocument altAPORequisition = RequisitionDocumentFixture.REQ_ALTERNATE_APO
189: .createRequisitionDocument();
190: AccountingDocumentTestUtils.testSaveDocument(altAPORequisition,
191: SpringContext.getBean(DocumentService.class));
192: }
193:
194: private RequisitionDocument buildSimpleDocument() throws Exception {
195: return RequisitionDocumentFixture.REQ_ONLY_REQUIRED_FIELDS
196: .createRequisitionDocument();
197: }
198:
199: private UserNameFixture getInitialUserName() {
200: return RJWEISS;
201: }
202:
203: protected UserNameFixture getTestUserName() {
204: return RORENFRO;
205: }
206:
207: // create document fixture
208: }
|