1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.kuali.kfs.module.cam.document.service;
20
21 import java.util.List;
22
23 import org.kuali.kfs.module.cam.CamsConstants;
24 import org.kuali.kfs.module.cam.businessobject.Asset;
25 import org.kuali.kfs.module.cam.businessobject.AssetPayment;
26 import org.kuali.kfs.module.cam.businessobject.AssetRetirementGlobal;
27 import org.kuali.kfs.module.cam.businessobject.AssetRetirementGlobalDetail;
28 import org.kuali.kfs.module.cam.document.gl.AssetRetirementGeneralLedgerPendingEntrySource;
29 import org.kuali.kfs.module.cam.fixture.AssetRetirementGlobalMaintainableFixture;
30 import org.kuali.kfs.sys.ConfigureContext;
31 import org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader;
32 import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySourceDetail;
33 import org.kuali.kfs.sys.context.KualiTestBase;
34 import org.kuali.kfs.sys.context.SpringContext;
35 import org.kuali.kfs.sys.fixture.UserNameFixture;
36 import org.kuali.kfs.sys.service.UniversityDateService;
37 import org.kuali.rice.core.api.util.type.KualiDecimal;
38 import org.kuali.rice.kns.document.MaintenanceDocument;
39 import org.kuali.rice.krad.service.DocumentService;
40
41 public class AssetRetirementServiceTest extends KualiTestBase {
42 private AssetRetirementService assetRetirementService;
43 private UniversityDateService universityDateService;
44
45 @Override
46 @ConfigureContext(session = UserNameFixture.bomiddle, shouldCommitTransactions = false)
47 protected void setUp() throws Exception {
48 super.setUp();
49 assetRetirementService = SpringContext.getBean(AssetRetirementService.class);
50 universityDateService = SpringContext.getBean(UniversityDateService.class);
51 }
52
53
54
55
56
57
58
59 @ConfigureContext(session = UserNameFixture.bomiddle, shouldCommitTransactions = false)
60 public void testCreateGLPostables_Success() throws Exception {
61 MaintenanceDocument document = (MaintenanceDocument) SpringContext.getBean(DocumentService.class).getNewDocument(CamsConstants.DocumentTypeName.ASSET_RETIREMENT_GLOBAL);
62 AssetRetirementGlobal assetRetirementGlobal = AssetRetirementGlobalMaintainableFixture.RETIREMENT1.newAssetRetirement();
63
64 AssetRetirementGeneralLedgerPendingEntrySource assetRetirementGlPoster = new AssetRetirementGeneralLedgerPendingEntrySource((FinancialSystemDocumentHeader) document.getDocumentHeader());
65 assetRetirementService.createGLPostables(assetRetirementGlobal, assetRetirementGlPoster);
66 List<GeneralLedgerPendingEntrySourceDetail> postables = assetRetirementGlPoster.getPostables();
67
68 assertFalse(postables.isEmpty());
69 assertEquals(10, postables.size());
70
71 int i = 0;
72 for (AssetRetirementGlobalDetail detail : assetRetirementGlobal.getAssetRetirementGlobalDetails()) {
73 Asset asset = detail.getAsset();
74
75 AssetPayment payment1 = asset.getAssetPayments().get(0);
76 assertGLPostable(postables.get(i++), asset.getOrganizationOwnerChartOfAccountsCode(), payment1.getAccountChargeAmount(), "9520004", "Asset retirement cost reversal entry", "8610");
77 assertGLPostable(postables.get(i++), asset.getOrganizationOwnerChartOfAccountsCode(), payment1.getAccumulatedPrimaryDepreciationAmount(), "9520004", "Asset retirement depreciation reversal", "8910");
78 assertGLPostable(postables.get(i++), asset.getOrganizationOwnerChartOfAccountsCode(), payment1.getAccountChargeAmount().subtract(payment1.getAccumulatedPrimaryDepreciationAmount()), "9520004", "Asset retirement fund balance adjustment", "4998");
79
80 AssetPayment payment2 = asset.getAssetPayments().get(1);
81 assertGLPostable(postables.get(i++), asset.getOrganizationOwnerChartOfAccountsCode(), payment2.getAccountChargeAmount(), "9520004", "Asset retirement cost reversal entry", "8610");
82 assertGLPostable(postables.get(i++), asset.getOrganizationOwnerChartOfAccountsCode(), payment2.getAccumulatedPrimaryDepreciationAmount(), "9520004", "Asset retirement depreciation reversal", "8910");
83 }
84 }
85
86
87
88
89
90
91
92
93
94
95
96 private void assertGLPostable(GeneralLedgerPendingEntrySourceDetail glPostable, String chartOfAccountsCode, KualiDecimal amount, String plantAccount, String financialLineDesc, String financialObjectCode) {
97 assertEquals(plantAccount, glPostable.getAccountNumber());
98 assertEquals(amount, glPostable.getAmount());
99 assertEquals(CamsConstants.Postable.GL_BALANCE_TYPE_CODE_AC, glPostable.getBalanceTypeCode());
100 assertEquals(chartOfAccountsCode, glPostable.getChartOfAccountsCode());
101 assertEquals(financialLineDesc, glPostable.getFinancialDocumentLineDescription());
102 assertEquals(financialObjectCode, glPostable.getFinancialObjectCode());
103 assertEquals(this.universityDateService.getCurrentFiscalYear(), glPostable.getPostingYear());
104 assertNull(glPostable.getOrganizationReferenceId());
105 assertNull(glPostable.getProjectCode());
106 assertNull(glPostable.getReferenceNumber());
107 assertNull(glPostable.getReferenceOriginCode());
108 assertNull(glPostable.getReferenceTypeCode());
109 }
110 }
111