View Javadoc

1   /**
2    * Copyright 2005-2013 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.Ignore;
19  import org.kuali.rice.krad.test.KRADTestCase;
20  
21  
22  /**
23   * Test case for InactivateableFromToService. Note on usage that the tests sets the activeAsOfDate so that the results
24   * will be consistent over time. However this is not necessary and the service will default to using the current date if
25   * not given.
26   * 
27   * @see org.kuali.rice.krad.service.InactivateableFromToService
28   */
29  /*@PerTestUnitTestData(
30          value = @UnitTestData(
31                  order = {UnitTestData.Type.SQL_STATEMENTS, UnitTestData.Type.SQL_FILES},
32                  sqlStatements = {
33                          @UnitTestSql("delete from trv_acct_use_rt_t")
34                  },
35                  sqlFiles = {
36                          @UnitTestFile(filename = "classpath:testAccountUseRate.sql", delimiter = ";")
37                  }
38          ),
39          tearDown = @UnitTestData(
40                  sqlStatements = {
41                  		@UnitTestSql("delete from trv_acct_use_rt_t")
42                  }
43         )
44  )*/
45  @Ignore
46  public class InactivateableFromToServiceTest extends KRADTestCase {
47  
48  
49  //	/**
50  //	 * Test finding active records
51  //	 *
52  //	 * @see InactivateableFromToService#findMatchingActive(Class, Map)
53  //	 */
54  //	@Test
55  //	public void testFindMatchingActive() throws Exception {
56  //		InactivateableFromToService inactivateableFromToService = KRADServiceLocatorInternal.getInactivateableFromToService();
57  //
58  //		Map fieldValues = new HashMap();
59  //		fieldValues.put(KNSPropertyConstants.ACTIVE_AS_OF_DATE, "04/01/2010");
60  //		fieldValues.put("number", "a2");
61  //
62  //		List<InactivateableFromTo> results = inactivateableFromToService.findMatchingActive(TravelAccountUseRate.class,
63  //				fieldValues);
64  //		assertEquals(2, results.size());
65  //
66  //		TravelAccountUseRate useRate = (TravelAccountUseRate) results.get(0);
67  //		assertTrue("Incorrect active records returned, do not match expected ids",
68  //				"2".equals(useRate.getId()) || "3".equals(useRate.getId()));
69  //
70  //		useRate = (TravelAccountUseRate) results.get(1);
71  //		assertTrue("Incorrect active records returned, do not match expected ids",
72  //				"2".equals(useRate.getId()) || "3".equals(useRate.getId()));
73  //
74  //		fieldValues = new HashMap();
75  //		fieldValues.put(KNSPropertyConstants.ACTIVE_AS_OF_DATE, "04/01/2010");
76  //		fieldValues.put("number", "a1");
77  //
78  //		results = inactivateableFromToService.findMatchingActive(TravelAccountUseRate.class, fieldValues);
79  //		assertEquals(1, results.size());
80  //
81  //		useRate = (TravelAccountUseRate) results.get(0);
82  //		assertTrue("Incorrect active record returned, does not match expected id", "1".equals(useRate.getId()));
83  //
84  //		fieldValues = new HashMap();
85  //		fieldValues.put(KNSPropertyConstants.ACTIVE_AS_OF_DATE, "01/01/2010 01:31 PM");
86  //		fieldValues.put("number", "b1");
87  //
88  //		results = inactivateableFromToService.findMatchingActive(TravelAccountUseRate.class, fieldValues);
89  //		assertEquals(1, results.size());
90  //
91  //		useRate = (TravelAccountUseRate) results.get(0);
92  //		assertTrue("Incorrect active record returned, does not match expected id", "9".equals(useRate.getId()));
93  //	}
94  //
95  //	/**
96  //	 * Test finding inactive records through LookupService
97  //	 */
98  //	@Test
99  //	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 }