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.chart.rules;
017:
018: import java.util.ArrayList;
019: import java.util.List;
020:
021: import org.kuali.module.chart.bo.DelegateGlobalDetail;
022: import org.kuali.test.ConfigureContext;
023:
024: @ConfigureContext
025: public class DelegateGlobalRuleTest extends ChartRuleTestBase {
026:
027: private DelegateGlobalDetail delegateGlobal;
028: private List<DelegateGlobalDetail> delegateGlobals;
029:
030: public void testCheckPrimaryRouteOnlyAllowOneAllDocType_InputValidations() {
031: DelegateGlobalRule rule = new DelegateGlobalRule();
032: delegateGlobal = null;
033: delegateGlobals = null;
034: Integer offendingLine = null;
035: Integer result = rule.checkPrimaryRouteOnlyAllowOneAllDocType(
036: delegateGlobal, delegateGlobals, null);
037: assertNull(result);
038:
039: delegateGlobal = new DelegateGlobalDetail();
040: delegateGlobals = null;
041: offendingLine = null;
042: result = rule.checkPrimaryRouteOnlyAllowOneAllDocType(
043: delegateGlobal, delegateGlobals, null);
044: assertNull(result);
045:
046: delegateGlobal = new DelegateGlobalDetail();
047: delegateGlobals = new ArrayList<DelegateGlobalDetail>();
048: offendingLine = null;
049: result = rule.checkPrimaryRouteOnlyAllowOneAllDocType(
050: delegateGlobal, delegateGlobals, null);
051: assertNull(result);
052:
053: delegateGlobal = new DelegateGlobalDetail();
054: delegateGlobal.setAccountDelegatePrimaryRoutingIndicator(false);
055: delegateGlobal.setFinancialDocumentTypeCode("ALL");
056: delegateGlobals = new ArrayList<DelegateGlobalDetail>();
057: offendingLine = null;
058: result = rule.checkPrimaryRouteOnlyAllowOneAllDocType(
059: delegateGlobal, delegateGlobals, null);
060: assertNull(result);
061:
062: delegateGlobal = new DelegateGlobalDetail();
063: delegateGlobal.setAccountDelegatePrimaryRoutingIndicator(true);
064: delegateGlobal.setFinancialDocumentTypeCode("A21");
065: delegateGlobals = new ArrayList<DelegateGlobalDetail>();
066: offendingLine = null;
067: result = rule.checkPrimaryRouteOnlyAllowOneAllDocType(
068: delegateGlobal, delegateGlobals, null);
069: assertNull(result);
070:
071: }
072:
073: public void testCheckPrimaryRouteOnlyAllowOneAllDocType_NewLine_NoOtherPrimaryAll() {
074: DelegateGlobalRule rule = new DelegateGlobalRule();
075: delegateGlobals = new ArrayList<DelegateGlobalDetail>();
076: DelegateGlobalDetail listItem;
077:
078: delegateGlobal = new DelegateGlobalDetail();
079: delegateGlobal.setAccountDelegatePrimaryRoutingIndicator(true);
080: delegateGlobal.setFinancialDocumentTypeCode("ALL");
081:
082: listItem = new DelegateGlobalDetail();
083: listItem.setAccountDelegatePrimaryRoutingIndicator(false);
084: listItem.setFinancialDocumentTypeCode("A21");
085: delegateGlobals.add(listItem);
086:
087: Integer result = rule.checkPrimaryRouteOnlyAllowOneAllDocType(
088: delegateGlobal, delegateGlobals, null);
089: assertNull(result);
090: }
091:
092: public void testCheckPrimaryRouteOnlyAllowOneAllDocType_NewLine_OtherPrimaryNotAll() {
093: DelegateGlobalRule rule = new DelegateGlobalRule();
094: delegateGlobals = new ArrayList<DelegateGlobalDetail>();
095: DelegateGlobalDetail listItem;
096:
097: delegateGlobal = new DelegateGlobalDetail();
098: delegateGlobal.setAccountDelegatePrimaryRoutingIndicator(true);
099: delegateGlobal.setFinancialDocumentTypeCode("ALL");
100:
101: listItem = new DelegateGlobalDetail();
102: listItem.setAccountDelegatePrimaryRoutingIndicator(true);
103: listItem.setFinancialDocumentTypeCode("A21");
104: delegateGlobals.add(listItem);
105:
106: Integer result = rule.checkPrimaryRouteOnlyAllowOneAllDocType(
107: delegateGlobal, delegateGlobals, null);
108: assertEquals(new Integer(0), result);
109: }
110:
111: public void testCheckPrimaryRouteOnlyAllowOneAllDocType_ExistingLine_OtherPrimaryNotAll() {
112: DelegateGlobalRule rule = new DelegateGlobalRule();
113: delegateGlobals = new ArrayList<DelegateGlobalDetail>();
114: DelegateGlobalDetail listItem;
115:
116: listItem = new DelegateGlobalDetail();
117: listItem.setAccountDelegatePrimaryRoutingIndicator(true);
118: listItem.setFinancialDocumentTypeCode("A21");
119: delegateGlobals.add(listItem);
120:
121: listItem = new DelegateGlobalDetail();
122: listItem.setAccountDelegatePrimaryRoutingIndicator(true);
123: listItem.setFinancialDocumentTypeCode("ALL");
124: delegateGlobals.add(listItem);
125:
126: Integer result = null;
127: DelegateGlobalDetail delegateGlobal = null;
128:
129: delegateGlobal = delegateGlobals.get(0);
130: result = rule.checkPrimaryRouteOnlyAllowOneAllDocType(
131: delegateGlobal, delegateGlobals, 0);
132: assertNull(result);
133:
134: delegateGlobal = delegateGlobals.get(1);
135: result = rule.checkPrimaryRouteOnlyAllowOneAllDocType(
136: delegateGlobal, delegateGlobals, 1);
137: assertEquals(new Integer(0), result);
138:
139: }
140:
141: public void testCheckPrimaryRoutePerDocType_InputValidations() {
142: DelegateGlobalRule rule = new DelegateGlobalRule();
143: delegateGlobal = null;
144: delegateGlobals = null;
145: Integer offendingLine = null;
146: Integer result = rule.checkPrimaryRoutePerDocType(
147: delegateGlobal, delegateGlobals, null);
148: assertNull(result);
149:
150: delegateGlobal = new DelegateGlobalDetail();
151: delegateGlobals = null;
152: offendingLine = null;
153: result = rule.checkPrimaryRoutePerDocType(delegateGlobal,
154: delegateGlobals, null);
155: assertNull(result);
156:
157: delegateGlobal = new DelegateGlobalDetail();
158: delegateGlobals = new ArrayList<DelegateGlobalDetail>();
159: offendingLine = null;
160: result = rule.checkPrimaryRoutePerDocType(delegateGlobal,
161: delegateGlobals, null);
162: assertNull(result);
163:
164: delegateGlobal = new DelegateGlobalDetail();
165: delegateGlobal.setAccountDelegatePrimaryRoutingIndicator(false);
166: delegateGlobal.setFinancialDocumentTypeCode("ALL");
167: delegateGlobals = new ArrayList<DelegateGlobalDetail>();
168: offendingLine = null;
169: result = rule.checkPrimaryRoutePerDocType(delegateGlobal,
170: delegateGlobals, null);
171: assertNull(result);
172:
173: delegateGlobal = new DelegateGlobalDetail();
174: delegateGlobal.setAccountDelegatePrimaryRoutingIndicator(true);
175: delegateGlobal.setFinancialDocumentTypeCode("A21");
176: delegateGlobals = new ArrayList<DelegateGlobalDetail>();
177: offendingLine = null;
178: result = rule.checkPrimaryRoutePerDocType(delegateGlobal,
179: delegateGlobals, null);
180: assertNull(result);
181:
182: }
183:
184: public void testCheckPrimaryRoutePerDocType_NewLine_NoOtherPrimariesWithSameDocType() {
185: DelegateGlobalRule rule = new DelegateGlobalRule();
186: delegateGlobals = new ArrayList<DelegateGlobalDetail>();
187: DelegateGlobalDetail listItem;
188:
189: delegateGlobal = new DelegateGlobalDetail();
190: delegateGlobal.setAccountDelegatePrimaryRoutingIndicator(true);
191: delegateGlobal.setFinancialDocumentTypeCode("ABC");
192:
193: listItem = new DelegateGlobalDetail();
194: listItem.setAccountDelegatePrimaryRoutingIndicator(true);
195: listItem.setFinancialDocumentTypeCode("A21");
196: delegateGlobals.add(listItem);
197:
198: Integer result = rule.checkPrimaryRoutePerDocType(
199: delegateGlobal, delegateGlobals, null);
200: assertNull(result);
201: }
202:
203: public void testCheckPrimaryRoutePerDocType_NewLine_AddingIdenticalLine() {
204: DelegateGlobalRule rule = new DelegateGlobalRule();
205: delegateGlobals = new ArrayList<DelegateGlobalDetail>();
206: DelegateGlobalDetail listItem;
207:
208: delegateGlobal = new DelegateGlobalDetail();
209: delegateGlobal.setAccountDelegatePrimaryRoutingIndicator(true);
210: delegateGlobal.setFinancialDocumentTypeCode("ABC");
211:
212: listItem = new DelegateGlobalDetail();
213: listItem.setAccountDelegatePrimaryRoutingIndicator(true);
214: listItem.setFinancialDocumentTypeCode("ABC");
215: delegateGlobals.add(listItem);
216:
217: Integer result = rule.checkPrimaryRoutePerDocType(
218: delegateGlobal, delegateGlobals, null);
219: assertEquals(new Integer(0), result);
220: }
221:
222: public void testCheckOnlyOnePrimaryRoute_NewLine_OnePrimaryWithSameDocType() {
223: DelegateGlobalRule rule = new DelegateGlobalRule();
224: delegateGlobals = new ArrayList<DelegateGlobalDetail>();
225: DelegateGlobalDetail listItem;
226:
227: delegateGlobal = new DelegateGlobalDetail();
228: delegateGlobal.setAccountDelegatePrimaryRoutingIndicator(true);
229: delegateGlobal.setFinancialDocumentTypeCode("A21");
230:
231: listItem = new DelegateGlobalDetail();
232: listItem.setAccountDelegatePrimaryRoutingIndicator(true);
233: listItem.setFinancialDocumentTypeCode("ABC");
234: delegateGlobals.add(listItem);
235:
236: listItem = new DelegateGlobalDetail();
237: listItem.setAccountDelegatePrimaryRoutingIndicator(true);
238: listItem.setFinancialDocumentTypeCode("A21");
239: delegateGlobals.add(listItem);
240:
241: Integer result = rule.checkPrimaryRoutePerDocType(
242: delegateGlobal, delegateGlobals, null);
243: assertEquals(new Integer(1), result);
244: }
245:
246: }
|