1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ken.core;
17
18 import org.apache.ojb.broker.query.Criteria;
19 import org.apache.ojb.broker.query.Query;
20 import org.apache.ojb.broker.query.QueryFactory;
21 import org.junit.Test;
22 import org.kuali.rice.ken.bo.NotificationBo;
23 import org.kuali.rice.ken.bo.NotificationChannelBo;
24 import org.kuali.rice.ken.bo.NotificationProducerBo;
25 import org.kuali.rice.ken.dao.BusinessObjectDaoTestCaseBase;
26 import org.kuali.rice.ken.test.util.MockObjectsUtil;
27 import org.kuali.rice.ken.util.NotificationConstants;
28 import org.kuali.rice.test.BaselineTestCase.BaselineMode;
29 import org.kuali.rice.test.BaselineTestCase.Mode;
30
31 import java.sql.Timestamp;
32
33 import static org.junit.Assert.assertEquals;
34
35
36
37
38
39
40
41
42
43 @BaselineMode(Mode.CLEAR_DB)
44 public class TestOJBTest extends BusinessObjectDaoTestCaseBase {
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 @Test
81 public void testCriteria() {
82 Criteria criteria_STATUS = new Criteria();
83 criteria_STATUS.addEqualTo(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.DELIVERED);
84
85 Criteria criteria_UNDELIVERED = new Criteria();
86 criteria_UNDELIVERED.addEqualTo(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.UNDELIVERED);
87
88
89 criteria_STATUS.addOrCriteria(criteria_UNDELIVERED);
90
91 Criteria criteria_NOTLOCKED = new Criteria();
92 criteria_NOTLOCKED.addIsNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE);
93
94 Criteria fullQueryCriteria = new Criteria();
95 fullQueryCriteria.addAndCriteria(criteria_NOTLOCKED);
96 fullQueryCriteria.addLessOrEqualThan(NotificationConstants.BO_PROPERTY_NAMES.NOTIFICATION_AUTO_REMOVE_DATE_TIME, new Timestamp(System.currentTimeMillis()));
97
98 fullQueryCriteria.addAndCriteria(criteria_STATUS);
99
100
101 System.err.println(fullQueryCriteria.toString());
102
103 Query q = QueryFactory.newQuery(NotificationBo.class, fullQueryCriteria);
104 System.err.println(q.toString());
105
106 }
107 @Test
108 public void testUpdateRelationships() {
109 NotificationChannelBo channel1 = MockObjectsUtil.getTestChannel1();
110 NotificationChannelBo channel2 = MockObjectsUtil.getTestChannel2();
111 NotificationProducerBo mockProducer1 = MockObjectsUtil.getTestProducer1();
112
113 businessObjectDao.save(mockProducer1);
114 assertEquals(0, mockProducer1.getChannels().size());
115
116
117 channel1.getProducers().add(mockProducer1);
118
119 businessObjectDao.save(channel1);
120
121 assertEquals(1, channel1.getProducers().size());
122
123
124
125 mockProducer1 = (NotificationProducerBo) businessObjectDao.findById(NotificationProducerBo.class, mockProducer1.getId());
126 assertEquals(1, mockProducer1.getChannels().size());
127
128 channel2.getProducers().add(mockProducer1);
129 businessObjectDao.save(channel2);
130
131 assertEquals(1, channel2.getProducers().size());
132
133 mockProducer1 = (NotificationProducerBo) businessObjectDao.findById(NotificationProducerBo.class, mockProducer1.getId());
134
135 assertEquals(2, mockProducer1.getChannels().size());
136 }
137 }