01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.core.util;
17:
18: import java.util.Properties;
19:
20: import org.apache.commons.lang.StringUtils;
21: import org.kuali.kfs.KFSConstants;
22: import org.kuali.kfs.context.KualiTestBase;
23:
24: /**
25: * This class tests the UrlFactory methods.
26: */
27: public class UrlFactoryTest extends KualiTestBase {
28:
29: /**
30: * Test that what is returned from url factory matches the url we expect.
31: */
32: final public void testFactoryMatch() throws Exception {
33: String basePath = "http://localhost:8080/";
34: String actionPath = "kr/lookup.do";
35: String testUrl = basePath + actionPath + "?"
36: + KFSConstants.DISPATCH_REQUEST_PARAMETER + "=start"
37: + "&" + KFSConstants.DOC_FORM_KEY + "=903"
38: + KFSConstants.LOOKUPABLE_IMPL_ATTRIBUTE_NAME
39: + "=accountLookupableImpl"
40: + KFSConstants.RETURN_LOCATION_PARAMETER + "="
41: + basePath + "ib.do";
42: testUrl = UrlFactory.encode(testUrl);
43:
44: // construct lookup url
45: Properties parameters = new Properties();
46: parameters
47: .put(KFSConstants.DISPATCH_REQUEST_PARAMETER, "start");
48: parameters.put(KFSConstants.DOC_FORM_KEY, "903");
49: parameters.put(KFSConstants.LOOKUPABLE_IMPL_ATTRIBUTE_NAME,
50: "accountLookupableImpl");
51: parameters.put(KFSConstants.RETURN_LOCATION_PARAMETER, basePath
52: + "ib.do");
53:
54: String returnedUrl = UrlFactory.parameterizeUrl(basePath
55: + actionPath, parameters);
56:
57: assertTrue("Returned url is empty", StringUtils
58: .isNotBlank(returnedUrl));
59: assertTrue("Returned url has incorrect base", returnedUrl
60: .startsWith(basePath + actionPath + "?"));
61: assertTrue("Returned url does not have correct # of &",
62: StringUtils.countMatches(returnedUrl, "&") == 3);
63: assertTrue("Returned url missing parameter 1", StringUtils
64: .contains(returnedUrl,
65: KFSConstants.DISPATCH_REQUEST_PARAMETER
66: + "=start"));
67: assertTrue("Returned url missing parameter 2", StringUtils
68: .contains(returnedUrl, KFSConstants.DOC_FORM_KEY
69: + "=903"));
70: assertTrue("Returned url missing parameter 3", StringUtils
71: .contains(returnedUrl,
72: KFSConstants.LOOKUPABLE_IMPL_ATTRIBUTE_NAME
73: + "=accountLookupableImpl"));
74: // assertTrue("Returned url missing parameter 4",StringUtils.contains(returnedUrl,
75: // UrlFactory.encode(KFSConstants.RETURN_LOCATION_PARAMETER + "=" + basePath + "ib.do")));
76: }
77: }
|