1 package org.kuali.ole.deliver.controller.checkin;
2
3 import org.junit.Before;
4 import org.junit.Test;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.deliver.bo.OleItemSearch;
7 import org.kuali.ole.deliver.calendar.bo.OleCalendar;
8 import org.kuali.ole.deliver.calendar.bo.OleCalendarGroup;
9 import org.kuali.ole.deliver.calendar.service.impl.OleCalendarServiceImpl;
10 import org.kuali.ole.deliver.service.ParameterValueResolver;
11 import org.kuali.ole.deliver.util.ItemFineRate;
12 import org.kuali.ole.deliver.util.ItemInfoUtil;
13 import org.kuali.ole.deliver.util.OleItemRecordForCirc;
14 import org.kuali.ole.docstore.engine.service.storage.rdbms.pojo.ItemRecord;
15 import org.kuali.ole.util.DocstoreUtil;
16 import org.kuali.rice.krad.service.BusinessObjectService;
17 import org.mockito.Mock;
18 import org.mockito.Mockito;
19 import org.mockito.MockitoAnnotations;
20
21 import java.sql.Timestamp;
22 import java.util.Calendar;
23
24 import static org.junit.Assert.*;
25
26
27
28
29 public class OleCalendarService_UT {
30
31 @Mock
32 private ParameterValueResolver mockParameterValueResolver;
33
34 @Mock
35 private OleCalendarGroup mockOleCalendarGroup;
36
37 @Mock
38 private OleCalendar mockOleCalendar;
39
40 @Mock
41 private BusinessObjectService mockBusinessObjectService;
42
43 @Mock
44 private ItemInfoUtil mockItemInfoUtil;
45
46 @Mock
47 private ItemRecord mockItemRecord;
48
49 @Mock
50 private DocstoreUtil mockDocstoreUtil;
51
52 @Mock
53 private OleItemSearch mockItemSearch;
54
55 @Mock
56 private OleItemRecordForCirc mockOleItemRecordForCirc;
57
58
59 @Before
60 public void setUp() throws Exception {
61 MockitoAnnotations.initMocks(this);
62 }
63
64 @Test
65 public void generateOverdueFineForHoursWithIncludingHours() throws Exception {
66 Mockito.when(mockParameterValueResolver.getParameter(OLEConstants
67 .APPL_ID_OLE, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT,OLEConstants.FINE_FLAG)).thenReturn("true");
68 OleCalendarServiceImpl oleCalendarService = new OleCalendarServiceImpl();
69 oleCalendarService.setParameterValueResolver(mockParameterValueResolver);
70 String groupId = "100";
71
72 Calendar calendar = Calendar.getInstance();
73 calendar.add(Calendar.DAY_OF_MONTH, -5);
74 Timestamp dueDate = new Timestamp(calendar.getTimeInMillis());
75
76 Timestamp checkInDate =new Timestamp(System.currentTimeMillis());
77
78 ItemFineRate itemFineRate = new ItemFineRate();
79 itemFineRate.setInterval("H");
80 itemFineRate.setFineRate(10.0);
81
82 Double fine = oleCalendarService.calculateOverdueFine(groupId, dueDate, checkInDate, itemFineRate);
83 assertNotNull(fine);
84 System.out.println("Fine Rate : " + fine);
85 }
86
87 @Test
88 public void generateOverdueFineForHoursWithOutIncludingHours() throws Exception {
89 Mockito.when(mockParameterValueResolver.getParameter(OLEConstants
90 .APPL_ID_OLE, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT, OLEConstants.FINE_FLAG)).thenReturn("false");
91
92 OleCalendarServiceImpl oleCalendarService = new MockMockOleCalendarServiceImpl();
93 oleCalendarService.setParameterValueResolver(mockParameterValueResolver);
94
95 String groupId = "100";
96
97 Calendar calendar = Calendar.getInstance();
98 calendar.add(Calendar.DAY_OF_MONTH, -5);
99 Timestamp dueDate = new Timestamp(calendar.getTimeInMillis());
100
101 Timestamp checkInDate =new Timestamp(System.currentTimeMillis());
102
103 ItemFineRate itemFineRate = new ItemFineRate();
104 itemFineRate.setInterval("H");
105 itemFineRate.setFineRate(10.0);
106
107
108 Double fine = oleCalendarService.calculateOverdueFine(groupId, dueDate, checkInDate, itemFineRate);
109 assertNotNull(fine);
110 System.out.println("Fine Rate : " + fine);
111 }
112
113 @Test
114 public void generateOverdueFineForDays() throws Exception {
115 Mockito.when(mockParameterValueResolver.getParameter(OLEConstants
116 .APPL_ID_OLE, OLEConstants.DLVR_NMSPC, OLEConstants.DLVR_CMPNT,OLEConstants.FINE_FLAG)).thenReturn("true");
117 OleCalendarServiceImpl oleCalendarService = new MockMockOleCalendarServiceImpl();
118 oleCalendarService.setParameterValueResolver(mockParameterValueResolver);
119 String groupId = "100";
120
121 Calendar calendar = Calendar.getInstance();
122 calendar.add(Calendar.DAY_OF_MONTH, -5);
123
124 Timestamp dueDate = new Timestamp(calendar.getTimeInMillis());
125
126 Timestamp checkInDate =new Timestamp(System.currentTimeMillis());
127
128
129 ItemFineRate itemFineRate = new ItemFineRate();
130 itemFineRate.setInterval("D");
131 itemFineRate.setFineRate(10.0);
132
133 Double fine = oleCalendarService.calculateOverdueFine(groupId, dueDate, checkInDate, itemFineRate);
134 assertNotNull(fine);
135 System.out.println("Fine Rate : " + fine);
136 }
137
138
139 class MockMockOleCalendarServiceImpl extends OleCalendarServiceImpl {
140 @Override
141 public boolean isHoliday(String deskId, Timestamp currentDate) {
142 return true;
143 }
144
145 @Override
146 public Integer workingHours(String deskId, Timestamp dueDateTime, Timestamp currentDate) {
147 return 12;
148 }
149 }
150
151 }