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