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