1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ken.dao;
17
18 import java.util.HashMap;
19
20 import org.kuali.rice.ken.bo.NotificationChannel;
21 import org.kuali.rice.ken.bo.UserChannelSubscription;
22 import org.kuali.rice.ken.test.util.MockObjectsUtil;
23 import org.kuali.rice.ken.util.NotificationConstants;
24
25
26
27
28
29
30
31 public class UserChannelSubscriptionDaoTest extends BusinessObjectPersistenceTestCaseBase {
32 NotificationChannel channel1 = MockObjectsUtil.getTestChannel1();
33 NotificationChannel channel2 = MockObjectsUtil.getTestChannel2();
34
35 UserChannelSubscription subscription1 = new UserChannelSubscription();
36 UserChannelSubscription subscription2 = new UserChannelSubscription();
37
38 private String[] userIds = {"ag266", "jaf30"};
39 private String[] updatedUserIds = {"bh79", "arh14"};
40
41
42
43
44 @Override
45 protected void setup() {
46 businessObjectDao.save(channel1);
47 businessObjectDao.save(channel2);
48 }
49
50
51
52
53 @Override
54 protected boolean delete() {
55 try {
56 businessObjectDao.delete(subscription1);
57 businessObjectDao.delete(subscription2);
58 } catch(Exception e) {
59 return false;
60 }
61 return true;
62 }
63
64
65
66
67 @Override
68 protected boolean retrieve() {
69 subscription1 = null;
70 subscription2 = null;
71
72 HashMap criteria = new HashMap();
73
74 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.CHANNEL_ID, channel1.getId());
75 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.USER_ID, userIds[0]);
76 subscription1 = (UserChannelSubscription) businessObjectDao.findByUniqueKey(UserChannelSubscription.class, criteria);
77
78 criteria.clear();
79
80 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.CHANNEL_ID, channel2.getId());
81 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.USER_ID, userIds[1]);
82 subscription2 = (UserChannelSubscription) businessObjectDao.findByUniqueKey(UserChannelSubscription.class, criteria);
83
84 boolean success = true;
85
86 success &= subscription1 != null;
87 success &= subscription1.getId()>0;
88 success &= subscription1.getChannel().getId().equals(channel1.getId());
89
90 success &= subscription2 != null;
91 success &= subscription2.getId()>0;
92 success &= subscription2.getChannel().getId().equals(channel2.getId());
93
94 return success;
95 }
96
97
98
99
100 @Override
101 protected boolean insert() {
102 subscription1.setChannel(channel1);
103 subscription1.setUserId(userIds[0]);
104
105 subscription2.setChannel(channel2);
106 subscription2.setUserId(userIds[1]);
107
108 try {
109 businessObjectDao.save(subscription1);
110 businessObjectDao.save(subscription2);
111 } catch(Exception e) {
112 return false;
113 }
114 return true;
115 }
116
117
118
119
120 @Override
121 protected boolean update() {
122 subscription1.setUserId(updatedUserIds[0]);
123
124 subscription2.setUserId(updatedUserIds[1]);
125
126 try {
127 businessObjectDao.save(subscription1);
128 businessObjectDao.save(subscription2);
129 } catch(Exception e) {
130 return false;
131 }
132 return true;
133 }
134
135
136
137
138 @Override
139 protected boolean validateChanges() {
140 subscription1 = new UserChannelSubscription();
141 subscription2 = new UserChannelSubscription();
142
143 HashMap criteria = new HashMap();
144
145 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.CHANNEL_ID, channel1.getId());
146 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.USER_ID, updatedUserIds[0]);
147 subscription1 = (UserChannelSubscription) businessObjectDao.findByUniqueKey(UserChannelSubscription.class, criteria);
148
149 criteria.clear();
150
151 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.CHANNEL_ID, channel2.getId());
152 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.USER_ID, updatedUserIds[1]);
153 subscription2 = (UserChannelSubscription) businessObjectDao.findByUniqueKey(UserChannelSubscription.class, criteria);
154
155 boolean success = true;
156
157 success &= subscription1 != null;
158 success &= subscription1.getId()>0;
159 success &= subscription1.getChannel().getId().equals(channel1.getId());
160 success &= subscription1.getUserId().equals(updatedUserIds[0]);
161
162 success &= subscription2 != null;
163 success &= subscription2.getId()>0;
164 success &= subscription2.getChannel().getId().equals(channel2.getId());
165 success &= subscription2.getUserId().equals(updatedUserIds[1]);
166
167 return success;
168 }
169 }