1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
37
38
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
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
78
79
80
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
97
98
99
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
116
117
118
119
120 }