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.Map;
23
24 import org.junit.Test;
25 import org.kuali.rice.kns.lookup.KualiLookupableImpl;
26 import org.kuali.rice.kns.lookup.LookupableHelperService;
27 import org.kuali.rice.krad.service.KRADServiceLocatorInternal;
28 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
29 import org.kuali.rice.krad.test.document.bo.Account;
30 import org.kuali.rice.krad.util.KRADConstants;
31 import org.kuali.rice.test.BaselineTestCase;
32 import org.kuali.rice.test.data.PerTestUnitTestData;
33 import org.kuali.rice.test.data.UnitTestData;
34 import org.kuali.rice.test.data.UnitTestFile;
35 import org.kuali.rice.test.data.UnitTestSql;
36 import org.kuali.test.KRADTestCase;
37 import org.kuali.test.KRADTestConstants.TestConstants;
38
39
40
41
42
43
44 @PerTestUnitTestData(
45 value = @UnitTestData(
46 order = {UnitTestData.Type.SQL_STATEMENTS, UnitTestData.Type.SQL_FILES},
47 sqlStatements = {
48 @UnitTestSql("delete from trv_acct where acct_fo_id between 101 and 301")
49 ,@UnitTestSql("delete from trv_acct_fo where acct_fo_id between 101 and 301")
50 },
51 sqlFiles = {
52 @UnitTestFile(filename = "classpath:testAccountManagers.sql", delimiter = ";")
53 , @UnitTestFile(filename = "classpath:testAccounts.sql", delimiter = ";")
54 }
55 ),
56 tearDown = @UnitTestData(
57 sqlStatements = {
58 @UnitTestSql("delete from trv_acct where acct_fo_id between 101 and 301")
59 ,@UnitTestSql("delete from trv_acct_fo where acct_fo_id between 101 and 301")
60 }
61 )
62 )
63 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
64 public class KualiLookupableTest extends KRADTestCase {
65 private KualiLookupableImpl lookupableImpl;
66
67 @Override
68 public void setUp() throws Exception {
69 super.setUp();
70 lookupableImpl = new KualiLookupableImpl();
71 lookupableImpl.setLookupableHelperService((LookupableHelperService) KRADServiceLocatorInternal.getService("lookupableHelperService"));
72 lookupableImpl.setBusinessObjectClass(Account.class);
73 }
74
75
76
77
78
79
80 @Test public void testReturnUrl() throws Exception {
81 Map<String, String> lookupProps = new HashMap<String, String>();
82 lookupProps.put("number", "b101");
83 lookupProps.put("name", "b101");
84
85 Account account = (Account) KRADServiceLocatorWeb.getLookupService().findObjectBySearch(Account.class, lookupProps);
86
87
88 Map fieldConversions = new HashMap();
89 lookupableImpl.setDocFormKey("8888888");
90 lookupableImpl.setBackLocation(TestConstants.BASE_PATH + "ib.do");
91
92 String returnUrl = lookupableImpl.getReturnUrl(account, fieldConversions, "kualiLookupable", null).constructCompleteHtmlTag();
93
94
95 checkURLContains("Lookup return url does not contain docFormKey", KRADConstants.DOC_FORM_KEY + "=8888888", returnUrl);
96
97
98 checkURLContains("Lookup return url does not go back to back location", TestConstants.BASE_PATH + "ib.do", returnUrl);
99
100 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>");
101
102
103 fieldConversions.put("number", "myAccount[0].chartCode");
104
105 returnUrl = lookupableImpl.getReturnUrl(account, fieldConversions, "kualiLookupable", null).constructCompleteHtmlTag();
106
107
108 checkURLContains("Lookup return url does not map key", "myAccount[0].chartCode=b101", returnUrl);
109 }
110
111
112
113
114
115
116
117
118
119 private void checkURLContains(String message, String containString, String url) {
120 assertTrue(message, url.indexOf(containString) > 0);
121 }
122 }