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.gl.service;
017:
018: import org.apache.commons.lang.StringUtils;
019: import org.kuali.core.util.GlobalVariables;
020: import org.kuali.kfs.KFSKeyConstants;
021: import org.kuali.kfs.KFSConstants.SystemGroupParameterNames;
022: import org.kuali.kfs.context.KualiTestBase;
023: import org.kuali.kfs.context.SpringContext;
024: import org.kuali.kfs.service.MockCollectorBatch;
025: import org.kuali.kfs.service.ParameterService;
026: import org.kuali.module.gl.batch.collector.CollectorStep;
027: import org.kuali.module.gl.bo.CollectorDetail;
028: import org.kuali.module.gl.bo.OriginEntryFull;
029: import org.kuali.test.ConfigureContext;
030:
031: // import org.kuali.test.suite.RelatesTo;
032:
033: /**
034: * Test the CollectorService.
035: */
036: @ConfigureContext
037: public class CollectorServiceTest extends KualiTestBase {
038: private ParameterService parameterService;
039: private CollectorHelperService collectorHelperService;
040:
041: /**
042: * Initializes services needed by this test
043: * @see junit.framework.TestCase#setUp()
044: */
045: @Override
046: protected void setUp() throws Exception {
047: super .setUp();
048:
049: parameterService = SpringContext
050: .getBean(ParameterService.class);
051: collectorHelperService = SpringContext
052: .getBean(CollectorHelperService.class);
053: }
054:
055: /**
056: * Verifies system parameters needed to send the collector email exists.
057: */
058: // @RelatesTo(RelatesTo.JiraIssue.KULUT31)
059: public final void testEmailSystemParametersExist() throws Exception {
060: String subject = parameterService
061: .getParameterValue(
062: CollectorStep.class,
063: SystemGroupParameterNames.COLLECTOR_VALIDATOR_EMAIL_SUBJECT_PARAMETER_NAME);
064: assertTrue(
065: "system parameter "
066: + SystemGroupParameterNames.COLLECTOR_VALIDATOR_EMAIL_SUBJECT_PARAMETER_NAME
067: + " is not setup or is empty", StringUtils
068: .isNotBlank(subject));
069:
070: String[] documentTypes = parameterService
071: .getParameterValues(
072: CollectorStep.class,
073: SystemGroupParameterNames.COLLECTOR_EQUAL_DC_TOTAL_DOCUMENT_TYPES)
074: .toArray(new String[] {});
075: assertTrue(
076: "system parameter "
077: + SystemGroupParameterNames.COLLECTOR_EQUAL_DC_TOTAL_DOCUMENT_TYPES
078: + " is not setup or is empty",
079: documentTypes.length > 0);
080: }
081:
082: /**
083: * Verifies an error is added when the batch header is a duplicate (a batch loaded previously had the same header).
084: */
085: // @RelatesTo(RelatesTo.JiraIssue.KULUT31)
086: public final void testPerformValidate_duplicateHeader()
087: throws Exception {
088:
089: }
090:
091: /**
092: * Verifies an error is added when the batch entries contain multiple document types. Note: Actual test values here do not have
093: * to be valid document types, only need to be different.
094: */
095: // @RelatesTo(RelatesTo.JiraIssue.KULUT31)
096: public final void testPerformValidation_mixedDocumentTypes()
097: throws Exception {
098: MockCollectorBatch collectorBatch = new MockCollectorBatch();
099:
100: OriginEntryFull entry1 = new OriginEntryFull();
101: entry1.setFinancialDocumentTypeCode("foo1");
102: collectorBatch.addOriginEntry(entry1);
103:
104: OriginEntryFull entry2 = new OriginEntryFull();
105: entry2.setFinancialDocumentTypeCode("foo2");
106: collectorBatch.addOriginEntry(entry2);
107:
108: boolean isValid = collectorHelperService
109: .performValidation(collectorBatch);
110: assertFalse(
111: "returned batch was valid but there were multiple document types",
112: isValid);
113: assertTrue(
114: "error message for mixed document types does not exist",
115: GlobalVariables.getErrorMap().containsMessageKey(
116: KFSKeyConstants.Collector.MIXED_DOCUMENT_TYPES));
117: }
118:
119: /**
120: * Verifies an error is added when a collector detail key does not have a matching gl entry. Note: Actual test values do have to
121: * be valid, only need to be different from the gl record to the detail
122: */
123: // @RelatesTo(RelatesTo.JiraIssue.KULUT31)
124: public final void testPerformValidation_unmatchedDetailKey()
125: throws Exception {
126: MockCollectorBatch collectorBatch = new MockCollectorBatch();
127:
128: OriginEntryFull entry = new OriginEntryFull();
129: entry.setUniversityFiscalYear(new Integer(2007));
130: entry.setChartOfAccountsCode("BA");
131: entry.setAccountNumber("1912610");
132: collectorBatch.addOriginEntry(entry);
133:
134: CollectorDetail collectorDetail = new CollectorDetail();
135: collectorDetail.setUniversityFiscalYear(new Integer(2007));
136: collectorDetail.setChartOfAccountsCode("UA");
137: collectorDetail.setAccountNumber("1912660");
138: collectorBatch.addCollectorDetail(collectorDetail);
139:
140: boolean isValid = collectorHelperService
141: .performValidation(collectorBatch);
142: assertFalse(
143: "returned batch was valid but there was detail record without a matching gl entry",
144: isValid);
145: assertTrue(
146: "error message for unmatched detail key does not exist",
147: GlobalVariables
148: .getErrorMap()
149: .containsMessageKey(
150: KFSKeyConstants.Collector.NONMATCHING_DETAIL_KEY));
151: }
152:
153: /**
154: * Verifies an error is added when the batch entries contain multiple balance types. Note: Actual test values here do not have
155: * to be valid balance types, only need to be different.
156: */
157: // @RelatesTo(RelatesTo.JiraIssue.KULUT31)
158: public final void testPerformValidation_mixedBalanceTypes()
159: throws Exception {
160: MockCollectorBatch collectorBatch = new MockCollectorBatch();
161:
162: OriginEntryFull entry1 = new OriginEntryFull();
163: entry1.setFinancialBalanceTypeCode("AC");
164: collectorBatch.addOriginEntry(entry1);
165:
166: OriginEntryFull entry2 = new OriginEntryFull();
167: entry2.setFinancialBalanceTypeCode("IE");
168: collectorBatch.addOriginEntry(entry2);
169:
170: boolean isValid = collectorHelperService
171: .performValidation(collectorBatch);
172: assertFalse(
173: "returned batch was valid but there were multiple balance types",
174: isValid);
175: assertTrue(
176: "error message for mixed balance types does not exist",
177: GlobalVariables.getErrorMap().containsMessageKey(
178: KFSKeyConstants.Collector.MIXED_BALANCE_TYPES));
179: }
180: }
|