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.sql.Timestamp;
19 import java.util.ArrayList;
20 import java.util.Calendar;
21 import java.util.HashMap;
22 import java.util.List;
23
24 import org.kuali.rice.ken.bo.Notification;
25 import org.kuali.rice.ken.bo.NotificationChannel;
26 import org.kuali.rice.ken.bo.NotificationContentType;
27 import org.kuali.rice.ken.bo.NotificationPriority;
28 import org.kuali.rice.ken.bo.NotificationProducer;
29 import org.kuali.rice.ken.bo.NotificationRecipient;
30 import org.kuali.rice.ken.bo.NotificationSender;
31 import org.kuali.rice.ken.test.util.MockObjectsUtil;
32 import org.kuali.rice.ken.util.NotificationConstants;
33
34
35
36
37
38
39
40
41
42 public class NotificationDaoTest extends BusinessObjectPersistenceTestCaseBase {
43 Long id = new Long(-1);
44 NotificationPriority mockPriority = MockObjectsUtil.getTestPriority1();
45 NotificationContentType mockContentType = MockObjectsUtil.getTestContentType1();
46 NotificationChannel mockChannel = MockObjectsUtil.getTestChannel1();
47 NotificationProducer mockProducer = MockObjectsUtil.getTestProducer1();
48
49 Notification notification = new Notification();
50
51 private String deliveryType = NotificationConstants.DELIVERY_TYPES.ACK;
52 private Timestamp sendDateTime = new Timestamp(Calendar.getInstance().getTimeInMillis());
53 private Timestamp autoRemoveDateTime = null;
54 private String content = "Notification Content!";
55
56
57
58
59 @Override
60 protected void setup() {
61 super.setup();
62 businessObjectDao.save(mockPriority);
63 businessObjectDao.save(mockContentType);
64 businessObjectDao.save(mockChannel);
65 businessObjectDao.save(mockProducer);
66 }
67
68
69
70
71 @Override
72 protected boolean delete() {
73 try {
74 businessObjectDao.delete(notification);
75 } catch(Exception e) {
76 return false;
77 }
78 return true;
79 }
80
81
82
83
84 @Override
85 protected boolean retrieve() {
86 notification = new Notification();
87
88 HashMap criteria = new HashMap();
89
90 criteria.put(NotificationConstants.BO_PROPERTY_NAMES.ID, id);
91 notification = (Notification) businessObjectDao.findByPrimaryKey(Notification.class, criteria);
92
93 boolean success = true;
94
95 success &= notification != null;
96 success &= notification.getContentType().getName().equals(MockObjectsUtil.getTestContentType1().getName());
97 success &= notification.getRecipients().size()==2;
98 success &= notification.getSenders().size()==2;
99 success &= notification.getCreationDateTime()!=null;
100 success &= notification.getAutoRemoveDateTime()==null;
101 success &= notification.getDeliveryType().equals(NotificationConstants.DELIVERY_TYPES.ACK);
102 success &= notification.getProcessingFlag().equals(NotificationConstants.PROCESSING_FLAGS.UNRESOLVED);
103
104 return success;
105 }
106
107
108
109
110 @Override
111 protected boolean insert() {
112 List<NotificationRecipient> recipients = new ArrayList();
113 recipients.add(MockObjectsUtil.getTestRecipient1());
114 recipients.add(MockObjectsUtil.getTestRecipient2());
115
116 List<NotificationSender> senders = new ArrayList();
117 senders.add(MockObjectsUtil.getTestSender1());
118 senders.add(MockObjectsUtil.getTestSender2());
119
120 notification = MockObjectsUtil.buildTestNotification(deliveryType, sendDateTime, autoRemoveDateTime, mockContentType,
121 content, mockPriority, mockProducer, mockChannel, recipients, senders);
122 try {
123 businessObjectDao.save(notification);
124 id = new Long(notification.getId());
125 } catch(Exception e) {
126 LOG.error("Error saving notification", e);
127 return false;
128 }
129 return true;
130 }
131
132
133
134
135 @Override
136 protected boolean update() {
137 notification.setDeliveryType(NotificationConstants.DELIVERY_TYPES.FYI);
138
139 try {
140 businessObjectDao.save(notification);
141 } catch(Exception e) {
142 return false;
143 }
144 return true;
145 }
146
147
148
149
150 @Override
151 protected boolean validateChanges() {
152 retrieve();
153
154 boolean success = true;
155
156 success &= notification.getDeliveryType().equals(NotificationConstants.DELIVERY_TYPES.FYI);
157
158 return success;
159 }
160 }