1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.lookup;
17
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertTrue;
20
21 import java.util.HashMap;
22 import java.util.List;
23 import java.util.Map;
24
25 import org.junit.Test;
26 import org.kuali.rice.kns.lookup.KualiLookupableImpl;
27 import org.kuali.rice.kns.lookup.LookupableHelperService;
28 import org.kuali.rice.kns.web.ui.Field;
29 import org.kuali.rice.kns.web.ui.Row;
30 import org.kuali.rice.krad.service.KRADServiceLocatorInternal;
31 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
32 import org.kuali.rice.krad.test.document.bo.Account;
33 import org.kuali.rice.krad.util.KRADConstants;
34 import org.kuali.rice.test.BaselineTestCase;
35 import org.kuali.rice.test.data.PerTestUnitTestData;
36 import org.kuali.rice.test.data.UnitTestData;
37 import org.kuali.rice.test.data.UnitTestFile;
38 import org.kuali.rice.test.data.UnitTestSql;
39 import org.kuali.test.KRADTestCase;
40 import org.kuali.test.KRADTestConstants.TestConstants;
41
42
43
44
45
46
47 @PerTestUnitTestData(
48 value = @UnitTestData(
49 order = {UnitTestData.Type.SQL_STATEMENTS, UnitTestData.Type.SQL_FILES},
50 sqlStatements = {
51 @UnitTestSql("delete from trv_acct where acct_fo_id between 101 and 301")
52 ,@UnitTestSql("delete from trv_acct_fo where acct_fo_id between 101 and 301")
53 },
54 sqlFiles = {
55 @UnitTestFile(filename = "classpath:testAccountManagers.sql", delimiter = ";")
56 , @UnitTestFile(filename = "classpath:testAccounts.sql", delimiter = ";")
57 }
58 ),
59 tearDown = @UnitTestData(
60 sqlStatements = {
61 @UnitTestSql("delete from trv_acct where acct_fo_id between 101 and 301")
62 ,@UnitTestSql("delete from trv_acct_fo where acct_fo_id between 101 and 301")
63 }
64 )
65 )
66 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
67 public class KualiLookupableTest extends KRADTestCase {
68 private KualiLookupableImpl lookupableImpl;
69
70 @Override
71 public void setUp() throws Exception {
72 super.setUp();
73 lookupableImpl = new KualiLookupableImpl();
74 lookupableImpl.setLookupableHelperService((LookupableHelperService) KRADServiceLocatorInternal.getService("lookupableHelperService"));
75 lookupableImpl.setBusinessObjectClass(Account.class);
76 }
77
78
79
80
81
82
83 @Test public void testGetRows() throws Exception {
84
85 List<? extends Row> rows = lookupableImpl.getRows();
86 assertEquals(4, rows.size());
87
88 Field f = rows.get(0).getField(0);
89 assertEquals("number", f.getPropertyName());
90 assertEquals("Account Number", f.getFieldLabel());
91 assertEquals("text", f.getFieldType());
92
93 f = rows.get(1).getField(0);
94 assertEquals("name", f.getPropertyName());
95 assertEquals("Account Name", f.getFieldLabel());
96 assertEquals("text", f.getFieldType());
97
98 f = rows.get(2).getField(0);
99 assertEquals("extension.accountTypeCode", f.getPropertyName());
100 assertEquals("Account Type Code", f.getFieldLabel());
101 assertEquals("dropdown", f.getFieldType());
102
103 f = rows.get(3).getField(0);
104 assertEquals("amId", f.getPropertyName());
105 assertEquals("Account Manager Id", f.getFieldLabel());
106 assertEquals("text", f.getFieldType());
107 }
108
109
110
111
112
113
114 @Test public void testReturnUrl() throws Exception {
115 Map<String, String> lookupProps = new HashMap<String, String>();
116 lookupProps.put("number", "b101");
117 lookupProps.put("name", "b101");
118
119 Account account = (Account) KRADServiceLocatorWeb.getLookupService().findObjectBySearch(Account.class, lookupProps);
120
121
122 Map fieldConversions = new HashMap();
123 lookupableImpl.setDocFormKey("8888888");
124 lookupableImpl.setBackLocation(TestConstants.BASE_PATH + "ib.do");
125
126 String returnUrl = lookupableImpl.getReturnUrl(account, fieldConversions, "kualiLookupable", null).constructCompleteHtmlTag();
127
128
129 checkURLContains("Lookup return url does not contain docFormKey", KRADConstants.DOC_FORM_KEY + "=8888888", returnUrl);
130
131
132 checkURLContains("Lookup return url does not go back to back location", TestConstants.BASE_PATH + "ib.do", returnUrl);
133
134 assertEquals(returnUrl, "<a title=\"return valueAccount Number=b101 \" href=\"http://localhost:8080/ib.do?refreshCaller=kualiLookupable&number=b101&methodToCall=refresh&docFormKey=8888888\" >return value</a>");
135
136
137 fieldConversions.put("number", "myAccount[0].chartCode");
138
139 returnUrl = lookupableImpl.getReturnUrl(account, fieldConversions, "kualiLookupable", null).constructCompleteHtmlTag();
140
141
142 checkURLContains("Lookup return url does not map key", "myAccount[0].chartCode=b101", returnUrl);
143 }
144
145
146
147
148
149
150
151
152
153 private void checkURLContains(String message, String containString, String url) {
154 assertTrue(message, url.indexOf(containString) > 0);
155 }
156 }