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.NotificationChannel;
19 import org.kuali.rice.ken.bo.NotificationChannelReviewer;
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 NotificationChannel mockChannel1 = MockObjectsUtil.getTestChannel1();
33 private NotificationChannelReviewer 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 NotificationChannelReviewer reviewer = (NotificationChannelReviewer) businessObjectDao.findByUniqueKey(NotificationChannelReviewer.class, criteria);
53
54 try {
55 businessObjectDao.delete(reviewer);
56 } catch(Exception e) {
57 return false;
58 }
59 return true;
60 }
61
62
63
64
65
66 @Override
67 protected boolean insert() {
68 mockReviewer.setChannel(mockChannel1);
69
70 try {
71 businessObjectDao.save(mockReviewer);
72 } catch(Exception e) {
73 return false;
74 }
75 return true;
76 }
77
78
79
80
81 @Override
82 protected boolean retrieve() {
83 HashMap criteria = new HashMap();
84
85 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.REVIEWER_ID, mockReviewer.getReviewerId());
86 NotificationChannelReviewer reviewer = (NotificationChannelReviewer) businessObjectDao.findByUniqueKey(NotificationChannelReviewer.class, criteria);
87
88 boolean success = true;
89
90 success &= reviewer != null;
91 success &= reviewer.getReviewerId().equals(mockReviewer.getReviewerId());
92 success &= reviewer.getReviewerType().equals(mockReviewer.getReviewerType());
93 success &= reviewer.getChannel() != null;
94 success &= reviewer.getChannel().getId().equals(mockChannel1.getId());
95
96 return success;
97 }
98
99
100
101
102 @Override
103 protected boolean update() {
104 HashMap criteria = new HashMap();
105
106 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.REVIEWER_ID, mockReviewer.getReviewerId());
107 NotificationChannelReviewer reviewer = (NotificationChannelReviewer) businessObjectDao.findByUniqueKey(NotificationChannelReviewer.class, criteria);
108
109 reviewer.setReviewerId("updatedReviewerId");
110 reviewer.setReviewerType(KimGroupMemberTypes.GROUP_MEMBER_TYPE.getCode());
111
112 try {
113 businessObjectDao.save(reviewer);
114 } catch(Exception e) {
115 return false;
116 }
117 return true;
118 }
119
120
121
122
123 @Override
124 protected boolean validateChanges() {
125 NotificationChannelReviewer reviewer = (NotificationChannelReviewer) businessObjectDao.findById(NotificationChannelReviewer.class, mockReviewer.getId());
126
127 boolean success = reviewer != null;
128 success &= reviewer.getReviewerId().equals("updatedReviewerId");
129 success &= reviewer.getReviewerType().equals(KimGroupMemberTypes.GROUP_MEMBER_TYPE);
130
131 return success;
132 }
133 }