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 org.kuali.rice.ken.bo.NotificationChannelBo;
19 import org.kuali.rice.ken.bo.NotificationChannelReviewerBo;
20 import org.kuali.rice.ken.test.util.MockObjectsUtil;
21 import org.kuali.rice.ken.util.NotificationConstants;
22 import org.kuali.rice.kim.api.KimConstants.KimGroupMemberTypes;
23
24 import java.util.HashMap;
25
26
27
28
29
30
31 public class NotificationChannelReviewerDaoTest extends BusinessObjectPersistenceTestCaseBase {
32 private NotificationChannelBo mockChannel1 = MockObjectsUtil.getTestChannel1();
33 private NotificationChannelReviewerBo mockReviewer = MockObjectsUtil.buildTestNotificationChannelReviewer(KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, "aReviewer");
34
35
36
37
38 @Override
39 protected void setup() {
40 super.setup();
41 businessObjectDao.save(mockChannel1);
42 }
43
44
45
46
47 @Override
48 protected boolean delete() {
49 HashMap criteria = new HashMap();
50
51 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.REVIEWER_ID, mockReviewer.getReviewerId());
52 NotificationChannelReviewerBo
53 reviewer = (NotificationChannelReviewerBo) businessObjectDao.findByUniqueKey(NotificationChannelReviewerBo.class, criteria);
54
55 try {
56 businessObjectDao.delete(reviewer);
57 } catch(Exception e) {
58 return false;
59 }
60 return true;
61 }
62
63
64
65
66
67 @Override
68 protected boolean insert() {
69 mockReviewer.setChannel(mockChannel1);
70
71 try {
72 businessObjectDao.save(mockReviewer);
73 } catch(Exception e) {
74 return false;
75 }
76 return true;
77 }
78
79
80
81
82 @Override
83 protected boolean retrieve() {
84 HashMap criteria = new HashMap();
85
86 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.REVIEWER_ID, mockReviewer.getReviewerId());
87 NotificationChannelReviewerBo
88 reviewer = (NotificationChannelReviewerBo) businessObjectDao.findByUniqueKey(NotificationChannelReviewerBo.class, criteria);
89
90 boolean success = true;
91
92 success &= reviewer != null;
93 success &= reviewer.getReviewerId().equals(mockReviewer.getReviewerId());
94 success &= reviewer.getReviewerType().equals(mockReviewer.getReviewerType());
95 success &= reviewer.getChannel() != null;
96 success &= reviewer.getChannel().getId().equals(mockChannel1.getId());
97
98 return success;
99 }
100
101
102
103
104 @Override
105 protected boolean update() {
106 HashMap criteria = new HashMap();
107
108 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.REVIEWER_ID, mockReviewer.getReviewerId());
109 NotificationChannelReviewerBo
110 reviewer = (NotificationChannelReviewerBo) businessObjectDao.findByUniqueKey(NotificationChannelReviewerBo.class, criteria);
111
112 reviewer.setReviewerId("updatedReviewerId");
113 reviewer.setReviewerType(KimGroupMemberTypes.GROUP_MEMBER_TYPE.getCode());
114
115 try {
116 businessObjectDao.save(reviewer);
117 } catch(Exception e) {
118 return false;
119 }
120 return true;
121 }
122
123
124
125
126 @Override
127 protected boolean validateChanges() {
128 NotificationChannelReviewerBo
129 reviewer = (NotificationChannelReviewerBo) businessObjectDao.findById(NotificationChannelReviewerBo.class, mockReviewer.getId());
130
131 boolean success = reviewer != null;
132 success &= reviewer.getReviewerId().equals("updatedReviewerId");
133 success &= reviewer.getReviewerType().equals(KimGroupMemberTypes.GROUP_MEMBER_TYPE.getCode());
134
135 return success;
136 }
137 }