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
19
20
21
22
23
24
25 @ContextConfiguration(locations = {"classpath:/SpringBeans.xml"})
26 @RunWith(value = SpringJUnit4ClassRunner.class)
27 @TransactionConfiguration(defaultRollback = true)
28 public class OleStatisticalSearchingCodes_UT {
29 private BusinessObjectService boService;
30
31 @Test
32 @Transactional
33 public void testSave() {
34 OleStatisticalSearchingCodes oleStatisticalSearchingCodes = new OleStatisticalSearchingCodes();
35 oleStatisticalSearchingCodes.setStatisticalSearchingCode("mockCd1");
36 oleStatisticalSearchingCodes.setStatisticalSearchingName("mockStatisticalSearchingName1");
37 oleStatisticalSearchingCodes.setSource("mockSource1");
38 Timestamp st = new Timestamp(System.currentTimeMillis());
39 oleStatisticalSearchingCodes.setSourceDate(new java.sql.Date(st.getTime()));
40 oleStatisticalSearchingCodes.setActive(true);
41 boService = KRADServiceLocator.getBusinessObjectService();
42 boolean exists = false;
43 Collection<OleStatisticalSearchingCodes> oleStatisticalSearchingCodesCollection = boService
44 .findAll(OleStatisticalSearchingCodes.class);
45 for (OleStatisticalSearchingCodes statisticalSearchingCodes : oleStatisticalSearchingCodesCollection) {
46 if (statisticalSearchingCodes.getStatisticalSearchingCode().equalsIgnoreCase(
47 oleStatisticalSearchingCodes.getStatisticalSearchingCode())) {
48 exists = true;
49 }
50 }
51
52 if (!exists && oleStatisticalSearchingCodes.getSourceDate() != null) {
53 boService.save(oleStatisticalSearchingCodes);
54 OleStatisticalSearchingCodes oleStatisticalSearchingCodesService = boService
55 .findBySinglePrimaryKey(OleStatisticalSearchingCodes.class,
56 oleStatisticalSearchingCodes.getStatisticalSearchingCodeId());
57 assertEquals("mockCd1", oleStatisticalSearchingCodesService.getStatisticalSearchingCode());
58 assertEquals("mockStatisticalSearchingName1",
59 oleStatisticalSearchingCodesService.getStatisticalSearchingName());
60 }
61
62
63 }
64
65 @Test
66 @Transactional
67 public void testSearch() {
68 OleStatisticalSearchingCodes oleStatisticalSearchingCodes = new OleStatisticalSearchingCodes();
69 oleStatisticalSearchingCodes.setStatisticalSearchingCode("mockCd1");
70 oleStatisticalSearchingCodes.setStatisticalSearchingName("mockStatisticalSearchingName1");
71 oleStatisticalSearchingCodes.setSource("mockSource1");
72 Timestamp st = new Timestamp(System.currentTimeMillis());
73 oleStatisticalSearchingCodes.setSourceDate(new java.sql.Date(st.getTime()));
74 oleStatisticalSearchingCodes.setActive(true);
75 boService = KRADServiceLocator.getBusinessObjectService();
76 boolean exists = false;
77 Collection<OleStatisticalSearchingCodes> oleStatisticalSearchingCodesCollection = boService
78 .findAll(OleStatisticalSearchingCodes.class);
79 for (OleStatisticalSearchingCodes statisticalSearchingCodes : oleStatisticalSearchingCodesCollection) {
80 if (statisticalSearchingCodes.getStatisticalSearchingCode().equalsIgnoreCase(
81 oleStatisticalSearchingCodes.getStatisticalSearchingCode())) {
82 exists = true;
83 }
84 }
85
86 if (!exists && oleStatisticalSearchingCodes.getSourceDate() != null) {
87 boService.save(oleStatisticalSearchingCodes);
88 OleStatisticalSearchingCodes oleStatisticalSearchingCodesService = boService
89 .findBySinglePrimaryKey(OleStatisticalSearchingCodes.class,
90 oleStatisticalSearchingCodes.getStatisticalSearchingCodeId());
91 assertEquals("mockCd1", oleStatisticalSearchingCodesService.getStatisticalSearchingCode());
92 assertEquals("mockStatisticalSearchingName1",
93 oleStatisticalSearchingCodesService.getStatisticalSearchingName());
94 }
95 }
96 }