Clover Coverage Report - Kuali Student 1.2-M3-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Jun 6 2011 05:02:46 EDT
108   312   29   4.32
2   239   0.27   12.5
25     1.16  
2    
 
  TestValidator       Line # 26 94 0% 16 0 100% 1.0
  TestValidator.MockSearchService       Line # 211 14 0% 13 23 8% 0.08
 
  (9)
 
1    package org.kuali.student.common.validator;
2   
3    import static org.junit.Assert.assertEquals;
4   
5    import java.util.List;
6   
7    import org.junit.Before;
8    import org.junit.Test;
9    import org.kuali.student.common.dictionary.dto.ObjectStructureDefinition;
10    import org.kuali.student.common.dictionary.service.impl.DictionaryServiceImpl;
11    import org.kuali.student.common.exceptions.DoesNotExistException;
12    import org.kuali.student.common.exceptions.InvalidParameterException;
13    import org.kuali.student.common.exceptions.MissingParameterException;
14    import org.kuali.student.common.exceptions.OperationFailedException;
15    import org.kuali.student.common.search.dto.SearchCriteriaTypeInfo;
16    import org.kuali.student.common.search.dto.SearchRequest;
17    import org.kuali.student.common.search.dto.SearchResult;
18    import org.kuali.student.common.search.dto.SearchResultRow;
19    import org.kuali.student.common.search.dto.SearchResultTypeInfo;
20    import org.kuali.student.common.search.dto.SearchTypeInfo;
21    import org.kuali.student.common.search.service.SearchDispatcher;
22    import org.kuali.student.common.search.service.SearchService;
23    import org.kuali.student.common.search.service.impl.SearchDispatcherImpl;
24    import org.kuali.student.common.validation.dto.ValidationResultInfo;
25   
 
26    public class TestValidator {
27    DefaultValidatorImpl val = null;
28    ValidatorFactory valFactory = new ValidatorFactory();
29    DictionaryServiceImpl dictionaryDelegate = new DictionaryServiceImpl(
30    "classpath:test-validator-context.xml");
31   
 
32  9 toggle @Before
33    public void init() {
34   
35  9 val = new DefaultValidatorImpl();
36  9 val.setDateParser(new ServerDateParser());
37  9 val.setMessageService(null);
38  9 valFactory.setDefaultValidator(val);
39   
40    }
41   
 
42  1 toggle @Test
43    public void testRequired() {
44   
45  1 List<ValidationResultInfo> results = val.validateObject(buildTestPerson1(), getSimpleStudentObjectStructure());
46  1 assertEquals(results.size(), 1);
47   
48  1 assertEquals(results.get(0).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
49  1 assertEquals(results.get(0).getMessage(), "validation.required");
50    }
51   
 
52  1 toggle @Test
53    public void testLengthRange() {
54   
55  1 ConstraintMockPerson p = buildTestPerson1();
56  1 p.setFirstName("thisisaveryveryverylo");
57   
58  1 List<ValidationResultInfo> results = val.validateObject(p, getSimpleStudentObjectStructure());
59  1 assertEquals(results.size(), 2);
60   
61  1 assertEquals(results.get(0).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
62  1 assertEquals(results.get(0).getMessage(), "validation.lengthOutOfRange");
63    }
64   
 
65  1 toggle @Test
66    public void testMinLength() {
67   
68  1 ConstraintMockPerson p = buildTestPerson1();
69  1 p.setFirstName("t");
70   
71  1 ObjectStructureDefinition o1 = getSimpleStudentObjectStructure();
72  1 o1.getAttributes().get(0).setMaxLength(null);
73   
74  1 List<ValidationResultInfo> results = val.validateObject(p, o1);
75  1 assertEquals(results.size(), 2);
76   
77  1 assertEquals(results.get(0).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
78  1 assertEquals(results.get(0).getMessage(), "validation.minLengthFailed");
79    }
80   
 
81  1 toggle @Test
82    public void testMinDateValue() {
83  1 ConstraintMockPerson p = buildTestPerson1();
84  1 ServerDateParser sp = new ServerDateParser();
85  1 p.setDob(sp.parseDate("1960-01-01"));
86  1 ObjectStructureDefinition o1 = getSimpleStudentObjectStructure();
87   
88  1 List<ValidationResultInfo> results = val.validateObject(p, o1);
89  1 assertEquals(results.size(), 1);
90   
91  1 assertEquals(results.get(0).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
92  1 assertEquals(results.get(0).getMessage(), "validation.minValueFailed");
93    }
94   
 
95  1 toggle @Test
96    public void testMaxLength() {
97   
98  1 ConstraintMockPerson p = buildTestPerson1();
99  1 p.setFirstName("thisisaveryveryverylo");
100   
101  1 ObjectStructureDefinition o1 = getSimpleStudentObjectStructure();
102  1 o1.getAttributes().get(0).setMinLength(0);
103   
104  1 List<ValidationResultInfo> results = val.validateObject(p, o1);
105  1 assertEquals(results.size(), 2);
106   
107  1 assertEquals(results.get(0).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
108  1 assertEquals(results.get(0).getMessage(), "validation.maxLengthFailed");
109    }
110   
 
111  1 toggle @Test
112    public void testValidChars() {
113   
114  1 ConstraintMockPerson p = buildTestPerson1();
115  1 p.setFirstName("in$#valid");
116   
117  1 ObjectStructureDefinition o1 = getSimpleStudentObjectStructure();
118   
119  1 List<ValidationResultInfo> results = val.validateObject(p, o1);
120  1 assertEquals(results.size(), 2);
121   
122  1 assertEquals(results.get(0).getErrorLevel(),
123    ValidationResultInfo.ErrorLevel.ERROR);
124  1 assertEquals(results.get(0).getMessage(), "validation.validCharsFailed");
125    }
126   
 
127  1 toggle @Test
128    public void testDoubleValueRange() {
129   
130  1 ConstraintMockPerson p = buildTestPerson2();
131  1 p.setGpa(5.0);
132   
133  1 ObjectStructureDefinition o1 = getSimpleStudentObjectStructure();
134   
135  1 List<ValidationResultInfo> results = val.validateObject(p, o1);
136  1 assertEquals(results.size(), 1);
137   
138  1 assertEquals(results.get(0).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
139  1 assertEquals(results.get(0).getMessage(), "validation.outOfRange");
140    }
141   
 
142  1 toggle @Test
143    public void testNestedCaseConstraint() {
144   
145  1 ConstraintMockPerson p = buildTestPerson4();
146   
147  1 ObjectStructureDefinition o1 = getStudentWithAddressObjectStructure();
148   
149  1 List<ValidationResultInfo> results = val.validateObject(p, o1);
150  1 assertEquals(2, results.size());
151   
152  1 p.getAddress().get(0).setState("ACTIVE");
153  1 results = val.validateObject(p, o1);
154   
155  1 assertEquals(4, results.size());
156    }
157   
158   
 
159  1 toggle @Test
160    public void testNestedStructures() {
161  1 ConstraintMockPerson p = buildTestPerson3();
162   
163  1 ObjectStructureDefinition o = getStudentWithAddressObjectStructure();
164   
165  1 List<ValidationResultInfo> results = val.validateObject(p, o);
166    // ERROR address/0/line1 validation.required
167    // ERROR address/0/line2 validation.validCharsFailed
168    // ERROR address/0/line2 validation.requiresField
169  1 System.out.println(results.size() + " errors found");
170  1 for (ValidationResultInfo vri : results) {
171  4 System.out.println(vri.getErrorLevel() + " " + vri.getElement()
172    + " " + vri.getMessage());
173    }
174  1 assertEquals(4, results.size());
175   
176  1 assertEquals(results.get(0).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
177  1 assertEquals(results.get(0).getMessage(), "validation.required");
178   
179  1 assertEquals(results.get(1).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
180  1 assertEquals(results.get(1).getMessage(), "validation.validCharsFailed");
181   
182  1 assertEquals(results.get(2).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
183  1 assertEquals(results.get(2).getMessage(), "validation.requiresField");
184   
185  1 SearchDispatcher searchDispatcher = new SearchDispatcherImpl(
186    new MockSearchService());
187   
188  1 val.setSearchDispatcher(searchDispatcher);
189  1 p.getAddress().get(0).setLine1("something");
190  1 results = val.validateObject(p, o);
191  1 System.out.println(results.size() + " errors found");
192  1 for (ValidationResultInfo vri : results) {
193  3 System.out.println(vri.getErrorLevel() + " " + vri.getElement()
194    + " " + vri.getMessage());
195    }
196  1 assertEquals(3, results.size());
197   
198  1 p.getAddress().get(0).setLine2("notrightlookupvalue");
199  1 results = val.validateObject(p, o);
200  1 System.out.println(results.size() + " errors found");
201  1 for (ValidationResultInfo vri : results) {
202  2 System.out.println(vri.getErrorLevel() + " " + vri.getElement()
203    + " " + vri.getMessage());
204    }
205  1 assertEquals(2, results.size());
206  1 assertEquals(results.get(0).getErrorLevel(),
207    ValidationResultInfo.ErrorLevel.ERROR);
208  1 assertEquals(results.get(0).getMessage(), "validation.lookup");
209    }
210   
 
211    public class MockSearchService implements SearchService {
212   
 
213  0 toggle @Override
214    public SearchCriteriaTypeInfo getSearchCriteriaType(
215    String searchCriteriaTypeKey) throws DoesNotExistException,
216    InvalidParameterException, MissingParameterException,
217    OperationFailedException {
218  0 return null;
219    }
220   
 
221  0 toggle @Override
222    public List<SearchCriteriaTypeInfo> getSearchCriteriaTypes()
223    throws OperationFailedException {
224  0 return null;
225    }
226   
 
227  0 toggle @Override
228    public SearchResultTypeInfo getSearchResultType(
229    String searchResultTypeKey) throws DoesNotExistException,
230    InvalidParameterException, MissingParameterException,
231    OperationFailedException {
232  0 return null;
233    }
234   
 
235  0 toggle @Override
236    public List<SearchResultTypeInfo> getSearchResultTypes()
237    throws OperationFailedException {
238  0 return null;
239    }
240   
 
241  0 toggle @Override
242    public SearchTypeInfo getSearchType(String searchTypeKey)
243    throws DoesNotExistException, InvalidParameterException,
244    MissingParameterException, OperationFailedException {
245  0 return null;
246    }
247   
 
248  1 toggle @Override
249    public List<SearchTypeInfo> getSearchTypes()
250    throws OperationFailedException {
251  1 return null;
252    }
253   
 
254  0 toggle @Override
255    public List<SearchTypeInfo> getSearchTypesByCriteria(
256    String searchCriteriaTypeKey) throws DoesNotExistException,
257    InvalidParameterException, MissingParameterException,
258    OperationFailedException {
259  0 return null;
260    }
261   
 
262  0 toggle @Override
263    public List<SearchTypeInfo> getSearchTypesByResult(
264    String searchResultTypeKey) throws DoesNotExistException,
265    InvalidParameterException, MissingParameterException,
266    OperationFailedException {
267  0 return null;
268    }
269   
 
270  0 toggle @Override
271    public SearchResult search(SearchRequest searchRequest)
272    throws MissingParameterException {
273  0 if (searchRequest != null
274    && searchRequest.getParams() != null
275    && "param1".equals(searchRequest.getParams().get(0)
276    .getKey())
277    && "line2value".equals(searchRequest.getParams().get(0)
278    .getValue())) {
279  0 SearchResult result = new SearchResult();
280  0 SearchResultRow row = new SearchResultRow();
281  0 result.getRows().add(row);
282  0 return result;
283    }
284  0 return null;
285    }
286   
287    }
288   
 
289  6 toggle public ConstraintMockPerson buildTestPerson1() {
290  6 return ValidatorMockObjectGenerator.buildTestPerson1();
291    }
292   
 
293  1 toggle public ConstraintMockPerson buildTestPerson2() {
294  1 return ValidatorMockObjectGenerator.buildTestPerson2();
295    }
296   
 
297  1 toggle public ConstraintMockPerson buildTestPerson3() {
298  1 return ValidatorMockObjectGenerator.buildTestPerson3();
299    }
300   
 
301  1 toggle public ConstraintMockPerson buildTestPerson4() {
302  1 return ValidatorMockObjectGenerator.buildTestPerson4();
303    }
304   
 
305  7 toggle public ObjectStructureDefinition getSimpleStudentObjectStructure() {
306  7 return dictionaryDelegate.getObjectStructure("simpleStudent");
307    }
308   
 
309  2 toggle public ObjectStructureDefinition getStudentWithAddressObjectStructure() {
310  2 return dictionaryDelegate.getObjectStructure("studentWithAddress");
311    }
312    }