View Javadoc
1   /**
2    * Copyright 2005-2014 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.keyvalues;
17  
18  import org.junit.Test;
19  import org.kuali.rice.core.api.util.ConcreteKeyValue;
20  import org.kuali.rice.core.api.util.KeyValue;
21  import org.kuali.rice.krad.keyvalues.PersistableBusinessObjectValuesFinder;
22  import org.kuali.rice.krad.test.document.bo.AccountType;
23  import org.kuali.rice.test.BaselineTestCase;
24  import org.kuali.rice.test.data.PerTestUnitTestData;
25  import org.kuali.rice.test.data.UnitTestData;
26  import org.kuali.rice.test.data.UnitTestFile;
27  import org.kuali.rice.test.data.UnitTestSql;
28  import org.kuali.rice.krad.test.KRADTestCase;
29  
30  import java.util.ArrayList;
31  import java.util.List;
32  
33  import static org.junit.Assert.assertEquals;
34  
35  /**
36   * PersistableBusinessObjectValuesFinderTest tests the {@link PersistableBusinessObjectValuesFinder}
37   *
38   * @author Kuali Rice Team (rice.collab@kuali.org)
39   */
40  @PerTestUnitTestData(
41          value = @UnitTestData(
42                  order = {UnitTestData.Type.SQL_STATEMENTS, UnitTestData.Type.SQL_FILES},
43                  sqlStatements = {
44                          @UnitTestSql("delete from trv_acct_type")
45                  },
46                  sqlFiles = {
47                          @UnitTestFile(filename = "classpath:testAccountType.sql", delimiter = ";")
48                  }
49          ),
50          tearDown = @UnitTestData(
51                  sqlStatements = {
52                          @UnitTestSql("delete from trv_acct_type")
53                  }
54          )
55  )
56  @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
57  public class PersistableBusinessObjectValuesFinderTest extends KRADTestCase {
58  
59      private List<KeyValue> testKeyValues = new ArrayList<KeyValue>();
60      private List<KeyValue> testKeyValuesKeyInLabel = new ArrayList<KeyValue>();
61  
62      /**
63       * Default Constructor builds KeyValue Lists used for tests.
64       *
65       */
66      public PersistableBusinessObjectValuesFinderTest() {
67          testKeyValues.add(new ConcreteKeyValue("CAT", "Clearing Account Type"));
68          testKeyValues.add(new ConcreteKeyValue("EAT", "Expense Account Type"));
69          testKeyValues.add(new ConcreteKeyValue("IAT", "Income Account Type"));
70  
71          testKeyValuesKeyInLabel.add(new ConcreteKeyValue("CAT", "CAT - Clearing Account Type"));
72          testKeyValuesKeyInLabel.add(new ConcreteKeyValue("EAT", "EAT - Expense Account Type"));
73          testKeyValuesKeyInLabel.add(new ConcreteKeyValue("IAT", "IAT - Income Account Type"));
74      }
75  
76      /**
77       * tests to make sure the <code>PersistableBusinessObjectValuesFinder</code> works
78       * as expected for the TravelAccountType BO
79       *
80       * @throws Exception
81       */
82      @Test public void testGetKeyValues() throws Exception {
83          PersistableBusinessObjectValuesFinder valuesFinder = new PersistableBusinessObjectValuesFinder();
84          valuesFinder.setBusinessObjectClass(AccountType.class);
85          valuesFinder.setKeyAttributeName("accountTypeCode");
86          valuesFinder.setLabelAttributeName("name");
87          valuesFinder.setIncludeKeyInDescription(false);
88          List<KeyValue> keyValues = valuesFinder.getKeyValues();
89          assertEquals(testKeyValues.size(), keyValues.size());
90          for (KeyValue testKeyValue: testKeyValues) {
91              assertEquals(testKeyValue.getValue(), valuesFinder.getKeyLabel(testKeyValue.getKey()));
92          }
93      }
94  
95      /**
96       * tests to make sure the <code>PersistableBusinessObjectValuesFinder</code> works
97       * as expected for the TravelAccountType BO with the key included in the label
98       *
99       * @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 }