View Javadoc
1   package org.kuali.ole.deliver.service;
2   
3   import org.junit.Before;
4   import org.junit.Test;
5   import org.kuali.ole.OLEConstants;
6   import org.kuali.ole.OLEParameterConstants;
7   import org.kuali.ole.deliver.bo.OLEDeliverNotice;
8   import org.kuali.ole.deliver.bo.OleLoanDocument;
9   import org.kuali.ole.deliver.bo.OlePatronDocument;
10  import org.kuali.ole.deliver.processor.LoanProcessor;
11  import org.kuali.rice.kim.impl.identity.entity.EntityBo;
12  import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
13  import org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo;
14  import org.kuali.rice.krad.service.BusinessObjectService;
15  import org.mockito.Mock;
16  import org.mockito.Mockito;
17  import org.mockito.MockitoAnnotations;
18  
19  import java.sql.Timestamp;
20  import java.util.*;
21  
22  import static org.junit.Assert.assertNotNull;
23  import static org.junit.Assert.assertTrue;
24  
25  public class OverdueNoticesExecutorTest {
26  
27      @Mock
28      private OleDeliverRequestDocumentHelperServiceImpl mockOleDeliverRequestDocumentHelperServiceImpl;
29  
30      @Mock
31      private LoanProcessor mockLoanProcessor;
32      @Mock
33      private BusinessObjectService mockBusinessObjectService;
34      @Mock
35      private ParameterValueResolver mockParameterResolverInstance;
36      @Mock
37      private NoticeMailContentFormatter mockNoticeMailContentFormatter;
38  
39      @Before
40      public void setUp() throws Exception {
41          MockitoAnnotations.initMocks(this);
42      }
43  
44      @Test
45      public void testGenerateOverDueNoticeContent() throws Exception {
46  
47          Mockito.when(mockLoanProcessor.getParameter(OLEParameterConstants.OVERDUE_TITLE)).thenReturn("TITLE");
48          Mockito.when(mockLoanProcessor.getParameter(OLEConstants.OleDeliverRequest.OVERDUE_NOTICE_CONTENT))
49                  .thenReturn
50                          ("CONTENT");
51  
52          List<OleLoanDocument> loanDocuments = new ArrayList<>();
53          OverdueNoticesExecutor overdueNoticesExecutor = new OverdueNoticesExecutor(loanDocuments);
54  
55          overdueNoticesExecutor.setNoticeMailContentFormatter(mockNoticeMailContentFormatter);
56  
57          OleLoanDocument oleLoanDocument = new OleLoanDocument();
58          OLEDeliverNotice oleDeliverNotice = new OLEDeliverNotice();
59  
60          OlePatronDocument olePatron = new OlePatronDocument();
61          olePatron.setBarcode("123125");
62          EntityBo entity = new EntityBo();
63          ArrayList<EntityNameBo> entityNameBos = new ArrayList<EntityNameBo>();
64          EntityNameBo entityNameBo = new EntityNameBo();
65          entityNameBo.setFirstName("FirtName");
66          entityNameBos.add(entityNameBo);
67          entity.setNames(entityNameBos);
68          ArrayList<EntityTypeContactInfoBo> entityTypeContactInfos = new ArrayList<EntityTypeContactInfoBo>();
69          entityTypeContactInfos.add(new EntityTypeContactInfoBo());
70          entity.setEntityTypeContactInfos(entityTypeContactInfos);
71          olePatron.setEntity(entity);
72  
73          oleLoanDocument.setOlePatron(olePatron);
74  
75  //
76  //        deliverNoticesExecutor.setLoanProcessor(mockLoanProcessor);
77  //        deliverNoticesExecutor.setOleDeliverRequestDocumentHelperService(mockOleDeliverRequestDocumentHelperServiceImpl);
78  //        deliverNoticesExecutor.setSimpleDateFormat(new SimpleDateFormat());
79  //        deliverNoticesExecutor.setUrlProperty("http://localhost:8080/olefs");
80  //
81  //
82  //        String fileName = deliverNoticesExecutor.generateOverDueNoticeContent(oleLoanDocument);
83  //        assertNotNull(fileName);
84      }
85  
86      @Test
87      public void generateDateStringsForMySQL() {
88          String generateDateStringsForMySQL = DateFormatHelper.getInstance().generateDateStringsForMySQL("3/3/2015");
89          System.out.println(generateDateStringsForMySQL);
90      }
91  
92      @Test
93      public void generateDateStringsForOracle() {
94          String generateDateStringsForOracle = DateFormatHelper.getInstance().generateDateStringsForOracle("3/3/2015");
95          System.out.println(generateDateStringsForOracle);
96      }
97  
98      @Test
99      public void generateTimeStampBasedOnDateString() {
100         String dateString = "4/7/2015";
101 
102         Timestamp timeStamp = new Timestamp(new Date(dateString).getTime());
103         System.out.println(timeStamp.toString());
104 
105         Timestamp systemTimestamp = new Timestamp((System.currentTimeMillis()));
106         System.out.println(systemTimestamp);
107 
108         System.out.println(systemTimestamp.compareTo(timeStamp) > 0);
109 
110     }
111 
112 
113     @Test
114     public void generateOverDueNotices() throws Exception {
115         ArrayList<OleLoanDocument> loanDocuments = new ArrayList<>();
116         OverdueNoticesExecutor overdueNoticesExecutor = new OverdueNoticesExecutor(loanDocuments);
117         overdueNoticesExecutor.setBusinessObjectService(mockBusinessObjectService);
118 //        deliverNoticesExecutor.setParameterResolverInstance(mockParameterResolverInstance);
119         OleLoanDocument loanDocument = new OleLoanDocument();
120 //        List<OLEDeliverNotice> oleDeliverNotices = deliverNoticesExecutor.generateOverDueNotices(loanDocument);
121 //        assertNotNull(oleDeliverNotices);
122 //        assertTrue(!oleDeliverNotices.isEmpty());
123     }
124 
125     @Test
126     public void generateAndSendOverdueNoticesToPatron() throws Exception {
127         ArrayList<OleLoanDocument> loanDocuments = new ArrayList<>();
128         OleLoanDocument loanDocument = new OleLoanDocument();
129         loanDocuments.add(loanDocument);
130         OverdueNoticesExecutor overdueNoticesExecutor = new OverdueNoticesExecutor(loanDocuments);
131         overdueNoticesExecutor.setBusinessObjectService(mockBusinessObjectService);
132 //        deliverNoticesExecutor.setParameterResolverInstance(mockParameterResolverInstance);
133         overdueNoticesExecutor.setNoticeMailContentFormatter(mockNoticeMailContentFormatter);
134 //        deliverNoticesExecutor.generateAndSendOverdueNoticesToPatron(loanDocuments);
135 
136     }
137 
138     @Test
139     public void generateNotices() throws Exception {
140         ArrayList<OleLoanDocument> loanDocuments = new ArrayList<>();
141         OleLoanDocument oleLoanDocument = new OleLoanDocument();
142         oleLoanDocument.setPatronId("12");
143 
144         OleLoanDocument oleLoanDocument1 = new OleLoanDocument();
145         oleLoanDocument1.setPatronId("12");
146 
147 
148         OleLoanDocument oleLoanDocument2 = new OleLoanDocument();
149         oleLoanDocument2.setPatronId("1234");
150 
151         OleLoanDocument oleLoanDocument3 = new OleLoanDocument();
152         oleLoanDocument3.setPatronId("12345");
153 
154         loanDocuments.add(oleLoanDocument);
155         loanDocuments.add(oleLoanDocument1);
156         loanDocuments.add(oleLoanDocument2);
157         loanDocuments.add(oleLoanDocument3);
158         OverdueNoticesExecutor overdueNoticesExecutor = new MockOverdueNoticesExecutor(loanDocuments);
159         //deliverNoticesExecutor.buildNoticesForDeletion(loanDocuments);
160 
161 
162     }
163 
164     class MockOverdueNoticesExecutor extends OverdueNoticesExecutor {
165 
166         MockOverdueNoticesExecutor(List<OleLoanDocument> loanDocuments) {
167             super(loanDocuments);
168         }
169         public void generateAndSendOverdueNoticesToPatron(List<OleLoanDocument> oleLoanDocuments) {
170             for (Iterator<OleLoanDocument> iterator = oleLoanDocuments.iterator(); iterator.hasNext(); ) {
171                 OleLoanDocument oleLoanDocument = iterator.next();
172 
173                 System.out.println("Mail sent to: " + oleLoanDocument.getPatronId());
174             }
175         }
176     }
177 }