View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
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   * NotificationTest
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       * Test business of class fr.paris.lutece.plugins.crm.business.notification.Notification
66       */
67      public void testBusiness( )
68      {
69          // Initialize an object
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          // Test create
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          // Test update
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         // Test finders
111         NotificationFilter nFilter = new NotificationFilter( );
112         nFilter.setIdDemand( ID_DEMAND1 );
113         nFilter.setIsRead( IS_READ2 );
114         NotificationHome.findByFilter( nFilter );
115         NotificationHome.findAll( );
116 
117         // Test remove
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 }