View Javadoc

1   /*
2    * Copyright 2005-2007 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.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   * This class tests the KualiLookupable methods.
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       * Test that the return url for a business object is getting set correctly based on the defined return fields.
46       * 
47       * @throws Exception
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  //        ObjectCode objCode = getObjectCodeService().getByPrimaryId(TestConstants.Data1.UNIVERSITY_FISCAL_YEAR, TestConstants.Data1.CHART_OF_ACCOUNTS_CODE, TestConstants.Data1.OBJECT_CODE);
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          // check url has our doc form key
64          checkURLContains("Lookup return url does not contain docFormKey", KNSConstants.DOC_FORM_KEY + "=8888888", returnUrl);
65  
66          // check url goes back to our back location
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          // check that field conversions are working correctly for keys
72          fieldConversions.put("number", "myAccount[0].chartCode");
73  
74          returnUrl = lookupableImpl.getReturnUrl(account, fieldConversions, "kualiLookupable", null).constructCompleteHtmlTag();
75  
76          // check keys have been mapped properly
77          checkURLContains("Lookup return url does not map key", "myAccount[0].chartCode=a1", returnUrl);
78      }
79  
80  
81      /**
82       * Checks the url string contains a substring.
83       * 
84       * @param message
85       * @param containString
86       * @param url
87       */
88      private void checkURLContains(String message, String containString, String url) {
89          assertTrue(message, url.indexOf(containString) > 0);
90      }
91  }