View Javadoc

1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   package org.kuali.student.enrollment.class1.lpr.service.impl;
6   
7   import org.kuali.student.common.test.util.IdEntityTester;
8   import org.kuali.student.common.test.util.ListOfStringTester;
9   import org.kuali.student.enrollment.lpr.dto.LprTransactionItemInfo;
10  import org.kuali.student.r2.common.util.constants.LprServiceConstants;
11  
12  import java.util.ArrayList;
13  import java.util.Collections;
14  import java.util.Comparator;
15  import java.util.List;
16  
17  import static org.junit.Assert.assertEquals;
18  
19  /**
20   * Helps create a dynamic 
21   * @author nwright
22   */
23  public class LprTransactionItemTester {
24  
25      public void add2ForCreate(List<LprTransactionItemInfo> expected) {
26          LprTransactionItemInfo item = new LprTransactionItemInfo();
27          item.setTypeKey(LprServiceConstants.LPRTRANS_ITEM_ADD_TYPE_KEY);
28          item.setStateKey(LprServiceConstants.LPRTRANS_ITEM_NEW_STATE_KEY);
29          item.setNewLuiId("Luiid1");
30          item.setPersonId("person1");
31          expected.add(item);
32          item = new LprTransactionItemInfo();
33          item.setTypeKey(LprServiceConstants.LPRTRANS_ITEM_ADD_TYPE_KEY);
34          item.setStateKey(LprServiceConstants.LPRTRANS_ITEM_NEW_STATE_KEY);
35          item.setNewLuiId("Luiid2");
36          item.setPersonId("person1");
37          expected.add(item);
38      }
39  
40      public List<LprTransactionItemInfo> findItem(List<LprTransactionItemInfo> items, String id) {
41          List<LprTransactionItemInfo> list = new ArrayList<LprTransactionItemInfo>();
42          for (LprTransactionItemInfo actual : items) {
43              if (id.equals(actual.getId())) {
44                  list.add(actual);
45              }
46          }
47          return list;
48      }
49  
50      
51      public void check(List<LprTransactionItemInfo> expectedList, List<LprTransactionItemInfo> actualList) {
52          if (expectedList.size() != actualList.size()) {
53              this.dump(expectedList, actualList);
54          }
55          assertEquals(expectedList.size(), actualList.size());
56          List<LprTransactionItemInfo> expectedSorted = new ArrayList<LprTransactionItemInfo>(expectedList);
57         Collections.sort(expectedSorted, new LprTransactionItemInfoComparator());
58          List<LprTransactionItemInfo> actualSorted = new ArrayList<LprTransactionItemInfo>(actualList);
59         Collections.sort(actualSorted, new LprTransactionItemInfoComparator());
60          for (int i = 0; i < expectedSorted.size(); i++) {
61              LprTransactionItemInfo expected = expectedSorted.get(i);
62              LprTransactionItemInfo actual = actualSorted.get(i);
63              if (expected.getId() != null) {
64                  assertEquals(i + "", expected.getId(), actual.getId());
65              }
66              new IdEntityTester().check(expected, actual);
67              assertEquals(expected.getPersonId(), actual.getPersonId());
68              assertEquals(expected.getNewLuiId(), actual.getNewLuiId());
69              assertEquals(expected.getExistingLuiId(), actual.getExistingLuiId());
70              new ListOfStringTester().check(expected.getResultValuesGroupKeys(), actual.getResultValuesGroupKeys());
71              new LprTransactionItemResultTester ().check(expected.getLprTransactionItemResult(), actual.getLprTransactionItemResult());
72          }
73      }
74  
75      public void dump(List<LprTransactionItemInfo> expectedList, List<LprTransactionItemInfo> actualList) {
76          System.out.println("Original List");
77          this.dump(expectedList);
78          System.out.println("Updated List");
79          this.dump(actualList);
80      }
81  
82      public void dump(List<LprTransactionItemInfo> list) {
83          for (int i = 0; i < list.size(); i++) {
84              LprTransactionItemInfo expected = list.get(i);
85              System.out.println(i + ".) " + expected.getId() + "=" + expected.getExistingLuiId() + "\t" + expected.getNewLuiId());
86          }
87      }
88  
89      private static class LprTransactionItemInfoComparator implements Comparator<LprTransactionItemInfo> {
90  
91          @Override
92          public int compare(LprTransactionItemInfo o1, LprTransactionItemInfo o2) {
93          	
94          	String k1 = o1.getNewLuiId();
95          	String k2 = o2.getNewLuiId();
96          	
97              return k1.compareTo(k2);
98          }
99  
100     }
101 }