1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.grustoragedb.business;
35
36 import fr.paris.lutece.plugins.grubusiness.business.customer.Customer;
37 import fr.paris.lutece.plugins.grubusiness.business.demand.Demand;
38 import fr.paris.lutece.plugins.grubusiness.business.demand.IDemandDAO;
39 import fr.paris.lutece.plugins.grubusiness.business.notification.BackofficeNotification;
40 import fr.paris.lutece.plugins.grubusiness.business.notification.BroadcastNotification;
41 import fr.paris.lutece.plugins.grubusiness.business.notification.MyDashboardNotification;
42 import fr.paris.lutece.plugins.grubusiness.business.notification.EmailAddress;
43 import fr.paris.lutece.plugins.grubusiness.business.notification.EmailNotification;
44 import fr.paris.lutece.plugins.grubusiness.business.notification.INotificationDAO;
45 import fr.paris.lutece.plugins.grubusiness.business.notification.Notification;
46 import fr.paris.lutece.plugins.grubusiness.business.notification.NotificationFilter;
47 import fr.paris.lutece.plugins.grubusiness.business.notification.SMSNotification;
48 import fr.paris.lutece.test.LuteceTestCase;
49 import static org.hamcrest.CoreMatchers.is;
50 import static org.junit.Assert.assertEquals;
51
52 import java.util.ArrayList;
53 import java.util.Collection;
54 import java.util.Iterator;
55 import java.util.List;
56
57
58
59
60
61 public class NotificationDAOTest extends LuteceTestCase
62 {
63 private static final String DEMAND_ID_1 = "1";
64 private static final String DEMAND_ID_2 = "2";
65 private static final String DEMAND_TYPE_ID_1 = "1";
66 private static final String DEMAND_TYPE_ID_2 = "2";
67 private static final String DEMAND_SUBTYPE_ID_1 = "sub1";
68 private static final String DEMAND_SUBTYPE_ID_2 = "sub2";
69 private static final String DEMAND_REFERENCE_1 = "DemandReference1";
70 private static final String DEMAND_REFERENCE_2 = "DemandReference2";
71 private static final int DEMAND_STATUS_ID_1 = 1;
72 private static final int DEMAND_STATUS_ID_2 = 2;
73 private static final long NOTIFICATION_DATE_1 = 1L;
74 private static final long NOTIFICATION_DATE_2 = 2L;
75 private static final long NOTIFICATION_DATE_3 = 3L;
76 private static final long NOTIFICATION_DATE_4 = 4L;
77 private static final long NOTIFICATION_DATE_5 = 5L;
78 private static final long NOTIFICATION_DATE_6 = 6L;
79 private static final String BACKOFFICE_NOTIFICATION_MESSAGE_1 = "BackofficeMessage1";
80 private static final String BACKOFFICE_NOTIFICATION_STATUS_TEXT_1 = "BackofficeStatusText1";
81 private static final String SMS_NOTIFICATION_MESSAGE_1 = "SmsMessage1";
82 private static final String SMS_NOTIFICATION_PHONE_NUMBER_1 = "SmsPhoneNumber1";
83 private static final String CUSTOMER_ID_1 = "CustomerId1";
84 private static final String CUSTOMER_ID_2 = "CustomerId2";
85 private static final String CUSTOMER_EMAIL_NOTIFICATION_SENDER_EMAIL_1 = "CustomerEmailSenderEmail1";
86 private static final String CUSTOMER_EMAIL_NOTIFICATION_SENDER_NAME_1 = "CustomerEmailSenderName1";
87 private static final String CUSTOMER_EMAIL_NOTIFICATION_SUBJECT_1 = "CustomerEmailSubject1";
88 private static final String CUSTOMER_EMAIL_NOTIFICATION_MESSAGE_1 = "CustomerEmailMessage1";
89 private static final String CUSTOMER_EMAIL_NOTIFICATION_RECIPIENT_1 = "CustomerEmailRecipient1.1;EmailRecipient1.2";
90 private static final String CUSTOMER_EMAIL_NOTIFICATION_COPIES_1 = "CustomerEmailCopies1.1;EmailCopies1.2";
91 private static final String CUSTOMER_EMAIL_NOTIFICATION_BLIND_COPIES_1 = "CustomerEmailBlindCopies1.1;EmailBlindCopies1.2";
92 private static final int MYDASHBOARD_NOTIFICATION_STATUS_ID_1 = 1;
93 private static final String MYDASHBOARD_NOTIFICATION_STATUS_TEXT_1 = "MyDashboardStatusText1";
94 private static final String MYDASHBOARD_NOTIFICATION_MESSAGE_1 = "MyDashboardMessage1";
95 private static final String MYDASHBOARD_NOTIFICATION_SUBJECT_1 = "MyDashboardSubject1";
96 private static final String MYDASHBOARD_NOTIFICATION_DATA_1 = "MyDashboardData1";
97 private static final String MYDASHBOARD_NOTIFICATION_SENDER_NAME_1 = "MyDashboardSenderName1";
98 private static final String BROADCAST_EMAIL_NOTIFICATION_SENDER_EMAIL_1 = "BroadcastEmailSenderEmail1";
99 private static final String BROADCAST_EMAIL_NOTIFICATION_SENDER_NAME_1 = "BroadcastEmailSenderName1";
100 private static final String BROADCAST_EMAIL_NOTIFICATION_SUBJECT_1 = "BroadcastEmailSubject1";
101 private static final String BROADCAST_EMAIL_NOTIFICATION_MESSAGE_1 = "BroadcastEmailMessage1";
102 private static final String EMAIL_ADDRESS_RECIPIENT_1 = "EmailAddressRecipient1";
103 private static final String EMAIL_ADDRESS_RECIPIENT_2 = "EmailAddressRecipient2";
104 private static final String EMAIL_ADDRESS_COPY_1 = "EmailAddressRecipient1";
105 private static final String EMAIL_ADDRESS_COPY_2 = "EmailAddressRecipient2";
106 private static final String EMAIL_ADDRESS_BLIND_COPY_1 = "EmailAddressRecipient1";
107 private static final String EMAIL_ADDRESS_BLIND_COPY_2 = "EmailAddressRecipient2";
108 private final IDemandDAO _demandDAO;
109 private final INotificationDAO _notificationDAO;
110 private final NotificationFilter _filterSMS;
111 private final NotificationFilter _filterCustomerEmail;
112 private final NotificationFilter _filterBackoffice;
113 private final NotificationFilter _filterMyDashboard;
114 private final NotificationFilter _filterBroadcast;
115
116
117
118
119 public NotificationDAOTest( )
120 {
121 _notificationDAO = new NotificationDAO( );
122 _demandDAO = new DemandDAO( );
123 _filterSMS = new NotificationFilter( );
124 _filterCustomerEmail = new NotificationFilter( );
125 _filterBackoffice = new NotificationFilter( );
126 _filterMyDashboard = new NotificationFilter( );
127 _filterBroadcast = new NotificationFilter( );
128 }
129
130
131
132
133 public void test1Business( )
134 {
135
136 Demand demand = new Demand( );
137 demand.setId( DEMAND_ID_1 );
138 demand.setTypeId( DEMAND_TYPE_ID_1 );
139 demand.setSubtypeId( DEMAND_SUBTYPE_ID_1 );
140 demand.setReference( DEMAND_REFERENCE_1 );
141 demand.setStatusId( DEMAND_STATUS_ID_1 );
142
143 Customer customer = new Customer( );
144 customer.setId( CUSTOMER_ID_1 );
145 demand.setCustomer( customer );
146
147 _demandDAO.insert( demand );
148
149 Notification notification = new Notification( );
150 notification.setDemand( demand );
151 notification.setDate( NOTIFICATION_DATE_1 );
152
153
154 _notificationDAO.insert( notification );
155
156 String strDemandId = notification.getDemand( ).getId( );
157 String strDemandTypeId = notification.getDemand( ).getTypeId( );
158 NotificationFilter filterDemand = new NotificationFilter( );
159 filterDemand.setDemandId( strDemandId );
160 filterDemand.setDemandTypeId( strDemandTypeId );
161 List<Notification> collectionNotificationStored = _notificationDAO.loadByDemand( strDemandId, strDemandTypeId );
162 assertEquals( collectionNotificationStored.size( ), 1 );
163
164 Iterator<Notification> iterator = collectionNotificationStored.iterator( );
165 Notification notificationStored = iterator.next( );
166
167 assertEquals( notificationStored.getDemand( ).getId( ), notification.getDemand( ).getId( ) );
168 assertEquals( notificationStored.getDemand( ).getTypeId( ), notification.getDemand( ).getTypeId( ) );
169 assertEquals( notificationStored.getDemand( ).getSubtypeId( ), notification.getDemand( ).getSubtypeId( ) );
170
171 collectionNotificationStored = _notificationDAO.loadByFilter( filterDemand );
172 assertEquals( collectionNotificationStored.size( ), 1 );
173 collectionNotificationStored = _notificationDAO.loadByFilter( _filterSMS );
174 assertEquals( collectionNotificationStored.size( ), 0 );
175 collectionNotificationStored = _notificationDAO.loadByFilter( _filterCustomerEmail );
176 assertEquals( collectionNotificationStored.size( ), 0 );
177 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBackoffice );
178 assertEquals( collectionNotificationStored.size( ), 0 );
179 collectionNotificationStored = _notificationDAO.loadByFilter( _filterMyDashboard );
180 assertEquals( collectionNotificationStored.size( ), 0 );
181 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBroadcast );
182 assertEquals( collectionNotificationStored.size( ), 0 );
183
184 notification.setDate( NOTIFICATION_DATE_2 );
185
186 BackofficeNotification backofficeNotification = new BackofficeNotification( );
187 backofficeNotification.setMessage( BACKOFFICE_NOTIFICATION_MESSAGE_1 );
188 backofficeNotification.setStatusText( BACKOFFICE_NOTIFICATION_STATUS_TEXT_1 );
189 notification.setBackofficeNotification( backofficeNotification );
190 _notificationDAO.insert( notification );
191
192 collectionNotificationStored = _notificationDAO.loadByDemand( strDemandId, strDemandTypeId );
193 assertEquals( collectionNotificationStored.size( ), 2 );
194 iterator = collectionNotificationStored.iterator( );
195 notificationStored = iterator.next( );
196
197 BackofficeNotification backofficeNotificationStored = notificationStored.getBackofficeNotification( );
198 assertEquals( backofficeNotificationStored.getMessage( ), backofficeNotification.getMessage( ) );
199 assertEquals( backofficeNotificationStored.getStatusText( ), backofficeNotification.getStatusText( ) );
200
201 collectionNotificationStored = _notificationDAO.loadByFilter( filterDemand );
202 assertEquals( collectionNotificationStored.size( ), 2 );
203 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBackoffice );
204 assertEquals( collectionNotificationStored.size( ), 1 );
205 collectionNotificationStored = _notificationDAO.loadByFilter( _filterSMS );
206 assertEquals( collectionNotificationStored.size( ), 0 );
207 collectionNotificationStored = _notificationDAO.loadByFilter( _filterCustomerEmail );
208 assertEquals( collectionNotificationStored.size( ), 0 );
209 collectionNotificationStored = _notificationDAO.loadByFilter( _filterMyDashboard );
210 assertEquals( collectionNotificationStored.size( ), 0 );
211 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBroadcast );
212 assertEquals( collectionNotificationStored.size( ), 0 );
213
214 notification.setDate( NOTIFICATION_DATE_3 );
215
216 SMSNotification smsNotification = new SMSNotification( );
217 smsNotification.setMessage( SMS_NOTIFICATION_MESSAGE_1 );
218 smsNotification.setPhoneNumber( SMS_NOTIFICATION_PHONE_NUMBER_1 );
219 notification.setSmsNotification( smsNotification );
220 _notificationDAO.insert( notification );
221
222 collectionNotificationStored = _notificationDAO.loadByDemand( strDemandId, strDemandTypeId );
223 assertEquals( collectionNotificationStored.size( ), 3 );
224 iterator = collectionNotificationStored.iterator( );
225 notificationStored = iterator.next( );
226
227 SMSNotification smsNotificationStored = notificationStored.getSmsNotification( );
228 assertEquals( smsNotificationStored.getMessage( ), smsNotification.getMessage( ) );
229 assertEquals( smsNotificationStored.getPhoneNumber( ), smsNotification.getPhoneNumber( ) );
230
231 collectionNotificationStored = _notificationDAO.loadByFilter( filterDemand );
232 assertEquals( collectionNotificationStored.size( ), 3 );
233 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBackoffice );
234 assertEquals( collectionNotificationStored.size( ), 2 );
235 collectionNotificationStored = _notificationDAO.loadByFilter( _filterSMS );
236 assertEquals( collectionNotificationStored.size( ), 1 );
237 collectionNotificationStored = _notificationDAO.loadByFilter( _filterCustomerEmail );
238 assertEquals( collectionNotificationStored.size( ), 0 );
239 collectionNotificationStored = _notificationDAO.loadByFilter( _filterMyDashboard );
240 assertEquals( collectionNotificationStored.size( ), 0 );
241 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBroadcast );
242 assertEquals( collectionNotificationStored.size( ), 0 );
243
244 notification.setDate( NOTIFICATION_DATE_4 );
245
246 EmailNotification emailNotification = new EmailNotification( );
247 emailNotification.setSenderEmail( CUSTOMER_EMAIL_NOTIFICATION_SENDER_EMAIL_1 );
248 emailNotification.setSenderName( CUSTOMER_EMAIL_NOTIFICATION_SENDER_NAME_1 );
249 emailNotification.setSubject( CUSTOMER_EMAIL_NOTIFICATION_SUBJECT_1 );
250 emailNotification.setMessage( CUSTOMER_EMAIL_NOTIFICATION_MESSAGE_1 );
251 emailNotification.setRecipient( CUSTOMER_EMAIL_NOTIFICATION_RECIPIENT_1 );
252 emailNotification.setCc( CUSTOMER_EMAIL_NOTIFICATION_COPIES_1 );
253 emailNotification.setBcc( CUSTOMER_EMAIL_NOTIFICATION_BLIND_COPIES_1 );
254 notification.setEmailNotification( emailNotification );
255 _notificationDAO.insert( notification );
256
257 collectionNotificationStored = _notificationDAO.loadByDemand( strDemandId, strDemandTypeId );
258 assertEquals( collectionNotificationStored.size( ), 4 );
259 iterator = collectionNotificationStored.iterator( );
260 notificationStored = iterator.next( );
261
262 EmailNotification emailNotificationStored = notificationStored.getEmailNotification( );
263 assertEquals( emailNotificationStored.getSenderEmail( ), emailNotification.getSenderEmail( ) );
264 assertEquals( emailNotificationStored.getSenderName( ), emailNotification.getSenderName( ) );
265 assertEquals( emailNotificationStored.getSubject( ), emailNotification.getSubject( ) );
266 assertEquals( emailNotificationStored.getMessage( ), emailNotification.getMessage( ) );
267 assertEquals( emailNotificationStored.getRecipient( ), emailNotification.getRecipient( ) );
268 assertEquals( emailNotificationStored.getCc( ), emailNotification.getCc( ) );
269 assertEquals( emailNotificationStored.getCci( ), emailNotification.getCci( ) );
270
271 collectionNotificationStored = _notificationDAO.loadByFilter( filterDemand );
272 assertEquals( collectionNotificationStored.size( ), 4 );
273 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBackoffice );
274 assertEquals( collectionNotificationStored.size( ), 3 );
275 collectionNotificationStored = _notificationDAO.loadByFilter( _filterSMS );
276 assertEquals( collectionNotificationStored.size( ), 2 );
277 collectionNotificationStored = _notificationDAO.loadByFilter( _filterCustomerEmail );
278 assertEquals( collectionNotificationStored.size( ), 1 );
279 collectionNotificationStored = _notificationDAO.loadByFilter( _filterMyDashboard );
280 assertEquals( collectionNotificationStored.size( ), 0 );
281 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBroadcast );
282 assertEquals( collectionNotificationStored.size( ), 0 );
283
284 notification.setDate( NOTIFICATION_DATE_5 );
285
286 MyDashboardNotification myDashboardNotification = new MyDashboardNotification( );
287 myDashboardNotification.setStatusId( MYDASHBOARD_NOTIFICATION_STATUS_ID_1 );
288 myDashboardNotification.setStatusText( MYDASHBOARD_NOTIFICATION_STATUS_TEXT_1 );
289 myDashboardNotification.setMessage( MYDASHBOARD_NOTIFICATION_MESSAGE_1 );
290 myDashboardNotification.setSubject( MYDASHBOARD_NOTIFICATION_SUBJECT_1 );
291 myDashboardNotification.setData( MYDASHBOARD_NOTIFICATION_DATA_1 );
292 myDashboardNotification.setSenderName( MYDASHBOARD_NOTIFICATION_SENDER_NAME_1 );
293 notification.setMyDashboardNotification( myDashboardNotification );
294 _notificationDAO.insert( notification );
295
296 collectionNotificationStored = _notificationDAO.loadByDemand( strDemandId, strDemandTypeId );
297 assertEquals( collectionNotificationStored.size( ), 5 );
298 iterator = collectionNotificationStored.iterator( );
299 notificationStored = iterator.next( );
300
301 MyDashboardNotification myDashboardNotificationStored = notificationStored.getMyDashboardNotification( );
302 assertEquals( myDashboardNotificationStored.getStatusId( ), myDashboardNotification.getStatusId( ) );
303 assertEquals( myDashboardNotificationStored.getStatusText( ), myDashboardNotification.getStatusText( ) );
304 assertEquals( myDashboardNotificationStored.getMessage( ), myDashboardNotification.getMessage( ) );
305 assertEquals( myDashboardNotificationStored.getSubject( ), myDashboardNotification.getSubject( ) );
306 assertEquals( myDashboardNotificationStored.getData( ), myDashboardNotification.getData( ) );
307 assertEquals( myDashboardNotificationStored.getSenderName( ), myDashboardNotification.getSenderName( ) );
308
309 collectionNotificationStored = _notificationDAO.loadByFilter( filterDemand );
310 assertEquals( collectionNotificationStored.size( ), 5 );
311 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBackoffice );
312 assertEquals( collectionNotificationStored.size( ), 4 );
313 collectionNotificationStored = _notificationDAO.loadByFilter( _filterSMS );
314 assertEquals( collectionNotificationStored.size( ), 3 );
315 collectionNotificationStored = _notificationDAO.loadByFilter( _filterCustomerEmail );
316 assertEquals( collectionNotificationStored.size( ), 2 );
317 collectionNotificationStored = _notificationDAO.loadByFilter( _filterMyDashboard );
318 assertEquals( collectionNotificationStored.size( ), 1 );
319 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBroadcast );
320 assertEquals( collectionNotificationStored.size( ), 0 );
321
322 notification.setDate( NOTIFICATION_DATE_6 );
323
324 List<BroadcastNotification> listBroadcastNotifications = new ArrayList<BroadcastNotification>( );
325 BroadcastNotification broadcastNotification = new BroadcastNotification( );
326 broadcastNotification.setSenderEmail( BROADCAST_EMAIL_NOTIFICATION_SENDER_EMAIL_1 );
327 broadcastNotification.setSenderName( BROADCAST_EMAIL_NOTIFICATION_SENDER_NAME_1 );
328 broadcastNotification.setSubject( BROADCAST_EMAIL_NOTIFICATION_SUBJECT_1 );
329 broadcastNotification.setMessage( BROADCAST_EMAIL_NOTIFICATION_MESSAGE_1 );
330
331 List<EmailAddress> listEmailAddresses = new ArrayList<EmailAddress>( );
332 EmailAddress emailAddress = new EmailAddress( );
333 emailAddress.setAddress( EMAIL_ADDRESS_RECIPIENT_1 );
334 listEmailAddresses.add( emailAddress );
335 emailAddress = new EmailAddress( );
336 emailAddress.setAddress( EMAIL_ADDRESS_RECIPIENT_2 );
337 listEmailAddresses.add( emailAddress );
338 broadcastNotification.setRecipient( listEmailAddresses );
339 listEmailAddresses = new ArrayList<EmailAddress>( );
340 emailAddress = new EmailAddress( );
341 emailAddress.setAddress( EMAIL_ADDRESS_COPY_1 );
342 listEmailAddresses.add( emailAddress );
343 emailAddress = new EmailAddress( );
344 emailAddress.setAddress( EMAIL_ADDRESS_COPY_2 );
345 listEmailAddresses.add( emailAddress );
346 broadcastNotification.setCc( listEmailAddresses );
347 listEmailAddresses = new ArrayList<EmailAddress>( );
348 emailAddress = new EmailAddress( );
349 emailAddress.setAddress( EMAIL_ADDRESS_BLIND_COPY_1 );
350 listEmailAddresses.add( emailAddress );
351 emailAddress = new EmailAddress( );
352 emailAddress.setAddress( EMAIL_ADDRESS_BLIND_COPY_2 );
353 listEmailAddresses.add( emailAddress );
354 broadcastNotification.setBcc( listEmailAddresses );
355 listBroadcastNotifications.add( broadcastNotification );
356
357 BroadcastNotification broadcastNotification2 = new BroadcastNotification( );
358 broadcastNotification2.setSenderEmail( BROADCAST_EMAIL_NOTIFICATION_SENDER_EMAIL_1 );
359 broadcastNotification2.setSenderName( BROADCAST_EMAIL_NOTIFICATION_SENDER_NAME_1 );
360 broadcastNotification2.setSubject( BROADCAST_EMAIL_NOTIFICATION_SUBJECT_1 );
361 broadcastNotification2.setMessage( BROADCAST_EMAIL_NOTIFICATION_MESSAGE_1 );
362 broadcastNotification2.setRecipient( listEmailAddresses );
363 broadcastNotification2.setCc( listEmailAddresses );
364 broadcastNotification2.setBcc( listEmailAddresses );
365 listBroadcastNotifications.add( broadcastNotification2 );
366
367 notification.setBroadcastEmail( listBroadcastNotifications );
368 _notificationDAO.insert( notification );
369
370 collectionNotificationStored = _notificationDAO.loadByDemand( strDemandId, strDemandTypeId );
371 assertEquals( collectionNotificationStored.size( ), 6 );
372 iterator = collectionNotificationStored.iterator( );
373 notificationStored = iterator.next( );
374
375 List<BroadcastNotification> listBroadcastNotificationsStored = notificationStored.getBroadcastEmail( );
376 assertEquals( listBroadcastNotificationsStored.size( ), 2 );
377
378 BroadcastNotification broadcastNotificationStored = listBroadcastNotificationsStored.get( 0 );
379 assertEquals( broadcastNotificationStored.getSenderEmail( ), broadcastNotification.getSenderEmail( ) );
380 assertEquals( broadcastNotificationStored.getSenderName( ), broadcastNotification.getSenderName( ) );
381 assertEquals( broadcastNotificationStored.getSubject( ), broadcastNotification.getSubject( ) );
382 assertEquals( broadcastNotificationStored.getMessage( ), broadcastNotification.getMessage( ) );
383
384 List<EmailAddress> listEmailAddressesStored = broadcastNotificationStored.getRecipient( );
385 assertEquals( listEmailAddressesStored.size( ), 2 );
386 listEmailAddressesStored = broadcastNotificationStored.getCc( );
387 assertEquals( listEmailAddressesStored.size( ), 2 );
388 listEmailAddressesStored = broadcastNotificationStored.getBcc( );
389 assertEquals( listEmailAddressesStored.size( ), 2 );
390
391 collectionNotificationStored = _notificationDAO.loadByFilter( filterDemand );
392 assertEquals( collectionNotificationStored.size( ), 6 );
393 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBackoffice );
394 assertEquals( collectionNotificationStored.size( ), 5 );
395 collectionNotificationStored = _notificationDAO.loadByFilter( _filterSMS );
396 assertEquals( collectionNotificationStored.size( ), 4 );
397 collectionNotificationStored = _notificationDAO.loadByFilter( _filterCustomerEmail );
398 assertEquals( collectionNotificationStored.size( ), 3 );
399 collectionNotificationStored = _notificationDAO.loadByFilter( _filterMyDashboard );
400 assertEquals( collectionNotificationStored.size( ), 2 );
401 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBroadcast );
402 assertEquals( collectionNotificationStored.size( ), 1 );
403
404 _notificationDAO.deleteByDemand( strDemandId, strDemandTypeId );
405 collectionNotificationStored = _notificationDAO.loadByDemand( strDemandId, strDemandTypeId );
406 assertEquals( collectionNotificationStored.size( ), 0 );
407
408 collectionNotificationStored = _notificationDAO.loadByFilter( filterDemand );
409 assertEquals( collectionNotificationStored.size( ), 0 );
410 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBackoffice );
411 assertEquals( collectionNotificationStored.size( ), 0 );
412 collectionNotificationStored = _notificationDAO.loadByFilter( _filterSMS );
413 assertEquals( collectionNotificationStored.size( ), 0 );
414 collectionNotificationStored = _notificationDAO.loadByFilter( _filterCustomerEmail );
415 assertEquals( collectionNotificationStored.size( ), 0 );
416 collectionNotificationStored = _notificationDAO.loadByFilter( _filterMyDashboard );
417 assertEquals( collectionNotificationStored.size( ), 0 );
418 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBroadcast );
419 assertEquals( collectionNotificationStored.size( ), 0 );
420
421 _demandDAO.delete( strDemandId, strDemandTypeId );
422 }
423
424
425
426
427 public void test2Business( )
428 {
429
430 Demand demand = new Demand( );
431 demand.setId( DEMAND_ID_1 );
432 demand.setTypeId( DEMAND_TYPE_ID_1 );
433 demand.setSubtypeId( DEMAND_SUBTYPE_ID_1 );
434 demand.setReference( DEMAND_REFERENCE_1 );
435 demand.setStatusId( DEMAND_STATUS_ID_1 );
436
437 Customer customer = new Customer( );
438 customer.setId( CUSTOMER_ID_1 );
439 demand.setCustomer( customer );
440
441 _demandDAO.insert( demand );
442
443 Demand demand2 = new Demand( );
444 demand2.setId( DEMAND_ID_2 );
445 demand2.setTypeId( DEMAND_TYPE_ID_2 );
446 demand.setSubtypeId( DEMAND_SUBTYPE_ID_2 );
447 demand2.setReference( DEMAND_REFERENCE_2 );
448 demand2.setStatusId( DEMAND_STATUS_ID_2 );
449
450 Customer customer2 = new Customer( );
451 customer2.setId( CUSTOMER_ID_2 );
452 demand2.setCustomer( customer2 );
453
454 _demandDAO.insert( demand2 );
455
456 Notification notification = new Notification( );
457 notification.setDemand( demand );
458 notification.setDate( NOTIFICATION_DATE_1 );
459 _notificationDAO.insert( notification );
460
461 notification = new Notification( );
462 notification.setDemand( demand2 );
463 notification.setDate( NOTIFICATION_DATE_2 );
464 _notificationDAO.insert( notification );
465
466 Collection<Notification> collectionNotificationStored = _notificationDAO.loadByDemand( DEMAND_ID_1, DEMAND_TYPE_ID_1 );
467 assertEquals( collectionNotificationStored.size( ), 1 );
468
469 Iterator<Notification> iterator = collectionNotificationStored.iterator( );
470 Notification notificationStored = iterator.next( );
471 assertSame( notificationStored.getDate( ), NOTIFICATION_DATE_1 );
472
473 collectionNotificationStored = _notificationDAO.loadByDemand( DEMAND_ID_2, DEMAND_TYPE_ID_2 );
474 assertEquals( collectionNotificationStored.size( ), 1 );
475 iterator = collectionNotificationStored.iterator( );
476 notificationStored = iterator.next( );
477 assertSame( notificationStored.getDate( ), NOTIFICATION_DATE_2 );
478
479 _notificationDAO.deleteByDemand( DEMAND_ID_1, DEMAND_TYPE_ID_1 );
480 collectionNotificationStored = _notificationDAO.loadByDemand( DEMAND_ID_1, DEMAND_TYPE_ID_1 );
481 assertEquals( collectionNotificationStored.size( ), 0 );
482
483 _notificationDAO.deleteByDemand( DEMAND_ID_2, DEMAND_TYPE_ID_2 );
484 collectionNotificationStored = _notificationDAO.loadByDemand( DEMAND_ID_2, DEMAND_TYPE_ID_2 );
485 assertEquals( collectionNotificationStored.size( ), 0 );
486
487 _demandDAO.delete( DEMAND_ID_1, DEMAND_TYPE_ID_1 );
488 _demandDAO.delete( DEMAND_ID_2, DEMAND_TYPE_ID_2 );
489 }
490 }