1 package org.kuali.student.lum.statement.config.context;
2
3 import java.util.ArrayList;
4 import java.util.Date;
5 import java.util.HashMap;
6 import java.util.List;
7 import java.util.Map;
8
9 import org.junit.Assert;
10 import org.junit.Before;
11 import org.junit.Test;
12 import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition;
13 import org.kuali.student.common.dto.StatusInfo;
14 import org.kuali.student.common.exceptions.AlreadyExistsException;
15 import org.kuali.student.common.exceptions.DataValidationErrorException;
16 import org.kuali.student.common.exceptions.DoesNotExistException;
17 import org.kuali.student.common.exceptions.InvalidParameterException;
18 import org.kuali.student.common.exceptions.MissingParameterException;
19 import org.kuali.student.common.exceptions.OperationFailedException;
20 import org.kuali.student.common.exceptions.PermissionDeniedException;
21 import org.kuali.student.common.exceptions.VersionMismatchException;
22 import org.kuali.student.common.search.dto.SearchCriteriaTypeInfo;
23 import org.kuali.student.common.search.dto.SearchRequest;
24 import org.kuali.student.common.search.dto.SearchResult;
25 import org.kuali.student.common.search.dto.SearchResultTypeInfo;
26 import org.kuali.student.common.search.dto.SearchTypeInfo;
27 import org.kuali.student.common.validation.dto.ValidationResultInfo;
28 import org.kuali.student.core.atp.dto.AtpDurationTypeInfo;
29 import org.kuali.student.core.atp.dto.AtpInfo;
30 import org.kuali.student.core.atp.dto.AtpSeasonalTypeInfo;
31 import org.kuali.student.core.atp.dto.AtpTypeInfo;
32 import org.kuali.student.core.atp.dto.DateRangeInfo;
33 import org.kuali.student.core.atp.dto.DateRangeTypeInfo;
34 import org.kuali.student.core.atp.dto.MilestoneInfo;
35 import org.kuali.student.core.atp.dto.MilestoneTypeInfo;
36 import org.kuali.student.core.atp.service.AtpService;
37 import org.kuali.student.core.statement.dto.ReqCompFieldInfo;
38 import org.kuali.student.core.statement.dto.ReqComponentInfo;
39
40 public class AtpContextImplTest {
41 private AtpService atpService = new AtpServiceMock();
42 private AtpContextImpl atpContext = new AtpContextImpl();
43 private ReqComponentInfo reqComponent1;
44 private ReqComponentInfo reqComponent2;
45
46 private void setupReqComponent1() {
47 reqComponent1 = new ReqComponentInfo();
48 List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
49 ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
50 reqCompField1.setType("kuali.reqComponent.field.type.duration");
51 reqCompField1.setValue("2");
52 reqCompFieldList.add(reqCompField1);
53 ReqCompFieldInfo reqCompField2 = new ReqCompFieldInfo();
54 reqCompField2.setType("kuali.reqComponent.field.type.durationType.id");
55 reqCompField2.setValue("kuali.atp.duration.Year");
56 reqCompFieldList.add(reqCompField2);
57
58 reqComponent1.setReqCompFields(reqCompFieldList);
59 }
60
61 private void setupReqComponent2() {
62 reqComponent2 = new ReqComponentInfo();
63 List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
64 ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
65 reqCompField1.setType("kuali.reqComponent.field.type.duration");
66 reqCompField1.setValue(null);
67 reqCompFieldList.add(reqCompField1);
68 ReqCompFieldInfo reqCompField2 = new ReqCompFieldInfo();
69 reqCompField2.setType("kuali.reqComponent.field.type.durationType.id");
70 reqCompField2.setValue(null);
71 reqCompFieldList.add(reqCompField2);
72
73 reqComponent2.setReqCompFields(reqCompFieldList);
74 }
75
76 @Before
77 public void beforeMethod() {
78 atpContext.setAtpService(atpService);
79 setupReqComponent1();
80 setupReqComponent2();
81 }
82
83 @Test
84 public void testCreateContextMap_ContainsTokens() throws OperationFailedException {
85 Map<String, Object> contextMap = atpContext.createContextMap(reqComponent1);
86 Assert.assertNotNull(contextMap);
87 Assert.assertTrue(contextMap.containsKey(AtpContextImpl.DURATION_TOKEN));
88 Assert.assertTrue(contextMap.containsKey(AtpContextImpl.DURATION_TYPE_TOKEN));
89 }
90
91 @Test
92 public void testCreateContextMap_TokenValues() throws OperationFailedException {
93 Map<String, Object> contextMap = atpContext.createContextMap(reqComponent1);
94 String duration = (String) contextMap.get(AtpContextImpl.DURATION_TOKEN);
95 AtpDurationTypeInfo type = (AtpDurationTypeInfo) contextMap.get(AtpContextImpl.DURATION_TYPE_TOKEN);
96
97 Assert.assertEquals("2", duration);
98 Assert.assertEquals("kuali.atp.duration.Year", type.getId());
99 }
100
101 @Test
102 public void testCreateContextMap_NullTokenValues() throws OperationFailedException {
103 Map<String, Object> contextMap = atpContext.createContextMap(reqComponent2);
104 String duration = (String) contextMap.get(AtpContextImpl.DURATION_TOKEN);
105 AtpDurationTypeInfo type = (AtpDurationTypeInfo) contextMap.get(AtpContextImpl.DURATION_TYPE_TOKEN);
106
107 Assert.assertEquals(null, duration);
108 Assert.assertEquals(null, type);
109 }
110
111 private static class AtpServiceMock implements AtpService {
112
113 private Map<String, AtpDurationTypeInfo> durationTypeMap = new HashMap<String, AtpDurationTypeInfo>();
114
115 public AtpServiceMock() {
116 AtpDurationTypeInfo type1 = new AtpDurationTypeInfo();
117 type1.setId("kuali.atp.duration.Year");
118 type1.setName("Year");
119 durationTypeMap.put("kuali.atp.duration.Year", type1);
120
121 AtpDurationTypeInfo type2 = new AtpDurationTypeInfo();
122 type2.setId("kuali.atp.duration.Term");
123 type2.setName("Term");
124 durationTypeMap.put("kuali.atp.duration.Term", type2);
125 }
126
127 @Override
128 public DateRangeInfo addDateRange(String atpKey, String dateRangeKey,
129 DateRangeInfo dateRangeInfo) throws AlreadyExistsException,
130 DataValidationErrorException, InvalidParameterException,
131 MissingParameterException, OperationFailedException,
132 PermissionDeniedException {
133
134 return null;
135 }
136
137 @Override
138 public MilestoneInfo addMilestone(String atpKey, String milestoneKey,
139 MilestoneInfo milestoneInfo) throws AlreadyExistsException,
140 DataValidationErrorException, InvalidParameterException,
141 MissingParameterException, OperationFailedException,
142 PermissionDeniedException {
143
144 return null;
145 }
146
147 @Override
148 public AtpInfo createAtp(String atpTypeKey, String atpKey,
149 AtpInfo atpInfo) throws AlreadyExistsException,
150 DataValidationErrorException, InvalidParameterException,
151 MissingParameterException, OperationFailedException,
152 PermissionDeniedException {
153
154 return null;
155 }
156
157 @Override
158 public StatusInfo deleteAtp(String atpKey)
159 throws DoesNotExistException, InvalidParameterException,
160 MissingParameterException, OperationFailedException,
161 PermissionDeniedException {
162
163 return null;
164 }
165
166 @Override
167 public AtpInfo getAtp(String atpKey) throws DoesNotExistException,
168 InvalidParameterException, MissingParameterException,
169 OperationFailedException {
170
171 return null;
172 }
173
174 @Override
175 public AtpDurationTypeInfo getAtpDurationType(String atpDurationTypeKey)
176 throws DoesNotExistException, InvalidParameterException,
177 MissingParameterException, OperationFailedException {
178 return durationTypeMap.get(atpDurationTypeKey);
179 }
180
181 @Override
182 public List<AtpDurationTypeInfo> getAtpDurationTypes()
183 throws OperationFailedException {
184
185 return null;
186 }
187
188 @Override
189 public AtpSeasonalTypeInfo getAtpSeasonalType(String atpSeasonalTypeKey)
190 throws DoesNotExistException, InvalidParameterException,
191 MissingParameterException, OperationFailedException {
192
193 return null;
194 }
195
196 @Override
197 public List<AtpSeasonalTypeInfo> getAtpSeasonalTypes()
198 throws OperationFailedException {
199
200 return null;
201 }
202
203 @Override
204 public AtpTypeInfo getAtpType(String atpTypeKey)
205 throws DoesNotExistException, InvalidParameterException,
206 MissingParameterException, OperationFailedException {
207
208 return null;
209 }
210
211 @Override
212 public List<AtpTypeInfo> getAtpTypes() throws OperationFailedException {
213
214 return null;
215 }
216
217 @Override
218 public List<AtpInfo> getAtpsByAtpType(String atpTypeKey)
219 throws InvalidParameterException, MissingParameterException,
220 OperationFailedException {
221
222 return null;
223 }
224
225 @Override
226 public List<AtpInfo> getAtpsByDate(Date searchDate)
227 throws InvalidParameterException, MissingParameterException,
228 OperationFailedException {
229
230 return null;
231 }
232
233 @Override
234 public List<AtpInfo> getAtpsByDates(Date startDate, Date endDate)
235 throws InvalidParameterException, MissingParameterException,
236 OperationFailedException {
237
238 return null;
239 }
240
241 @Override
242 public DateRangeInfo getDateRange(String dateRangeKey)
243 throws DoesNotExistException, InvalidParameterException,
244 MissingParameterException, OperationFailedException {
245
246 return null;
247 }
248
249 @Override
250 public DateRangeTypeInfo getDateRangeType(String dateRangeTypeKey)
251 throws DoesNotExistException, InvalidParameterException,
252 MissingParameterException, OperationFailedException {
253
254 return null;
255 }
256
257 @Override
258 public List<DateRangeTypeInfo> getDateRangeTypes()
259 throws OperationFailedException {
260
261 return null;
262 }
263
264 @Override
265 public List<DateRangeTypeInfo> getDateRangeTypesForAtpType(
266 String atpTypeKey) throws DoesNotExistException,
267 InvalidParameterException, MissingParameterException,
268 OperationFailedException {
269
270 return null;
271 }
272
273 @Override
274 public List<DateRangeInfo> getDateRangesByAtp(String atpKey)
275 throws InvalidParameterException, MissingParameterException,
276 OperationFailedException {
277
278 return null;
279 }
280
281 @Override
282 public List<DateRangeInfo> getDateRangesByDate(Date searchDate)
283 throws InvalidParameterException, MissingParameterException,
284 OperationFailedException {
285
286 return null;
287 }
288
289 @Override
290 public MilestoneInfo getMilestone(String milestoneKey)
291 throws DoesNotExistException, InvalidParameterException,
292 MissingParameterException, OperationFailedException {
293
294 return null;
295 }
296
297 @Override
298 public MilestoneTypeInfo getMilestoneType(String milestoneTypeKey)
299 throws DoesNotExistException, InvalidParameterException,
300 MissingParameterException, OperationFailedException {
301
302 return null;
303 }
304
305 @Override
306 public List<MilestoneTypeInfo> getMilestoneTypes()
307 throws OperationFailedException {
308
309 return null;
310 }
311
312 @Override
313 public List<MilestoneTypeInfo> getMilestoneTypesForAtpType(
314 String atpTypeKey) throws DoesNotExistException,
315 InvalidParameterException, MissingParameterException,
316 OperationFailedException {
317
318 return null;
319 }
320
321 @Override
322 public List<MilestoneInfo> getMilestonesByAtp(String atpKey)
323 throws InvalidParameterException, MissingParameterException,
324 OperationFailedException {
325
326 return null;
327 }
328
329 @Override
330 public List<MilestoneInfo> getMilestonesByDates(Date startDate,
331 Date endDate) throws InvalidParameterException,
332 MissingParameterException, OperationFailedException {
333
334 return null;
335 }
336
337 @Override
338 public List<MilestoneInfo> getMilestonesByDatesAndType(
339 String milestoneTypeKey, Date startDate, Date endDate)
340 throws InvalidParameterException, MissingParameterException,
341 OperationFailedException {
342
343 return null;
344 }
345
346 @Override
347 public StatusInfo removeDateRange(String dateRangeKey)
348 throws DoesNotExistException, InvalidParameterException,
349 MissingParameterException, OperationFailedException,
350 PermissionDeniedException {
351
352 return null;
353 }
354
355 @Override
356 public StatusInfo removeMilestone(String milestoneKey)
357 throws DoesNotExistException, InvalidParameterException,
358 MissingParameterException, OperationFailedException,
359 PermissionDeniedException {
360
361 return null;
362 }
363
364 @Override
365 public AtpInfo updateAtp(String atpKey, AtpInfo atpInfo)
366 throws DataValidationErrorException, DoesNotExistException,
367 InvalidParameterException, MissingParameterException,
368 OperationFailedException, PermissionDeniedException,
369 VersionMismatchException {
370
371 return null;
372 }
373
374 @Override
375 public DateRangeInfo updateDateRange(String dateRangeKey,
376 DateRangeInfo dateRangeInfo)
377 throws DataValidationErrorException, DoesNotExistException,
378 InvalidParameterException, MissingParameterException,
379 OperationFailedException, PermissionDeniedException,
380 VersionMismatchException {
381
382 return null;
383 }
384
385 @Override
386 public MilestoneInfo updateMilestone(String milestoneKey,
387 MilestoneInfo milestoneInfo)
388 throws DataValidationErrorException, DoesNotExistException,
389 InvalidParameterException, MissingParameterException,
390 OperationFailedException, PermissionDeniedException,
391 VersionMismatchException {
392
393 return null;
394 }
395
396 @Override
397 public List<ValidationResultInfo> validateAtp(String validationType,
398 AtpInfo atpInfo) throws DoesNotExistException,
399 InvalidParameterException, MissingParameterException,
400 OperationFailedException {
401
402 return null;
403 }
404
405 @Override
406 public List<ValidationResultInfo> validateDateRange(
407 String validationType, DateRangeInfo dateRangeInfo)
408 throws DoesNotExistException, InvalidParameterException,
409 MissingParameterException, OperationFailedException {
410
411 return null;
412 }
413
414 @Override
415 public List<ValidationResultInfo> validateMilestone(
416 String validationType, MilestoneInfo milestoneInfo)
417 throws DoesNotExistException, InvalidParameterException,
418 MissingParameterException, OperationFailedException {
419
420 return null;
421 }
422
423 @Override
424 public SearchCriteriaTypeInfo getSearchCriteriaType(
425 String searchCriteriaTypeKey) throws DoesNotExistException,
426 InvalidParameterException, MissingParameterException,
427 OperationFailedException {
428
429 return null;
430 }
431
432 @Override
433 public List<SearchCriteriaTypeInfo> getSearchCriteriaTypes()
434 throws OperationFailedException {
435
436 return null;
437 }
438
439 @Override
440 public SearchResultTypeInfo getSearchResultType(
441 String searchResultTypeKey) throws DoesNotExistException,
442 InvalidParameterException, MissingParameterException,
443 OperationFailedException {
444
445 return null;
446 }
447
448 @Override
449 public List<SearchResultTypeInfo> getSearchResultTypes()
450 throws OperationFailedException {
451
452 return null;
453 }
454
455 @Override
456 public SearchTypeInfo getSearchType(String searchTypeKey)
457 throws DoesNotExistException, InvalidParameterException,
458 MissingParameterException, OperationFailedException {
459
460 return null;
461 }
462
463 @Override
464 public List<SearchTypeInfo> getSearchTypes()
465 throws OperationFailedException {
466
467 return null;
468 }
469
470 @Override
471 public List<SearchTypeInfo> getSearchTypesByCriteria(
472 String searchCriteriaTypeKey) throws DoesNotExistException,
473 InvalidParameterException, MissingParameterException,
474 OperationFailedException {
475
476 return null;
477 }
478
479 @Override
480 public List<SearchTypeInfo> getSearchTypesByResult(
481 String searchResultTypeKey) throws DoesNotExistException,
482 InvalidParameterException, MissingParameterException,
483 OperationFailedException {
484
485 return null;
486 }
487
488 @Override
489 public SearchResult search(SearchRequest searchRequest)
490 throws MissingParameterException {
491
492 return null;
493 }
494
495 @Override
496 public ObjectStructureDefinition getObjectStructure(String objectTypeKey) {
497
498 return null;
499 }
500
501 @Override
502 public List<String> getObjectTypes() {
503
504 return null;
505 }
506
507 }
508 }