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 OleElectronicLocationAndAccessRelationship_UT {
29
30 private BusinessObjectService boService;
31
32 @Test
33 @Transactional
34 public void testSave() {
35 OleElectronicLocationAndAccessRelationship oleElaRelationship
36 = new OleElectronicLocationAndAccessRelationship();
37 oleElaRelationship.setElaRelationshipCode("testCode");
38 oleElaRelationship.setElaRelationshipName("testName");
39 oleElaRelationship.setSource("testSource");
40 Timestamp st = new Timestamp(System.currentTimeMillis());
41 oleElaRelationship.setSourceDate(new java.sql.Date(st.getTime()));
42 oleElaRelationship.setActive(true);
43 boService = KRADServiceLocator.getBusinessObjectService();
44 boolean exists = false;
45 Collection<OleElectronicLocationAndAccessRelationship> elaRelationshipCollection = boService
46 .findAll(OleElectronicLocationAndAccessRelationship.class);
47 for (OleElectronicLocationAndAccessRelationship elaRelationship : elaRelationshipCollection) {
48 if (elaRelationship.getElaRelationshipCode()
49 .equalsIgnoreCase(oleElaRelationship.getElaRelationshipCode())) {
50 exists = true;
51 }
52 }
53
54 if (!exists && oleElaRelationship.getElaRelationshipCode() != null) {
55 boService.save(oleElaRelationship);
56 OleElectronicLocationAndAccessRelationship oleElaRelationshipService = boService
57 .findBySinglePrimaryKey(OleElectronicLocationAndAccessRelationship.class,
58 oleElaRelationship.getElaRelationshipId());
59 assertEquals("testCode", oleElaRelationshipService.getElaRelationshipCode());
60 assertEquals("testName", oleElaRelationshipService.getElaRelationshipName());
61 }
62 }
63
64 @Test
65 @Transactional
66 public void testSearch() {
67 OleElectronicLocationAndAccessRelationship oleElaRelationship
68 = new OleElectronicLocationAndAccessRelationship();
69 oleElaRelationship.setElaRelationshipCode("testCode");
70 oleElaRelationship.setElaRelationshipName("testName");
71 oleElaRelationship.setSource("testSource");
72 Timestamp st = new Timestamp(System.currentTimeMillis());
73 oleElaRelationship.setSourceDate(new java.sql.Date(st.getTime()));
74 oleElaRelationship.setActive(true);
75 boService = KRADServiceLocator.getBusinessObjectService();
76 boolean exists = false;
77 Collection<OleElectronicLocationAndAccessRelationship> elaRelationshipCollection = boService
78 .findAll(OleElectronicLocationAndAccessRelationship.class);
79 for (OleElectronicLocationAndAccessRelationship elaRelationship : elaRelationshipCollection) {
80 if (elaRelationship.getElaRelationshipCode()
81 .equalsIgnoreCase(oleElaRelationship.getElaRelationshipCode())) {
82 exists = true;
83 }
84 }
85
86 if (!exists && oleElaRelationship.getElaRelationshipCode() != null) {
87 boService.save(oleElaRelationship);
88 OleElectronicLocationAndAccessRelationship oleElaRelationshipService = boService
89 .findBySinglePrimaryKey(OleElectronicLocationAndAccessRelationship.class,
90 oleElaRelationship.getElaRelationshipId());
91 assertEquals("testCode", oleElaRelationshipService.getElaRelationshipCode());
92 assertEquals("testName", oleElaRelationshipService.getElaRelationshipName());
93 }
94 }
95 }