1
2
3
4
5
6
7
8 package org.kuali.ole.catalog.bo;
9
10
11 import org.junit.Test;
12 import org.junit.runner.RunWith;
13 import org.kuali.rice.krad.service.BusinessObjectService;
14 import org.kuali.rice.krad.service.KRADServiceLocator;
15 import org.springframework.test.context.ContextConfiguration;
16 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
17 import org.springframework.test.context.transaction.TransactionConfiguration;
18 import org.springframework.transaction.annotation.Transactional;
19
20 import java.sql.Timestamp;
21 import java.util.Collection;
22
23 import static junit.framework.Assert.assertEquals;
24
25
26 @ContextConfiguration(locations = {"classpath:/SpringBeans.xml"})
27 @RunWith(value = SpringJUnit4ClassRunner.class)
28 @TransactionConfiguration(defaultRollback = true)
29
30 public class OleLocationStatus_UT {
31
32 private BusinessObjectService boService;
33
34 @Test
35 @Transactional
36 public void testSave() {
37
38 OleLocationStatus oleLocationStatus = new OleLocationStatus();
39 oleLocationStatus.setLocationStatusCode("mockCd");
40 oleLocationStatus.setLocationStatusName("mockLocationStatusName");
41 oleLocationStatus.setSource("mockSource");
42 Timestamp st = new Timestamp(System.currentTimeMillis());
43 oleLocationStatus.setSourceDate(new java.sql.Date(st.getTime()));
44 oleLocationStatus.setActive(true);
45 boService = KRADServiceLocator.getBusinessObjectService();
46 boolean exists = false;
47 Collection<OleLocationStatus> oleLocationStatusCollection = boService.findAll(OleLocationStatus.class);
48 for (OleLocationStatus locationStatus : oleLocationStatusCollection) {
49 if (locationStatus.getLocationStatusCode().equalsIgnoreCase(oleLocationStatus.getLocationStatusCode())) {
50 exists = true;
51 }
52 }
53
54 if (!exists && oleLocationStatus.getSourceDate() != null) {
55 boService.save(oleLocationStatus);
56 OleLocationStatus oleLocationStatusService = boService
57 .findBySinglePrimaryKey(OleLocationStatus.class, oleLocationStatus.getLocationStatusId());
58 assertEquals("mockCd", oleLocationStatusService.getLocationStatusCode());
59 assertEquals("mockLocationStatusName", oleLocationStatusService.getLocationStatusName());
60 }
61
62 }
63
64 @Test
65 @Transactional
66 public void testSearch() {
67
68 OleLocationStatus oleLocationStatus = new OleLocationStatus();
69 oleLocationStatus.setLocationStatusCode("mockCd");
70 oleLocationStatus.setLocationStatusName("mockLocationStatusName");
71 oleLocationStatus.setSource("mockSource");
72 Timestamp st = new Timestamp(System.currentTimeMillis());
73 oleLocationStatus.setSourceDate(new java.sql.Date(st.getTime()));
74 oleLocationStatus.setActive(true);
75 boService = KRADServiceLocator.getBusinessObjectService();
76 boolean exists = false;
77 Collection<OleLocationStatus> oleLocationStatusCollection = boService.findAll(OleLocationStatus.class);
78 for (OleLocationStatus locationStatus : oleLocationStatusCollection) {
79 if (locationStatus.getLocationStatusCode().equalsIgnoreCase(oleLocationStatus.getLocationStatusCode())) {
80 exists = true;
81 }
82 }
83
84 if (!exists && oleLocationStatus.getSourceDate() != null) {
85 boService.save(oleLocationStatus);
86 OleLocationStatus oleLocationStatusService = boService
87 .findBySinglePrimaryKey(OleLocationStatus.class, oleLocationStatus.getLocationStatusId());
88 assertEquals("mockCd", oleLocationStatusService.getLocationStatusCode());
89 assertEquals("mockLocationStatusName", oleLocationStatusService.getLocationStatusName());
90 }
91 }
92 }