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 java.util.HashMap;
19 import java.util.Map;
20
21 import org.junit.Test;
22 import org.kuali.rice.kns.service.KNSServiceLocator;
23 import org.kuali.rice.kns.test.document.bo.Account;
24 import org.kuali.rice.kns.util.KNSConstants;
25 import org.kuali.test.KNSTestCase;
26 import org.kuali.test.KNSTestConstants.TestConstants;
27
28
29
30
31
32
33 public class KualiLookupableTest extends KNSTestCase {
34 private KualiLookupableImpl lookupableImpl;
35
36 @Override
37 public void setUp() throws Exception {
38 super.setUp();
39 lookupableImpl = new KualiLookupableImpl();
40 lookupableImpl.setLookupableHelperService((LookupableHelperService)KNSServiceLocator.getService("lookupableHelperService"));
41 lookupableImpl.setBusinessObjectClass(Account.class);
42 }
43
44
45
46
47
48
49 @Test public void testReturnUrl() throws Exception {
50 Map<String, Object> lookupProps = new HashMap<String, Object>();
51 lookupProps.put("number", "a1");
52 lookupProps.put("name", "a1");
53
54 Account account = (Account)KNSServiceLocator.getLookupService().findObjectBySearch(Account.class, lookupProps);
55
56
57 Map fieldConversions = new HashMap();
58 lookupableImpl.setDocFormKey("8888888");
59 lookupableImpl.setBackLocation(TestConstants.BASE_PATH + "ib.do");
60
61 String returnUrl = lookupableImpl.getReturnUrl(account, fieldConversions, "kualiLookupable", null).constructCompleteHtmlTag();
62
63
64 checkURLContains("Lookup return url does not contain docFormKey", KNSConstants.DOC_FORM_KEY + "=8888888", returnUrl);
65
66
67 checkURLContains("Lookup return url does not go back to back location", TestConstants.BASE_PATH + "ib.do", returnUrl);
68
69 assertEquals(returnUrl, "<a title=\"return valueAccount Number=a1 \" href=\"http://localhost:8080/ib.do?refreshCaller=kualiLookupable&number=a1&methodToCall=refresh&docFormKey=8888888\">return value</a>");
70
71
72 fieldConversions.put("number", "myAccount[0].chartCode");
73
74 returnUrl = lookupableImpl.getReturnUrl(account, fieldConversions, "kualiLookupable", null).constructCompleteHtmlTag();
75
76
77 checkURLContains("Lookup return url does not map key", "myAccount[0].chartCode=a1", returnUrl);
78 }
79
80
81
82
83
84
85
86
87
88 private void checkURLContains(String message, String containString, String url) {
89 assertTrue(message, url.indexOf(containString) > 0);
90 }
91 }