001 /**
002 * Copyright 2005-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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.rice.krad.service;
017
018 import org.junit.Test;
019 import org.kuali.rice.krad.test.document.bo.Account;
020 import org.kuali.rice.krad.test.document.bo.AccountManager;
021 import org.kuali.rice.test.BaselineTestCase;
022 import org.kuali.rice.test.data.PerTestUnitTestData;
023 import org.kuali.rice.test.data.UnitTestData;
024 import org.kuali.rice.test.data.UnitTestFile;
025 import org.kuali.rice.test.data.UnitTestSql;
026 import org.kuali.rice.krad.test.KRADTestCase;
027
028 import java.util.Collection;
029 import java.util.HashMap;
030 import java.util.Map;
031
032 import static org.junit.Assert.assertEquals;
033 import static org.junit.Assert.assertTrue;
034
035 /**
036 * LookupServiceTest tests KULRICE-984: Lookups - Relative Limit Gap
037 *
038 * <p>Making sure that lookup resultSetLimits set in the DD for
039 * a BO will override the system wide default.</p>
040 *
041 * @author Kuali Rice Team (rice.collab@kuali.org)
042 */
043
044 @PerTestUnitTestData(
045 value = @UnitTestData(
046 order = {UnitTestData.Type.SQL_STATEMENTS, UnitTestData.Type.SQL_FILES},
047 sqlStatements = {
048 @UnitTestSql("delete from trv_acct where acct_fo_id between 101 and 301")
049 ,@UnitTestSql("delete from trv_acct_fo where acct_fo_id between 101 and 301")
050 },
051 sqlFiles = {
052 @UnitTestFile(filename = "classpath:testAccountManagers.sql", delimiter = ";")
053 , @UnitTestFile(filename = "classpath:testAccounts.sql", delimiter = ";")
054 }
055 ),
056 tearDown = @UnitTestData(
057 sqlStatements = {
058 @UnitTestSql("delete from trv_acct where acct_fo_id between 101 and 301")
059 ,@UnitTestSql("delete from trv_acct_fo where acct_fo_id between 101 and 301")
060 }
061 )
062 )
063 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
064 public class LookupServiceTest extends KRADTestCase {
065
066 public LookupServiceTest() {}
067
068 /**
069 * tests lookup return limits
070 *
071 * @throws Exception
072 */
073 @Test
074 public void testLookupReturnLimits() throws Exception {
075 LookupService lookupService = KRADServiceLocatorWeb.getLookupService();
076 Map formProps = new HashMap();
077 Collection accountManagers = lookupService.findCollectionBySearchHelper(AccountManager.class, formProps, false);
078 assertEquals(90, accountManagers.size());
079
080 accountManagers = null;
081 accountManagers = lookupService.findCollectionBySearch(AccountManager.class, formProps);
082 assertEquals(90, accountManagers.size());
083 }
084
085 /**
086 * tests a lookup with the default limit
087 *
088 * @throws Exception
089 */
090 @Test
091 public void testLookupReturnDefaultLimit() throws Exception {
092 LookupService lookupService = KRADServiceLocatorWeb.getLookupService();
093 Map formProps = new HashMap();
094 Collection travelAccounts = lookupService.findCollectionBySearchHelper(Account.class, formProps, false);
095 assertEquals(200, travelAccounts.size());
096
097 travelAccounts = null;
098 travelAccounts = lookupService.findCollectionBySearch(Account.class, formProps);
099 assertEquals(200, travelAccounts.size());
100 }
101
102 /**
103 * tests an unbounded lookup
104 *
105 * @throws Exception
106 */
107 @Test
108 public void testLookupReturnDefaultUnbounded() throws Exception {
109 LookupService lookupService = KRADServiceLocatorWeb.getLookupService();
110 Map formProps = new HashMap();
111 Collection accountManagers = lookupService.findCollectionBySearchHelper(AccountManager.class, formProps, true);
112 int size = accountManagers.size();
113 assertTrue("# of Fiscal Officers should be > 200", size > 200);
114
115 accountManagers = null;
116 accountManagers = lookupService.findCollectionBySearchUnbounded(AccountManager.class, formProps);
117 size = accountManagers.size();
118 assertTrue("# of Fiscal Officers should be > 200", size > 200);
119 }
120
121 /**
122 * tests an unbounded lookup
123 *
124 * @throws Exception
125 */
126 @Test
127 public void testLookupReturnDefaultUnbounded2() throws Exception {
128 LookupService lookupService = KRADServiceLocatorWeb.getLookupService();
129 Map formProps = new HashMap();
130 Collection travelAccounts = lookupService.findCollectionBySearchHelper(Account.class, formProps, true);
131 int size = travelAccounts.size();
132 assertTrue("# of Travel Accounts should be > 200", size > 200);
133
134 travelAccounts = null;
135 travelAccounts = lookupService.findCollectionBySearchUnbounded(Account.class, formProps);
136 size = travelAccounts.size();
137 assertTrue("# of Travel Accounts should be > 200", size > 200);
138 }
139
140 }