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.core.service.impl;
017:
018: import static org.kuali.test.fixtures.AccountingLineFixture.LINE;
019: import static org.kuali.test.util.KualiTestAssertionUtils.assertNotNullHandlingOjbProxies;
020:
021: import java.util.Map;
022:
023: import org.kuali.core.bo.DocumentType;
024: import org.kuali.core.bo.PersistableBusinessObject;
025: import org.kuali.core.service.PersistenceStructureService;
026: import org.kuali.core.util.ForeignKeyFieldsPopulationState;
027: import org.kuali.core.util.KualiDecimal;
028: import org.kuali.core.util.ObjectUtils;
029: import org.kuali.kfs.bo.AccountingLine;
030: import org.kuali.kfs.context.KualiTestBase;
031: import org.kuali.kfs.context.SpringContext;
032: import org.kuali.module.chart.bo.A21SubAccount;
033: import org.kuali.module.chart.bo.Account;
034: import org.kuali.module.chart.bo.AccountDescription;
035: import org.kuali.module.chart.bo.AccountGuideline;
036: import org.kuali.module.chart.bo.DelegateGlobalDetail;
037: import org.kuali.module.chart.bo.ProjectCode;
038: import org.kuali.module.chart.bo.SubAccount;
039: import org.kuali.test.ConfigureContext;
040:
041: /**
042: * This class tests that the PersistenceServices functionality works as intended and as expected.
043: */
044: @ConfigureContext
045: public class PersistenceServiceImplTest extends KualiTestBase {
046:
047: private static final String ORIGINAL_PROJECT_NAME = "TEST";
048: private static final String NEW_PROJECT_NAME = "wet";
049:
050: /**
051: * This method tests what happens when you call refresh/retrieveNonKeyFields on an object that has the primitive FKs set in the
052: * parent object, and null reference objects.
053: */
054: @SuppressWarnings("deprecation")
055: public final void testRetrieveNonKeyFields_fkButNullReferences()
056: throws Exception {
057:
058: AccountingLine accountingLine = LINE
059: .createSourceAccountingLine();
060: accountingLine.setChart(null);
061: accountingLine.setAccount(null);
062: accountingLine.setObjectCode(null);
063: accountingLine.setSubAccount(null);
064: accountingLine.setSubObjectCode(null);
065: accountingLine.setProject(null);
066:
067: // prove that all the reference objects that should be null are null
068: assertNull("Chart object should be null.", accountingLine
069: .getChart());
070: assertNull("Account object should be null.", accountingLine
071: .getAccount());
072: assertNull("ObjectCode object should be null.", accountingLine
073: .getObjectCode());
074: assertNull("SubAccount object should be null.", accountingLine
075: .getSubAccount());
076: assertNull("SubObjectCode object should be null.",
077: accountingLine.getSubObjectCode());
078: assertNull("Project object should be null.", accountingLine
079: .getProject());
080:
081: // this should populate the sub objects
082: accountingLine.refresh();
083:
084: // now these reference objects should NOT be null. This is assuming that the
085: // fk values used are actually in the DB, so there's a problematic dependency there
086: // still.
087: assertNotNullHandlingOjbProxies(
088: "Chart object should not be null.", accountingLine
089: .getChart());
090: assertNotNullHandlingOjbProxies(
091: "Account object should not be null.", accountingLine
092: .getAccount());
093: assertNotNullHandlingOjbProxies(
094: "ObjectCode object should not be null.", accountingLine
095: .getObjectCode());
096: assertNotNullHandlingOjbProxies(
097: "SubAccount object should not be null.", accountingLine
098: .getSubAccount());
099: assertNotNullHandlingOjbProxies(
100: "SubObjectCode object should not be null.",
101: accountingLine.getSubObjectCode());
102: assertNotNullHandlingOjbProxies(
103: "Project object should not be null.", accountingLine
104: .getProject());
105:
106: }
107:
108: /**
109: * This method tests what happens when you call refresh/retrieveNonKeyFields on an object that has the primitive FKs set in the
110: * parent object, and the references objects have different PKs, and empty on all the other fields. If this works, it shows that
111: * when running refresh with non-matching/different primitives and references, the primitives win.
112: */
113: public final void testRetrieveNonKeyFields_fkDiffersFromReference()
114: throws Exception {
115:
116: AccountingLine accountingLine = LINE
117: .createSourceAccountingLine();
118: String NEW_PROJECT = "KUL9";
119:
120: // this should populate the sub objects
121: accountingLine.refresh();
122: assertEquals("original project name", ORIGINAL_PROJECT_NAME,
123: accountingLine.getProject().getName());
124: ProjectCode originalReference = accountingLine.getProject();
125:
126: // change the FK to something different
127: accountingLine.setProjectCode(NEW_PROJECT);
128: accountingLine.refresh();
129: assertNotSame(originalReference, accountingLine.getProject());
130:
131: // the Project object reference should now match the new primitive FK that was set
132: assertNotNullHandlingOjbProxies(
133: "New Project object should not be null", accountingLine
134: .getProject());
135: assertEquals(
136: "The reference object project code and the parent primitive object code should be the same.",
137: NEW_PROJECT, accountingLine.getProject().getCode());
138: assertEquals("new project name", NEW_PROJECT_NAME,
139: accountingLine.getProject().getName());
140: }
141:
142: /**
143: * This method tests what happens when you change one of the keys on a multi-part foreign key reference. For example (and the
144: * test being done), SubAccount is keyed on Chart, AccountNumber and SubAccountNumber. In this test, we change one of those
145: * foreign key parts (SubAccountNumber) such that the resulting multi-part foreign key no longer matches any SubAccount in the
146: * database. This then attempts to show that the reference object becomes nullified, but the primitives in the parent objects
147: * are not modified by the refresh method.
148: */
149: public final void testRetrieveNonKeyFields_brokenMultiPartKeysReferences()
150: throws Exception {
151:
152: AccountingLine accountingLine = LINE
153: .createSourceAccountingLine();
154: String NEW_SUBACCOUNT = "ARREC";
155:
156: // this should populate the sub objects
157: accountingLine.refresh();
158:
159: // change the primitives to something different. this is a broken subaccount pk, since
160: // the chart and subaccount number dont match
161: accountingLine.setSubAccountNumber(NEW_SUBACCOUNT);
162: accountingLine.refresh();
163:
164: // the Project object cannot match the new primitive set
165: assertTrue("New SubAccount should be null", ObjectUtils
166: .isNull(accountingLine.getSubAccount()));
167: assertEquals("New SubAccountNumber should not be changed.",
168: accountingLine.getSubAccountNumber(), NEW_SUBACCOUNT);
169: }
170:
171: /**
172: * Tests that refresh/retrieveNonKeyFields updates foreign key references, but not other non-key fields (often called
173: * "primitives", altho AccountingLine actually has no primitives, only Java (not database) references such as String and
174: * KualiDecimal).
175: */
176: public final void testRetrieveNonKeyFields_fkAndNonkeyChanged()
177: throws Exception {
178:
179: AccountingLine accountingLine = LINE
180: .createSourceAccountingLine();
181: String NEW_PROJECT = "KUL9";
182: KualiDecimal ORIGINAL_AMOUNT = accountingLine.getAmount();
183: KualiDecimal NEW_AMOUNT = new KualiDecimal(ORIGINAL_AMOUNT
184: .doubleValue() + 42.0);
185:
186: assertEquals("amount before first refresh", ORIGINAL_AMOUNT
187: .doubleValue(), accountingLine.getAmount()
188: .doubleValue(), 0.001);
189:
190: // this should populate the references
191: accountingLine.refresh();
192: assertEquals("original project name", ORIGINAL_PROJECT_NAME,
193: accountingLine.getProject().getName());
194: assertEquals("amount after first refresh", ORIGINAL_AMOUNT
195: .doubleValue(), accountingLine.getAmount()
196: .doubleValue(), 0.001);
197:
198: // change an FK and primitive to something different.
199: accountingLine.setProjectCode(NEW_PROJECT);
200: accountingLine.setAmount(NEW_AMOUNT);
201: accountingLine.refresh();
202:
203: assertEquals(
204: "The reference object project code and the parent primitive object code should be the same.",
205: NEW_PROJECT, accountingLine.getProject().getCode());
206: assertEquals("new project name", NEW_PROJECT_NAME,
207: accountingLine.getProject().getName());
208: assertEquals("amount after second refresh", NEW_AMOUNT
209: .doubleValue(), accountingLine.getAmount()
210: .doubleValue(), 0.001);
211: }
212:
213: /**
214: * Tests that refresh/retrieveNonKeyFields ignores PKs. We should not change primary keys.
215: */
216: public final void testRetrieveNonKeyFields_pkChanged()
217: throws Exception {
218: AccountingLine accountingLine = LINE
219: .createSourceAccountingLine();
220: String NEW_PROJECT_CODE = "KUL9";
221:
222: // get a project from OJB
223: accountingLine.refresh();
224: ProjectCode originalReference = accountingLine.getProject();
225: assertEquals("original project name", ORIGINAL_PROJECT_NAME,
226: originalReference.getName());
227: assertEquals("original project code", LINE.projectCode,
228: originalReference.getCode());
229: assertEquals("original project name", ORIGINAL_PROJECT_NAME,
230: accountingLine.getProject().getName());
231: assertSame("no proxy substitution", originalReference,
232: accountingLine.getProject());
233:
234: // change the PK
235: originalReference.setCode(NEW_PROJECT_CODE);
236: assertEquals("new project code", NEW_PROJECT_CODE,
237: originalReference.getCode());
238: assertEquals("still original project name",
239: ORIGINAL_PROJECT_NAME, originalReference.getName());
240: originalReference.refresh();
241: assertEquals("still original project name",
242: ORIGINAL_PROJECT_NAME, originalReference.getName());
243: assertEquals("still new project code", NEW_PROJECT_CODE,
244: originalReference.getCode());
245: }
246:
247: private static final String CHART = "UA";
248: private static final String ACCOUNT = "1912201";
249: private static final String ORG = "KUL";
250: private static final String ACCT_TYPE = "AI";
251: private static final String CAMPUS = "BL";
252: private static final String STATE = "IN";
253: private static final String SUB_FUND_GROUP = "ENDOW";
254: private static final String HIGHER_ED_FUNC_CODE = "AUX";
255: private static final String RESTRICTED_STATUS_CODE = "U";
256: private static final String FISCAL_OFFICER = "6162502038";
257: private static final String SUPERVISOR = "6162502038";
258: private static final String MANAGER = "6162502038";
259: private static final String ZIP_CODE = "47405-3085";
260: private static final String PURPOSE = "This is my purpose.";
261: private static final String EXPENSE_GUIDELINE = "Expense Guidelines";
262: private static final String INCOME_GUIDELINE = "Income Guidelines";
263: private static final String BUILDING = "PO";
264: private static final String REPORTCD_CHART = "UA";
265: private static final String REPORTCD_ORG = "VPIT";
266: private static final String REPORTCD_CD = "ABNOC";
267:
268: @SuppressWarnings("deprecation")
269: public final void testRefreshAllNonUpdatingReferences_Account() {
270:
271: Account account = new Account();
272:
273: // setup a bunch of reference primitives
274: account.setChartOfAccountsCode(CHART);
275: account.setAccountNumber(ACCOUNT);
276: account.setOrganizationCode(ORG);
277: account.setAccountTypeCode(ACCT_TYPE);
278: account.setAccountPhysicalCampusCode(CAMPUS);
279: account.setAccountStateCode(STATE);
280: account.setSubFundGroupCode(SUB_FUND_GROUP);
281: account.setFinancialHigherEdFunctionCd(HIGHER_ED_FUNC_CODE);
282: account.setAccountRestrictedStatusCode(RESTRICTED_STATUS_CODE);
283: account.setAccountFiscalOfficerSystemIdentifier(FISCAL_OFFICER);
284: account.setAccountsSupervisorySystemsIdentifier(SUPERVISOR);
285: account.setAccountManagerSystemIdentifier(MANAGER);
286: account.setAccountZipCode(ZIP_CODE);
287:
288: // create a guideline, and populate some fields
289: AccountGuideline accountGuideline = new AccountGuideline();
290: accountGuideline.setAccountPurposeText(PURPOSE);
291: accountGuideline
292: .setAccountExpenseGuidelineText(EXPENSE_GUIDELINE);
293: accountGuideline
294: .setAccountIncomeGuidelineText(INCOME_GUIDELINE);
295: account.setAccountGuideline(accountGuideline);
296:
297: // create a description, and populate some fields
298: AccountDescription accountDescription = new AccountDescription();
299: accountDescription.setBuildingCode(BUILDING);
300: accountDescription.setCampusCode(CAMPUS);
301: accountDescription.setCampusDescription(PURPOSE);
302: account.setAccountDescription(accountDescription);
303:
304: // prove that all the sub-objects are starting null
305: assertNull("Chart should be null prior to the refresh.",
306: account.getChartOfAccounts());
307: assertNull("Organization should be null prior to the refresh.",
308: account.getOrganization());
309: assertNull("AccountType should be null prior to the refresh.",
310: account.getAccountType());
311: assertNull("Campus should be null prior to the refresh.",
312: account.getAccountPhysicalCampus());
313: assertNull("State should be null prior to the refresh.",
314: account.getAccountState());
315: assertNull("SubFundGroup should be null prior to the refresh.",
316: account.getSubFundGroup());
317: assertNull(
318: "Financial Higher Ed Function Code should be null prior to the refresh.",
319: account.getFinancialHigherEdFunction());
320: assertNull(
321: "RestrictedStatusCode should be null prior to the refresh.",
322: account.getAccountRestrictedStatus());
323: assertEquals(
324: "FiscalOfficer should be null prior to the refresh.",
325: FISCAL_OFFICER, account.getAccountFiscalOfficerUser()
326: .getPersonUniversalIdentifier());
327: assertEquals("Manager should be null prior to the refresh.",
328: MANAGER, account.getAccountManagerUser()
329: .getPersonUniversalIdentifier());
330: assertEquals("Supervisor should be null prior to the refresh.",
331: SUPERVISOR, account.getAccountSupervisoryUser()
332: .getPersonUniversalIdentifier());
333:
334: // prove that the guidelines & description are non-null and populated before the refresh
335: assertNotNull(
336: "AccountGuidelines should not be null prior to the refresh.",
337: account.getAccountGuideline());
338: assertEquals(PURPOSE, account.getAccountGuideline()
339: .getAccountPurposeText());
340: assertEquals(EXPENSE_GUIDELINE, account.getAccountGuideline()
341: .getAccountExpenseGuidelineText());
342: assertEquals(INCOME_GUIDELINE, account.getAccountGuideline()
343: .getAccountIncomeGuidelineText());
344: assertNotNull(
345: "AccountDescription should not be null prior to the refresh.",
346: account.getAccountDescription());
347: assertEquals(BUILDING, account.getAccountDescription()
348: .getBuildingCode());
349: assertEquals(CAMPUS, account.getAccountDescription()
350: .getCampusCode());
351: assertEquals(PURPOSE, account.getAccountDescription()
352: .getCampusDescription());
353:
354: // do the refresh
355: account.refreshNonUpdateableReferences();
356:
357: // prove that all the sub-objects are now populated from the DB
358: assertNotNull("Chart should not be null after the refresh.",
359: account.getChartOfAccounts());
360: assertNotNull(
361: "Organization should not be null after the refresh.",
362: account.getOrganization());
363: assertNotNull(
364: "AccountType should not be null after the refresh.",
365: account.getAccountType());
366: assertNotNull("Campus should not be null after the refresh.",
367: account.getAccountPhysicalCampus());
368: assertNotNull("State should not be null after the refresh.",
369: account.getAccountState());
370: assertNotNull(
371: "SubFundGroup should not be null after the refresh.",
372: account.getSubFundGroup());
373: assertNotNull(
374: "Financial Higher Ed Function Code should not be null after the refresh.",
375: account.getFinancialHigherEdFunction());
376: assertNotNull(
377: "RestrictedStatusCode should not be null after the refresh.",
378: account.getAccountRestrictedStatus());
379: assertEquals(
380: "FiscalOfficer should not be null after the refresh.",
381: FISCAL_OFFICER, account.getAccountFiscalOfficerUser()
382: .getPersonUniversalIdentifier());
383: assertEquals("Manager should not be null after the refresh.",
384: MANAGER, account.getAccountManagerUser()
385: .getPersonUniversalIdentifier());
386: assertEquals(
387: "Supervisor should not be null after the refresh.",
388: SUPERVISOR, account.getAccountSupervisoryUser()
389: .getPersonUniversalIdentifier());
390:
391: // prove that the guidelines & description are unchanged
392: assertNotNull(
393: "AccountGuidelines should not be null prior to the refresh.",
394: account.getAccountGuideline());
395: assertEquals(PURPOSE, account.getAccountGuideline()
396: .getAccountPurposeText());
397: assertEquals(EXPENSE_GUIDELINE, account.getAccountGuideline()
398: .getAccountExpenseGuidelineText());
399: assertEquals(INCOME_GUIDELINE, account.getAccountGuideline()
400: .getAccountIncomeGuidelineText());
401: assertNotNull(
402: "AccountDescription should not be null prior to the refresh.",
403: account.getAccountDescription());
404: assertEquals(BUILDING, account.getAccountDescription()
405: .getBuildingCode());
406: assertEquals(CAMPUS, account.getAccountDescription()
407: .getCampusCode());
408: assertEquals(PURPOSE, account.getAccountDescription()
409: .getCampusDescription());
410:
411: }
412:
413: public final void testRefreshAllNonUpdatingReferences_SubAccount() {
414:
415: SubAccount subAccount = new SubAccount();
416:
417: // setup a bunch of reference primitives
418: subAccount.setChartOfAccountsCode(CHART);
419: subAccount.setAccountNumber(ACCOUNT);
420: subAccount.setFinancialReportChartCode(REPORTCD_CHART);
421: subAccount.setFinReportOrganizationCode(REPORTCD_ORG);
422: subAccount.setFinancialReportingCode(REPORTCD_CD);
423:
424: // create an A21SubAccount, and populate some fields
425: A21SubAccount a21 = new A21SubAccount();
426: a21.setCostShareChartOfAccountCode(CHART);
427: a21.setCostShareSourceAccountNumber(ACCOUNT);
428: subAccount.setA21SubAccount(a21);
429:
430: // prove that all the sub-objects are starting null
431: assertNull("Account should be null prior to the refresh.",
432: subAccount.getAccount());
433: assertNull(
434: "Financial Reporting Code should be null prior to the refresh.",
435: subAccount.getReportingCode());
436:
437: // prove that the guidelines & description are non-null and populated before the refresh
438: assertNotNull(
439: "AccountGuidelines should not be null prior to the refresh.",
440: subAccount.getA21SubAccount());
441: assertEquals(CHART, subAccount.getA21SubAccount()
442: .getCostShareChartOfAccountCode());
443: assertEquals(ACCOUNT, subAccount.getA21SubAccount()
444: .getCostShareSourceAccountNumber());
445:
446: // do the refresh
447: subAccount.refreshNonUpdateableReferences();
448:
449: // prove that all the sub-objects are starting null
450: assertNotNull("Account should not be null after the refresh.",
451: subAccount.getAccount());
452: assertNotNull(
453: "Financial Reporting Code should not be null after the refresh.",
454: subAccount.getReportingCode());
455:
456: // prove that the a21 subaccount is non-null and populated same as before
457: assertNotNull(
458: "AccountGuidelines should not be null prior to the refresh.",
459: subAccount.getA21SubAccount());
460: assertEquals(CHART, subAccount.getA21SubAccount()
461: .getCostShareChartOfAccountCode());
462: assertEquals(ACCOUNT, subAccount.getA21SubAccount()
463: .getCostShareSourceAccountNumber());
464:
465: }
466:
467: public void testGetForeignKeyFieldsPopulationState_NullParams() {
468:
469: boolean exceptionThrown;
470:
471: exceptionThrown = false;
472: try {
473: SpringContext.getBean(PersistenceStructureService.class)
474: .getForeignKeyFieldsPopulationState(null,
475: "attributeName");
476: } catch (RuntimeException e) {
477: exceptionThrown = true;
478: }
479: assertTrue(
480: "A runtimeException should be thrown due to null params.",
481: exceptionThrown);
482:
483: exceptionThrown = false;
484: try {
485: SpringContext.getBean(PersistenceStructureService.class)
486: .getForeignKeyFieldsPopulationState(new Account(),
487: null);
488: } catch (RuntimeException e) {
489: exceptionThrown = true;
490: }
491: assertTrue(
492: "A runtimeException should be thrown due to null params.",
493: exceptionThrown);
494:
495: }
496:
497: public void testGetForeignKeyFieldsPopulationState_Org_NonePopulated() {
498:
499: Account account = new Account();
500:
501: ForeignKeyFieldsPopulationState fkFieldsPop;
502: fkFieldsPop = SpringContext.getBean(
503: PersistenceStructureService.class)
504: .getForeignKeyFieldsPopulationState(account,
505: "organization");
506:
507: assertFalse(
508: "The returned class should indicate no fields filled out.",
509: fkFieldsPop.isAnyFieldsPopulated());
510: assertFalse(
511: "The returned class should indicate all fields not filled out.",
512: fkFieldsPop.isAllFieldsPopulated());
513: assertEquals("All fk fields should be returned.", 2,
514: fkFieldsPop.getUnpopulatedFieldNames().size());
515: assertTrue("fkFieldPop should contain this field.", fkFieldsPop
516: .hasUnpopulatedFieldName("chartOfAccountsCode"));
517: assertTrue("fkFieldPop should contain this field.", fkFieldsPop
518: .hasUnpopulatedFieldName("organizationCode"));
519:
520: }
521:
522: public void testGetForeignKeyFieldsPopulationState_Org_OnePopulated() {
523:
524: Account account = new Account();
525: account.setChartOfAccountsCode("UA");
526:
527: ForeignKeyFieldsPopulationState fkFieldsPop;
528: fkFieldsPop = SpringContext.getBean(
529: PersistenceStructureService.class)
530: .getForeignKeyFieldsPopulationState(account,
531: "organization");
532:
533: assertTrue(
534: "The returned class should indicate some fields filled out.",
535: fkFieldsPop.isAnyFieldsPopulated());
536: assertFalse(
537: "The returned class should indicate all fields not filled out.",
538: fkFieldsPop.isAllFieldsPopulated());
539: assertEquals("Some fk fields should be returned.", 1,
540: fkFieldsPop.getUnpopulatedFieldNames().size());
541: assertFalse("fkFieldPop should not contain this field.",
542: fkFieldsPop
543: .hasUnpopulatedFieldName("chartOfAccountsCode"));
544: assertTrue("fkFieldPop should contain this field.", fkFieldsPop
545: .hasUnpopulatedFieldName("organizationCode"));
546: }
547:
548: public void testGetForeignKeyFieldsPopulationState_Org_AllPopulated() {
549:
550: Account account = new Account();
551: account.setChartOfAccountsCode("UA");
552: account.setOrganizationCode("ACCT");
553:
554: ForeignKeyFieldsPopulationState fkFieldsPop;
555: fkFieldsPop = SpringContext.getBean(
556: PersistenceStructureService.class)
557: .getForeignKeyFieldsPopulationState(account,
558: "organization");
559:
560: assertTrue(
561: "The returned class should indicate some fields filled out.",
562: fkFieldsPop.isAnyFieldsPopulated());
563: assertTrue(
564: "The returned class should indicate all fields filled out.",
565: fkFieldsPop.isAllFieldsPopulated());
566: assertEquals("No fk fields should be returned.", 0, fkFieldsPop
567: .getUnpopulatedFieldNames().size());
568: assertFalse("fkFieldPop should not contain this field.",
569: fkFieldsPop
570: .hasUnpopulatedFieldName("chartOfAccountsCode"));
571: assertFalse("fkFieldPop should not contain this field.",
572: fkFieldsPop.hasUnpopulatedFieldName("organizationCode"));
573: }
574:
575: public void testGetForeignKeyFieldsPopulationState_Chart_NonePopulated() {
576:
577: Account account = new Account();
578:
579: ForeignKeyFieldsPopulationState fkFieldsPop;
580: fkFieldsPop = SpringContext.getBean(
581: PersistenceStructureService.class)
582: .getForeignKeyFieldsPopulationState(account,
583: "chartOfAccounts");
584:
585: assertFalse(
586: "The returned class should indicate no fields filled out.",
587: fkFieldsPop.isAnyFieldsPopulated());
588: assertFalse(
589: "The returned class should indicate all fields not filled out.",
590: fkFieldsPop.isAllFieldsPopulated());
591: assertEquals("One fk fields should be returned.", 1,
592: fkFieldsPop.getUnpopulatedFieldNames().size());
593: assertTrue("fkFieldPop should contain this field.", fkFieldsPop
594: .hasUnpopulatedFieldName("chartOfAccountsCode"));
595: }
596:
597: public void testGetForeignKeyFieldsPopulationState_Chart_AllPopulated() {
598:
599: Account account = new Account();
600: account.setChartOfAccountsCode("UA");
601:
602: ForeignKeyFieldsPopulationState fkFieldsPop;
603: fkFieldsPop = SpringContext.getBean(
604: PersistenceStructureService.class)
605: .getForeignKeyFieldsPopulationState(account,
606: "chartOfAccounts");
607:
608: assertTrue(
609: "The returned class should indicate some fields filled out.",
610: fkFieldsPop.isAnyFieldsPopulated());
611: assertTrue(
612: "The returned class should indicate all fields filled out.",
613: fkFieldsPop.isAllFieldsPopulated());
614: assertEquals("No fk fields should be returned.", 0, fkFieldsPop
615: .getUnpopulatedFieldNames().size());
616: assertFalse("fkFieldPop should not contain this field.",
617: fkFieldsPop
618: .hasUnpopulatedFieldName("chartOfAccountsCode"));
619: }
620:
621: public void testListReferenceObjectFields_IllegalArguments() {
622:
623: boolean errorThrown = false;
624:
625: Map results;
626: try {
627: results = SpringContext.getBean(
628: PersistenceStructureService.class)
629: .listReferenceObjectFields(
630: (PersistableBusinessObject) null);
631: } catch (IllegalArgumentException e) {
632: errorThrown = true;
633: }
634: assertEquals(
635: "An IllegalArgumentException should have been thrown.",
636: true, errorThrown);
637: try {
638: results = SpringContext.getBean(
639: PersistenceStructureService.class)
640: .listReferenceObjectFields(Integer.class);
641: } catch (IllegalArgumentException e) {
642: errorThrown = true;
643: }
644: assertEquals(
645: "An IllegalArgumentException should have been thrown.",
646: true, errorThrown);
647:
648: try {
649: results = SpringContext.getBean(
650: PersistenceStructureService.class)
651: .listReferenceObjectFields((Class) null);
652: } catch (IllegalArgumentException e) {
653: errorThrown = true;
654: }
655: assertEquals(
656: "An IllegalArgumentException should have been thrown.",
657: true, errorThrown);
658:
659: }
660:
661: public void testListReferenceObjectFields_DelegateGlobalDetail() {
662:
663: Map<String, Class> results;
664: results = SpringContext.getBean(
665: PersistenceStructureService.class)
666: .listReferenceObjectFields(DelegateGlobalDetail.class);
667: assertEquals(
668: "DelegateGlobalDetail should have two (1) references.",
669: 1, results.size());
670:
671: Class referenceClass = results.get("documentType");
672: assertNotNull("documentType should be present.", referenceClass);
673: assertEquals("documentType should be a specific class.",
674: DocumentType.class, referenceClass);
675:
676: }
677:
678: }
|