001    /**
002     * Copyright 2005-2011 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.Ignore;
019    import org.kuali.test.KRADTestCase;
020    
021    
022    /**
023     * Test case for InactivateableFromToService. Note on usage that the tests sets the activeAsOfDate so that the results
024     * will be consistent over time. However this is not necessary and the service will default to using the current date if
025     * not given.
026     * 
027     * @see org.kuali.rice.krad.service.InactivateableFromToService
028     */
029    /*@PerTestUnitTestData(
030            value = @UnitTestData(
031                    order = {UnitTestData.Type.SQL_STATEMENTS, UnitTestData.Type.SQL_FILES},
032                    sqlStatements = {
033                            @UnitTestSql("delete from trv_acct_use_rt_t")
034                    },
035                    sqlFiles = {
036                            @UnitTestFile(filename = "classpath:testAccountUseRate.sql", delimiter = ";")
037                    }
038            ),
039            tearDown = @UnitTestData(
040                    sqlStatements = {
041                                    @UnitTestSql("delete from trv_acct_use_rt_t")
042                    }
043           )
044    )*/
045    @Ignore
046    public class InactivateableFromToServiceTest extends KRADTestCase {
047    
048    
049    //      /**
050    //       * Test finding active records
051    //       *
052    //       * @see InactivateableFromToService#findMatchingActive(Class, Map)
053    //       */
054    //      @Test
055    //      public void testFindMatchingActive() throws Exception {
056    //              InactivateableFromToService inactivateableFromToService = KRADServiceLocatorInternal.getInactivateableFromToService();
057    //
058    //              Map fieldValues = new HashMap();
059    //              fieldValues.put(KNSPropertyConstants.ACTIVE_AS_OF_DATE, "04/01/2010");
060    //              fieldValues.put("number", "a2");
061    //
062    //              List<InactivateableFromTo> results = inactivateableFromToService.findMatchingActive(TravelAccountUseRate.class,
063    //                              fieldValues);
064    //              assertEquals(2, results.size());
065    //
066    //              TravelAccountUseRate useRate = (TravelAccountUseRate) results.get(0);
067    //              assertTrue("Incorrect active records returned, do not match expected ids",
068    //                              "2".equals(useRate.getId()) || "3".equals(useRate.getId()));
069    //
070    //              useRate = (TravelAccountUseRate) results.get(1);
071    //              assertTrue("Incorrect active records returned, do not match expected ids",
072    //                              "2".equals(useRate.getId()) || "3".equals(useRate.getId()));
073    //
074    //              fieldValues = new HashMap();
075    //              fieldValues.put(KNSPropertyConstants.ACTIVE_AS_OF_DATE, "04/01/2010");
076    //              fieldValues.put("number", "a1");
077    //
078    //              results = inactivateableFromToService.findMatchingActive(TravelAccountUseRate.class, fieldValues);
079    //              assertEquals(1, results.size());
080    //
081    //              useRate = (TravelAccountUseRate) results.get(0);
082    //              assertTrue("Incorrect active record returned, does not match expected id", "1".equals(useRate.getId()));
083    //
084    //              fieldValues = new HashMap();
085    //              fieldValues.put(KNSPropertyConstants.ACTIVE_AS_OF_DATE, "01/01/2010 01:31 PM");
086    //              fieldValues.put("number", "b1");
087    //
088    //              results = inactivateableFromToService.findMatchingActive(TravelAccountUseRate.class, fieldValues);
089    //              assertEquals(1, results.size());
090    //
091    //              useRate = (TravelAccountUseRate) results.get(0);
092    //              assertTrue("Incorrect active record returned, does not match expected id", "9".equals(useRate.getId()));
093    //      }
094    //
095    //      /**
096    //       * Test finding inactive records through LookupService
097    //       */
098    //      @Test
099    //      public void testFindMatchingActive_inactive() throws Exception {
100    //              LookupService lookupService = KRADServiceLocatorWeb.getLookupService();
101    //
102    //              Map fieldValues = new HashMap();
103    //              fieldValues.put(KNSPropertyConstants.ACTIVE, "N");
104    //              fieldValues.put(KNSPropertyConstants.ACTIVE_AS_OF_DATE, "04/01/2010");
105    //              fieldValues.put("number", "a2");
106    //
107    //              List<InactivateableFromTo> results = (List<InactivateableFromTo>) lookupService.findCollectionBySearchUnbounded(TravelAccountUseRate.class,
108    //                              fieldValues);
109    //              assertEquals(1, results.size());
110    //
111    //              TravelAccountUseRate useRate = (TravelAccountUseRate) results.get(0);
112    //              assertTrue("Incorrect inactive record returned, does not match expected id",
113    //                              "4".equals(useRate.getId()));
114    //
115    //              fieldValues = new HashMap();
116    //              fieldValues.put(KNSPropertyConstants.ACTIVE, "N");
117    //              fieldValues.put(KNSPropertyConstants.ACTIVE_AS_OF_DATE, "07/01/2010");
118    //              fieldValues.put("number", "a3");
119    //
120    //              results = (List<InactivateableFromTo>) lookupService.findCollectionBySearchUnbounded(TravelAccountUseRate.class, fieldValues);
121    //              assertEquals(1, results.size());
122    //
123    //              useRate = (TravelAccountUseRate) results.get(0);
124    //              assertTrue("Incorrect inactive record returned, does not match expected id", "5".equals(useRate.getId()));
125    //      }
126    //
127    //      /**
128    //       * Test query results when begin date is null
129    //       *
130    //       * @see InactivateableFromToService#findMatchingActive(Class, Map)
131    //       */
132    //      @Test
133    //      public void testFindMatchingActive_nullBeginDate() throws Exception {
134    //              InactivateableFromToService inactivateableFromToService = KRADServiceLocatorInternal.getInactivateableFromToService();
135    //
136    //              Map fieldValues = new HashMap();
137    //              fieldValues.put(KNSPropertyConstants.ACTIVE_AS_OF_DATE, "04/01/2010");
138    //              fieldValues.put("number", "a4");
139    //
140    //              List<InactivateableFromTo> results = inactivateableFromToService.findMatchingActive(TravelAccountUseRate.class,
141    //                              fieldValues);
142    //              assertEquals(1, results.size());
143    //
144    //              TravelAccountUseRate useRate = (TravelAccountUseRate) results.get(0);
145    //              assertTrue("Incorrect inactive record returned, does not match expected id", "6".equals(useRate.getId()));
146    //
147    //              LookupService lookupService = KRADServiceLocatorWeb.getLookupService();
148    //
149    //              fieldValues = new HashMap();
150    //              fieldValues.put(KNSPropertyConstants.ACTIVE, "N");
151    //              fieldValues.put(KNSPropertyConstants.ACTIVE_AS_OF_DATE, "04/01/2010");
152    //              fieldValues.put("number", "a4");
153    //
154    //              results = (List<InactivateableFromTo>) lookupService.findCollectionBySearchUnbounded(TravelAccountUseRate.class, fieldValues);
155    //              assertEquals(0, results.size());
156    //      }
157    //
158    //      /**
159    //       * Test query results when end date is null
160    //       *
161    //       * @see InactivateableFromToService#findMatchingActive(Class, Map)
162    //       */
163    //      @Test
164    //      public void testFindMatchingActive_nullEndDate() throws Exception {
165    //              InactivateableFromToService inactivateableFromToService = KRADServiceLocatorInternal.getInactivateableFromToService();
166    //
167    //              Map fieldValues = new HashMap();
168    //              fieldValues.put(KNSPropertyConstants.ACTIVE_AS_OF_DATE, "04/01/2030");
169    //              fieldValues.put("number", "a5");
170    //
171    //              List<InactivateableFromTo> results = inactivateableFromToService.findMatchingActive(TravelAccountUseRate.class,
172    //                              fieldValues);
173    //              assertEquals(1, results.size());
174    //
175    //              TravelAccountUseRate useRate = (TravelAccountUseRate) results.get(0);
176    //              assertTrue("Incorrect active record returned, does not match expected id", "7".equals(useRate.getId()));
177    //      }
178    //
179    //      /**
180    //       * Test query results when the begin and end date is null
181    //       *
182    //       * @see InactivateableFromToService#findMatchingActive(Class, Map)
183    //       */
184    //      @Test
185    //      public void testFindMatchingActive_nullBeginEndDate() throws Exception {
186    //              InactivateableFromToService inactivateableFromToService = KRADServiceLocatorInternal.getInactivateableFromToService();
187    //
188    //              Map fieldValues = new HashMap();
189    //              fieldValues.put(KNSPropertyConstants.ACTIVE_AS_OF_DATE, "04/01/2010");
190    //              fieldValues.put("number", "a6");
191    //
192    //              List<InactivateableFromTo> results = inactivateableFromToService.findMatchingActive(TravelAccountUseRate.class,
193    //                              fieldValues);
194    //              assertEquals(1, results.size());
195    //
196    //              TravelAccountUseRate useRate = (TravelAccountUseRate) results.get(0);
197    //              assertTrue("Incorrect active record returned, does not match expected id", "8".equals(useRate.getId()));
198    //      }
199    //
200    //      /**
201    //       * Test for the filterOutNonActive method
202    //       *
203    //       * @see InactivateableFromToService#filterOutNonActive(List)
204    //       */
205    //      @Test
206    //      public void testFilterOutNonActive() throws Exception {
207    //              InactivateableFromToService inactivateableFromToService = KRADServiceLocatorInternal.getInactivateableFromToService();
208    //
209    //              List<InactivateableFromTo> filterList = new ArrayList<InactivateableFromTo>();
210    //              filterList.add(constructUseRate("1", "a1", "01/01/2010", "01/01/2011"));
211    //              filterList.add(constructUseRate("2", "a1", "01/01/2012", "01/01/2013"));
212    //              filterList.add(constructUseRate("3", "a2", "01/01/2009", "01/01/2010"));
213    //              filterList.add(constructUseRate("4", "a3", "01/01/2010", "05/16/2010"));
214    //              filterList.add(constructUseRate("5", "a4", null, "01/01/2011"));
215    //
216    //              Date activeAsOfDate = KRADServiceLocator.getDateTimeService().convertToSqlDate("06/01/2010");
217    //              List<InactivateableFromTo> accessibleList = inactivateableFromToService.filterOutNonActive(filterList,
218    //                              activeAsOfDate);
219    //              assertEquals(2, accessibleList.size());
220    //
221    //              TravelAccountUseRate useRate = (TravelAccountUseRate) accessibleList.get(0);
222    //              assertTrue("Incorrect active records returned, do not match expected ids", "1".equals(useRate.getId()) || "5".equals(useRate.getId()));
223    //
224    //              useRate = (TravelAccountUseRate) accessibleList.get(1);
225    //              assertTrue("Incorrect active records returned, do not match expected ids", "1".equals(useRate.getId()) || "5".equals(useRate.getId()));
226    //      }
227    //
228    //      /**
229    //       * Test finding current records through the findMatchingCurrent method
230    //       *
231    //       * @see InactivateableFromToService#findMatchingCurrent(Class, Map)
232    //       */
233    //      @Test
234    //      public void testFindMatchingCurrent() throws Exception {
235    //              InactivateableFromToService inactivateableFromToService = KRADServiceLocatorInternal.getInactivateableFromToService();
236    //
237    //              Map fieldValues = new HashMap();
238    //              fieldValues.put(KNSPropertyConstants.ACTIVE_AS_OF_DATE, "06/01/2010");
239    //              fieldValues.put("number", "a2");
240    //
241    //              List<InactivateableFromTo> results = inactivateableFromToService.findMatchingCurrent(TravelAccountUseRate.class,
242    //                              fieldValues);
243    //              assertEquals(1, results.size());
244    //
245    //              TravelAccountUseRate useRate = (TravelAccountUseRate) results.get(0);
246    //              assertTrue("Incorrect current record returned, does not match expected id", "3".equals(useRate.getId()));
247    //      }
248    //
249    //      /**
250    //       * Test for the filterOutNonCurrent method
251    //       *
252    //       * @see InactivateableFromToService#filterOutNonCurrent(List)
253    //       */
254    //      @Test
255    //      public void testFilterOutNonCurrent() throws Exception {
256    //              InactivateableFromToService inactivateableFromToService = KRADServiceLocatorInternal.getInactivateableFromToService();
257    //
258    //              List<InactivateableFromTo> filterList = new ArrayList<InactivateableFromTo>();
259    //              filterList.add(constructUseRate("1", "a1", "01/01/2010", "01/01/2011"));
260    //              filterList.add(constructUseRate("2", "a1", "01/16/2010", "01/01/2011"));
261    //              filterList.add(constructUseRate("3", "a1", "01/01/2012", "01/01/2013"));
262    //              filterList.add(constructUseRate("4", "a2", "01/01/2009", "01/01/2010"));
263    //              filterList.add(constructUseRate("5", "a3", "01/01/2010", "05/16/2011"));
264    //              filterList.add(constructUseRate("6", "a3", "06/01/2010", "05/16/2011"));
265    //
266    //              Date activeAsOfDate = KRADServiceLocator.getDateTimeService().convertToSqlDate("06/10/2010");
267    //              List<InactivateableFromTo> accessibleList = inactivateableFromToService.filterOutNonCurrent(filterList,
268    //                              activeAsOfDate);
269    //              assertEquals(2, accessibleList.size());
270    //
271    //              TravelAccountUseRate useRate = (TravelAccountUseRate) accessibleList.get(0);
272    //              assertTrue("Incorrect curren records returned, do not match expected ids",
273    //                              "2".equals(useRate.getId()) || "6".equals(useRate.getId()));
274    //
275    //              useRate = (TravelAccountUseRate) accessibleList.get(1);
276    //              assertTrue("Incorrect curren records returned, do not match expected ids",
277    //                              "2".equals(useRate.getId()) || "6".equals(useRate.getId()));
278    //      }
279    //
280    //      protected TravelAccountUseRate constructUseRate(String id, String number, String fromDate, String toDate)
281    //                      throws Exception {
282    //              TravelAccountUseRate useRate = new TravelAccountUseRate();
283    //
284    //              DateTimeService dateTimeService = KRADServiceLocator.getDateTimeService();
285    //              useRate.setId(id);
286    //              useRate.setNumber(number);
287    //              if (fromDate != null) {
288    //                      useRate.setActiveFromDate(new Timestamp(dateTimeService.convertToSqlDate(fromDate).getTime()));
289    //              }
290    //              if (toDate != null) {
291    //                      useRate.setActiveToDate(new Timestamp(dateTimeService.convertToSqlDate(toDate).getTime()));
292    //              }
293    //
294    //              return useRate;
295    //      }
296    }