1 package org.kuali.ole.myaccount.renewal;
2
3 import org.apache.log4j.Logger;
4 import org.junit.Before;
5 import org.junit.Test;
6 import org.junit.runner.RunWith;
7 import org.kuali.ole.ingest.FileUtil;
8 import org.kuali.ole.myaccount.renewal.bo.OleRenewalLoanDocument;
9 import org.kuali.ole.patron.api.OlePatronDefinition;
10 import org.kuali.ole.patron.bo.OlePatronDocument;
11 import org.kuali.ole.patron.bo.OlePatronIngestSummaryRecord;
12 import org.kuali.ole.service.OlePatronConverterService;
13 import org.kuali.ole.service.OlePatronService;
14 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
15 import org.kuali.ole.myaccount.renewal.service.OleMyAccountProcess;
16 import org.springframework.test.context.ContextConfiguration;
17 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
18 import org.springframework.test.context.transaction.TransactionConfiguration;
19
20 import java.io.File;
21 import java.net.URL;
22 import java.util.ArrayList;
23 import java.util.Date;
24 import java.util.List;
25
26 import static junit.framework.Assert.assertNotNull;
27
28
29
30
31
32
33
34
35
36
37 @ContextConfiguration(locations = {"classpath:/SpringBeans.xml"})
38 @RunWith(value = SpringJUnit4ClassRunner.class)
39 @TransactionConfiguration(defaultRollback = true)
40 public class OleMyAccountProcess_UT {
41
42 private static final Logger LOG = Logger.getLogger(OleMyAccountProcess_UT.class);
43 private OlePatronConverterService olePatronConverterService;
44 private OleMyAccountProcess oleMyAccountProcess;
45 @Before
46 public void setUp() throws Exception {
47 olePatronConverterService = new OlePatronConverterService();
48 oleMyAccountProcess= new OleMyAccountProcess();
49 }
50
51 @Test
52 public void testGetPatronInfo() throws Exception {
53 LOG.debug("Inside the testGetPatronInfo method");
54 createPatronRecords();
55 OlePatronDefinition olePatronDefinition=oleMyAccountProcess.getPatronInfo("0010005");
56 assertNotNull(olePatronDefinition);
57
58 }
59
60 @Test
61 public void testGetPatronLoanedItems() throws Exception {
62 LOG.debug("Inside the testGetPatronLoanedItems method");
63 createPatronRecords();
64 OlePatronDefinition olePatronDefinition=oleMyAccountProcess.getPatronInfo("0010005");
65 List<OleRenewalLoanDocument> oleRenewalLoanDocumentList=oleMyAccountProcess.getPatronLoanedItems(olePatronDefinition.getBarcode());
66 assertNotNull(oleRenewalLoanDocumentList);
67 }
68
69 @Test
70 public void testPerformRenewalItem() throws Exception {
71 LOG.debug("Inside the testPerformRenewalItem method");
72 OleRenewalLoanDocument oleRenewalLoanDocument=createOleRenewalLoanDocument();
73 List<OleRenewalLoanDocument> oleRenewalLoanDocumentList=new ArrayList<OleRenewalLoanDocument>();
74 oleRenewalLoanDocumentList.add(oleRenewalLoanDocument);
75 oleRenewalLoanDocumentList=oleMyAccountProcess.performRenewalItem(oleRenewalLoanDocumentList);
76 assertNotNull(oleRenewalLoanDocumentList);
77 }
78
79
80 private void createPatronRecords(){
81 LOG.debug("Inside the createPatronRecords method");
82 try{
83 URL resource = getClass().getResource("samplePatronRecord.xml");
84 File file = new File(resource.toURI());
85 String fileContent = new FileUtil().readFile(file);
86 OlePatronIngestSummaryRecord olePatronIngestSummaryRecord = new OlePatronIngestSummaryRecord();
87 OlePatronService olePatronService = (OlePatronService) GlobalResourceLoader.getService("olePatronService");
88 olePatronConverterService.setOlePatronService(olePatronService);
89 olePatronConverterService.persistPatronFromFileContent(fileContent, true,"PatronIngest",olePatronIngestSummaryRecord,"4");
90 }
91 catch (Exception e){
92 LOG.info("exception --->"+e);
93 }
94 }
95
96 private OleRenewalLoanDocument createOleRenewalLoanDocument(){
97 LOG.debug("Inside the createOleRenewalLoanDocument method");
98 OleRenewalLoanDocument oleRenewalLoanDocument=new OleRenewalLoanDocument();
99 oleRenewalLoanDocument.setItemBarcode("11111111111");
100 oleRenewalLoanDocument.setTitle("Speed Rider");
101 oleRenewalLoanDocument.setAuthor("james");
102 oleRenewalLoanDocument.setDueDate(new Date());
103 return oleRenewalLoanDocument;
104 }
105
106
107 }