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 @Test public void testGetRows() throws Exception {
83
84 List<? extends Row> rows = lookupableImpl.getRows();
85 assertEquals(4, rows.size());
86
87 Field f = rows.get(0).getField(0);
88 assertEquals("number", f.getPropertyName());
89 assertEquals("Account Number", f.getFieldLabel());
90 assertEquals("text", f.getFieldType());
91
92 f = rows.get(1).getField(0);
93 assertEquals("name", f.getPropertyName());
94 assertEquals("Account Name", f.getFieldLabel());
95 assertEquals("text", f.getFieldType());
96
97 f = rows.get(2).getField(0);
98 assertEquals("extension.accountTypeCode", f.getPropertyName());
99 assertEquals("Account Type Code", f.getFieldLabel());
100 assertEquals("dropdown", f.getFieldType());
101
102 f = rows.get(3).getField(0);
103 assertEquals("amId", f.getPropertyName());
104 assertEquals("Account Manager Id", f.getFieldLabel());
105 assertEquals("text", f.getFieldType());
106 }
107
108
109
110
111
112
113 @Test public void testReturnUrl() throws Exception {
114 Map<String, String> lookupProps = new HashMap<String, String>();
115 lookupProps.put("number", "b101");
116 lookupProps.put("name", "b101");
117
118 Account account = (Account) KRADServiceLocatorWeb.getLookupService().findObjectBySearch(Account.class, lookupProps);
119
120
121 Map fieldConversions = new HashMap();
122 lookupableImpl.setDocFormKey("8888888");
123 lookupableImpl.setBackLocation(TestConstants.BASE_PATH + "ib.do");
124
125 String returnUrl = lookupableImpl.getReturnUrl(account, fieldConversions, "kualiLookupable", null).constructCompleteHtmlTag();
126
127
128 checkURLContains("Lookup return url does not contain docFormKey", KRADConstants.DOC_FORM_KEY + "=8888888", returnUrl);
129
130
131 checkURLContains("Lookup return url does not go back to back location", TestConstants.BASE_PATH + "ib.do", returnUrl);
132
133 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>");
134
135
136 fieldConversions.put("number", "myAccount[0].chartCode");
137
138 returnUrl = lookupableImpl.getReturnUrl(account, fieldConversions, "kualiLookupable", null).constructCompleteHtmlTag();
139
140
141 checkURLContains("Lookup return url does not map key", "myAccount[0].chartCode=b101", returnUrl);
142 }
143
144
145
146
147
148
149
150
151
152 private void checkURLContains(String message, String containString, String url) {
153 assertTrue(message, url.indexOf(containString) > 0);
154 }
155 }