View Javadoc
1   package org.kuali.student.ap.coursesearch.util;
2   
3   import org.junit.Test;
4   import org.kuali.student.ap.coursesearch.CourseSearchItem;
5   import org.kuali.student.ap.coursesearch.dataobject.CourseSearchItemImpl;
6   import org.kuali.student.ap.coursesearch.dataobject.FacetItem;
7   
8   import static org.junit.Assert.assertEquals;
9   import static org.junit.Assert.assertTrue;
10  
11  import java.math.BigDecimal;
12  import java.util.ArrayList;
13  import java.util.List;
14  
15  
16  public class CreditsFacetTest {
17      @Test
18      public void testGetFacetItems() throws Exception {
19          CreditsFacet facet = new CreditsFacet();
20  
21          CourseSearchItemImpl multiple = new CourseSearchItemImpl();
22          multiple.setCreditMin(1);
23          multiple.setCreditMax(3);
24          List<BigDecimal> multipleCredits = new ArrayList<BigDecimal>();
25          multipleCredits.add(new BigDecimal(1.0));
26          multipleCredits.add(new BigDecimal(3.0));
27          multiple.setMultipleCredits(multipleCredits);
28          multiple.setCreditType(CourseSearchItem.CreditType.MULTIPLE);
29          facet.process(multiple);
30  
31          CourseSearchItemImpl range = new CourseSearchItemImpl();
32          range.setCreditMin(4);
33          range.setCreditMax(6);
34          range.setCreditType(CourseSearchItem.CreditType.RANGE);
35          facet.process(range);
36  
37          CourseSearchItemImpl fixed = new CourseSearchItemImpl();
38          fixed.setCreditMin(7);
39          fixed.setCreditMax(7);
40          fixed.setCreditType(CourseSearchItem.CreditType.FIXED);
41          facet.process(fixed);
42  
43          List<FacetItem> list = facet.getFacetItems();
44  
45          assertEquals(6, list.size());
46          assertEquals("5", list.get( 3 ).getDisplayName());
47          assertEquals("5.0", list.get( 3 ).getKey());
48      }
49  
50      @Test
51      public void testProcessCreditsTypeMultiple() throws Exception {
52          CourseSearchItemImpl course = new CourseSearchItemImpl();
53  //        course.setCreditMin(1);
54  //        course.setCreditMax(3);
55          course.setCredit("1, 3");
56          List<BigDecimal> multipleCredits = new ArrayList<BigDecimal>();
57          multipleCredits.add(new BigDecimal(1.0));
58          multipleCredits.add(new BigDecimal(3.0));
59          course.setMultipleCredits(multipleCredits);
60          course.setCreditType(CourseSearchItem.CreditType.MULTIPLE);
61  
62          CreditsFacet facet = new CreditsFacet();
63          facet.process(course);
64          assertTrue(course.getCreditsFacetKeys().contains("1.0"));
65          assertTrue(course.getCreditsFacetKeys().contains("3.0"));
66          assertTrue(course.getCreditsFacetKeys().size() == 2);
67      }
68  
69      @Test
70      public void testProcessCreditsTypeMultiple2() throws Exception {
71          CourseSearchItemImpl course = new CourseSearchItemImpl();
72  //        course.setCreditMin(1);
73  //        course.setCreditMax(3);
74          course.setCredit("1, 3, 3.5");
75          List<BigDecimal> multipleCredits = new ArrayList<BigDecimal>();
76          multipleCredits.add(new BigDecimal(1.0));
77          multipleCredits.add(new BigDecimal(3.0));
78          multipleCredits.add(new BigDecimal(3.5));
79          course.setMultipleCredits(multipleCredits);
80          course.setCreditType(CourseSearchItem.CreditType.MULTIPLE);
81  
82          CreditsFacet facet = new CreditsFacet();
83          facet.process(course);
84          assertTrue(course.getCreditsFacetKeys().contains("1.0"));
85          assertTrue(course.getCreditsFacetKeys().contains("3.0"));
86          assertTrue(course.getCreditsFacetKeys().contains("3.5"));
87          assertTrue(course.getCreditsFacetKeys().size() == 3);
88      }
89  
90      @Test
91      public void testProcessCreditsTypeMultipleAboveMax() throws Exception {
92          CourseSearchItemImpl course = new CourseSearchItemImpl();
93  //        course.setCreditMin(1);
94  //        course.setCreditMax(3);
95          course.setCredit("1, 3, 3.5, 5.5, 6, 7, 7.5");
96          List<BigDecimal> multipleCredits = new ArrayList<BigDecimal>();
97          multipleCredits.add(new BigDecimal(1.0));
98          multipleCredits.add(new BigDecimal(3.0));
99          multipleCredits.add(new BigDecimal(3.5));
100         multipleCredits.add(new BigDecimal(5.5));
101         multipleCredits.add(new BigDecimal(6.0));
102         multipleCredits.add(new BigDecimal(7.0));
103         multipleCredits.add(new BigDecimal(7.5));
104         course.setMultipleCredits(multipleCredits);
105         course.setCreditType(CourseSearchItem.CreditType.MULTIPLE);
106 
107         CreditsFacet facet = new CreditsFacet();
108         facet.process(course);
109         assertTrue(course.getCreditsFacetKeys().contains("1.0"));
110         assertTrue(course.getCreditsFacetKeys().contains("3.0"));
111         assertTrue(course.getCreditsFacetKeys().contains("3.5"));
112         assertTrue(course.getCreditsFacetKeys().contains("5.5"));
113         assertTrue(!course.getCreditsFacetKeys().contains("6.0"));
114         assertTrue(course.getCreditsFacetKeys().contains("6+"));
115         assertEquals(5, course.getCreditsFacetKeys().size());
116     }
117 
118     @Test
119     public void testProcessCreditsTypeRange() throws Exception {
120         CourseSearchItemImpl course = new CourseSearchItemImpl();
121         course.setCreditMin(1);
122         course.setCreditMax(3);
123         course.setCreditType(CourseSearchItem.CreditType.RANGE);
124 
125         CreditsFacet facet = new CreditsFacet();
126         facet.process(course);
127         assertTrue(course.getCreditsFacetKeys().contains("1.0"));
128         assertTrue(course.getCreditsFacetKeys().contains("2.0"));
129         assertTrue(course.getCreditsFacetKeys().contains("3.0"));
130         assertTrue(course.getCreditsFacetKeys().size() == 3);
131     }
132 
133     @Test
134     public void testProcessCreditsTypeRangeAboveMax() throws Exception {
135         CourseSearchItemImpl course = new CourseSearchItemImpl();
136         course.setCreditMin(4);
137         course.setCreditMax(7);
138         course.setCreditType(CourseSearchItem.CreditType.RANGE);
139 
140         CreditsFacet facet = new CreditsFacet();
141         facet.process(course);
142         assertTrue(course.getCreditsFacetKeys().contains("4.0"));
143         assertTrue(course.getCreditsFacetKeys().contains("5.0"));
144         assertTrue(course.getCreditsFacetKeys().contains("6+"));
145         assertEquals(3, course.getCreditsFacetKeys().size());
146     }
147 
148     @Test
149     public void testProcessCreditsTypeFixed() throws Exception {
150         CourseSearchItemImpl course = new CourseSearchItemImpl();
151         course.setCreditMin(1);
152         course.setCreditMax(1);
153         course.setCreditType(CourseSearchItem.CreditType.FIXED);
154 
155         CreditsFacet facet = new CreditsFacet();
156         facet.process(course);
157         assertEquals("1.0", course.getCreditsFacetKey());
158     }
159 
160     @Test
161     public void testProcessCreditsTypeFixedAboveMax() throws Exception {
162         CourseSearchItemImpl course = new CourseSearchItemImpl();
163         course.setCreditMin(9);
164         course.setCreditMax(9);
165         course.setCreditType(CourseSearchItem.CreditType.FIXED);
166 
167         CreditsFacet facet = new CreditsFacet();
168         facet.process(course);
169         assertEquals("6+", course.getCreditsFacetKey());
170     }
171 }