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.crm.business.notification;
35
36 import fr.paris.lutece.test.LuteceTestCase;
37 import fr.paris.lutece.util.date.DateUtil;
38
39 import java.sql.Timestamp;
40
41 import java.util.Date;
42 import java.util.Locale;
43
44
45
46
47
48
49 public class NotificationTest extends LuteceTestCase
50 {
51 private static final String DATE1 = "01/09/2011";
52 private static final String DATE2 = "10/10/2011";
53 private static final int ID_DEMAND1 = 1;
54 private static final boolean IS_READ1 = false;
55 private static final boolean IS_READ2 = true;
56 private static final String MESSAGE1 = "Message1";
57 private static final String MESSAGE2 = "Message2";
58 private static final String OBJECT1 = "Object1";
59 private static final String OBJECT2 = "Object2";
60 private static final String SENDER1 = "Sender1";
61 private static final String SENDER2 = "Sender2";
62 private static Locale _locale = Locale.getDefault( );
63
64
65
66
67 public void testBusiness( )
68 {
69
70 Date date = DateUtil.formatDateLongYear( DATE1, _locale );
71 Timestamp dateCreation = new Timestamp( date.getTime( ) );
72 Notification notification = new Notification( );
73 notification.setDateCreation( dateCreation );
74 notification.setIdDemand( ID_DEMAND1 );
75 notification.setIsRead( IS_READ1 );
76 notification.setMessage( MESSAGE1 );
77 notification.setObject( OBJECT1 );
78 notification.setSender( SENDER1 );
79
80
81 NotificationHome.create( notification );
82
83 Notification notificationStored = NotificationHome.findByPrimaryKey( notification.getIdNotification( ) );
84 assertEquals( notification.getIdNotification( ), notificationStored.getIdNotification( ) );
85 assertEquals( notification.getDateCreation( ), notificationStored.getDateCreation( ) );
86 assertEquals( notification.getIdDemand( ), notificationStored.getIdDemand( ) );
87 assertEquals( notification.isRead( ), notificationStored.isRead( ) );
88 assertEquals( notification.getMessage( ), notificationStored.getMessage( ) );
89 assertEquals( notification.getObject( ), notificationStored.getObject( ) );
90 assertEquals( notification.getSender( ), notificationStored.getSender( ) );
91
92
93 date = DateUtil.formatDateLongYear( DATE2, _locale );
94 dateCreation = new Timestamp( date.getTime( ) );
95 notification.setDateCreation( dateCreation );
96 notification.setIsRead( IS_READ2 );
97 notification.setMessage( MESSAGE2 );
98 notification.setObject( OBJECT2 );
99 notification.setSender( SENDER2 );
100 NotificationHome.update( notification );
101 notificationStored = NotificationHome.findByPrimaryKey( notification.getIdNotification( ) );
102 assertEquals( notification.getIdNotification( ), notificationStored.getIdNotification( ) );
103 assertEquals( notification.getDateCreation( ), notificationStored.getDateCreation( ) );
104 assertEquals( notification.getIdDemand( ), notificationStored.getIdDemand( ) );
105 assertEquals( notification.isRead( ), notificationStored.isRead( ) );
106 assertEquals( notification.getMessage( ), notificationStored.getMessage( ) );
107 assertEquals( notification.getObject( ), notificationStored.getObject( ) );
108 assertEquals( notification.getSender( ), notificationStored.getSender( ) );
109
110
111 NotificationFilter nFilter = new NotificationFilter( );
112 nFilter.setIdDemand( ID_DEMAND1 );
113 nFilter.setIsRead( IS_READ2 );
114 NotificationHome.findByFilter( nFilter );
115 NotificationHome.findAll( );
116
117
118 NotificationHome.remove( notification.getIdNotification( ) );
119 notificationStored = NotificationHome.findByPrimaryKey( notification.getIdNotification( ) );
120 assertNull( notificationStored );
121 NotificationHome.create( notification );
122 NotificationHome.removeByIdDemand( notification.getIdDemand( ) );
123 notificationStored = NotificationHome.findByPrimaryKey( notification.getIdNotification( ) );
124 assertNull( notificationStored );
125 }
126 }