View Javadoc

1   package org.kuali.ole.deliver.circulationdesk.service;
2   
3   import org.junit.Before;
4   import org.junit.Test;
5   import org.junit.runner.RunWith;
6   import org.kuali.ole.deliver.circulationdesk.bo.OleCirculationDesk;
7   import org.kuali.ole.deliver.circulationdesk.bo.OleCirculationDeskDetail;
8   import org.kuali.ole.deliver.circulationdesk.form.OleCirculationDeskDetailForm;
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 static junit.framework.Assert.assertEquals;
17  import static junit.framework.Assert.assertTrue;
18  
19  import java.util.*;
20  
21  /**
22   * Created with IntelliJ IDEA.
23   * User: ?
24   * Date: 11/8/12
25   * Time: 7:35 PM
26   * To change this template use File | Settings | File Templates.
27   */
28  
29  @ContextConfiguration(locations = {"classpath:/SpringBeans.xml"})
30  @RunWith(value = SpringJUnit4ClassRunner.class)
31  @TransactionConfiguration(defaultRollback = true)
32  public class OleCirculationDeskDetailServiceImpl_UT {
33  
34      private BusinessObjectService               boService;
35      private OleCirculationDeskDetailServiceImpl service;
36      private OleCirculationDesk                  oleCirculationDesk;
37  
38      @Before
39      public void setUp() throws Exception {
40          boService = KRADServiceLocator.getBusinessObjectService();
41          service = new OleCirculationDeskDetailServiceImpl();
42  
43      }
44  
45  
46      @Test
47      @Transactional
48      public void populateCreateListTest() {
49          OleCirculationDesk oleCirculationDesk = new OleCirculationDesk();
50          oleCirculationDesk.setCirculationDeskCode("code");
51          oleCirculationDesk.setCirculationDeskPublicName("publicName");
52          oleCirculationDesk.setCirculationDeskStaffName("staffName");
53          oleCirculationDesk.setActive(true);
54          oleCirculationDesk.setLocationId("1");
55  
56          boService = KRADServiceLocator.getBusinessObjectService();
57          boolean exists = false;
58          Collection<OleCirculationDesk> oleCirculationDeskCollection = boService.findAll(OleCirculationDesk.class);
59          for (OleCirculationDesk circulationDesk : oleCirculationDeskCollection) {
60              if (circulationDesk.getCirculationDeskCode()
61                                 .equalsIgnoreCase(oleCirculationDesk.getCirculationDeskCode())) {
62                  exists = true;
63              }
64          }
65  
66          if (!exists) {
67              boService.save(oleCirculationDesk);
68              List<OleCirculationDeskDetail> oleCirculationDeskDetailList = service.populateCreateList();
69              for (int i = 0; i < oleCirculationDeskDetailList.size(); i++) {
70                  if (oleCirculationDeskDetailList.get(i).getOleCirculationDesk().getCirculationDeskCode()
71                                                  .equalsIgnoreCase("code")) {
72                      assertEquals(
73                              oleCirculationDeskDetailList.get(i).getOleCirculationDesk().getCirculationDeskPublicName(),
74                              "publicName");
75                  }
76              }
77          }
78      }
79  
80      @Test
81      @Transactional
82      public void performSaveTest() {
83  
84          OleCirculationDesk oleCirculationDesk = new OleCirculationDesk();
85          oleCirculationDesk.setCirculationDeskCode("testCode");
86          oleCirculationDesk.setCirculationDeskPublicName("publicName");
87          oleCirculationDesk.setCirculationDeskStaffName("staffName");
88          oleCirculationDesk.setActive(true);
89          oleCirculationDesk.setLocationId("1");
90          oleCirculationDesk.setOnHoldDays("2");
91  
92          boService = KRADServiceLocator.getBusinessObjectService();
93          boolean exists = false;
94          Collection<OleCirculationDesk> oleCirculationDeskCollection = boService.findAll(OleCirculationDesk.class);
95          for (OleCirculationDesk circulationDesk : oleCirculationDeskCollection) {
96              if (circulationDesk.getCirculationDeskCode()
97                                 .equalsIgnoreCase(oleCirculationDesk.getCirculationDeskCode())) {
98                  exists = true;
99              }
100         }
101 
102         if (!exists && oleCirculationDesk.getOnHoldDays() != null) {
103             boService.save(oleCirculationDesk);
104             Map<String, String> deskMap = new HashMap<String, String>();
105             deskMap.put("circulationDeskCode", oleCirculationDesk.getCirculationDeskCode());
106             List<OleCirculationDesk> oleCirculationDeskSave = (List<OleCirculationDesk>) boService
107                     .findMatching(OleCirculationDesk.class, deskMap);
108             if (oleCirculationDeskSave != null && oleCirculationDeskSave.size() > 0) {
109                 OleCirculationDeskDetail oleCirculationDeskDetail = new OleCirculationDeskDetail();
110                 oleCirculationDeskDetail.setCirculationDeskId(oleCirculationDeskSave.get(0).getCirculationDeskId());
111                 oleCirculationDeskDetail.setDefaultLocation(true);
112                 oleCirculationDeskDetail.setAllowedLocation(false);
113                 oleCirculationDeskDetail.setOperatorId("test1");
114                 oleCirculationDeskDetail.setOleCirculationDesk(oleCirculationDeskSave.get(0));
115                 List<OleCirculationDeskDetail> oleCirculationDeskDetailList = new ArrayList<OleCirculationDeskDetail>();
116                 oleCirculationDeskDetailList.add(oleCirculationDeskDetail);
117                 OleCirculationDeskDetailForm oleCirculationDeskDetailTestForm = new OleCirculationDeskDetailForm();
118                 oleCirculationDeskDetailTestForm.setOperatorId("test1");
119                 oleCirculationDeskDetailTestForm.setOleCirculationDetailsCreateList(oleCirculationDeskDetailList);
120                 OleCirculationDeskDetailForm oleCirculationDeskDetailForm = service
121                         .performSave(oleCirculationDeskDetailTestForm);
122                 Map<String, String> optId = new HashMap<String, String>();
123                 optId.put("operatorId", "test1");
124                 List<OleCirculationDeskDetail> matchedList = (List<OleCirculationDeskDetail>) boService
125                         .findMatching(OleCirculationDeskDetail.class, optId);
126                 for (int j = 0; j < matchedList.size(); j++) {
127                     if (matchedList.get(j).getOleCirculationDesk().getCirculationDeskCode()
128                                    .equalsIgnoreCase("testCode")) {
129                         assertEquals(matchedList.get(j).getOleCirculationDesk().getCirculationDeskPublicName(),
130                                      "publicName");
131                     }
132                 }
133             }
134         }
135 
136 
137     }
138 
139     @Test
140     @Transactional
141     public void performSearchTest() {
142         OleCirculationDesk oleCirculationDesk = new OleCirculationDesk();
143         oleCirculationDesk.setCirculationDeskCode("testCode");
144         oleCirculationDesk.setCirculationDeskPublicName("publicName");
145         oleCirculationDesk.setCirculationDeskStaffName("staffName");
146         oleCirculationDesk.setActive(true);
147         oleCirculationDesk.setLocationId("1");
148         oleCirculationDesk.setOnHoldDays("2");
149 
150         boService = KRADServiceLocator.getBusinessObjectService();
151         boolean exists = false;
152         Collection<OleCirculationDesk> oleCirculationDeskCollection = boService.findAll(OleCirculationDesk.class);
153         for (OleCirculationDesk circulationDesk : oleCirculationDeskCollection) {
154             if (circulationDesk.getCirculationDeskCode()
155                                .equalsIgnoreCase(oleCirculationDesk.getCirculationDeskCode())) {
156                 exists = true;
157             }
158         }
159 
160         if (!exists && oleCirculationDesk != null) {
161             boService.save(oleCirculationDesk);
162             Map<String, String> deskMap = new HashMap<String, String>();
163             deskMap.put("circulationDeskCode", oleCirculationDesk.getCirculationDeskCode());
164             List<OleCirculationDesk> oleCirculationDeskSave = (List<OleCirculationDesk>) boService
165                     .findMatching(OleCirculationDesk.class, deskMap);
166             if (oleCirculationDeskSave != null && oleCirculationDeskSave.size() > 0) {
167                 OleCirculationDeskDetail oleCirculationDeskDetail = new OleCirculationDeskDetail();
168                 oleCirculationDeskDetail.setCirculationDeskId(oleCirculationDeskSave.get(0).getCirculationDeskId());
169                 oleCirculationDeskDetail.setDefaultLocation(true);
170                 oleCirculationDeskDetail.setAllowedLocation(false);
171                 oleCirculationDeskDetail.setOperatorId("test1");
172                 oleCirculationDeskDetail.setOleCirculationDesk(oleCirculationDeskSave.get(0));
173                 List<OleCirculationDeskDetail> oleCirculationDeskDetailList = new ArrayList<OleCirculationDeskDetail>();
174                 oleCirculationDeskDetailList.add(oleCirculationDeskDetail);
175                 OleCirculationDeskDetailForm oleCirculationDeskDetailTestForm = new OleCirculationDeskDetailForm();
176                 oleCirculationDeskDetailTestForm.setOperatorId("test1");
177                 oleCirculationDeskDetailTestForm.setOleCirculationDetailsCreateList(oleCirculationDeskDetailList);
178                 OleCirculationDeskDetailForm oleCirculationDeskDetailForm = service
179                         .performSave(oleCirculationDeskDetailTestForm);
180                 OleCirculationDeskDetailForm oleCirculationDeskDetailSearchForm = new OleCirculationDeskDetailForm();
181                 oleCirculationDeskDetailSearchForm.setOperatorId("test1");
182                 OleCirculationDeskDetailForm oleCirculationDeskDetailForm1 = service
183                         .performSearch(oleCirculationDeskDetailSearchForm);
184                 List<OleCirculationDeskDetail> oleCirculationDeskDetail1 = oleCirculationDeskDetailForm1
185                         .getOleCirculationDetailsCreateList();
186                 for (int k = 0; k < oleCirculationDeskDetail1.size(); k++) {
187                     if (oleCirculationDeskDetail1.get(k).getOleCirculationDesk().getCirculationDeskCode()
188                                                  .equalsIgnoreCase("testCode")) {
189                         assertEquals(
190                                 oleCirculationDeskDetail1.get(k).getOleCirculationDesk().getCirculationDeskPublicName(),
191                                 "publicName");
192                     }
193                 }
194             }
195         }
196     }
197 }