View Javadoc

1   package org.kuali.ole.deliver.request;
2   
3   import org.junit.Before;
4   import org.junit.Test;
5   import org.junit.runner.RunWith;
6   import org.kuali.ole.OLEConstants;
7   import org.kuali.ole.OleBaseTestCase;
8   import org.kuali.ole.deliver.circulationdesk.bo.OleCirculationDesk;
9   import org.kuali.ole.deliver.request.bo.OleDeliverRequestBo;
10  import org.kuali.ole.deliver.request.bo.OleDeliverRequestType;
11  import org.kuali.ole.deliver.request.service.OleDeliverRequestDocumentHelperServiceImpl;
12  import org.kuali.ole.patron.api.OlePatronDefinition;
13  import org.kuali.ole.patron.api.OlePatronDefintionHelper;
14  import org.kuali.ole.patron.bo.OlePatronDocument;
15  import org.kuali.rice.krad.service.BusinessObjectService;
16  import org.kuali.rice.krad.service.KRADServiceLocator;
17  import org.springframework.test.context.ContextConfiguration;
18  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
19  import org.springframework.test.context.transaction.TransactionConfiguration;
20  import org.springframework.transaction.annotation.Transactional;
21  import static junit.framework.Assert.*;
22  
23  import java.util.*;
24  
25  /**
26   * Created with IntelliJ IDEA.
27   * User: ?
28   * Date: 11/2/12
29   * Time: 12:21 PM
30   * To change this template use File | Settings | File Templates.
31   */
32  @ContextConfiguration(locations = {"classpath:/SpringBeans.xml"})
33  @RunWith(value = SpringJUnit4ClassRunner.class)
34  @TransactionConfiguration(defaultRollback = true)
35  public class OleDeliverRequestDocumentHelperServiceimpl_UT extends OleBaseTestCase {
36         private BusinessObjectService businessObjectService;
37         private OleDeliverRequestDocumentHelperServiceImpl service;
38         private OlePatronDocument olePatronDocument;
39  
40  
41  
42  
43      @Before
44      public void setUp() throws Exception {
45          businessObjectService = KRADServiceLocator.getBusinessObjectService();
46          service = new OleDeliverRequestDocumentHelperServiceImpl();
47          olePatronDocument =  getOlePatronDocument();
48  
49      }
50  
51      public OlePatronDocument getOlePatronDocument (){
52          OlePatronDefinition olePatronDefinition = OlePatronDefintionHelper.create();
53          OlePatronDocument olePatronDocument = OlePatronDocument.from(olePatronDefinition);
54          return olePatronDocument;
55      }
56  
57  
58      @Test
59      @Transactional
60      public void validateRequestTypeTest(){
61          OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
62          oleDeliverRequestBo.setRequestId("1");
63          oleDeliverRequestBo.setRequestTypeId("2");
64        boolean isValid =  service.validateRequestType(oleDeliverRequestBo);
65          assertFalse(isValid);
66  
67      }
68  
69  
70      @Test
71      @Transactional
72      public void validateDeliveryPrivilegeTest(){
73         if(olePatronDocument!=null){
74             olePatronDocument.setDeliveryPrivilege(true);
75             businessObjectService.save(olePatronDocument);
76             OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
77             oleDeliverRequestBo.setRequestId("1");
78             oleDeliverRequestBo.setRequestTypeId("1");
79             oleDeliverRequestBo.setOlePatron(olePatronDocument);
80         boolean isValid=    service.validateDeliveryPrivilege(oleDeliverRequestBo);
81             assertTrue(isValid);
82         }   }
83  
84  
85    @Test
86    @Transactional
87   public void validatePagingPrivilegeTest(){
88       if(olePatronDocument!=null){
89           olePatronDocument.setPagingPrivilege(true);
90           businessObjectService.save(olePatronDocument);
91           OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
92           oleDeliverRequestBo.setRequestId("1");
93           oleDeliverRequestBo.setRequestTypeId("1");
94           oleDeliverRequestBo.setOlePatron(olePatronDocument);
95           boolean isValid= service.validatePagingPrivilege(oleDeliverRequestBo);
96           assertTrue(isValid);
97       }   }
98  
99  
100 
101     @Test
102     @Transactional
103     public void validateProxyPatronTest(){
104         if(olePatronDocument!=null){
105             olePatronDocument.setPagingPrivilege(true);
106             businessObjectService.save(olePatronDocument);
107             OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
108             oleDeliverRequestBo.setRequestId("1");
109             oleDeliverRequestBo.setRequestTypeId("1");
110             oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
111             oleDeliverRequestBo.setProxyBorrowerId(olePatronDocument.getProxyPatronId());
112             oleDeliverRequestBo.setOlePatron(olePatronDocument);
113             assertTrue(service.isValidProxyPatron(oleDeliverRequestBo)) ;
114         }   }
115 
116 
117     @Test
118     @Transactional
119     public void isRequestAlreadyRaisedByPatronTest(){
120         if(olePatronDocument!=null){
121             olePatronDocument.setPagingPrivilege(true);
122             businessObjectService.save(olePatronDocument);
123             OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
124             oleDeliverRequestBo.setRequestId("1");
125             oleDeliverRequestBo.setRequestTypeId("1");
126             oleDeliverRequestBo.setItemId("1");
127             oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
128             oleDeliverRequestBo.setOlePatron(olePatronDocument);
129             businessObjectService.save(oleDeliverRequestBo);
130             OleDeliverRequestBo oleDeliverRequestBo1 = new OleDeliverRequestBo();
131             oleDeliverRequestBo1.setRequestId("2");
132             oleDeliverRequestBo1.setRequestTypeId("1");
133             oleDeliverRequestBo1.setItemId("1");
134             oleDeliverRequestBo1.setBorrowerId(olePatronDocument.getOlePatronId());
135             oleDeliverRequestBo1.setOlePatron(olePatronDocument);
136            boolean isRequestRaised = service.isRequestAlreadyRaisedByPatron(oleDeliverRequestBo1);
137             assertTrue(isRequestRaised);
138 
139         }
140     }
141 
142 
143     @Test
144     @Transactional
145     public void isPatronRecordExpiredTest(){
146         if(olePatronDocument!=null){
147             OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
148             oleDeliverRequestBo.setRequestId("1");
149             oleDeliverRequestBo.setRequestTypeId("1");
150             olePatronDocument.setExpirationDate(new Date(2013, 5, 5));
151             businessObjectService.save(olePatronDocument);
152             oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
153             oleDeliverRequestBo.setOlePatron(olePatronDocument);
154             boolean isValid=    service.isPatronRecordExpired(oleDeliverRequestBo);
155             assertFalse(isValid);
156         }   }
157 
158 
159 
160     //working
161     @Test
162     @Transactional
163     public void isItemEligibleTest(){
164         OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
165         oleDeliverRequestBo.setRequestId("1");
166         oleDeliverRequestBo.setRequestTypeId("1");
167         oleDeliverRequestBo.setItemStatus("AVAILABLE");
168 
169        assertTrue(service.isItemEligible(oleDeliverRequestBo));
170 
171     }
172 
173     @Test
174     @Transactional
175     public void processRequesterTest(){
176         businessObjectService.save(olePatronDocument);
177         OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
178         oleDeliverRequestBo.setRequestId("1");
179         oleDeliverRequestBo.setRequestTypeId("1");
180         oleDeliverRequestBo.setRequestCreator("Patron");
181         oleDeliverRequestBo.setBorrowerId("1");
182         oleDeliverRequestBo.setProxyBorrowerId("2");
183 
184         assertNull(service.processRequester(oleDeliverRequestBo).getProxyBorrowerId());
185     }
186 
187     @Test
188     @Transactional
189     public void processRequestTypeTest(){
190         businessObjectService.save(olePatronDocument);
191         OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
192         oleDeliverRequestBo.setRequestId("1");
193         oleDeliverRequestBo.setRequestTypeId("1");
194         oleDeliverRequestBo.setPickUpLocationId("1");
195         oleDeliverRequestBo = service.processRequestType(oleDeliverRequestBo);
196 
197         assertEquals("2",oleDeliverRequestBo.getRequestTypeId());
198     }
199 
200 
201     @Test
202     @Transactional
203     public void processPatronTest(){
204         businessObjectService.save(olePatronDocument);
205         OleCirculationDesk oleCirculationDesk = new OleCirculationDesk();
206         oleCirculationDesk.setCirculationDeskId("1");
207         oleCirculationDesk.setCirculationDeskCode("Mock Circulation Desk Code");
208         oleCirculationDesk.setCirculationDeskPublicName("Mock Circulation Desk Public Name");
209         oleCirculationDesk.setCirculationDeskStaffName("Mock Circulation Desk Staff Name");
210         oleCirculationDesk.setActive(true);
211         businessObjectService.save(oleCirculationDesk);
212         OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
213         oleDeliverRequestBo.setRequestId("1");
214         oleDeliverRequestBo.setRequestTypeId("1");
215         oleDeliverRequestBo.setPickUpLocationId("1");
216         oleDeliverRequestBo.setRequestCreator(OLEConstants.OleDeliverRequest.REQUESTER_PATRON);
217         oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
218         oleDeliverRequestBo = service.processPatron(oleDeliverRequestBo);
219 
220         assertEquals(olePatronDocument.getOlePatronId(),oleDeliverRequestBo.getOlePatron().getOlePatronId());
221     }
222 
223     @Test
224     @Transactional
225     public void deleteRequestTest(){
226         businessObjectService.save(olePatronDocument);
227         OleCirculationDesk oleCirculationDesk = new OleCirculationDesk();
228         oleCirculationDesk.setCirculationDeskId("1");
229         oleCirculationDesk.setCirculationDeskCode("Mock Circulation Desk Code");
230         oleCirculationDesk.setCirculationDeskPublicName("Mock Circulation Desk Public Name");
231         oleCirculationDesk.setCirculationDeskStaffName("Mock Circulation Desk Staff Name");
232         oleCirculationDesk.setActive(true);
233         businessObjectService.save(oleCirculationDesk);
234         OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
235         oleDeliverRequestBo.setRequestId("1");
236         oleDeliverRequestBo.setRequestTypeId("1");
237         oleDeliverRequestBo.setRequestTypeCode("Copy Request");
238         oleDeliverRequestBo.setPickUpLocationId("1");
239         oleDeliverRequestBo.setItemId("1");
240         oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
241         businessObjectService.save(oleDeliverRequestBo);
242          service.deleteRequest("1", "1","1","1");
243         Map<String,String> requestMap = new HashMap<String,String>();
244         requestMap.put("requestId",oleDeliverRequestBo.getRequestId());
245         requestMap.put("itemId",oleDeliverRequestBo.getItemId());
246         List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>) businessObjectService.findMatching(OleDeliverRequestBo.class,requestMap);
247         assertTrue(oleDeliverRequestBoList.size() == 0);
248 
249     }
250 
251 
252   /*  @Test
253     @Transactional
254     public void getRequestedItemsTest(){
255         businessObjectService.save(olePatronDocument);
256         OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
257         oleDeliverRequestBo.setRequestId("1");
258         oleDeliverRequestBo.setRequestTypeId("1");
259         oleDeliverRequestBo.setPickUpLocationId("1");
260         oleDeliverRequestBo.setItemId("1");
261         oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
262         OleDeliverRequestBo oleDeliverRequestBo1 = new OleDeliverRequestBo();
263         oleDeliverRequestBo1.setRequestId("2");
264         oleDeliverRequestBo1.setRequestTypeId("1");
265         oleDeliverRequestBo1.setPickUpLocationId("1");
266         oleDeliverRequestBo1.setItemId("2");
267         oleDeliverRequestBo1.setBorrowerId(olePatronDocument.getOlePatronId());
268         businessObjectService.save(oleDeliverRequestBo);
269         businessObjectService.save(oleDeliverRequestBo1);
270 
271         List<OleDeliverRequestBo> oleDeliverRequestBoList = service.getRequestedItems(olePatronDocument.getOlePatronId());
272 
273         assertTrue(oleDeliverRequestBoList.size()==2);
274     }*/
275 
276     @Test
277     @Transactional
278     public void isRequestedRaisedTest(){
279         businessObjectService.save(olePatronDocument);
280         OleCirculationDesk oleCirculationDesk = new OleCirculationDesk();
281         oleCirculationDesk.setCirculationDeskId("1");
282         oleCirculationDesk.setCirculationDeskCode("Mock Circulation Desk Code");
283         oleCirculationDesk.setCirculationDeskPublicName("Mock Circulation Desk Public Name");
284         oleCirculationDesk.setCirculationDeskStaffName("Mock Circulation Desk Staff Name");
285         oleCirculationDesk.setActive(true);
286         businessObjectService.save(oleCirculationDesk);
287         OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
288         oleDeliverRequestBo.setRequestId("1");
289         oleDeliverRequestBo.setRequestTypeId("1");
290         oleDeliverRequestBo.setPickUpLocationId("1");
291         oleDeliverRequestBo.setItemId("1");
292         oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
293         OleDeliverRequestBo oleDeliverRequestBo1 = new OleDeliverRequestBo();
294         oleDeliverRequestBo1.setRequestId("2");
295         oleDeliverRequestBo1.setRequestTypeId("1");
296         oleDeliverRequestBo1.setPickUpLocationId("1");
297         oleDeliverRequestBo1.setItemId("1");
298         oleDeliverRequestBo1.setBorrowerId(olePatronDocument.getOlePatronId());
299         businessObjectService.save(oleDeliverRequestBo);
300           boolean isRaised= service.isRequestRaised(oleDeliverRequestBo1);
301         assertTrue(isRaised);
302     }
303 
304     @Test
305     @Transactional
306     public void isItemAvailableTest(){
307         businessObjectService.save(olePatronDocument);
308         OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
309         oleDeliverRequestBo.setRequestId("1");
310         oleDeliverRequestBo.setRequestTypeId("1");
311         oleDeliverRequestBo.setPickUpLocationId("1");
312         oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
313         boolean available = service.isItemAvailable(oleDeliverRequestBo);
314 
315         assertTrue(available);
316     }
317     @Test
318     @Transactional
319     public void isAlreadyLoanedTest(){
320         businessObjectService.save(olePatronDocument);
321         OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
322         oleDeliverRequestBo.setRequestId("1");
323         oleDeliverRequestBo.setRequestTypeId("1");
324         oleDeliverRequestBo.setPickUpLocationId("1");
325         oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
326         boolean available = service.isAlreadyLoaned(oleDeliverRequestBo);
327 
328         assertFalse(available);
329     }
330 
331     @Test
332     @Transactional
333     public void canRaiseRequestTest(){
334         businessObjectService.save(olePatronDocument);
335         OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
336         oleDeliverRequestBo.setRequestId("1");
337         oleDeliverRequestBo.setRequestTypeId("1");
338         oleDeliverRequestBo.setPickUpLocationId("1");
339         oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
340         boolean available = service.canRaiseRequest(oleDeliverRequestBo);
341         assertFalse(available);
342     }
343     @Test
344     @Transactional
345     public void reOrderQueuePositionTest(){
346         businessObjectService.save(olePatronDocument);
347         OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
348         oleDeliverRequestBo.setRequestId("1");
349         oleDeliverRequestBo.setRequestTypeId("1");
350         oleDeliverRequestBo.setBorrowerQueuePosition(1);
351         oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
352         Map<String,String> requestTypeMap = new HashMap<String,String>();
353         requestTypeMap.put("requestTypeId",oleDeliverRequestBo.getRequestTypeId());
354         List<OleDeliverRequestType> oleDeliverRequestTypes = (List<OleDeliverRequestType>)businessObjectService.findMatching(OleDeliverRequestType.class,requestTypeMap);
355         oleDeliverRequestBo.setOleDeliverRequestType(oleDeliverRequestTypes.get(0));
356         businessObjectService.save(oleDeliverRequestBo);
357         OleDeliverRequestBo oleDeliverRequestBo1 = new OleDeliverRequestBo();
358         oleDeliverRequestBo1.setRequestId("2");
359         oleDeliverRequestBo1.setRequestTypeId("5");
360         oleDeliverRequestBo1.setBorrowerQueuePosition(2);
361         oleDeliverRequestBo1.setBorrowerId(olePatronDocument.getOlePatronId());
362         Map<String,String> requestTypeMap1 = new HashMap<String,String>();
363         requestTypeMap.put("requestTypeId",oleDeliverRequestBo1.getRequestTypeId());
364         List<OleDeliverRequestType> oleDeliverRequestTypes1 = (List<OleDeliverRequestType>)businessObjectService.findMatching(OleDeliverRequestType.class,requestTypeMap1);
365         oleDeliverRequestBo1.setOleDeliverRequestType(oleDeliverRequestTypes1.get(0));
366         businessObjectService.save(oleDeliverRequestBo1);
367 
368         OleDeliverRequestBo oleDeliverRequestBo2 = new OleDeliverRequestBo();
369         oleDeliverRequestBo2.setRequestTypeId("3");
370         oleDeliverRequestBo2.setBorrowerId(olePatronDocument.getOlePatronId());
371         Map<String,String> requestTypeMap2 = new HashMap<String,String>();
372         requestTypeMap.put("requestTypeId",oleDeliverRequestBo2.getRequestTypeId());
373         List<OleDeliverRequestType> oleDeliverRequestTypes2 = (List<OleDeliverRequestType>)businessObjectService.findMatching(OleDeliverRequestType.class,requestTypeMap2);
374         oleDeliverRequestBo2.setOleDeliverRequestType(oleDeliverRequestTypes2.get(0));
375         OleDeliverRequestBo oleDeliverRequestBo3 = service.reOrderQueuePosition(oleDeliverRequestBo2);
376 
377 
378     }
379 
380     @Test
381     @Transactional
382     public void validateQueuePositionTest(){
383         businessObjectService.save(olePatronDocument);
384         List<OleDeliverRequestBo> oleDeliverRequestBoList = new ArrayList<OleDeliverRequestBo>();
385         OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
386         oleDeliverRequestBo.setRequestId("1");
387         oleDeliverRequestBo.setRequestTypeId("1");
388         oleDeliverRequestBo.setBorrowerQueuePosition(1);
389         oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
390         oleDeliverRequestBoList.add(oleDeliverRequestBo);
391 
392         OleDeliverRequestBo oleDeliverRequestBo1 = new OleDeliverRequestBo();
393         oleDeliverRequestBo1.setRequestId("2");
394         oleDeliverRequestBo1.setRequestTypeId("5");
395         oleDeliverRequestBo1.setBorrowerQueuePosition(2);
396         oleDeliverRequestBo1.setBorrowerId(olePatronDocument.getOlePatronId());
397         oleDeliverRequestBoList.add(oleDeliverRequestBo1);
398 
399         OleDeliverRequestBo oleDeliverRequestBo2 = new OleDeliverRequestBo();
400         oleDeliverRequestBo2.setRequestTypeId("3");
401         oleDeliverRequestBo2.setBorrowerId(olePatronDocument.getOlePatronId());
402         oleDeliverRequestBo1.setBorrowerQueuePosition(3);
403         oleDeliverRequestBoList.add(oleDeliverRequestBo2);
404         String valid = service.validateQueuePosition(oleDeliverRequestBoList);
405 
406         assertTrue(valid.equals(OLEConstants.OleDeliverRequest.REORDER_SUCCESS));
407 
408 
409     }
410 
411     @Test
412     @Transactional
413     public void cancelDocumentTest(){
414         businessObjectService.save(olePatronDocument);
415         OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
416         oleDeliverRequestBo.setRequestId("1");
417         oleDeliverRequestBo.setRequestTypeId("1");
418         oleDeliverRequestBo.setBorrowerQueuePosition(1);
419         oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
420         businessObjectService.save(oleDeliverRequestBo);
421 
422         service.cancelDocument(oleDeliverRequestBo);
423 
424         Map<String,String> requestMap = new HashMap<String,String>();
425         requestMap.put("requestId",oleDeliverRequestBo.getRequestId());
426 
427         List<OleDeliverRequestBo> oleDeliverRequestBoList = (List<OleDeliverRequestBo>)businessObjectService.findMatching(OleDeliverRequestBo.class,requestMap);
428 
429         assertTrue(oleDeliverRequestBoList.size()==0);
430     }
431 
432 
433     @Test
434     @Transactional
435     public void isRequestRaisedTest(){
436         businessObjectService.save(olePatronDocument);
437         OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
438         oleDeliverRequestBo.setRequestId("1");
439         oleDeliverRequestBo.setRequestTypeId("1");
440         oleDeliverRequestBo.setItemId("1");
441         oleDeliverRequestBo.setBorrowerQueuePosition(1);
442         oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
443         businessObjectService.save(oleDeliverRequestBo);
444         assertTrue(service.isRequestRaised(oleDeliverRequestBo)) ;
445 
446     }
447 
448     @Test
449     @Transactional
450     public void processItemTypeTest(){
451         businessObjectService.save(olePatronDocument);
452         OleDeliverRequestBo oleDeliverRequestBo = new OleDeliverRequestBo();
453         oleDeliverRequestBo.setRequestId("1");
454         oleDeliverRequestBo.setRequestTypeId("1");
455         oleDeliverRequestBo.setItemId("1");
456         oleDeliverRequestBo.setBorrowerQueuePosition(1);
457         oleDeliverRequestBo.setItemType("BOOK");
458         oleDeliverRequestBo.setBorrowerId(olePatronDocument.getOlePatronId());
459 
460        OleDeliverRequestBo oleDeliverRequestBo1 =service.processItemType(oleDeliverRequestBo) ;
461          assertEquals("book",oleDeliverRequestBo1.getItemTypeName());
462     }
463 
464 
465 }
466 
467 
468 
469 
470