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