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