001/** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.krad.keyvalues; 017 018import org.junit.Test; 019import org.kuali.rice.core.api.util.ConcreteKeyValue; 020import org.kuali.rice.core.api.util.KeyValue; 021import org.kuali.rice.krad.keyvalues.PersistableBusinessObjectValuesFinder; 022import org.kuali.rice.krad.test.document.bo.AccountType; 023import org.kuali.rice.test.BaselineTestCase; 024import org.kuali.rice.test.data.PerTestUnitTestData; 025import org.kuali.rice.test.data.UnitTestData; 026import org.kuali.rice.test.data.UnitTestFile; 027import org.kuali.rice.test.data.UnitTestSql; 028import org.kuali.rice.krad.test.KRADTestCase; 029 030import java.util.ArrayList; 031import java.util.List; 032 033import static org.junit.Assert.assertEquals; 034 035/** 036 * PersistableBusinessObjectValuesFinderTest tests the {@link PersistableBusinessObjectValuesFinder} 037 * 038 * @author Kuali Rice Team (rice.collab@kuali.org) 039 */ 040@PerTestUnitTestData( 041 value = @UnitTestData( 042 order = {UnitTestData.Type.SQL_STATEMENTS, UnitTestData.Type.SQL_FILES}, 043 sqlStatements = { 044 @UnitTestSql("delete from trv_acct_type") 045 }, 046 sqlFiles = { 047 @UnitTestFile(filename = "classpath:testAccountType.sql", delimiter = ";") 048 } 049 ), 050 tearDown = @UnitTestData( 051 sqlStatements = { 052 @UnitTestSql("delete from trv_acct_type") 053 } 054 ) 055) 056@BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE) 057public class PersistableBusinessObjectValuesFinderTest extends KRADTestCase { 058 059 private List<KeyValue> testKeyValues = new ArrayList<KeyValue>(); 060 private List<KeyValue> testKeyValuesKeyInLabel = new ArrayList<KeyValue>(); 061 062 /** 063 * Default Constructor builds KeyValue Lists used for tests. 064 * 065 */ 066 public PersistableBusinessObjectValuesFinderTest() { 067 testKeyValues.add(new ConcreteKeyValue("CAT", "Clearing Account Type")); 068 testKeyValues.add(new ConcreteKeyValue("EAT", "Expense Account Type")); 069 testKeyValues.add(new ConcreteKeyValue("IAT", "Income Account Type")); 070 071 testKeyValuesKeyInLabel.add(new ConcreteKeyValue("CAT", "CAT - Clearing Account Type")); 072 testKeyValuesKeyInLabel.add(new ConcreteKeyValue("EAT", "EAT - Expense Account Type")); 073 testKeyValuesKeyInLabel.add(new ConcreteKeyValue("IAT", "IAT - Income Account Type")); 074 } 075 076 /** 077 * tests to make sure the <code>PersistableBusinessObjectValuesFinder</code> works 078 * as expected for the TravelAccountType BO 079 * 080 * @throws Exception 081 */ 082 @Test public void testGetKeyValues() throws Exception { 083 PersistableBusinessObjectValuesFinder valuesFinder = new PersistableBusinessObjectValuesFinder(); 084 valuesFinder.setBusinessObjectClass(AccountType.class); 085 valuesFinder.setKeyAttributeName("accountTypeCode"); 086 valuesFinder.setLabelAttributeName("name"); 087 valuesFinder.setIncludeKeyInDescription(false); 088 List<KeyValue> keyValues = valuesFinder.getKeyValues(); 089 assertEquals(testKeyValues.size(), keyValues.size()); 090 for (KeyValue testKeyValue: testKeyValues) { 091 assertEquals(testKeyValue.getValue(), valuesFinder.getKeyLabel(testKeyValue.getKey())); 092 } 093 } 094 095 /** 096 * tests to make sure the <code>PersistableBusinessObjectValuesFinder</code> works 097 * as expected for the TravelAccountType BO with the key included in the label 098 * 099 * @throws Exception 100 */ 101 @Test public void testGetKeyValuesKeyInLabel() throws Exception { 102 PersistableBusinessObjectValuesFinder valuesFinder = new PersistableBusinessObjectValuesFinder(); 103 valuesFinder.setBusinessObjectClass(AccountType.class); 104 valuesFinder.setKeyAttributeName("accountTypeCode"); 105 valuesFinder.setLabelAttributeName("name"); 106 valuesFinder.setIncludeKeyInDescription(true); 107 List<KeyValue> keyValues = valuesFinder.getKeyValues(); 108 assertEquals(testKeyValuesKeyInLabel.size(), keyValues.size()); 109 for (KeyValue testKeyValue: testKeyValuesKeyInLabel) { 110 assertEquals(testKeyValue.getValue(), valuesFinder.getKeyLabel(testKeyValue.getKey())); 111 } 112 } 113 114 /** 115 * KULRICE-11708 - removing the two tests for FiscalOfficer since the TRV_ACCT_FO table no longer exists. 116 * No replacement tests are needed since testGetKeyValues and testGetKeyValuesKeyInLabel are testing similar 117 * functionality for the accountTypeCode. Choosing to delete these tests rather than ingore them so that 118 * the AccountManager class can be deleted if so desired. 119 */ 120}