1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.lookup.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.AccountManager;
23 import org.kuali.rice.krad.test.document.bo.AccountType;
24 import org.kuali.rice.test.BaselineTestCase;
25 import org.kuali.rice.test.data.PerTestUnitTestData;
26 import org.kuali.rice.test.data.UnitTestData;
27 import org.kuali.rice.test.data.UnitTestFile;
28 import org.kuali.rice.test.data.UnitTestSql;
29 import org.kuali.test.KRADTestCase;
30
31 import java.util.ArrayList;
32 import java.util.List;
33
34 import static org.junit.Assert.assertEquals;
35
36
37
38
39
40
41
42 @PerTestUnitTestData(
43 value = @UnitTestData(
44 order = {UnitTestData.Type.SQL_STATEMENTS, UnitTestData.Type.SQL_FILES},
45 sqlStatements = {
46 @UnitTestSql("delete from trv_acct_type")
47 ,@UnitTestSql("delete from trv_acct_fo where acct_fo_id between 101 and 301")
48 },
49 sqlFiles = {
50 @UnitTestFile(filename = "classpath:testAccountManagers.sql", delimiter = ";")
51 , @UnitTestFile(filename = "classpath:testAccountType.sql", delimiter = ";")
52 }
53 ),
54 tearDown = @UnitTestData(
55 sqlStatements = {
56 @UnitTestSql("delete from trv_acct_type")
57 ,@UnitTestSql("delete from trv_acct_fo where acct_fo_id between 101 and 301")
58 }
59 )
60 )
61 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
62 public class PersistableBusinessObjectValuesFinderTest extends KRADTestCase {
63
64 private List<KeyValue> testKeyValues = new ArrayList<KeyValue>();
65 private List<KeyValue> testKeyValuesKeyInLabel = new ArrayList<KeyValue>();
66 private List<KeyValue> testKeyValuesLongKey = new ArrayList<KeyValue>();
67 private List<KeyValue> testKeyValuesKeyInLabelLongKey = new ArrayList<KeyValue>();
68
69
70
71
72
73 public PersistableBusinessObjectValuesFinderTest() {
74 testKeyValues.add(new ConcreteKeyValue("CAT", "Clearing Account Type"));
75 testKeyValues.add(new ConcreteKeyValue("EAT", "Expense Account Type"));
76 testKeyValues.add(new ConcreteKeyValue("IAT", "Income Account Type"));
77
78 testKeyValuesKeyInLabel.add(new ConcreteKeyValue("CAT", "CAT - Clearing Account Type"));
79 testKeyValuesKeyInLabel.add(new ConcreteKeyValue("EAT", "EAT - Expense Account Type"));
80 testKeyValuesKeyInLabel.add(new ConcreteKeyValue("IAT", "IAT - Income Account Type"));
81
82
83 for (int x=101;x<302;x++) {
84 testKeyValuesLongKey.add(new ConcreteKeyValue(new Long(x).toString(), "fo-" + x));
85 testKeyValuesKeyInLabelLongKey.add(new ConcreteKeyValue(new Long(x).toString(), x + " - fo-" + x));
86 }
87 }
88
89
90
91
92
93
94
95 @Test public void testGetKeyValues() throws Exception {
96 PersistableBusinessObjectValuesFinder valuesFinder = new PersistableBusinessObjectValuesFinder();
97 valuesFinder.setBusinessObjectClass(AccountType.class);
98 valuesFinder.setKeyAttributeName("accountTypeCode");
99 valuesFinder.setLabelAttributeName("name");
100 valuesFinder.setIncludeKeyInDescription(false);
101 List<KeyValue> keyValues = valuesFinder.getKeyValues();
102 assertEquals(testKeyValues.size(), keyValues.size());
103 for (KeyValue testKeyValue: testKeyValues) {
104 assertEquals(testKeyValue.getValue(), valuesFinder.getKeyLabel(testKeyValue.getKey()));
105 }
106 }
107
108
109
110
111
112
113
114 @Test public void testGetKeyValuesKeyInLabel() throws Exception {
115 PersistableBusinessObjectValuesFinder valuesFinder = new PersistableBusinessObjectValuesFinder();
116 valuesFinder.setBusinessObjectClass(AccountType.class);
117 valuesFinder.setKeyAttributeName("accountTypeCode");
118 valuesFinder.setLabelAttributeName("name");
119 valuesFinder.setIncludeKeyInDescription(true);
120 List<KeyValue> keyValues = valuesFinder.getKeyValues();
121 assertEquals(testKeyValuesKeyInLabel.size(), keyValues.size());
122 for (KeyValue testKeyValue: testKeyValuesKeyInLabel) {
123 assertEquals(testKeyValue.getValue(), valuesFinder.getKeyLabel(testKeyValue.getKey()));
124 }
125 }
126
127
128
129
130
131
132
133 @Test public void testGetKeyValuesLongKey() throws Exception {
134 PersistableBusinessObjectValuesFinder valuesFinder = new PersistableBusinessObjectValuesFinder();
135 valuesFinder.setBusinessObjectClass(AccountManager.class);
136 valuesFinder.setKeyAttributeName("amId");
137 valuesFinder.setLabelAttributeName("userName");
138 valuesFinder.setIncludeKeyInDescription(false);
139 List<KeyValue> keyValues = valuesFinder.getKeyValues();
140 assertEquals(testKeyValuesLongKey.size(), keyValues.size());
141 for (KeyValue testKeyValue: testKeyValuesLongKey) {
142 assertEquals(testKeyValue.getValue(), valuesFinder.getKeyLabel(testKeyValue.getKey()));
143 }
144 }
145
146
147
148
149
150
151
152 @Test public void testGetKeyValuesKeyInLabelLongKey() throws Exception {
153 PersistableBusinessObjectValuesFinder valuesFinder = new PersistableBusinessObjectValuesFinder();
154 valuesFinder.setBusinessObjectClass(AccountManager.class);
155 valuesFinder.setKeyAttributeName("amId");
156 valuesFinder.setLabelAttributeName("userName");
157 valuesFinder.setIncludeKeyInDescription(true);
158 List<KeyValue> keyValues = valuesFinder.getKeyValues();
159 assertEquals(testKeyValuesKeyInLabelLongKey.size(), keyValues.size());
160 for (KeyValue testKeyValue: testKeyValuesKeyInLabelLongKey) {
161 assertEquals(testKeyValue.getValue(), valuesFinder.getKeyLabel(testKeyValue.getKey()));
162 }
163 }
164
165 }