|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BeanConstraintDataProvider | Line # 25 | 21 | 0% | 11 | 2 | 93.3% |
0.93333334
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (9) | |||
| Result | |||
|
0.93333334
|
org.kuali.student.common.validator.old.ValidatorTest.testMaxLength
org.kuali.student.common.validator.old.ValidatorTest.testMaxLength
|
1 PASS | |
|
0.93333334
|
org.kuali.student.common.validator.old.ValidatorTest.testDoubleValueRange
org.kuali.student.common.validator.old.ValidatorTest.testDoubleValueRange
|
1 PASS | |
|
0.93333334
|
org.kuali.student.common.validator.old.ValidatorTest.testLengthRange
org.kuali.student.common.validator.old.ValidatorTest.testLengthRange
|
1 PASS | |
|
0.93333334
|
org.kuali.student.common.validator.old.ValidatorTest.testValidChars
org.kuali.student.common.validator.old.ValidatorTest.testValidChars
|
1 PASS | |
|
0.93333334
|
org.kuali.student.common.validator.old.ValidatorTest.testMinDateValue
org.kuali.student.common.validator.old.ValidatorTest.testMinDateValue
|
1 PASS | |
|
0.93333334
|
org.kuali.student.core.dictionary.service.impl.DictionaryValidatorTest.testRequiredValidation
org.kuali.student.core.dictionary.service.impl.DictionaryValidatorTest.testRequiredValidation
|
1 PASS | |
|
0.93333334
|
org.kuali.student.common.validator.old.ValidatorTest.testNestedStructures
org.kuali.student.common.validator.old.ValidatorTest.testNestedStructures
|
1 PASS | |
|
0.93333334
|
org.kuali.student.common.validator.old.ValidatorTest.testMinLength
org.kuali.student.common.validator.old.ValidatorTest.testMinLength
|
1 PASS | |
|
0.93333334
|
org.kuali.student.common.validator.old.ValidatorTest.testRequired
org.kuali.student.common.validator.old.ValidatorTest.testRequired
|
1 PASS | |
| 1 | /** | |
| 2 | * Copyright 2010 The Kuali Foundation Licensed under the | |
| 3 | * Educational Community License, Version 2.0 (the "License"); you may | |
| 4 | * not use this file except in compliance with the License. You may | |
| 5 | * obtain a copy of the License at | |
| 6 | * | |
| 7 | * http://www.osedu.org/licenses/ECL-2.0 | |
| 8 | * | |
| 9 | * Unless required by applicable law or agreed to in writing, | |
| 10 | * software distributed under the License is distributed on an "AS IS" | |
| 11 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | |
| 12 | * or implied. See the License for the specific language governing | |
| 13 | * permissions and limitations under the License. | |
| 14 | */ | |
| 15 | ||
| 16 | package org.kuali.student.common.validator.old; | |
| 17 | ||
| 18 | import java.beans.BeanInfo; | |
| 19 | import java.beans.IntrospectionException; | |
| 20 | import java.beans.Introspector; | |
| 21 | import java.beans.PropertyDescriptor; | |
| 22 | import java.util.HashMap; | |
| 23 | import java.util.Map; | |
| 24 | ||
| 25 | public class BeanConstraintDataProvider implements ConstraintDataProvider { | |
| 26 | ||
| 27 | Map<String, Object> dataMap = null; | |
| 28 | ||
| 29 | /* | |
| 30 | * The only place where the dataprovider should get initialized is | |
| 31 | * BeanConstraintSetupFactory | |
| 32 | */ | |
| 33 | 10 |
protected BeanConstraintDataProvider() { |
| 34 | ||
| 35 | } | |
| 36 | //TODO fix it later. | |
| 37 | 10 |
public String getPath(){ |
| 38 | 10 | return ""; |
| 39 | } | |
| 40 | 10 |
@Override |
| 41 | public void initialize(Object o) { | |
| 42 | ||
| 43 | 10 | dataMap = new HashMap<String, Object>(); |
| 44 | ||
| 45 | 10 | Map<String, PropertyDescriptor> beanInfo = getBeanInfo(o.getClass()); |
| 46 | ||
| 47 | 10 | for (String propName : beanInfo.keySet()) { |
| 48 | 102 | PropertyDescriptor pd = beanInfo.get(propName); |
| 49 | 102 | Object value = null; |
| 50 | 102 | try { |
| 51 | 102 | value = pd.getReadMethod().invoke(o); |
| 52 | } catch (Exception e) { | |
| 53 | // TODO: Should not be ignoring exception | |
| 54 | } | |
| 55 | ||
| 56 | 102 | dataMap.put(propName, value); |
| 57 | } | |
| 58 | } | |
| 59 | ||
| 60 | 20 |
@Override |
| 61 | public String getObjectId() { | |
| 62 | 20 | return (dataMap.containsKey("id") && null != dataMap.get("id")) ? dataMap.get("id").toString() : null; |
| 63 | } | |
| 64 | ||
| 65 | 56 |
@Override |
| 66 | public Object getValue(String fieldKey) { | |
| 67 | 56 | return dataMap.get(fieldKey); |
| 68 | } | |
| 69 | ||
| 70 | 20 |
@Override |
| 71 | public Boolean hasField(String fieldKey) { | |
| 72 | 20 | return dataMap.containsKey(fieldKey); |
| 73 | } | |
| 74 | ||
| 75 | 10 |
private Map<String, PropertyDescriptor> getBeanInfo(Class<?> clazz) { |
| 76 | 10 | Map<String, PropertyDescriptor> properties = new HashMap<String, PropertyDescriptor>(); |
| 77 | 10 | BeanInfo beanInfo = null; |
| 78 | 10 | try { |
| 79 | 10 | beanInfo = Introspector.getBeanInfo(clazz); |
| 80 | } catch (IntrospectionException e) { | |
| 81 | 0 | throw new RuntimeException(e); |
| 82 | } | |
| 83 | 10 | PropertyDescriptor[] propertyDescriptors = beanInfo |
| 84 | .getPropertyDescriptors(); | |
| 85 | 10 | for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { |
| 86 | 102 | properties.put(propertyDescriptor.getName(), propertyDescriptor); |
| 87 | } | |
| 88 | 10 | return properties; |
| 89 | } | |
| 90 | } | |
|
||||||||||||