View Javadoc

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.ItemBillForm;
8   import org.kuali.ole.patron.bill.form.PatronBillForm;
9   import org.kuali.rice.krad.service.BusinessObjectService;
10  import org.kuali.rice.krad.service.KRADServiceLocator;
11  import org.springframework.test.context.ContextConfiguration;
12  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13  import org.springframework.test.context.transaction.TransactionConfiguration;
14  import org.springframework.transaction.annotation.Transactional;
15  
16  import java.math.BigDecimal;
17  import java.util.Date;
18  import java.util.HashMap;
19  import java.util.List;
20  import java.util.Map;
21  
22  import static junit.framework.Assert.assertEquals;
23  import static junit.framework.Assert.assertNotNull;
24  
25  /**
26   * Created with IntelliJ IDEA.
27   * User: ?
28   * Date: 11/15/12
29   * Time: 7:22 PM
30   * To change this template use File | Settings | File Templates.
31   */
32  
33  @ContextConfiguration(locations = {"classpath:/SpringBeans.xml"})
34  @RunWith(value = SpringJUnit4ClassRunner.class)
35  @TransactionConfiguration(defaultRollback = true)
36  public class ItemBillController_UT {
37  
38      private BusinessObjectService boService ;
39  
40      /**
41       *  Gets the businessObjectService attribute.
42       * @return  Returns the businessObjectService
43       */
44      private BusinessObjectService getBusinessObjectService() {
45          if (null == boService) {
46              boService = KRADServiceLocator.getBusinessObjectService();
47          }
48          return boService;
49      }
50      @Test
51      @Transactional
52      public void testAcceptAndForgivePayment() {
53          PatronBillPayment patronBillPayment = new PatronBillPayment();
54          FeeType feeType = new FeeType();
55          patronBillPayment.setBillDate(new Date());
56          patronBillPayment.setBillNumber("9999");
57          patronBillPayment.setPatronId("Mock PatronId");
58          patronBillPayment.setFirstName("Mock FirstName");
59          patronBillPayment.setLastName("Mock LastName");
60          patronBillPayment.setOperatorId("Mock OperatorId");
61          patronBillPayment.setMachineId("Mock MachineId");
62          feeType.setItemBarcode("TEST");
63          feeType.setFeeType("Mock Fine");
64          feeType.setFeeTypeName("Mock fee name");
65          feeType.setBillNumber("9999");
66          feeType.setFeeAmount(new BigDecimal(100.00));
67          patronBillPayment.setTotalAmount(new BigDecimal(100.00));
68          OlePaymentStatus olePaymentStatus = getPaymentStatus();
69          if(olePaymentStatus!=null){
70              patronBillPayment.setOlePaymentStatus(olePaymentStatus);
71              patronBillPayment.setPaymentStatus(olePaymentStatus.getPaymentStatusId());
72          }
73          boService = KRADServiceLocator.getBusinessObjectService();
74          boService.save(patronBillPayment);
75          boService.save(feeType);
76          String billNumber = patronBillPayment.getBillNumber();
77          Map billNoMap = new HashMap();
78          billNoMap.put("billNumber",billNumber);
79          List<FeeType> patronBillPaymentService =(List<FeeType>) boService.findMatching(FeeType.class,billNoMap);
80          ItemBillHelperService itemBillHelperService = new ItemBillHelperService();
81          List<ItemBill> itemBillList = itemBillHelperService.getItemBills("TEST");
82          assertNotNull(itemBillList);
83      }
84      private OlePaymentStatus getPaymentStatus(){
85          Map statusMap = new HashMap();
86          statusMap.put("paymentStatusName", "Outstanding");
87          List<OlePaymentStatus> olePaymentStatusList = (List<OlePaymentStatus>)getBusinessObjectService().findMatching(OlePaymentStatus.class,statusMap);
88          return olePaymentStatusList!=null && olePaymentStatusList.size()>0 ? olePaymentStatusList.get(0): null;
89      }
90  
91  
92  }