View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.util;
17  
18  import org.junit.Test;
19  import org.kuali.rice.coreservice.impl.parameter.ParameterBo;
20  import org.kuali.rice.krad.datadictionary.AttributeDefinition;
21  import org.kuali.rice.krad.datadictionary.DataDictionaryEntryBase;
22  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
23  import org.kuali.test.KRADTestCase;
24  
25  import static org.junit.Assert.assertFalse;
26  
27  /**
28   * ObjectUtilsTest
29   * 
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class ObjectUtilsTest extends KRADTestCase {
33      @Test
34      public void testObjectUtils_equalsByKey() throws Exception {
35          ParameterBo parameterInDB = new ParameterBo();
36          parameterInDB.setNamespaceCode("KR-NS");
37          parameterInDB.setName("OBJ_UTIL_TEST");
38          
39          ParameterBo parameterNew = new ParameterBo();
40          parameterNew.setNamespaceCode("KR-NS");
41          parameterInDB.setName(null);
42          
43          boolean equalsResult = false;
44          equalsResult = ObjectUtils.equalByKeys(parameterInDB, parameterNew);
45          assertFalse(equalsResult);
46      }
47      
48  /*	@Test
49  	public void testGetFormatterWithDataDictionary() throws Exception {
50  		// test formatter getting correctly pulled from data dictionary
51  		TravelAccountUseRate useRate = new TravelAccountUseRate();
52  		Formatter formatter = ObjectUtils.getFormatterWithDataDictionary(useRate, "active");
53  		assertTrue("Incorrect formatter returned for active property", formatter instanceof BooleanFormatter);
54  
55  		changeAttributeDefinitionFormatter(useRate.getClass(), "active", IntegerFormatter.class);
56  		formatter = ObjectUtils.getFormatterWithDataDictionary(useRate, "active");
57  		assertTrue("Incorrect formatter returned for active property", formatter instanceof IntegerFormatter);
58  		
59  		// test formatter getting correctly pulled by data type
60  		formatter = ObjectUtils.getFormatterWithDataDictionary(useRate, "activeFromDate");
61  		assertTrue("Incorrect formatter returned for date type", formatter instanceof DateFormatter);
62  		
63  		formatter = ObjectUtils.getFormatterWithDataDictionary(useRate, "rate");
64  		assertTrue("Incorrect formatter returned for percent type", formatter instanceof PercentageFormatter);
65  		
66  		formatter = ObjectUtils.getFormatterWithDataDictionary(useRate, "number");
67  		assertTrue("Incorrect formatter returned for string type", formatter.getClass().getName().equals("org.kuali.rice.core.web.format.Formatter"));
68  	}
69  */
70  	private void changeAttributeDefinitionFormatter(Class boClass, String attributeName, Class formatterClass) {
71  		DataDictionaryEntryBase entry = (DataDictionaryEntryBase) KRADServiceLocatorWeb.getDataDictionaryService()
72  				.getDataDictionary().getDictionaryObjectEntry(boClass.getName());
73  		if (entry != null) {
74  			AttributeDefinition attributeDefinition = entry.getAttributeDefinition(attributeName);
75  			attributeDefinition.setFormatterClass(formatterClass.getName());
76  		}
77  	}
78  }