View Javadoc

1   /**
2    * Copyright 2005-2011 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.krad.service;
17  
18  import org.junit.Test;
19  import org.kuali.rice.krad.test.document.bo.Account;
20  import org.kuali.rice.krad.test.document.bo.AccountManager;
21  import org.kuali.rice.test.BaselineTestCase;
22  import org.kuali.rice.test.data.PerTestUnitTestData;
23  import org.kuali.rice.test.data.UnitTestData;
24  import org.kuali.rice.test.data.UnitTestFile;
25  import org.kuali.rice.test.data.UnitTestSql;
26  import org.kuali.test.KRADTestCase;
27  
28  import java.util.Collection;
29  import java.util.HashMap;
30  import java.util.Map;
31  
32  import static org.junit.Assert.assertEquals;
33  import static org.junit.Assert.assertTrue;
34  
35  /**
36   * LookupServiceTest tests KULRICE-984: Lookups - Relative Limit Gap
37   *
38   * <p>Making sure that lookup resultSetLimits set in the DD for
39   * a BO will override the system wide default.</p>
40   *
41   * @author Kuali Rice Team (rice.collab@kuali.org)
42   */
43  
44  @PerTestUnitTestData(
45          value = @UnitTestData(
46                  order = {UnitTestData.Type.SQL_STATEMENTS, UnitTestData.Type.SQL_FILES},
47                  sqlStatements = {
48                          @UnitTestSql("delete from trv_acct where acct_fo_id between 101 and 301")
49                          ,@UnitTestSql("delete from trv_acct_fo where acct_fo_id between 101 and 301")
50                  },
51                  sqlFiles = {
52                          @UnitTestFile(filename = "classpath:testAccountManagers.sql", delimiter = ";")
53                          , @UnitTestFile(filename = "classpath:testAccounts.sql", delimiter = ";")
54                  }
55          ),
56          tearDown = @UnitTestData(
57                  sqlStatements = {
58                          @UnitTestSql("delete from trv_acct where acct_fo_id between 101 and 301")
59                          ,@UnitTestSql("delete from trv_acct_fo where acct_fo_id between 101 and 301")
60                  }
61         )
62  )
63  @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
64  public class LookupServiceTest extends KRADTestCase {
65  
66      public LookupServiceTest() {}
67  
68      /**
69       * tests lookup return limits
70       *
71       * @throws Exception
72       */
73      @Test
74      public void testLookupReturnLimits() throws Exception {
75          LookupService lookupService = KRADServiceLocatorWeb.getLookupService();
76          Map formProps = new HashMap();
77          Collection accountManagers = lookupService.findCollectionBySearchHelper(AccountManager.class, formProps, false);
78          assertEquals(90, accountManagers.size());
79  
80          accountManagers = null;
81          accountManagers = lookupService.findCollectionBySearch(AccountManager.class, formProps);
82          assertEquals(90, accountManagers.size());
83      }
84  
85      /**
86       * tests a lookup with the default limit
87       *
88       * @throws Exception
89       */
90      @Test
91      public void testLookupReturnDefaultLimit() throws Exception {
92          LookupService lookupService = KRADServiceLocatorWeb.getLookupService();
93          Map formProps = new HashMap();
94          Collection travelAccounts = lookupService.findCollectionBySearchHelper(Account.class, formProps, false);
95          assertEquals(200, travelAccounts.size());
96  
97          travelAccounts = null;
98          travelAccounts = lookupService.findCollectionBySearch(Account.class, formProps);
99          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 }