View Javadoc

1   package org.kuali.ole.patron.bill;
2   
3   import org.junit.Test;
4   import org.junit.runner.RunWith;
5   import org.kuali.ole.patron.bo.OleBorrowerType;
6   import org.kuali.rice.krad.service.BusinessObjectService;
7   import org.kuali.rice.krad.service.KRADServiceLocator;
8   import org.springframework.test.context.ContextConfiguration;
9   import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
10  import org.springframework.test.context.transaction.TransactionConfiguration;
11  import org.springframework.transaction.annotation.Transactional;
12  
13  import java.math.BigDecimal;
14  import java.util.*;
15  
16  import static junit.framework.Assert.assertEquals;
17  
18  /**
19   * Created with IntelliJ IDEA.
20   * User: ?
21   * Date: 11/6/12
22   * Time: 11:34 AM
23   * To change this template use File | Settings | File Templates.
24   */
25  @ContextConfiguration(locations = {"classpath:/SpringBeans.xml"})
26  @RunWith(value = SpringJUnit4ClassRunner.class)
27  @TransactionConfiguration(defaultRollback = true)
28  public class PatronBillPayment_UT {
29  
30      private BusinessObjectService boService ;
31  
32      /**
33       *  Gets the businessObjectService attribute.
34       * @return  Returns the businessObjectService
35       */
36      private BusinessObjectService getBusinessObjectService() {
37          if (null == boService) {
38              boService = KRADServiceLocator.getBusinessObjectService();
39          }
40          return boService;
41      }
42      @Test
43      @Transactional
44      public void testSaveAndSearch() {
45          PatronBillPayment patronBillPayment = new PatronBillPayment();
46          FeeType feeType = new FeeType();
47          patronBillPayment.setBillDate(new Date());
48          patronBillPayment.setBillNumber("9999");
49          patronBillPayment.setPatronId("Mock PatronId");
50          patronBillPayment.setFirstName("Mock FirstName");
51          patronBillPayment.setLastName("Mock LastName");
52          patronBillPayment.setOperatorId("Mock OperatorId");
53          patronBillPayment.setMachineId("Mock MachineId");
54          feeType.setFeeType("Mock Fine");
55          feeType.setBillNumber("9999");
56          feeType.setFeeAmount(new BigDecimal(100.00));
57          patronBillPayment.setTotalAmount(new BigDecimal(100.00));
58          OlePaymentStatus olePaymentStatus = getPaymentStatus();
59          if(olePaymentStatus!=null){
60              patronBillPayment.setOlePaymentStatus(olePaymentStatus);
61              patronBillPayment.setPaymentStatus(olePaymentStatus.getPaymentStatusId());
62          }
63          boService = KRADServiceLocator.getBusinessObjectService();
64          boService.save(patronBillPayment);
65          boService.save(feeType);
66          PatronBillPayment patronBillPaymentService = boService.findBySinglePrimaryKey(PatronBillPayment.class,patronBillPayment.getBillNumber());
67          assertEquals("Mock PatronId",patronBillPaymentService.getPatronId());
68          assertEquals("Mock LastName",patronBillPaymentService.getLastName());
69      }
70      private OlePaymentStatus getPaymentStatus(){
71          Map statusMap = new HashMap();
72          statusMap.put("paymentStatusName", "Outstanding");
73          List<OlePaymentStatus> olePaymentStatusList = (List<OlePaymentStatus>)getBusinessObjectService().findMatching(OlePaymentStatus.class,statusMap);
74          return olePaymentStatusList!=null && olePaymentStatusList.size()>0 ? olePaymentStatusList.get(0): null;
75      }
76    }