Clover Coverage Report - KS Common 1.3.0-SNAPSHOT (Aggregated)
Coverage timestamp: Thu Apr 28 2011 06:00:36 EDT
99   291   27   4.3
2   219   0.27   11.5
23     1.17  
2    
 
  TestValidator       Line # 26 85 0% 14 99 0% 0.0
  TestValidator.MockSearchService       Line # 194 14 0% 13 25 0% 0.0
 
No Tests
 
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("classpath:test-validator-context.xml");
30   
 
31  0 toggle @Before
32    public void init() {
33   
34  0 val = new DefaultValidatorImpl();
35  0 val.setDateParser(new ServerDateParser());
36  0 val.setMessageService(null);
37  0 valFactory.setDefaultValidator(val);
38   
39    }
40   
 
41  0 toggle @Test
42    public void testRequired() {
43   
44  0 List<ValidationResultInfo> results = val.validateObject( buildTestPerson1(), getSimpleStudentObjectStructure());
45  0 assertEquals(results.size(), 1);
46   
47  0 assertEquals(results.get(0).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
48  0 assertEquals(results.get(0).getMessage(), "validation.required");
49    }
50   
51   
 
52  0 toggle @Test
53    public void testLengthRange() {
54   
55  0 ConstraintMockPerson p = buildTestPerson1();
56  0 p.setFirstName("thisisaveryveryverylo");
57   
58  0 List<ValidationResultInfo> results = val.validateObject( p, getSimpleStudentObjectStructure());
59  0 assertEquals(results.size(), 2);
60   
61  0 assertEquals(results.get(0).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
62  0 assertEquals(results.get(0).getMessage(), "validation.lengthOutOfRange");
63    }
64   
 
65  0 toggle @Test
66    public void testMinLength() {
67   
68  0 ConstraintMockPerson p = buildTestPerson1();
69  0 p.setFirstName("t");
70   
71  0 ObjectStructureDefinition o1 = getSimpleStudentObjectStructure();
72  0 o1.getAttributes().get(0).setMaxLength(null);
73   
74  0 List<ValidationResultInfo> results = val.validateObject( p, o1);
75  0 assertEquals(results.size(), 2);
76   
77  0 assertEquals(results.get(0).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
78  0 assertEquals(results.get(0).getMessage(), "validation.minLengthFailed");
79    }
80   
81   
 
82  0 toggle @Test
83    public void testMinDateValue() {
84  0 ConstraintMockPerson p = buildTestPerson1();
85  0 ServerDateParser sp = new ServerDateParser();
86  0 p.setDob(sp.parseDate("1960-01-01"));
87  0 ObjectStructureDefinition o1 = getSimpleStudentObjectStructure();
88   
89  0 List<ValidationResultInfo> results = val.validateObject( p, o1);
90  0 assertEquals(results.size(), 1);
91   
92  0 assertEquals(results.get(0).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
93  0 assertEquals(results.get(0).getMessage(), "validation.minValueFailed");
94    }
95   
 
96  0 toggle @Test
97    public void testMaxLength() {
98   
99  0 ConstraintMockPerson p = buildTestPerson1();
100  0 p.setFirstName("thisisaveryveryverylo");
101   
102  0 ObjectStructureDefinition o1 = getSimpleStudentObjectStructure();
103  0 o1.getAttributes().get(0).setMinLength(0);
104   
105  0 List<ValidationResultInfo> results = val.validateObject( p, o1);
106  0 assertEquals(results.size(), 2);
107   
108  0 assertEquals(results.get(0).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
109  0 assertEquals(results.get(0).getMessage(), "validation.maxLengthFailed");
110    }
111   
 
112  0 toggle @Test
113    public void testValidChars() {
114   
115  0 ConstraintMockPerson p = buildTestPerson1();
116  0 p.setFirstName("in$#valid");
117   
118  0 ObjectStructureDefinition o1 = getSimpleStudentObjectStructure();
119   
120  0 List<ValidationResultInfo> results = val.validateObject( p, o1);
121  0 assertEquals(results.size(), 2);
122   
123  0 assertEquals(results.get(0).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
124  0 assertEquals(results.get(0).getMessage(), "validation.validCharsFailed");
125    }
126   
127   
 
128  0 toggle @Test
129    public void testDoubleValueRange() {
130   
131  0 ConstraintMockPerson p = buildTestPerson2();
132  0 p.setGpa(5.0);
133   
134  0 ObjectStructureDefinition o1 = getSimpleStudentObjectStructure();
135   
136  0 List<ValidationResultInfo> results = val.validateObject( p, o1);
137  0 assertEquals(results.size(), 1);
138   
139  0 assertEquals(results.get(0).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
140  0 assertEquals(results.get(0).getMessage(), "validation.outOfRange");
141    }
142   
 
143  0 toggle @Test
144    public void testNestedStructures() {
145  0 ConstraintMockPerson p = buildTestPerson3();
146   
147  0 ObjectStructureDefinition o = getStudentWithAddressObjectStructure();
148   
149  0 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  0 System.out.println (results.size () + " errors found");
158  0 for (ValidationResultInfo vri : results)
159    {
160  0 System.out.println (vri.getErrorLevel () + " " + vri.getElement () + " " + vri.getMessage ());
161    }
162  0 assertEquals(7, results.size());
163   
164  0 assertEquals(results.get(0).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
165  0 assertEquals(results.get(0).getMessage(), "validation.required");
166   
167  0 assertEquals(results.get(1).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
168  0 assertEquals(results.get(1).getMessage(), "validation.validCharsFailed");
169  0 assertEquals(results.get(2).getMessage(), "validation.requiresField");
170  0 SearchDispatcher searchDispatcher= new SearchDispatcherImpl(new MockSearchService());
171   
172  0 val.setSearchDispatcher(searchDispatcher);
173  0 p.getAddress().get(0).setLine1("something");
174  0 results = val.validateObject( p, o);
175  0 System.out.println (results.size () + " errors found");
176  0 for (ValidationResultInfo vri : results)
177    {
178  0 System.out.println (vri.getErrorLevel () + " " + vri.getElement () + " " + vri.getMessage ());
179    }
180  0 assertEquals(6, results.size());
181   
182  0 p.getAddress().get(0).setLine2("notrightlookupvalue");
183  0 results = val.validateObject( p, o);
184  0 System.out.println (results.size () + " errors found");
185  0 for (ValidationResultInfo vri : results)
186    {
187  0 System.out.println (vri.getErrorLevel () + " " + vri.getElement () + " " + vri.getMessage ());
188    }
189  0 assertEquals(5, results.size());
190  0 assertEquals(results.get(0).getErrorLevel(), ValidationResultInfo.ErrorLevel.ERROR);
191  0 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  0 toggle @Override
232    public List<SearchTypeInfo> getSearchTypes()
233    throws OperationFailedException {
234  0 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  0 toggle public ConstraintMockPerson buildTestPerson1() {
271  0 return ValidatorMockObjectGenerator.buildTestPerson1();
272    }
273   
274   
 
275  0 toggle public ConstraintMockPerson buildTestPerson2() {
276  0 return ValidatorMockObjectGenerator.buildTestPerson2();
277    }
278   
279   
 
280  0 toggle public ConstraintMockPerson buildTestPerson3() {
281  0 return ValidatorMockObjectGenerator.buildTestPerson3();
282    }
283   
 
284  0 toggle public ObjectStructureDefinition getSimpleStudentObjectStructure() {
285  0 return dictionaryDelegate.getObjectStructure("simpleStudent");
286    }
287   
 
288  0 toggle public ObjectStructureDefinition getStudentWithAddressObjectStructure() {
289  0 return dictionaryDelegate.getObjectStructure("studentWithAddress");
290    }
291    }