1 package org.kuali.ole.patron.bill.controller;
2
3
4 import org.junit.Test;
5 import org.junit.runner.RunWith;
6 import org.kuali.ole.patron.bill.*;
7 import org.kuali.ole.patron.bill.form.PatronBillForm;
8 import org.kuali.rice.krad.service.BusinessObjectService;
9 import org.kuali.rice.krad.service.KRADServiceLocator;
10 import org.springframework.test.context.ContextConfiguration;
11 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12 import org.springframework.test.context.transaction.TransactionConfiguration;
13 import org.springframework.transaction.annotation.Transactional;
14
15 import java.math.BigDecimal;
16 import java.util.Date;
17 import java.util.HashMap;
18 import java.util.List;
19 import java.util.Map;
20
21 import static junit.framework.Assert.assertEquals;
22
23
24
25
26
27
28
29
30
31 @ContextConfiguration(locations = {"classpath:/SpringBeans.xml"})
32 @RunWith(value = SpringJUnit4ClassRunner.class)
33 @TransactionConfiguration(defaultRollback = true)
34 public class PatronBillController_UT {
35
36 private BusinessObjectService boService ;
37
38
39
40
41
42 private BusinessObjectService getBusinessObjectService() {
43 if (null == boService) {
44 boService = KRADServiceLocator.getBusinessObjectService();
45 }
46 return boService;
47 }
48 @Test
49 @Transactional
50 public void testAcceptAndForgivePayment() {
51 PatronBillPayment patronBillPayment = new PatronBillPayment();
52 FeeType feeType = new FeeType();
53 patronBillPayment.setBillDate(new Date());
54 patronBillPayment.setBillNumber("9999");
55 patronBillPayment.setPatronId("Mock PatronId");
56 patronBillPayment.setFirstName("Mock FirstName");
57 patronBillPayment.setLastName("Mock LastName");
58 patronBillPayment.setOperatorId("Mock OperatorId");
59 patronBillPayment.setMachineId("Mock MachineId");
60 feeType.setItemBarcode("TEST");
61 feeType.setFeeType("Mock Fine");
62 feeType.setFeeTypeName("Mock Fine");
63 feeType.setBillNumber("9999");
64 feeType.setFeeAmount(new BigDecimal(100.00));
65 patronBillPayment.setTotalAmount(new BigDecimal(100.00));
66 OlePaymentStatus olePaymentStatus = getPaymentStatus();
67 if(olePaymentStatus!=null){
68 patronBillPayment.setOlePaymentStatus(olePaymentStatus);
69 patronBillPayment.setPaymentStatus(olePaymentStatus.getPaymentStatusId());
70 }
71 boService = KRADServiceLocator.getBusinessObjectService();
72 boService.save(patronBillPayment);
73 boService.save(feeType);
74 PatronBillPayment patronBillPaymentService = boService.findBySinglePrimaryKey(PatronBillPayment.class,patronBillPayment.getBillNumber());
75 PatronBillHelperService patronBillHelperService = new PatronBillHelperService();
76 PatronBillForm patronBillForm = new PatronBillForm();
77 BigDecimal amount = new BigDecimal(50.00);
78 patronBillHelperService.updatePatronBillForAccept("9999",amount,amount,amount,"","","admin");
79 PatronBillPayment patronBillPaymentServiceForAccept = boService.findBySinglePrimaryKey(PatronBillPayment.class,patronBillPayment.getBillNumber());
80 assertEquals(amount,patronBillPaymentServiceForAccept.getPaymentAmount());
81 BigDecimal forgiveAmount = new BigDecimal(20.00);
82 BigDecimal totalAmount = amount.subtract(forgiveAmount);
83 patronBillHelperService.updatePatronBillForForgive("9999",amount,totalAmount,"","admin");
84 PatronBillPayment patronBillPaymentServiceForReject = boService.findBySinglePrimaryKey(PatronBillPayment.class,patronBillPayment.getBillNumber());
85 BigDecimal totalAmountDue = new BigDecimal(30.00);
86 assertEquals(totalAmountDue,patronBillPaymentServiceForReject.getTotalAmount());
87 }
88 private OlePaymentStatus getPaymentStatus(){
89 Map statusMap = new HashMap();
90 statusMap.put("paymentStatusName", "Outstanding");
91 List<OlePaymentStatus> olePaymentStatusList = (List<OlePaymentStatus>)getBusinessObjectService().findMatching(OlePaymentStatus.class,statusMap);
92 return olePaymentStatusList!=null && olePaymentStatusList.size()>0 ? olePaymentStatusList.get(0): null;
93 }
94
95
96 }