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.notificationstore.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.setCustomerId( 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 String strCustomerId = notification.getDemand( ).getCustomer( ).getCustomerId( );
159 NotificationFilter filterDemand = new NotificationFilter( );
160 filterDemand.setDemandId( strDemandId );
161 filterDemand.setDemandTypeId( strDemandTypeId );
162 List<Notification> collectionNotificationStored = _notificationDAO.loadByDemand( strDemandId, strDemandTypeId, strCustomerId );
163 assertEquals( collectionNotificationStored.size( ), 1 );
164
165 Iterator<Notification> iterator = collectionNotificationStored.iterator( );
166 Notification notificationStored = iterator.next( );
167
168 assertEquals( notificationStored.getDemand( ).getId( ), notification.getDemand( ).getId( ) );
169 assertEquals( notificationStored.getDemand( ).getTypeId( ), notification.getDemand( ).getTypeId( ) );
170 assertEquals( notificationStored.getDemand( ).getSubtypeId( ), notification.getDemand( ).getSubtypeId( ) );
171
172 collectionNotificationStored = _notificationDAO.loadByFilter( filterDemand );
173 assertEquals( collectionNotificationStored.size( ), 1 );
174 collectionNotificationStored = _notificationDAO.loadByFilter( _filterSMS );
175 assertEquals( collectionNotificationStored.size( ), 0 );
176 collectionNotificationStored = _notificationDAO.loadByFilter( _filterCustomerEmail );
177 assertEquals( collectionNotificationStored.size( ), 0 );
178 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBackoffice );
179 assertEquals( collectionNotificationStored.size( ), 0 );
180 collectionNotificationStored = _notificationDAO.loadByFilter( _filterMyDashboard );
181 assertEquals( collectionNotificationStored.size( ), 0 );
182 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBroadcast );
183 assertEquals( collectionNotificationStored.size( ), 0 );
184
185 notification.setDate( NOTIFICATION_DATE_2 );
186
187 BackofficeNotification backofficeNotification = new BackofficeNotification( );
188 backofficeNotification.setMessage( BACKOFFICE_NOTIFICATION_MESSAGE_1 );
189 backofficeNotification.setStatusText( BACKOFFICE_NOTIFICATION_STATUS_TEXT_1 );
190 notification.setBackofficeNotification( backofficeNotification );
191 _notificationDAO.insert( notification );
192
193 collectionNotificationStored = _notificationDAO.loadByDemand( strDemandId, strDemandTypeId, strCustomerId );
194 assertEquals( collectionNotificationStored.size( ), 2 );
195 iterator = collectionNotificationStored.iterator( );
196 notificationStored = iterator.next( );
197
198 BackofficeNotification backofficeNotificationStored = notificationStored.getBackofficeNotification( );
199 assertEquals( backofficeNotificationStored.getMessage( ), backofficeNotification.getMessage( ) );
200 assertEquals( backofficeNotificationStored.getStatusText( ), backofficeNotification.getStatusText( ) );
201
202 collectionNotificationStored = _notificationDAO.loadByFilter( filterDemand );
203 assertEquals( collectionNotificationStored.size( ), 2 );
204 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBackoffice );
205 assertEquals( collectionNotificationStored.size( ), 1 );
206 collectionNotificationStored = _notificationDAO.loadByFilter( _filterSMS );
207 assertEquals( collectionNotificationStored.size( ), 0 );
208 collectionNotificationStored = _notificationDAO.loadByFilter( _filterCustomerEmail );
209 assertEquals( collectionNotificationStored.size( ), 0 );
210 collectionNotificationStored = _notificationDAO.loadByFilter( _filterMyDashboard );
211 assertEquals( collectionNotificationStored.size( ), 0 );
212 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBroadcast );
213 assertEquals( collectionNotificationStored.size( ), 0 );
214
215 notification.setDate( NOTIFICATION_DATE_3 );
216
217 SMSNotification smsNotification = new SMSNotification( );
218 smsNotification.setMessage( SMS_NOTIFICATION_MESSAGE_1 );
219 smsNotification.setPhoneNumber( SMS_NOTIFICATION_PHONE_NUMBER_1 );
220 notification.setSmsNotification( smsNotification );
221 _notificationDAO.insert( notification );
222
223 collectionNotificationStored = _notificationDAO.loadByDemand( strDemandId, strDemandTypeId, strCustomerId );
224 assertEquals( collectionNotificationStored.size( ), 3 );
225 iterator = collectionNotificationStored.iterator( );
226 notificationStored = iterator.next( );
227
228 SMSNotification smsNotificationStored = notificationStored.getSmsNotification( );
229 assertEquals( smsNotificationStored.getMessage( ), smsNotification.getMessage( ) );
230 assertEquals( smsNotificationStored.getPhoneNumber( ), smsNotification.getPhoneNumber( ) );
231
232 collectionNotificationStored = _notificationDAO.loadByFilter( filterDemand );
233 assertEquals( collectionNotificationStored.size( ), 3 );
234 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBackoffice );
235 assertEquals( collectionNotificationStored.size( ), 2 );
236 collectionNotificationStored = _notificationDAO.loadByFilter( _filterSMS );
237 assertEquals( collectionNotificationStored.size( ), 1 );
238 collectionNotificationStored = _notificationDAO.loadByFilter( _filterCustomerEmail );
239 assertEquals( collectionNotificationStored.size( ), 0 );
240 collectionNotificationStored = _notificationDAO.loadByFilter( _filterMyDashboard );
241 assertEquals( collectionNotificationStored.size( ), 0 );
242 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBroadcast );
243 assertEquals( collectionNotificationStored.size( ), 0 );
244
245 notification.setDate( NOTIFICATION_DATE_4 );
246
247 EmailNotification emailNotification = new EmailNotification( );
248 emailNotification.setSenderEmail( CUSTOMER_EMAIL_NOTIFICATION_SENDER_EMAIL_1 );
249 emailNotification.setSenderName( CUSTOMER_EMAIL_NOTIFICATION_SENDER_NAME_1 );
250 emailNotification.setSubject( CUSTOMER_EMAIL_NOTIFICATION_SUBJECT_1 );
251 emailNotification.setMessage( CUSTOMER_EMAIL_NOTIFICATION_MESSAGE_1 );
252 emailNotification.setRecipient( CUSTOMER_EMAIL_NOTIFICATION_RECIPIENT_1 );
253 emailNotification.setCc( CUSTOMER_EMAIL_NOTIFICATION_COPIES_1 );
254 emailNotification.setBcc( CUSTOMER_EMAIL_NOTIFICATION_BLIND_COPIES_1 );
255 notification.setEmailNotification( emailNotification );
256 _notificationDAO.insert( notification );
257
258 collectionNotificationStored = _notificationDAO.loadByDemand( strDemandId, strDemandTypeId, strCustomerId );
259 assertEquals( collectionNotificationStored.size( ), 4 );
260 iterator = collectionNotificationStored.iterator( );
261 notificationStored = iterator.next( );
262
263 EmailNotification emailNotificationStored = notificationStored.getEmailNotification( );
264 assertEquals( emailNotificationStored.getSenderEmail( ), emailNotification.getSenderEmail( ) );
265 assertEquals( emailNotificationStored.getSenderName( ), emailNotification.getSenderName( ) );
266 assertEquals( emailNotificationStored.getSubject( ), emailNotification.getSubject( ) );
267 assertEquals( emailNotificationStored.getMessage( ), emailNotification.getMessage( ) );
268 assertEquals( emailNotificationStored.getRecipient( ), emailNotification.getRecipient( ) );
269 assertEquals( emailNotificationStored.getCc( ), emailNotification.getCc( ) );
270 assertEquals( emailNotificationStored.getCci( ), emailNotification.getCci( ) );
271
272 collectionNotificationStored = _notificationDAO.loadByFilter( filterDemand );
273 assertEquals( collectionNotificationStored.size( ), 4 );
274 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBackoffice );
275 assertEquals( collectionNotificationStored.size( ), 3 );
276 collectionNotificationStored = _notificationDAO.loadByFilter( _filterSMS );
277 assertEquals( collectionNotificationStored.size( ), 2 );
278 collectionNotificationStored = _notificationDAO.loadByFilter( _filterCustomerEmail );
279 assertEquals( collectionNotificationStored.size( ), 1 );
280 collectionNotificationStored = _notificationDAO.loadByFilter( _filterMyDashboard );
281 assertEquals( collectionNotificationStored.size( ), 0 );
282 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBroadcast );
283 assertEquals( collectionNotificationStored.size( ), 0 );
284
285 notification.setDate( NOTIFICATION_DATE_5 );
286
287 MyDashboardNotification myDashboardNotification = new MyDashboardNotification( );
288 myDashboardNotification.setStatusId( MYDASHBOARD_NOTIFICATION_STATUS_ID_1 );
289 myDashboardNotification.setStatusText( MYDASHBOARD_NOTIFICATION_STATUS_TEXT_1 );
290 myDashboardNotification.setMessage( MYDASHBOARD_NOTIFICATION_MESSAGE_1 );
291 myDashboardNotification.setSubject( MYDASHBOARD_NOTIFICATION_SUBJECT_1 );
292 myDashboardNotification.setData( MYDASHBOARD_NOTIFICATION_DATA_1 );
293 myDashboardNotification.setSenderName( MYDASHBOARD_NOTIFICATION_SENDER_NAME_1 );
294 notification.setMyDashboardNotification( myDashboardNotification );
295 _notificationDAO.insert( notification );
296
297 collectionNotificationStored = _notificationDAO.loadByDemand( strDemandId, strDemandTypeId, strCustomerId );
298 assertEquals( collectionNotificationStored.size( ), 5 );
299 iterator = collectionNotificationStored.iterator( );
300 notificationStored = iterator.next( );
301
302 MyDashboardNotification myDashboardNotificationStored = notificationStored.getMyDashboardNotification( );
303 assertEquals( myDashboardNotificationStored.getStatusId( ), myDashboardNotification.getStatusId( ) );
304 assertEquals( myDashboardNotificationStored.getStatusText( ), myDashboardNotification.getStatusText( ) );
305 assertEquals( myDashboardNotificationStored.getMessage( ), myDashboardNotification.getMessage( ) );
306 assertEquals( myDashboardNotificationStored.getSubject( ), myDashboardNotification.getSubject( ) );
307 assertEquals( myDashboardNotificationStored.getData( ), myDashboardNotification.getData( ) );
308 assertEquals( myDashboardNotificationStored.getSenderName( ), myDashboardNotification.getSenderName( ) );
309
310 collectionNotificationStored = _notificationDAO.loadByFilter( filterDemand );
311 assertEquals( collectionNotificationStored.size( ), 5 );
312 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBackoffice );
313 assertEquals( collectionNotificationStored.size( ), 4 );
314 collectionNotificationStored = _notificationDAO.loadByFilter( _filterSMS );
315 assertEquals( collectionNotificationStored.size( ), 3 );
316 collectionNotificationStored = _notificationDAO.loadByFilter( _filterCustomerEmail );
317 assertEquals( collectionNotificationStored.size( ), 2 );
318 collectionNotificationStored = _notificationDAO.loadByFilter( _filterMyDashboard );
319 assertEquals( collectionNotificationStored.size( ), 1 );
320 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBroadcast );
321 assertEquals( collectionNotificationStored.size( ), 0 );
322
323 notification.setDate( NOTIFICATION_DATE_6 );
324
325 List<BroadcastNotification> listBroadcastNotifications = new ArrayList<BroadcastNotification>( );
326 BroadcastNotification broadcastNotification = new BroadcastNotification( );
327 broadcastNotification.setSenderEmail( BROADCAST_EMAIL_NOTIFICATION_SENDER_EMAIL_1 );
328 broadcastNotification.setSenderName( BROADCAST_EMAIL_NOTIFICATION_SENDER_NAME_1 );
329 broadcastNotification.setSubject( BROADCAST_EMAIL_NOTIFICATION_SUBJECT_1 );
330 broadcastNotification.setMessage( BROADCAST_EMAIL_NOTIFICATION_MESSAGE_1 );
331
332 List<EmailAddress> listEmailAddresses = new ArrayList<EmailAddress>( );
333 EmailAddress emailAddress = new EmailAddress( );
334 emailAddress.setAddress( EMAIL_ADDRESS_RECIPIENT_1 );
335 listEmailAddresses.add( emailAddress );
336 emailAddress = new EmailAddress( );
337 emailAddress.setAddress( EMAIL_ADDRESS_RECIPIENT_2 );
338 listEmailAddresses.add( emailAddress );
339 broadcastNotification.setRecipient( listEmailAddresses );
340 listEmailAddresses = new ArrayList<EmailAddress>( );
341 emailAddress = new EmailAddress( );
342 emailAddress.setAddress( EMAIL_ADDRESS_COPY_1 );
343 listEmailAddresses.add( emailAddress );
344 emailAddress = new EmailAddress( );
345 emailAddress.setAddress( EMAIL_ADDRESS_COPY_2 );
346 listEmailAddresses.add( emailAddress );
347 broadcastNotification.setCc( listEmailAddresses );
348 listEmailAddresses = new ArrayList<EmailAddress>( );
349 emailAddress = new EmailAddress( );
350 emailAddress.setAddress( EMAIL_ADDRESS_BLIND_COPY_1 );
351 listEmailAddresses.add( emailAddress );
352 emailAddress = new EmailAddress( );
353 emailAddress.setAddress( EMAIL_ADDRESS_BLIND_COPY_2 );
354 listEmailAddresses.add( emailAddress );
355 broadcastNotification.setBcc( listEmailAddresses );
356 listBroadcastNotifications.add( broadcastNotification );
357
358 BroadcastNotification broadcastNotification2 = new BroadcastNotification( );
359 broadcastNotification2.setSenderEmail( BROADCAST_EMAIL_NOTIFICATION_SENDER_EMAIL_1 );
360 broadcastNotification2.setSenderName( BROADCAST_EMAIL_NOTIFICATION_SENDER_NAME_1 );
361 broadcastNotification2.setSubject( BROADCAST_EMAIL_NOTIFICATION_SUBJECT_1 );
362 broadcastNotification2.setMessage( BROADCAST_EMAIL_NOTIFICATION_MESSAGE_1 );
363 broadcastNotification2.setRecipient( listEmailAddresses );
364 broadcastNotification2.setCc( listEmailAddresses );
365 broadcastNotification2.setBcc( listEmailAddresses );
366 listBroadcastNotifications.add( broadcastNotification2 );
367
368 notification.setBroadcastEmail( listBroadcastNotifications );
369 _notificationDAO.insert( notification );
370
371 collectionNotificationStored = _notificationDAO.loadByDemand( strDemandId, strDemandTypeId, strCustomerId );
372 assertEquals( collectionNotificationStored.size( ), 6 );
373 iterator = collectionNotificationStored.iterator( );
374 notificationStored = iterator.next( );
375
376 List<BroadcastNotification> listBroadcastNotificationsStored = notificationStored.getBroadcastEmail( );
377 assertEquals( listBroadcastNotificationsStored.size( ), 2 );
378
379 BroadcastNotification broadcastNotificationStored = listBroadcastNotificationsStored.get( 0 );
380 assertEquals( broadcastNotificationStored.getSenderEmail( ), broadcastNotification.getSenderEmail( ) );
381 assertEquals( broadcastNotificationStored.getSenderName( ), broadcastNotification.getSenderName( ) );
382 assertEquals( broadcastNotificationStored.getSubject( ), broadcastNotification.getSubject( ) );
383 assertEquals( broadcastNotificationStored.getMessage( ), broadcastNotification.getMessage( ) );
384
385 List<EmailAddress> listEmailAddressesStored = broadcastNotificationStored.getRecipient( );
386 assertEquals( listEmailAddressesStored.size( ), 2 );
387 listEmailAddressesStored = broadcastNotificationStored.getCc( );
388 assertEquals( listEmailAddressesStored.size( ), 2 );
389 listEmailAddressesStored = broadcastNotificationStored.getBcc( );
390 assertEquals( listEmailAddressesStored.size( ), 2 );
391
392 collectionNotificationStored = _notificationDAO.loadByFilter( filterDemand );
393 assertEquals( collectionNotificationStored.size( ), 6 );
394 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBackoffice );
395 assertEquals( collectionNotificationStored.size( ), 5 );
396 collectionNotificationStored = _notificationDAO.loadByFilter( _filterSMS );
397 assertEquals( collectionNotificationStored.size( ), 4 );
398 collectionNotificationStored = _notificationDAO.loadByFilter( _filterCustomerEmail );
399 assertEquals( collectionNotificationStored.size( ), 3 );
400 collectionNotificationStored = _notificationDAO.loadByFilter( _filterMyDashboard );
401 assertEquals( collectionNotificationStored.size( ), 2 );
402 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBroadcast );
403 assertEquals( collectionNotificationStored.size( ), 1 );
404
405 _notificationDAO.deleteByDemand( strDemandId, strDemandTypeId, strCustomerId );
406 collectionNotificationStored = _notificationDAO.loadByDemand( strDemandId, strDemandTypeId, strCustomerId );
407 assertEquals( collectionNotificationStored.size( ), 0 );
408
409 collectionNotificationStored = _notificationDAO.loadByFilter( filterDemand );
410 assertEquals( collectionNotificationStored.size( ), 0 );
411 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBackoffice );
412 assertEquals( collectionNotificationStored.size( ), 0 );
413 collectionNotificationStored = _notificationDAO.loadByFilter( _filterSMS );
414 assertEquals( collectionNotificationStored.size( ), 0 );
415 collectionNotificationStored = _notificationDAO.loadByFilter( _filterCustomerEmail );
416 assertEquals( collectionNotificationStored.size( ), 0 );
417 collectionNotificationStored = _notificationDAO.loadByFilter( _filterMyDashboard );
418 assertEquals( collectionNotificationStored.size( ), 0 );
419 collectionNotificationStored = _notificationDAO.loadByFilter( _filterBroadcast );
420 assertEquals( collectionNotificationStored.size( ), 0 );
421
422 _demandDAO.delete( strDemandId, strDemandTypeId, strCustomerId );
423 }
424
425
426
427
428 public void test2Business( )
429 {
430
431 Demand demand = new Demand( );
432 demand.setId( DEMAND_ID_1 );
433 demand.setTypeId( DEMAND_TYPE_ID_1 );
434 demand.setSubtypeId( DEMAND_SUBTYPE_ID_1 );
435 demand.setReference( DEMAND_REFERENCE_1 );
436 demand.setStatusId( DEMAND_STATUS_ID_1 );
437
438 Customer customer = new Customer( );
439 customer.setCustomerId( CUSTOMER_ID_1 );
440 demand.setCustomer( customer );
441
442 _demandDAO.insert( demand );
443
444 Demand demand2 = new Demand( );
445 demand2.setId( DEMAND_ID_2 );
446 demand2.setTypeId( DEMAND_TYPE_ID_2 );
447 demand.setSubtypeId( DEMAND_SUBTYPE_ID_2 );
448 demand2.setReference( DEMAND_REFERENCE_2 );
449 demand2.setStatusId( DEMAND_STATUS_ID_2 );
450
451 Customer customer2 = new Customer( );
452 customer2.setCustomerId( CUSTOMER_ID_2 );
453 demand2.setCustomer( customer2 );
454
455 _demandDAO.insert( demand2 );
456
457 Notification notification = new Notification( );
458 notification.setDemand( demand );
459 notification.setDate( NOTIFICATION_DATE_1 );
460 _notificationDAO.insert( notification );
461
462 notification = new Notification( );
463 notification.setDemand( demand2 );
464 notification.setDate( NOTIFICATION_DATE_2 );
465 _notificationDAO.insert( notification );
466
467 Collection<Notification> collectionNotificationStored = _notificationDAO.loadByDemand( DEMAND_ID_1, DEMAND_TYPE_ID_1, CUSTOMER_ID_1 );
468 assertEquals( collectionNotificationStored.size( ), 1 );
469
470 Iterator<Notification> iterator = collectionNotificationStored.iterator( );
471 Notification notificationStored = iterator.next( );
472 assertSame( notificationStored.getDate( ), NOTIFICATION_DATE_1 );
473
474 collectionNotificationStored = _notificationDAO.loadByDemand( DEMAND_ID_2, DEMAND_TYPE_ID_2, CUSTOMER_ID_2 );
475 assertEquals( collectionNotificationStored.size( ), 1 );
476 iterator = collectionNotificationStored.iterator( );
477 notificationStored = iterator.next( );
478 assertSame( notificationStored.getDate( ), NOTIFICATION_DATE_2 );
479
480 _notificationDAO.deleteByDemand( DEMAND_ID_1, DEMAND_TYPE_ID_1, CUSTOMER_ID_1 );
481 collectionNotificationStored = _notificationDAO.loadByDemand( DEMAND_ID_1, DEMAND_TYPE_ID_1, CUSTOMER_ID_1 );
482 assertEquals( collectionNotificationStored.size( ), 0 );
483
484 _notificationDAO.deleteByDemand( DEMAND_ID_2, DEMAND_TYPE_ID_2, CUSTOMER_ID_2 );
485 collectionNotificationStored = _notificationDAO.loadByDemand( DEMAND_ID_2, DEMAND_TYPE_ID_2, CUSTOMER_ID_2 );
486 assertEquals( collectionNotificationStored.size( ), 0 );
487
488 _demandDAO.delete( DEMAND_ID_1, DEMAND_TYPE_ID_1, CUSTOMER_ID_1 );
489 _demandDAO.delete( DEMAND_ID_2, DEMAND_TYPE_ID_2, CUSTOMER_ID_2 );
490 }
491 }