View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.module.purap.document;
20  
21  import static org.kuali.kfs.sys.fixture.UserNameFixture.appleton;
22  import static org.kuali.kfs.sys.fixture.UserNameFixture.ferland;
23  import static org.kuali.kfs.sys.fixture.UserNameFixture.khuntley;
24  import static org.kuali.kfs.sys.fixture.UserNameFixture.parke;
25  
26  import org.kuali.kfs.module.purap.PurapConstants.PurchaseOrderDocTypes;
27  import org.kuali.kfs.module.purap.PurapConstants.PurchaseOrderStatuses;
28  import org.kuali.kfs.module.purap.document.service.PurchaseOrderService;
29  import org.kuali.kfs.module.purap.fixture.PaymentRequestDocumentFixture;
30  import org.kuali.kfs.sys.ConfigureContext;
31  import org.kuali.kfs.sys.context.KualiTestBase;
32  import org.kuali.kfs.sys.context.SpringContext;
33  import org.kuali.kfs.sys.document.AccountingDocumentTestUtils;
34  import org.kuali.kfs.sys.document.workflow.WorkflowTestUtils;
35  import org.kuali.kfs.sys.fixture.UserNameFixture;
36  import org.kuali.rice.core.api.util.type.KualiDecimal;
37  import org.kuali.rice.kew.api.document.DocumentStatus;
38  import org.kuali.rice.krad.service.DocumentService;
39  import org.kuali.rice.krad.service.impl.DocumentServiceImpl;
40  
41  /**
42   * Used to create and test populated Purchase Order Documents of various kinds.
43   */
44  @ConfigureContext(session = khuntley)
45  public class PurapFullProcessDocumentTest extends KualiTestBase {
46      private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(DocumentServiceImpl.class);
47  
48      private static final String SUB_ACCOUNT_REVIEW = "SubAccount";
49      private static final String ACCOUNT_REVIEW = "Account";
50      private static final String ORG_REVIEW = "AccountingOrganizationHierarchy";
51  
52      protected static DocumentService documentService = null;
53  
54      @Override
55      protected void setUp() throws Exception {
56          documentService = SpringContext.getBean(DocumentService.class);
57      }
58  
59      /**
60       * TODO: Remove once other tests are fixed
61       */
62      public void testNothing() {
63  
64      }
65  
66      /*
67       * Requisition
68      * PO
69      * Amend PO
70      * PREQ
71      * CM
72      * Close PO
73       */
74      @ConfigureContext(session = parke, shouldCommitTransactions = true)
75      public final void PATCHFIX_testFullProcess() throws Exception {
76          // 1. use the ACM document to create the REQ and PO
77          ContractManagerAssignmentDocumentTest acmDocTest = new ContractManagerAssignmentDocumentTest();
78          String reqNumber = acmDocTest.testRouteDocument2();
79          RequisitionDocument reqDoc = (RequisitionDocument) documentService.getByDocumentHeaderId(reqNumber);
80          String poNumber = reqDoc.getRelatedViews().getRelatedPurchaseOrderViews().get(0).getDocumentNumber();
81          PurchaseOrderDocument poDoc = (PurchaseOrderDocument) documentService.getByDocumentHeaderId(poNumber);
82          poDoc.setReceivingDocumentRequiredIndicator(false);
83          // approve the PO
84          poDoc.setPurchaseOrderVendorChoiceCode("LPRC");
85          // submit then approve the PO
86          documentService.routeDocument(poDoc, "Test routing as parke", null);
87  
88          poDoc = (PurchaseOrderDocument) documentService.getByDocumentHeaderId(poNumber);
89  
90          // 3 use the PO number to create a Payment Request and have it go final
91          PaymentRequestDocument preqDoc = routePREQDocumentToFinal(poDoc);
92  
93          // 4. use the PO number to create a Credit Memo and have it go final
94          changeCurrentUser(appleton);
95          CreditMemoDocumentTest cmDocTest = new CreditMemoDocumentTest();
96          VendorCreditMemoDocument cmDoc = cmDocTest.routeDocument(preqDoc);
97  
98          // 2. based on the PO document number, create the Amend PO doc and let it go final (with philips?)
99          changeCurrentUser(parke);
100         PurchaseOrderAmendmentDocument amendDoc = (PurchaseOrderAmendmentDocument) SpringContext.getBean(PurchaseOrderService.class).createAndSavePotentialChangeDocument(poNumber, PurchaseOrderDocTypes.PURCHASE_ORDER_AMENDMENT_DOCUMENT, PurchaseOrderStatuses.APPDOC_AMENDMENT);
101         documentService.routeDocument(amendDoc, "Test routing as parke", null);
102         WorkflowTestUtils.waitForDocumentApproval(amendDoc.getDocumentNumber());
103 
104         // 5. use the PO number to create a Close PO and have it go final
105         changeCurrentUser(parke);
106         PurchaseOrderCloseDocument closeDoc = (PurchaseOrderCloseDocument) SpringContext.getBean(PurchaseOrderService.class).createAndSavePotentialChangeDocument(poNumber, PurchaseOrderDocTypes.PURCHASE_ORDER_CLOSE_DOCUMENT, PurchaseOrderStatuses.APPDOC_PENDING_CLOSE);
107         documentService.routeDocument(closeDoc, "Test routing as parke", null);
108         WorkflowTestUtils.waitForDocumentApproval(closeDoc.getDocumentNumber());
109 
110         LOG.info("Requisition document: " + reqDoc.getDocumentNumber());
111         LOG.info("PO document: " + poDoc.getDocumentNumber());
112         LOG.info("PREQ document: " + preqDoc.getDocumentNumber());
113         LOG.info("CM document: " + cmDoc.getDocumentNumber());
114         LOG.info("Amend PO document: " + amendDoc.getDocumentNumber());
115         LOG.info("Close PO document: " + closeDoc.getDocumentNumber());
116     }
117 
118 
119 
120     @ConfigureContext(session = appleton, shouldCommitTransactions=true)
121     public final PaymentRequestDocument routePREQDocumentToFinal(PurchaseOrderDocument POdoc) throws Exception {
122 //        purchaseOrderDocument = createPurchaseOrderDocument(PurchaseOrderDocumentFixture.PO_APPROVAL_REQUIRED, true);
123         PaymentRequestDocumentTest preqDocTest = new PaymentRequestDocumentTest();
124         PaymentRequestDocument paymentRequestDocument = preqDocTest.createPaymentRequestDocument(PaymentRequestDocumentFixture.PREQ_APPROVAL_REQUIRED,
125                 POdoc, true, new KualiDecimal[] {new KualiDecimal(100)});
126 
127         final String docId = paymentRequestDocument.getDocumentNumber();
128         AccountingDocumentTestUtils.routeDocument(paymentRequestDocument, documentService);
129         /*WorkflowTestUtils.waitForNodeChange(paymentRequestDocument.getDocumentHeader().getWorkflowDocument(), SUB_ACCOUNT_REVIEW);
130 
131         // the document should now be routed to vputman as Fiscal Officer
132         changeCurrentUser(stroud);
133         paymentRequestDocument = (PaymentRequestDocument) documentService.getByDocumentHeaderId(docId);
134         assertTrue("At incorrect node.", WorkflowTestUtils.isAtNode(paymentRequestDocument, SUB_ACCOUNT_REVIEW));
135         assertTrue("Document should be enroute.", paymentRequestDocument.getDocumentHeader().getWorkflowDocument().isEnroute());
136         assertTrue("stroud should have an approve request.", paymentRequestDocument.getDocumentHeader().getWorkflowDocument().isApprovalRequested());
137         documentService.approveDocument(paymentRequestDocument, "Test approving as stroud", null); */
138         WorkflowTestUtils.waitForNodeChange(paymentRequestDocument.getDocumentHeader().getWorkflowDocument(), ACCOUNT_REVIEW);
139         changeCurrentUser(ferland);
140         paymentRequestDocument = (PaymentRequestDocument) documentService.getByDocumentHeaderId(docId);
141         assertTrue("At incorrect node.", WorkflowTestUtils.isAtNode(paymentRequestDocument,
142                 ACCOUNT_REVIEW));
143         assertTrue("Document should be enroute.", paymentRequestDocument.getDocumentHeader().getWorkflowDocument().isEnroute());
144         assertTrue("ferland should have an approve request.", paymentRequestDocument.getDocumentHeader().getWorkflowDocument().isApprovalRequested());
145         documentService.approveDocument(paymentRequestDocument, "Test approving as ferland", null);
146 
147         WorkflowTestUtils.waitForDocumentApproval(paymentRequestDocument.getDocumentNumber());
148 
149         paymentRequestDocument = (PaymentRequestDocument) documentService.getByDocumentHeaderId(docId);
150         assertTrue("Document should now be final.", paymentRequestDocument.getDocumentHeader().getWorkflowDocument().isFinal());
151         return paymentRequestDocument;
152     }
153 
154     private UserNameFixture getInitialUserName() {
155         return khuntley;
156     }
157 
158     protected UserNameFixture getTestUserName() {
159         return khuntley;
160     }
161 }
162