001    package org.kuali.student.lum.statement.config.context;
002    
003    import java.util.ArrayList;
004    import java.util.Arrays;
005    import java.util.HashMap;
006    import java.util.List;
007    import java.util.Map;
008    
009    import org.junit.Assert;
010    import org.junit.Before;
011    import org.junit.Test;
012    import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition;
013    import org.kuali.student.common.dto.StatusInfo;
014    import org.kuali.student.common.exceptions.AlreadyExistsException;
015    import org.kuali.student.common.exceptions.DataValidationErrorException;
016    import org.kuali.student.common.exceptions.DoesNotExistException;
017    import org.kuali.student.common.exceptions.InvalidParameterException;
018    import org.kuali.student.common.exceptions.MissingParameterException;
019    import org.kuali.student.common.exceptions.OperationFailedException;
020    import org.kuali.student.common.exceptions.PermissionDeniedException;
021    import org.kuali.student.common.exceptions.VersionMismatchException;
022    import org.kuali.student.common.search.dto.SearchCriteriaTypeInfo;
023    import org.kuali.student.common.search.dto.SearchRequest;
024    import org.kuali.student.common.search.dto.SearchResult;
025    import org.kuali.student.common.search.dto.SearchResultTypeInfo;
026    import org.kuali.student.common.search.dto.SearchTypeInfo;
027    import org.kuali.student.core.statement.dto.ReqCompFieldInfo;
028    import org.kuali.student.core.statement.dto.ReqComponentInfo;
029    import org.kuali.student.lum.lrc.dto.CredentialInfo;
030    import org.kuali.student.lum.lrc.dto.CredentialTypeInfo;
031    import org.kuali.student.lum.lrc.dto.CreditInfo;
032    import org.kuali.student.lum.lrc.dto.CreditTypeInfo;
033    import org.kuali.student.lum.lrc.dto.GradeInfo;
034    import org.kuali.student.lum.lrc.dto.GradeTypeInfo;
035    import org.kuali.student.lum.lrc.dto.ResultComponentInfo;
036    import org.kuali.student.lum.lrc.dto.ResultComponentTypeInfo;
037    import org.kuali.student.lum.lrc.dto.ScaleInfo;
038    import org.kuali.student.lum.lrc.service.LrcService;
039    import org.kuali.student.lum.statement.typekey.ReqComponentFieldTypes;
040    
041    public class LrcContextImplTest {
042            private LrcService lrcService = new LrcServiceMock();
043            private LrcContextImpl lrcContext = new LrcContextImpl();
044            private ReqComponentInfo reqComponent1;
045            private ReqComponentInfo reqComponent2;
046            private ReqComponentInfo reqComponent3;
047            private ReqComponentInfo reqComponent4;
048            
049            private void setupReqComponent1() {
050                    reqComponent1 = new ReqComponentInfo();
051            List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
052            ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
053            reqCompField1.setType(ReqComponentFieldTypes.GRADE_KEY.getId());
054            reqCompField1.setValue("A");
055            reqCompFieldList.add(reqCompField1);
056            ReqCompFieldInfo reqCompField2 = new ReqCompFieldInfo();
057            reqCompField2.setType(ReqComponentFieldTypes.GRADE_TYPE_KEY.getId());
058            reqCompField2.setValue("kuali.resultComponent.grade.letter");
059            reqCompFieldList.add(reqCompField2);
060    
061                    reqComponent1.setReqCompFields(reqCompFieldList);
062            }
063            
064            private void setupReqComponent2() {
065                    reqComponent2 = new ReqComponentInfo();
066            List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
067            ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
068            reqCompField1.setType(ReqComponentFieldTypes.GRADE_KEY.getId());
069            reqCompField1.setValue(null);
070            reqCompFieldList.add(reqCompField1);
071            ReqCompFieldInfo reqCompField2 = new ReqCompFieldInfo();
072            reqCompField2.setType(ReqComponentFieldTypes.GRADE_TYPE_KEY.getId());
073            reqCompField2.setValue(null);
074            reqCompFieldList.add(reqCompField2);
075    
076                    reqComponent2.setReqCompFields(reqCompFieldList);
077            }
078            
079            private void setupReqComponent3() {
080                    reqComponent3 = new ReqComponentInfo();
081            List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
082            ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
083            reqCompField1.setType(ReqComponentFieldTypes.GRADE_TYPE_KEY.getId());
084            reqCompField1.setValue("kuali.resultComponent.grade.letter");
085            reqCompFieldList.add(reqCompField1);
086    
087                    reqComponent3.setReqCompFields(reqCompFieldList);
088            }
089            
090            private void setupReqComponent4() {
091                    reqComponent4 = new ReqComponentInfo();
092            List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
093            ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
094            reqCompField1.setType(ReqComponentFieldTypes.GRADE_KEY.getId());
095            reqCompField1.setValue("A");
096            reqCompFieldList.add(reqCompField1);
097    
098                    reqComponent4.setReqCompFields(reqCompFieldList);
099            }
100            
101            @Before
102            public void beforeMethod() {
103                    lrcContext.setLrcService(lrcService);
104                    setupReqComponent1();
105                    setupReqComponent2();
106                    setupReqComponent3();
107                    setupReqComponent4();
108            }
109    
110            @Test
111        public void testCreateContextMap() throws OperationFailedException {
112                    Map<String, Object> contextMap = lrcContext.createContextMap(reqComponent1);
113                    Assert.assertNotNull(contextMap);
114                    Assert.assertTrue(contextMap.containsKey(LrcContextImpl.GRADE_TOKEN));
115                    Assert.assertTrue(contextMap.containsKey(LrcContextImpl.GRADE_TYPE_TOKEN));
116        }
117    
118            @Test
119        public void testCreateContextMap_GradeTypeToken() throws OperationFailedException {
120                    Map<String, Object> contextMap = lrcContext.createContextMap(reqComponent3);
121                    Assert.assertNotNull(contextMap);
122                    Assert.assertTrue(contextMap.containsKey(LrcContextImpl.GRADE_TYPE_TOKEN));
123        }
124    
125            @Test
126        public void testCreateContextMap_GradeToken() throws OperationFailedException {
127                    Map<String, Object> contextMap = lrcContext.createContextMap(reqComponent4);
128                    Assert.assertNotNull(contextMap);
129                    Assert.assertTrue(contextMap.containsKey(LrcContextImpl.GRADE_TOKEN));
130        }
131    
132            @Test
133        public void testCreateContextMap_GradeTypeTokenValues() throws OperationFailedException {
134                    Map<String, Object> contextMap = lrcContext.createContextMap(reqComponent3);
135                    ResultComponentInfo gradeTypeId = (ResultComponentInfo) contextMap.get(LrcContextImpl.GRADE_TYPE_TOKEN);
136                    
137                    Assert.assertEquals("kuali.resultComponent.grade.letter", gradeTypeId.getId());
138        }
139    
140            @Test
141        public void testCreateContextMap_GradeTokenValues() throws OperationFailedException {
142                    Map<String, Object> contextMap = lrcContext.createContextMap(reqComponent4);
143                    ResultComponentInfo gradeTypeId = (ResultComponentInfo) contextMap.get(LrcContextImpl.GRADE_TYPE_TOKEN);
144                    String gradeId = (String) contextMap.get(LrcContextImpl.GRADE_TOKEN);
145                    
146                    Assert.assertEquals("kuali.resultComponent.grade.letter", gradeTypeId.getId());
147                    Assert.assertEquals("A", gradeId);
148        }
149    
150            @Test
151        public void testCreateContextMap_TokenValues() throws OperationFailedException {
152                    Map<String, Object> contextMap = lrcContext.createContextMap(reqComponent1);
153                    ResultComponentInfo gradeTypeId = (ResultComponentInfo) contextMap.get(LrcContextImpl.GRADE_TYPE_TOKEN);
154                    String gradeId = (String) contextMap.get(LrcContextImpl.GRADE_TOKEN);
155                    
156                    Assert.assertEquals("kuali.resultComponent.grade.letter", gradeTypeId.getId());
157                    Assert.assertEquals("A", gradeId);
158        }
159    
160            @Test
161        public void testCreateContextMap_NullTokenValues() throws OperationFailedException {
162                    Map<String, Object> contextMap = lrcContext.createContextMap(reqComponent2);
163                    ResultComponentInfo gradeTypeId = (ResultComponentInfo) contextMap.get(LrcContextImpl.GRADE_TYPE_TOKEN);
164                    String gradeId = (String) contextMap.get(LrcContextImpl.GRADE_TOKEN);
165                    
166                    Assert.assertEquals(null, gradeTypeId);
167                    Assert.assertEquals(null, gradeId);
168        }
169    
170            private static class LrcServiceMock implements LrcService {
171    
172                    private Map<String, ResultComponentInfo> resultComponentMap = new HashMap<String, ResultComponentInfo>();
173                    private List<ResultComponentTypeInfo> resultComponentTypeList = new ArrayList<ResultComponentTypeInfo>();
174                    private Map<String, List<String>> typeIdMap = new HashMap<String, List<String>>();
175                    
176                    public LrcServiceMock() {
177                            ResultComponentInfo rc1 = new ResultComponentInfo();
178                            rc1.setId("kuali.resultComponent.grade.letter");
179                            rc1.setName("Letter");
180                            rc1.setResultValues(Arrays.asList(new String[] {"A", "B", "C", "D", "F"}));
181                            resultComponentMap.put("kuali.resultComponent.grade.letter", rc1);
182    
183                            ResultComponentInfo rc2 = new ResultComponentInfo();
184                            rc2.setId("kuali.resultComponent.grade.passFail");
185                            rc2.setName("Pass-Fail");
186                            rc2.setResultValues(Arrays.asList(new String[] {"Pass", "Fail"}));
187                            resultComponentMap.put("kuali.resultComponent.grade.passFail", rc2);
188    
189                            ResultComponentTypeInfo type1 = new ResultComponentTypeInfo();
190                            type1.setId("kuali.resultComponentType.grade.finalGrade");
191                            type1.setName("Final Grade");
192                            resultComponentTypeList.add(type1);
193                            
194                            ResultComponentTypeInfo type2 = new ResultComponentTypeInfo();
195                            type2.setId("kuali.resultComponentType.credit.degree.fixed");
196                            type2.setName("Fixed Number");
197                            resultComponentTypeList.add(type2);
198                            
199                            typeIdMap.put("kuali.resultComponentType.grade.finalGrade", Arrays.asList(new String[] {"kuali.resultComponent.grade.letter", "kuali.resultComponent.grade.passFail"}));
200                    }
201    
202                    @Override
203                    public String compareGrades(String gradeKey, String scaleKey,
204                                    String compareGradeKey, String compareScaleKey)
205                                    throws InvalidParameterException, MissingParameterException,
206                                    OperationFailedException {
207                            // TODO Auto-generated method stub
208                            return null;
209                    }
210    
211                    @Override
212                    public ResultComponentInfo createResultComponent(
213                                    String resultComponentTypeKey,
214                                    ResultComponentInfo resultComponentInfo)
215                                    throws AlreadyExistsException, DataValidationErrorException,
216                                    DoesNotExistException, InvalidParameterException,
217                                    MissingParameterException, OperationFailedException,
218                                    PermissionDeniedException {
219                            // TODO Auto-generated method stub
220                            return null;
221                    }
222    
223                    @Override
224                    public StatusInfo deleteResultComponent(String resultComponentId)
225                                    throws DoesNotExistException, InvalidParameterException,
226                                    MissingParameterException, OperationFailedException,
227                                    PermissionDeniedException {
228                            // TODO Auto-generated method stub
229                            return null;
230                    }
231    
232                    @Override
233                    public CredentialInfo getCredential(String credentialKey)
234                                    throws DoesNotExistException, InvalidParameterException,
235                                    MissingParameterException, OperationFailedException {
236                            // TODO Auto-generated method stub
237                            return null;
238                    }
239    
240                    @Override
241                    public List<String> getCredentialKeysByCredentialType(
242                                    String credentialTypeKey) throws DoesNotExistException,
243                                    InvalidParameterException, MissingParameterException,
244                                    OperationFailedException {
245                            // TODO Auto-generated method stub
246                            return null;
247                    }
248    
249                    @Override
250                    public CredentialTypeInfo getCredentialType(String credentialTypeKey)
251                                    throws DoesNotExistException, InvalidParameterException,
252                                    MissingParameterException, OperationFailedException {
253                            // TODO Auto-generated method stub
254                            return null;
255                    }
256    
257                    @Override
258                    public List<CredentialTypeInfo> getCredentialTypes()
259                                    throws OperationFailedException {
260                            // TODO Auto-generated method stub
261                            return null;
262                    }
263    
264                    @Override
265                    public List<CredentialInfo> getCredentialsByKeyList(
266                                    List<String> credentialKeyList) throws DoesNotExistException,
267                                    InvalidParameterException, MissingParameterException,
268                                    OperationFailedException {
269                            // TODO Auto-generated method stub
270                            return null;
271                    }
272    
273                    @Override
274                    public CreditInfo getCredit(String creditKey)
275                                    throws DoesNotExistException, InvalidParameterException,
276                                    MissingParameterException, OperationFailedException {
277                            // TODO Auto-generated method stub
278                            return null;
279                    }
280    
281                    @Override
282                    public List<String> getCreditKeysByCreditType(String creditTypeKey)
283                                    throws DoesNotExistException, InvalidParameterException,
284                                    MissingParameterException, OperationFailedException {
285                            // TODO Auto-generated method stub
286                            return null;
287                    }
288    
289                    @Override
290                    public CreditTypeInfo getCreditType(String creditTypeKey)
291                                    throws DoesNotExistException, InvalidParameterException,
292                                    MissingParameterException, OperationFailedException {
293                            // TODO Auto-generated method stub
294                            return null;
295                    }
296    
297                    @Override
298                    public List<CreditTypeInfo> getCreditTypes()
299                                    throws OperationFailedException {
300                            // TODO Auto-generated method stub
301                            return null;
302                    }
303    
304                    @Override
305                    public List<CreditInfo> getCreditsByKeyList(List<String> creditKeyList)
306                                    throws DoesNotExistException, InvalidParameterException,
307                                    MissingParameterException, OperationFailedException {
308                            // TODO Auto-generated method stub
309                            return null;
310                    }
311    
312                    @Override
313                    public GradeInfo getGrade(String gradeKey)
314                                    throws DoesNotExistException, InvalidParameterException,
315                                    MissingParameterException, OperationFailedException {
316                            // TODO Auto-generated method stub
317                            return null;
318                    }
319    
320                    @Override
321                    public List<String> getGradeKeysByGradeType(String gradeTypeKey)
322                                    throws DoesNotExistException, InvalidParameterException,
323                                    MissingParameterException, OperationFailedException {
324                            // TODO Auto-generated method stub
325                            return null;
326                    }
327    
328                    @Override
329                    public GradeTypeInfo getGradeType(String gradeTypeKey)
330                                    throws DoesNotExistException, InvalidParameterException,
331                                    MissingParameterException, OperationFailedException {
332                            // TODO Auto-generated method stub
333                            return null;
334                    }
335    
336                    @Override
337                    public List<GradeTypeInfo> getGradeTypes()
338                                    throws OperationFailedException {
339                            // TODO Auto-generated method stub
340                            return null;
341                    }
342    
343                    @Override
344                    public List<GradeInfo> getGradesByKeyList(List<String> gradeKeyList)
345                                    throws DoesNotExistException, InvalidParameterException,
346                                    MissingParameterException, OperationFailedException {
347                            // TODO Auto-generated method stub
348                            return null;
349                    }
350    
351                    @Override
352                    public List<GradeInfo> getGradesByScale(String scale)
353                                    throws DoesNotExistException, InvalidParameterException,
354                                    MissingParameterException, OperationFailedException {
355                            // TODO Auto-generated method stub
356                            return null;
357                    }
358    
359                    @Override
360                    public ResultComponentInfo getResultComponent(String resultComponentId)
361                                    throws DoesNotExistException, InvalidParameterException,
362                                    MissingParameterException, OperationFailedException {
363                            return resultComponentMap.get(resultComponentId);
364                    }
365    
366                    @Override
367                    public List<String> getResultComponentIdsByResult(String resultValueId,
368                                    String resultComponentTypeKey) throws DoesNotExistException,
369                                    InvalidParameterException, MissingParameterException,
370                                    OperationFailedException {
371                            // TODO Auto-generated method stub
372                            return null;
373                    }
374    
375                    @Override
376                    public List<String> getResultComponentIdsByResultComponentType(
377                                    String resultComponentTypeKey) throws DoesNotExistException,
378                                    InvalidParameterException, MissingParameterException,
379                                    OperationFailedException {
380                            return typeIdMap.get(resultComponentTypeKey);
381                    }
382    
383                    @Override
384                    public ResultComponentTypeInfo getResultComponentType(
385                                    String resultComponentTypeKey) throws DoesNotExistException,
386                                    InvalidParameterException, MissingParameterException,
387                                    OperationFailedException {
388                            // TODO Auto-generated method stub
389                            return null;
390                    }
391    
392                    @Override
393                    public List<ResultComponentTypeInfo> getResultComponentTypes()
394                                    throws OperationFailedException {
395                            return this.resultComponentTypeList;
396                    }
397    
398                    @Override
399                    public ScaleInfo getScale(String scaleKey)
400                                    throws DoesNotExistException, InvalidParameterException,
401                                    MissingParameterException, OperationFailedException {
402                            // TODO Auto-generated method stub
403                            return null;
404                    }
405    
406                    @Override
407                    public List<GradeInfo> translateGrade(String gradeKey, String scaleKey,
408                                    String translateScaleKey) throws InvalidParameterException,
409                                    MissingParameterException, OperationFailedException {
410                            // TODO Auto-generated method stub
411                            return null;
412                    }
413    
414                    @Override
415                    public ResultComponentInfo updateResultComponent(
416                                    String resultComponentId,
417                                    ResultComponentInfo resultComponentInfo)
418                                    throws DataValidationErrorException, DoesNotExistException,
419                                    InvalidParameterException, MissingParameterException,
420                                    OperationFailedException, PermissionDeniedException,
421                                    VersionMismatchException {
422                            // TODO Auto-generated method stub
423                            return null;
424                    }
425    
426                    @Override
427                    public SearchCriteriaTypeInfo getSearchCriteriaType(
428                                    String searchCriteriaTypeKey) throws DoesNotExistException,
429                                    InvalidParameterException, MissingParameterException,
430                                    OperationFailedException {
431                            // TODO Auto-generated method stub
432                            return null;
433                    }
434    
435                    @Override
436                    public List<SearchCriteriaTypeInfo> getSearchCriteriaTypes()
437                                    throws OperationFailedException {
438                            // TODO Auto-generated method stub
439                            return null;
440                    }
441    
442                    @Override
443                    public SearchResultTypeInfo getSearchResultType(
444                                    String searchResultTypeKey) throws DoesNotExistException,
445                                    InvalidParameterException, MissingParameterException,
446                                    OperationFailedException {
447                            // TODO Auto-generated method stub
448                            return null;
449                    }
450    
451                    @Override
452                    public List<SearchResultTypeInfo> getSearchResultTypes()
453                                    throws OperationFailedException {
454                            // TODO Auto-generated method stub
455                            return null;
456                    }
457    
458                    @Override
459                    public SearchTypeInfo getSearchType(String searchTypeKey)
460                                    throws DoesNotExistException, InvalidParameterException,
461                                    MissingParameterException, OperationFailedException {
462                            // TODO Auto-generated method stub
463                            return null;
464                    }
465    
466                    @Override
467                    public List<SearchTypeInfo> getSearchTypes()
468                                    throws OperationFailedException {
469                            // TODO Auto-generated method stub
470                            return null;
471                    }
472    
473                    @Override
474                    public List<SearchTypeInfo> getSearchTypesByCriteria(
475                                    String searchCriteriaTypeKey) throws DoesNotExistException,
476                                    InvalidParameterException, MissingParameterException,
477                                    OperationFailedException {
478                            // TODO Auto-generated method stub
479                            return null;
480                    }
481    
482                    @Override
483                    public List<SearchTypeInfo> getSearchTypesByResult(
484                                    String searchResultTypeKey) throws DoesNotExistException,
485                                    InvalidParameterException, MissingParameterException,
486                                    OperationFailedException {
487                            // TODO Auto-generated method stub
488                            return null;
489                    }
490    
491                    @Override
492                    public SearchResult search(SearchRequest searchRequest)
493                                    throws MissingParameterException {
494                            // TODO Auto-generated method stub
495                            return null;
496                    }
497    
498            @Override
499            public ObjectStructureDefinition getObjectStructure(String objectTypeKey) {
500                // TODO Kamal - THIS METHOD NEEDS JAVADOCS
501                return null;
502            }
503    
504            @Override
505            public List<String> getObjectTypes() {
506                // TODO Kamal - THIS METHOD NEEDS JAVADOCS
507                return null;
508            }
509                    
510            }
511    }