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