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.kfs.service;
017:
018: import java.util.List;
019:
020: import org.apache.commons.lang.StringUtils;
021: import org.kuali.core.bo.user.UniversalUser;
022: import org.kuali.core.service.UniversalUserService;
023: import org.kuali.kfs.KFSConstants;
024: import org.kuali.kfs.KFSConstants.SystemGroupParameterNames;
025: import org.kuali.kfs.batch.BatchInputFileType;
026: import org.kuali.kfs.context.KualiTestBase;
027: import org.kuali.kfs.context.SpringContext;
028: import org.kuali.kfs.context.TestUtils;
029: import org.kuali.kfs.service.impl.ParameterConstants;
030: import org.kuali.module.financial.batch.pcard.ProcurementCardInputFileType;
031: import org.kuali.module.gl.batch.collector.CollectorInputFileType;
032: import org.kuali.test.ConfigureContext;
033: import org.kuali.test.KualiTestConstants.TestConstants.Data4;
034:
035: /**
036: * Tests system parameters are setup and methods on the batch input types are correctly using them.
037: */
038: @ConfigureContext
039: public class BatchInputServiceSystemParametersTest extends
040: KualiTestBase {
041: private ParameterService parameterService;
042: private BatchInputFileService batchInputFileService;
043:
044: private BatchInputFileType pcdoBatchInputFileType;
045: private BatchInputFileType collectorBatchInputFileType;
046:
047: private UniversalUser validWorkgroupUser;
048: private UniversalUser invalidWorkgroupUser;
049:
050: /**
051: * @see junit.framework.TestCase#setUp()
052: */
053: @Override
054: protected void setUp() throws Exception {
055: super .setUp();
056:
057: parameterService = SpringContext
058: .getBean(ParameterService.class);
059: batchInputFileService = SpringContext
060: .getBean(BatchInputFileService.class);
061: pcdoBatchInputFileType = SpringContext
062: .getBean(ProcurementCardInputFileType.class);
063: collectorBatchInputFileType = SpringContext
064: .getBean(CollectorInputFileType.class);
065:
066: validWorkgroupUser = SpringContext.getBean(
067: UniversalUserService.class)
068: .getUniversalUserByAuthenticationUserId(Data4.USER_ID2);
069: invalidWorkgroupUser = SpringContext.getBean(
070: UniversalUserService.class)
071: .getUniversalUserByAuthenticationUserId(Data4.USER_ID1);
072: }
073:
074: /**
075: * Verifies system parameters needed by the batch upload process exist in the db.
076: */
077: public final void testSystemParametersExist() throws Exception {
078: List<String> activeFileTypes = parameterService
079: .getParameterValues(
080: ParameterConstants.FINANCIAL_SYSTEM_BATCH.class,
081: SystemGroupParameterNames.ACTIVE_INPUT_TYPES_PARAMETER_NAME);
082: assertTrue(
083: "system parameter "
084: + SystemGroupParameterNames.ACTIVE_INPUT_TYPES_PARAMETER_NAME
085: + " is not setup or contains no file types",
086: activeFileTypes != null
087: && activeFileTypes.size() > 0
088: && StringUtils.isNotBlank(activeFileTypes
089: .get(0)));
090:
091: String pcdoUploadWorkgroup = parameterService
092: .getParameterValue(
093: pcdoBatchInputFileType
094: .getUploadWorkgroupParameterComponent(),
095: KFSConstants.SystemGroupParameterNames.FILE_TYPE_WORKGROUP_PARAMETER_NAME);
096: assertTrue(
097: "system parameter pcdo "
098: + KFSConstants.SystemGroupParameterNames.FILE_TYPE_WORKGROUP_PARAMETER_NAME
099: + " does not exist or has empty value.",
100: StringUtils.isNotBlank(pcdoUploadWorkgroup));
101:
102: String collectorUploadWorkgroup = parameterService
103: .getParameterValue(
104: collectorBatchInputFileType
105: .getUploadWorkgroupParameterComponent(),
106: KFSConstants.SystemGroupParameterNames.FILE_TYPE_WORKGROUP_PARAMETER_NAME);
107: assertTrue(
108: "system parameter collector "
109: + KFSConstants.SystemGroupParameterNames.FILE_TYPE_WORKGROUP_PARAMETER_NAME
110: + " does not exist or has empty value.",
111: StringUtils.isNotBlank(pcdoUploadWorkgroup));
112: }
113:
114: /**
115: * Set SystemGroupParameterNames.ACTIVE_INPUT_TYPES_PARAMETER_NAME to empty and verify both pcdo & collector are inactive
116: */
117: public final void testIsBatchInputTypeActive_emptySystemParameter()
118: throws Exception {
119: setActiveSystemParameter("", true);
120: assertFalse(
121: "pcdo isActive method not false when active param is empty",
122: batchInputFileService
123: .isBatchInputTypeActive(pcdoBatchInputFileType));
124: assertFalse(
125: "collector isActive method not false when active param is empty",
126: batchInputFileService
127: .isBatchInputTypeActive(collectorBatchInputFileType));
128: }
129:
130: /**
131: * Set SystemGroupParameterNames.ACTIVE_INPUT_TYPES_PARAMETER_NAME to an invalid group and verify both pcdo & collector are
132: * inactive
133: */
134: public final void testIsBatchInputTypeActive_invalidSystemParameter()
135: throws Exception {
136: setActiveSystemParameter("foo", true);
137: assertFalse(
138: "pcdo isActive method not false when active param is foo",
139: batchInputFileService
140: .isBatchInputTypeActive(pcdoBatchInputFileType));
141: assertFalse(
142: "collector isActive method not false when active param is foo",
143: batchInputFileService
144: .isBatchInputTypeActive(collectorBatchInputFileType));
145: }
146:
147: /**
148: * Set SystemGroupParameterNames.ACTIVE_INPUT_TYPES_PARAMETER_NAME to contain both indentifiers and verify both pcdo & collector
149: * are active
150: */
151: public final void testIsBatchInputTypeActive_systemParameterContainsBoth()
152: throws Exception {
153: setActiveSystemParameter(collectorBatchInputFileType
154: .getFileTypeIdentifer()
155: + ";" + pcdoBatchInputFileType.getFileTypeIdentifer(),
156: true);
157: assertTrue(
158: "pcdo isActive method not true when active param contains identifier",
159: batchInputFileService
160: .isBatchInputTypeActive(pcdoBatchInputFileType));
161: assertTrue(
162: "collector isActive method not true when active param contains identifier",
163: batchInputFileService
164: .isBatchInputTypeActive(collectorBatchInputFileType));
165: }
166:
167: /**
168: * Set SystemGroupParameterNames.ACTIVE_INPUT_TYPES_PARAMETER_NAME to contain one indentifier and verify the correct one is
169: * active and other type is inactive.
170: */
171: public final void testIsBatchInputTypeActive_systemParameterContainsOne()
172: throws Exception {
173: setActiveSystemParameter(collectorBatchInputFileType
174: .getFileTypeIdentifer(), true);
175: assertFalse(
176: "pcdo isActive method is true when active param does not contain identifier",
177: batchInputFileService
178: .isBatchInputTypeActive(pcdoBatchInputFileType));
179: assertTrue(
180: "collector isActive method not true when active param contains identifier",
181: batchInputFileService
182: .isBatchInputTypeActive(collectorBatchInputFileType));
183:
184: setActiveSystemParameter(pcdoBatchInputFileType
185: .getFileTypeIdentifer(), true);
186: assertTrue(
187: "pcdo isActive method is false when active param contains identifier",
188: batchInputFileService
189: .isBatchInputTypeActive(pcdoBatchInputFileType));
190: assertFalse(
191: "collector isActive method is true when active param does not contain identifier",
192: batchInputFileService
193: .isBatchInputTypeActive(collectorBatchInputFileType));
194: }
195:
196: /**
197: * Changes the text for the batch input active system parameter, stores and clears cache.
198: */
199: private final void setActiveSystemParameter(String parameterText,
200: boolean multiValue) throws Exception {
201: TestUtils
202: .setSystemParameter(
203: ParameterConstants.FINANCIAL_SYSTEM_BATCH.class,
204: SystemGroupParameterNames.ACTIVE_INPUT_TYPES_PARAMETER_NAME,
205: parameterText);
206: }
207:
208: }
|