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