1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.util;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.junit.Test;
20
21 import java.util.Properties;
22
23 import static org.junit.Assert.assertTrue;
24
25
26
27
28 public class UrlFactoryTest {
29
30
31
32
33 @Test public void testFactoryMatch() throws Exception {
34 String basePath = "http://localhost:8080/";
35 String actionPath = "kr/lookup.do";
36 String testUrl = basePath + actionPath + "?" + KRADConstants.DISPATCH_REQUEST_PARAMETER + "=start" + "&" + KRADConstants.DOC_FORM_KEY + "=903" + KRADConstants.LOOKUPABLE_IMPL_ATTRIBUTE_NAME + "=accountLookupableImpl" + KRADConstants.RETURN_LOCATION_PARAMETER + "=" + basePath + "ib.do";
37 testUrl = UrlFactory.encode(testUrl);
38
39
40 Properties parameters = new Properties();
41 parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "start");
42 parameters.put(KRADConstants.DOC_FORM_KEY, "903");
43 parameters.put(KRADConstants.LOOKUPABLE_IMPL_ATTRIBUTE_NAME, "accountLookupableImpl");
44 parameters.put(KRADConstants.RETURN_LOCATION_PARAMETER, basePath + "ib.do");
45
46 String returnedUrl = UrlFactory.parameterizeUrl(basePath + actionPath, parameters);
47
48 assertTrue("Returned url is empty", StringUtils.isNotBlank(returnedUrl));
49 assertTrue("Returned url has incorrect base", returnedUrl.startsWith(basePath + actionPath + "?"));
50 assertTrue("Returned url does not have correct # of &", StringUtils.countMatches(returnedUrl, "&") == 3);
51 assertTrue("Returned url missing parameter 1", StringUtils.contains(returnedUrl, KRADConstants.DISPATCH_REQUEST_PARAMETER + "=start"));
52 assertTrue("Returned url missing parameter 2", StringUtils.contains(returnedUrl, KRADConstants.DOC_FORM_KEY + "=903"));
53 assertTrue("Returned url missing parameter 3", StringUtils.contains(returnedUrl, KRADConstants.LOOKUPABLE_IMPL_ATTRIBUTE_NAME + "=accountLookupableImpl"));
54
55
56 }
57 }