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.chart.globals;
017:
018: import static org.kuali.test.fixtures.UserNameFixture.KHUNTLEY;
019:
020: import java.util.ArrayList;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026: import org.kuali.core.bo.PersistableBusinessObject;
027: import org.kuali.core.document.MaintenanceDocument;
028: import org.kuali.core.maintenance.Maintainable;
029: import org.kuali.core.service.DocumentService;
030: import org.kuali.core.util.DateUtils;
031: import org.kuali.core.util.KualiDecimal;
032: import org.kuali.kfs.context.KualiTestBase;
033: import org.kuali.kfs.context.SpringContext;
034: import org.kuali.module.chart.bo.AccountGlobal;
035: import org.kuali.module.chart.bo.AccountGlobalDetail;
036: import org.kuali.module.chart.bo.DelegateGlobal;
037: import org.kuali.module.chart.bo.DelegateGlobalDetail;
038: import org.kuali.test.ConfigureContext;
039: import org.kuali.test.suite.AnnotationTestSuite;
040: import org.kuali.test.suite.CrossSectionSuite;
041:
042: @SuppressWarnings("deprecation")
043: @ConfigureContext(session=KHUNTLEY)
044: public class GlobalDocumentTest extends KualiTestBase {
045:
046: private static final Log LOG = LogFactory
047: .getLog(GlobalDocumentTest.class);
048:
049: private static final String KNOWN_DOCUMENT_TYPENAME = "DelegateGlobalMaintenanceDocument";
050: private static final String GLOBAL_DELEGATE_TYPENAME = "DelegateGlobalMaintenanceDocument";
051: private static final String GLOBAL_ACCOUNT_TYPENAME = "AccountGlobalMaintenanceDocument";
052:
053: public void testGlobalDelegateMaintenanceDocumentCreation_goodDocTypeName()
054: throws Exception {
055: MaintenanceDocument doc = (MaintenanceDocument) SpringContext
056: .getBean(DocumentService.class).getNewDocument(
057: KNOWN_DOCUMENT_TYPENAME);
058: assertNotNull(doc);
059: assertNotNull(doc.getNewMaintainableObject());
060: assertEquals("org.kuali.module.chart.bo.DelegateGlobal", doc
061: .getNewMaintainableObject().getBoClass().getName());
062: }
063:
064: public final void testGetNewDocument_globalDelegateMaintDoc()
065: throws Exception {
066:
067: MaintenanceDocument document = (MaintenanceDocument) SpringContext
068: .getBean(DocumentService.class).getNewDocument(
069: GLOBAL_DELEGATE_TYPENAME);
070:
071: // make sure the doc is setup
072: assertNotNull(document);
073: assertNotNull(document.getDocumentHeader());
074: assertNotNull(document.getDocumentHeader().getDocumentNumber());
075:
076: assertEquals("Global document should always appear as a New.",
077: true, document.isNew());
078: assertEquals("Global document should never appear as an edit.",
079: false, document.isEdit());
080:
081: Maintainable newMaintainable = document
082: .getNewMaintainableObject();
083: assertNotNull("New Maintainable should never be null.",
084: newMaintainable);
085: assertEquals("BO Class should be DelegateGlobal.",
086: DelegateGlobal.class, newMaintainable.getBoClass());
087:
088: PersistableBusinessObject newBo = newMaintainable
089: .getBusinessObject();
090: assertNotNull("New BO should never be null.", newBo);
091: assertEquals("New BO should be of the correct class.",
092: DelegateGlobal.class, newBo.getClass());
093:
094: }
095:
096: public final void testGetNewDocument_globalAccountMaintDoc()
097: throws Exception {
098:
099: MaintenanceDocument document = (MaintenanceDocument) SpringContext
100: .getBean(DocumentService.class).getNewDocument(
101: GLOBAL_ACCOUNT_TYPENAME);
102:
103: // make sure the doc is setup
104: assertNotNull(document);
105: assertNotNull(document.getDocumentHeader());
106: assertNotNull(document.getDocumentHeader().getDocumentNumber());
107:
108: assertEquals("Global document should always appear as a New.",
109: true, document.isNew());
110: assertEquals("Global document should never appear as an edit.",
111: false, document.isEdit());
112:
113: Maintainable newMaintainable = document
114: .getNewMaintainableObject();
115: assertNotNull("New Maintainable should never be null.",
116: newMaintainable);
117: assertEquals("BO Class should be AccountGlobal.",
118: AccountGlobal.class, newMaintainable.getBoClass());
119:
120: PersistableBusinessObject newBo = newMaintainable
121: .getBusinessObject();
122: assertNotNull("New BO should never be null.", newBo);
123: assertEquals("New BO should be of the correct class.",
124: AccountGlobal.class, newBo.getClass());
125: }
126:
127: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
128: public final void testSaveDocument_globalDelegate()
129: throws Exception {
130:
131: MaintenanceDocument document = (MaintenanceDocument) SpringContext
132: .getBean(DocumentService.class).getNewDocument(
133: GLOBAL_DELEGATE_TYPENAME);
134:
135: // get local references to the Maintainable and the BO
136: Maintainable newMaintainable = document
137: .getNewMaintainableObject();
138: DelegateGlobal bo = (DelegateGlobal) newMaintainable
139: .getBusinessObject();
140: String finDocNumber = document.getDocumentNumber();
141: document.getDocumentHeader().setFinancialDocumentDescription(
142: "blah");
143:
144: System.err.println("DOC_NBR = " + finDocNumber);
145:
146: List<DelegateGlobalDetail> changes = new ArrayList();
147:
148: DelegateGlobalDetail change = new DelegateGlobalDetail();
149: change.setAccountDelegatePrimaryRoutingIndicator(false);
150: change.setAccountDelegateStartDate(DateUtils
151: .newDate(2006, 6, 1));
152: change.setAccountDelegateUniversalId("6137600107");
153: change.setApprovalFromThisAmount(new KualiDecimal(0));
154: change.setApprovalToThisAmount(new KualiDecimal(0));
155: change.setFinancialDocumentTypeCode("ALL");
156: changes.add(change);
157:
158: bo.setDelegateGlobals(changes);
159:
160: AccountGlobalDetail account;
161:
162: account = new AccountGlobalDetail();
163: account.setDocumentNumber(finDocNumber);
164: account.setChartOfAccountsCode("BL");
165: account.setAccountNumber("1031400");
166: bo.addAccount(account);
167:
168: account = new AccountGlobalDetail();
169: account.setDocumentNumber(finDocNumber);
170: account.setChartOfAccountsCode("BL");
171: account.setAccountNumber("1031420");
172: bo.addAccount(account);
173:
174: account = new AccountGlobalDetail();
175: account.setDocumentNumber(finDocNumber);
176: account.setChartOfAccountsCode("BL");
177: account.setAccountNumber("1031467");
178: bo.addAccount(account);
179: SpringContext.getBean(DocumentService.class).saveDocument(
180: document);
181:
182: // now that it worked, lets cancel the doc so it doesnt lock for others
183: SpringContext.getBean(DocumentService.class).cancelDocument(
184: document, "cancelling test document");
185:
186: }
187:
188: @AnnotationTestSuite(CrossSectionSuite.class)
189: @ConfigureContext(session=KHUNTLEY,shouldCommitTransactions=true)
190: public final void testSaveAndLoadDocument_globalDelegate()
191: throws Exception {
192:
193: MaintenanceDocument document = (MaintenanceDocument) SpringContext
194: .getBean(DocumentService.class).getNewDocument(
195: GLOBAL_DELEGATE_TYPENAME);
196:
197: // get local references to the Maintainable and the BO
198: Maintainable newMaintainable = document
199: .getNewMaintainableObject();
200: DelegateGlobal bo = (DelegateGlobal) newMaintainable
201: .getBusinessObject();
202: String finDocNumber = document.getDocumentNumber();
203: document.getDocumentHeader().setFinancialDocumentDescription(
204: "blah");
205:
206: List<DelegateGlobalDetail> changes = new ArrayList();
207:
208: DelegateGlobalDetail change = new DelegateGlobalDetail();
209: change.setAccountDelegatePrimaryRoutingIndicator(false);
210: change.setAccountDelegateStartDate(DateUtils
211: .newDate(2006, 6, 1));
212: change.setAccountDelegateUniversalId("6137600107");
213: change.setApprovalFromThisAmount(new KualiDecimal(0));
214: change.setApprovalToThisAmount(new KualiDecimal(0));
215: change.setFinancialDocumentTypeCode("ALL");
216: changes.add(change);
217: bo.setDelegateGlobals(changes);
218:
219: AccountGlobalDetail account;
220:
221: account = new AccountGlobalDetail();
222: account.setDocumentNumber(finDocNumber);
223: account.setChartOfAccountsCode("BL");
224: account.setAccountNumber("1031400");
225: bo.addAccount(account);
226:
227: account = new AccountGlobalDetail();
228: account.setDocumentNumber(finDocNumber);
229: account.setChartOfAccountsCode("BL");
230: account.setAccountNumber("1031420");
231: bo.addAccount(account);
232:
233: account = new AccountGlobalDetail();
234: account.setDocumentNumber(finDocNumber);
235: account.setChartOfAccountsCode("BL");
236: account.setAccountNumber("1031467");
237: bo.addAccount(account);
238:
239: SpringContext.getBean(DocumentService.class).saveDocument(
240: document);
241:
242: // clear the document, and re-load it from the DB
243: document = null;
244: document = (MaintenanceDocument) SpringContext.getBean(
245: DocumentService.class).getByDocumentHeaderId(
246: finDocNumber);
247: assertNotNull(
248: "Document should not be null after loaded from the DB.",
249: document);
250: assertNotNull(
251: "Document Header should not be null after loaded from the DB.",
252: document.getDocumentHeader());
253: assertNotNull(
254: "Document FinDocNumber should not be null after loaded from the DB.",
255: document.getDocumentHeader().getDocumentNumber());
256:
257: // document should show up as a 'New' document
258: assertEquals("Global document should always appear as a New.",
259: true, document.isNew());
260: assertEquals("Global document should never appear as an edit.",
261: false, document.isEdit());
262:
263: // Maintainable should be populated and contain the right class
264: newMaintainable = document.getNewMaintainableObject();
265: assertNotNull("New Maintainable should never be null.",
266: newMaintainable);
267: assertEquals("BO Class should be DelegateGlobal.",
268: DelegateGlobal.class, newMaintainable.getBoClass());
269:
270: // BO should be non-null and the right class
271: bo = (DelegateGlobal) newMaintainable.getBusinessObject();
272: assertNotNull("New BO should never be null.", bo);
273: assertEquals("New BO should be of the correct class.",
274: DelegateGlobal.class, bo.getClass());
275:
276: // List should contain 3 elements
277: assertNotNull("AccountDetail list should not be null.", bo
278: .getAccountGlobalDetails());
279: List accounts = bo.getAccountGlobalDetails();
280: assertEquals("AccountDetail list should not be empty.", false,
281: accounts.isEmpty());
282: assertEquals("AccountDetail list should contain 3 elements.",
283: 3, accounts.size());
284:
285: // make sure all the accounts are non-null and at least have the Chart populated
286: for (Iterator iter = accounts.iterator(); iter.hasNext();) {
287: AccountGlobalDetail accountDetail = (AccountGlobalDetail) iter
288: .next();
289:
290: assertNotNull("AccountDetailChange should not be null.",
291: accountDetail);
292: assertNotNull("ChartOfAccountsCode", accountDetail
293: .getChartOfAccountsCode());
294: assertEquals("Account Chart should be known.", "BL",
295: accountDetail.getChartOfAccountsCode());
296: }
297:
298: // now that it worked, lets cancel the doc so it doesnt lock for others
299: SpringContext.getBean(DocumentService.class).cancelDocument(
300: document, "cancelling test document");
301:
302: }
303: }
|