001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.lookup;
017:
018: import java.util.HashMap;
019: import java.util.Map;
020:
021: import org.junit.Test;
022: import org.kuali.RiceConstants;
023: import org.kuali.rice.KNSServiceLocator;
024: import org.kuali.test.KNSTestBase;
025: import org.kuali.test.KNSWithTestSpringContext;
026:
027: import edu.sampleu.travel.bo.TravelAccount;
028:
029: /**
030: * This class tests the KualiLookupable methods.
031: *
032: *
033: */
034: @KNSWithTestSpringContext
035: public class KualiLookupableTest extends KNSTestBase {
036: private KualiLookupableImpl lookupableImpl;
037:
038: @Override
039: public void setUp() throws Exception {
040: super .setUp();
041: lookupableImpl = (KualiLookupableImpl) KNSServiceLocator
042: .getKualiLookupable();
043: lookupableImpl.setBusinessObjectClass(TravelAccount.class);
044: }
045:
046: /**
047: * Test that the return url for a business object is getting set correctly based on the defined return fields.
048: *
049: * @throws Exception
050: */
051: @Test
052: public void testReturnUrl() throws Exception {
053: Map<String, Object> lookupProps = new HashMap<String, Object>();
054: lookupProps.put("number", "a1");
055: lookupProps.put("name", "a1");
056:
057: TravelAccount account = (TravelAccount) KNSServiceLocator
058: .getLookupService().findObjectBySearch(
059: TravelAccount.class, lookupProps);
060: // ObjectCode objCode = getObjectCodeService().getByPrimaryId(TestConstants.Data1.UNIVERSITY_FISCAL_YEAR, TestConstants.Data1.CHART_OF_ACCOUNTS_CODE, TestConstants.Data1.OBJECT_CODE);
061:
062: Map fieldConversions = new HashMap();
063: lookupableImpl.setDocFormKey("8888888");
064: lookupableImpl.setBackLocation(TestConstants.BASE_PATH
065: + "ib.do");
066:
067: String returnUrl = lookupableImpl.getReturnUrl(account,
068: fieldConversions, "kualiLookupable");
069:
070: // check url has our doc form key
071: checkURLContains(
072: "Lookup return url does not contain docFormKey",
073: RiceConstants.DOC_FORM_KEY + "=8888888", returnUrl);
074:
075: // check url goes back to our back location
076: assertTrue(
077: "Lookup return url does not go back to back location",
078: returnUrl.startsWith(TestConstants.BASE_PATH + "ib.do"));
079:
080: assertEquals(
081: returnUrl,
082: "http://localhost:8080/ib.do?refreshCaller=kualiLookupable&number=a1&methodToCall=refresh&docFormKey=8888888");
083:
084: // check that field conversions are working correctly for keys
085: fieldConversions.put("number", "myAccount[0].chartCode");
086:
087: returnUrl = lookupableImpl.getReturnUrl(account,
088: fieldConversions, "kualiLookupable");
089:
090: // check keys have been mapped properly
091: checkURLContains("Lookup return url does not map key",
092: "myAccount%5B0%5D.chartCode=a1", returnUrl);
093: }
094:
095: /**
096: * Checks the url string contains a substring.
097: *
098: * @param message
099: * @param containString
100: * @param url
101: */
102: private void checkURLContains(String message, String containString,
103: String url) {
104: assertTrue(message, url.indexOf(containString) > 0);
105: }
106: }
|