View Javadoc
1   /**
2    * Copyright 2005-2014 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.data.jpa.testbo.TestDataObject;
20  import org.kuali.rice.krad.test.document.bo.Account;
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.rice.krad.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 = '1'")
49                          ,@UnitTestSql("delete from trv_acct_type")
50                          ,@UnitTestSql("delete from krtst_test_table_t")
51                  },
52                  sqlFiles = {
53                          @UnitTestFile(filename = "classpath:testAccountType.sql", delimiter = ";")
54                          ,@UnitTestFile(filename = "classpath:testAccounts.sql", delimiter = ";")
55                          ,@UnitTestFile(filename = "classpath:testDataObjects.sql", delimiter = ";")
56                  }
57          ),
58          tearDown = @UnitTestData(
59                  sqlStatements = {
60                          @UnitTestSql("delete from trv_acct where acct_fo_id = '1'")
61                          ,@UnitTestSql("delete from krtst_test_table_t")
62                  }
63         )
64  )
65  @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.NONE)
66  public class LookupServiceTest extends KRADTestCase {
67  
68      // Methods which can be overridden by subclasses to reuse test cases. Here we are just testing the LookupService
69      protected <T> Collection<T> findCollectionBySearchHelper(Class<T> clazz, Map<String, String> formProps, boolean unbounded) {
70          return KRADServiceLocatorWeb.getLookupService().findCollectionBySearchHelper(clazz, formProps, unbounded);
71      }
72  
73      protected <T> Collection<T> findCollectionBySearch(Class<T> clazz, Map<String, String> formProps) {
74          return KRADServiceLocatorWeb.getLookupService().findCollectionBySearch(clazz, formProps);
75      }
76  
77      protected <T> Collection<T> findCollectionBySearchUnbounded(Class<T> clazz, Map<String, String> formProps) {
78          return KRADServiceLocatorWeb.getLookupService().findCollectionBySearchUnbounded(clazz, formProps);
79      }
80  
81      /**
82       * tests lookup return limits
83       *
84       * @throws Exception
85       */
86       @Test
87       public void testLookupReturnLimits_Account() throws Exception {
88          Map formProps = new HashMap();
89          Collection travelAccounts = findCollectionBySearchHelper(Account.class, formProps, false);
90          assertEquals(200, travelAccounts.size());
91  
92          travelAccounts = findCollectionBySearch(Account.class, formProps);
93          assertEquals(200, travelAccounts.size());
94       }
95  
96      /**
97       * tests lookup return limits
98       *
99       * @throws Exception
100      */
101     @Test
102     public void testLookupReturnLimits_TestDataObject() throws Exception {
103         Map formProps = new HashMap();
104         Collection testDataObjects = findCollectionBySearchHelper(TestDataObject.class, formProps, false);
105         assertEquals(200, testDataObjects.size());
106 
107         testDataObjects = findCollectionBySearch(TestDataObject.class, formProps);
108         assertEquals(200, testDataObjects.size());
109     }
110 
111     /**
112      * tests a lookup with the default limit
113      *
114      * @throws Exception
115      */
116     @Test
117     public void testLookupReturnDefaultLimit() throws Exception {
118         Map formProps = new HashMap();
119         Collection travelAccounts = findCollectionBySearchHelper(Account.class, formProps, false);
120         assertEquals(200, travelAccounts.size());
121 
122         travelAccounts = findCollectionBySearch(Account.class, formProps);
123         assertEquals(200, travelAccounts.size());
124     }
125 
126     /**
127      * tests an unbounded lookup
128      *
129      * @throws Exception
130      */
131     @Test
132     public void testLookupReturnDefaultUnbounded_Account() throws Exception {
133         Map formProps = new HashMap();
134         Collection travelAccounts = findCollectionBySearchHelper(Account.class, formProps, true);
135         int size = travelAccounts.size();
136         assertTrue("# of Travel Accounts should be > 200", size > 200);
137 
138         travelAccounts = findCollectionBySearchUnbounded(Account.class, formProps);
139         size = travelAccounts.size();
140         assertTrue("# of Travel Accounts should be > 200", size > 200);
141     }
142 
143     /**
144      * tests an unbounded lookup
145      *
146      * @throws Exception
147      */
148     @Test
149     public void testLookupReturnDefaultUnbounded_TestDataObject() throws Exception {
150         Map formProps = new HashMap();
151         Collection testDataObjects = findCollectionBySearchHelper(TestDataObject.class, formProps, true);
152         int size = testDataObjects.size();
153         assertTrue("# of Test Data objects should be > 200", size > 200);
154 
155         testDataObjects = findCollectionBySearchUnbounded(TestDataObject.class, formProps);
156         size = testDataObjects.size();
157         assertTrue("# of Test Data objects should be > 200", size > 200);
158     }
159 
160 }