1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.util;
17
18 import org.junit.Test;
19 import org.kuali.rice.kns.bo.Parameter;
20 import org.kuali.rice.kns.datadictionary.AttributeDefinition;
21 import org.kuali.rice.kns.datadictionary.DataDictionaryEntryBase;
22 import org.kuali.rice.kns.service.KNSServiceLocator;
23 import org.kuali.rice.kns.web.format.BooleanFormatter;
24 import org.kuali.rice.kns.web.format.DateFormatter;
25 import org.kuali.rice.kns.web.format.Formatter;
26 import org.kuali.rice.kns.web.format.IntegerFormatter;
27 import org.kuali.rice.kns.web.format.PercentageFormatter;
28 import org.kuali.test.KNSTestCase;
29
30 import edu.sampleu.travel.bo.TravelAccountUseRate;
31
32
33
34
35
36
37 public class ObjectUtilsTest extends KNSTestCase {
38 @Test
39 public void testObjectUtils_equalsByKey() throws Exception {
40 Parameter parameterInDB = new Parameter();
41 parameterInDB.setParameterNamespaceCode("KR-NS");
42 parameterInDB.setParameterName("OBJ_UTIL_TEST");
43
44 Parameter parameterNew = new Parameter();
45 parameterNew.setParameterNamespaceCode("KR-NS");
46 parameterInDB.setParameterName(null);
47
48 boolean equalsResult = false;
49 equalsResult = ObjectUtils.equalByKeys(parameterInDB, parameterNew);
50 assertFalse(equalsResult);
51 }
52
53 @Test
54 public void testGetFormatterWithDataDictionary() throws Exception {
55
56 TravelAccountUseRate useRate = new TravelAccountUseRate();
57 Formatter formatter = ObjectUtils.getFormatterWithDataDictionary(useRate, "active");
58 assertTrue("Incorrect formatter returned for active property", formatter instanceof BooleanFormatter);
59
60 changeAttributeDefinitionFormatter(useRate.getClass(), "active", IntegerFormatter.class);
61 formatter = ObjectUtils.getFormatterWithDataDictionary(useRate, "active");
62 assertTrue("Incorrect formatter returned for active property", formatter instanceof IntegerFormatter);
63
64
65 formatter = ObjectUtils.getFormatterWithDataDictionary(useRate, "activeFromDate");
66 assertTrue("Incorrect formatter returned for date type", formatter instanceof DateFormatter);
67
68 formatter = ObjectUtils.getFormatterWithDataDictionary(useRate, "rate");
69 assertTrue("Incorrect formatter returned for percent type", formatter instanceof PercentageFormatter);
70
71 formatter = ObjectUtils.getFormatterWithDataDictionary(useRate, "number");
72 assertTrue("Incorrect formatter returned for string type", formatter.getClass().getName().equals("org.kuali.rice.kns.web.format.Formatter"));
73 }
74
75 private void changeAttributeDefinitionFormatter(Class boClass, String attributeName, Class formatterClass) {
76 DataDictionaryEntryBase entry = (DataDictionaryEntryBase) KNSServiceLocator.getDataDictionaryService()
77 .getDataDictionary().getDictionaryObjectEntry(boClass.getName());
78 if (entry != null) {
79 AttributeDefinition attributeDefinition = entry.getAttributeDefinition(attributeName);
80 attributeDefinition.setFormatterClass(formatterClass.getName());
81 }
82 }
83 }