View Javadoc

1   /*
2    * Copyright 2005-2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
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.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   * This class tests the UrlFactory methods.
28   */
29  public class UrlFactoryTest extends KNSTestCase {
30  
31      /**
32       * Test that what is returned from url factory matches the url we expect.
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          // construct lookup url
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          // assertTrue("Returned url missing parameter 4",StringUtils.contains(returnedUrl,
56          // UrlFactory.encode(KNSConstants.RETURN_LOCATION_PARAMETER + "=" + basePath + "ib.do")));
57      }
58  }