View Javadoc

1   package org.kuali.ole.catalog.bo;
2   
3   import org.junit.Test;
4   import org.junit.runner.RunWith;
5   import org.kuali.rice.krad.service.BusinessObjectService;
6   import org.kuali.rice.krad.service.KRADServiceLocator;
7   import org.springframework.test.context.ContextConfiguration;
8   import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9   import org.springframework.test.context.transaction.TransactionConfiguration;
10  import org.springframework.transaction.annotation.Transactional;
11  
12  import java.sql.Timestamp;
13  import java.util.Collection;
14  
15  import static junit.framework.Assert.assertEquals;
16  
17  /**
18   * Created by IntelliJ IDEA.
19   * User: meenau
20   * Date: 6/4/12
21   * Time: 7:53 PM
22   * To change this template use File | Settings | File Templates.
23   */
24  
25  @ContextConfiguration(locations = {"classpath:/SpringBeans.xml"})
26  @RunWith(value = SpringJUnit4ClassRunner.class)
27  @TransactionConfiguration(defaultRollback = true)
28  
29  public class OleAcquisitionMethod_UT {
30  
31      private BusinessObjectService boService;
32  
33      @Test
34      @Transactional
35      public void testSave() {
36          OleAcquisitionMethod oleAcquistionMethod = new OleAcquisitionMethod();
37          oleAcquistionMethod.setAcquisitionMethodCode("n");
38          oleAcquistionMethod.setAcquisitionMethodName("Non-library purchase");
39          oleAcquistionMethod.setSource("src");
40          Timestamp st = new Timestamp(System.currentTimeMillis());
41          oleAcquistionMethod.setSourceDate(new java.sql.Date(st.getTime()));
42          oleAcquistionMethod.setActive(true);
43          boService = KRADServiceLocator.getBusinessObjectService();
44          boolean exists = false;
45          Collection<OleAcquisitionMethod> oleAcquisitionMethodCollection = boService.findAll(OleAcquisitionMethod.class);
46          for (OleAcquisitionMethod acquisitionMethod : oleAcquisitionMethodCollection) {
47              if (acquisitionMethod.getAcquisitionMethodCode()
48                                   .equalsIgnoreCase(oleAcquistionMethod.getAcquisitionMethodCode())) {
49                  exists = true;
50              }
51          }
52  
53          if (!exists && oleAcquistionMethod.getSourceDate() != null) {
54              boService.save(oleAcquistionMethod);
55              OleAcquisitionMethod oleAcquisitionMethodService = boService
56                      .findBySinglePrimaryKey(OleAcquisitionMethod.class, oleAcquistionMethod.getAcquisitionMethodId());
57              assertEquals("n", oleAcquisitionMethodService.getAcquisitionMethodCode());
58              assertEquals("Non-library purchase", oleAcquisitionMethodService.getAcquisitionMethodName());
59          }
60      }
61  
62      @Test
63      @Transactional
64      public void testSearch() {
65          OleAcquisitionMethod oleAcquistionMethod = new OleAcquisitionMethod();
66          oleAcquistionMethod.setAcquisitionMethodCode("n");
67          oleAcquistionMethod.setAcquisitionMethodName("Non-library purchase");
68          oleAcquistionMethod.setSource("src");
69          Timestamp st = new Timestamp(System.currentTimeMillis());
70          oleAcquistionMethod.setSourceDate(new java.sql.Date(st.getTime()));
71          oleAcquistionMethod.setActive(true);
72          boService = KRADServiceLocator.getBusinessObjectService();
73          boolean exists = false;
74          Collection<OleAcquisitionMethod> oleAcquisitionMethodCollection = boService.findAll(OleAcquisitionMethod.class);
75          for (OleAcquisitionMethod acquisitionMethod : oleAcquisitionMethodCollection) {
76              if (acquisitionMethod.getAcquisitionMethodCode()
77                                   .equalsIgnoreCase(oleAcquistionMethod.getAcquisitionMethodCode())) {
78                  exists = true;
79              }
80          }
81  
82          if (!exists && oleAcquistionMethod.getSourceDate() != null) {
83              boService.save(oleAcquistionMethod);
84              OleAcquisitionMethod oleAcquisitionMethodService = boService
85                      .findBySinglePrimaryKey(OleAcquisitionMethod.class, oleAcquistionMethod.getAcquisitionMethodId());
86              assertEquals("n", oleAcquisitionMethodService.getAcquisitionMethodCode());
87              assertEquals("Non-library purchase", oleAcquisitionMethodService.getAcquisitionMethodName());
88          }
89      }
90  }