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.demand;
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   * DemandTest
47   *
48   */
49  public class DemandTest 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 String DATA1 = "Data1";
54      private static final String DATA2 = "Data2";
55      private static final int ID_CRM_USER1 = 1;
56      private static final int ID_CRM_USER2 = 2;
57      private static final int ID_DEMAND_TYPE1 = 1;
58      private static final int ID_DEMAND_TYPE2 = 2;
59      private static final int ID_STATUS_CRM1 = 0;
60      private static final int ID_STATUS_CRM2 = 1;
61      private static final String STATUS_TEXT1 = "StatusText1";
62      private static final String STATUS_TEXT2 = "StatusText2";
63      private static Locale _locale = Locale.getDefault( );
64  
65      /**
66       * Test business of class fr.paris.lutece.plugins.crm.business.demand.Demand
67       */
68      public void testBusiness( )
69      {
70          // Initialize an object
71          Date date = DateUtil.formatDateLongYear( DATE1, _locale );
72          Timestamp dateModification = new Timestamp( date.getTime( ) );
73          Demand demand = new Demand( );
74          demand.setData( DATA1 );
75          demand.setIdCRMUser( ID_CRM_USER1 );
76          demand.setIdDemandType( ID_DEMAND_TYPE1 );
77          demand.setIdStatusCRM( ID_STATUS_CRM1 );
78          demand.setStatusText( STATUS_TEXT1 );
79          demand.setDateModification( dateModification );
80  
81          // Test create
82          DemandHome.create( demand );
83  
84          Demand demandStored = DemandHome.findByPrimaryKey( demand.getIdDemand( ) );
85          assertEquals( demand.getIdDemand( ), demandStored.getIdDemand( ) );
86          assertEquals( demand.getData( ), demandStored.getData( ) );
87          assertEquals( demand.getIdCRMUser( ), demandStored.getIdCRMUser( ) );
88          assertEquals( demand.getIdDemandType( ), demandStored.getIdDemandType( ) );
89          assertEquals( demand.getIdStatusCRM( ), demandStored.getIdStatusCRM( ) );
90          assertEquals( demand.getStatusText( ), demandStored.getStatusText( ) );
91  
92          // Test update
93          date = DateUtil.formatDateLongYear( DATE2, _locale );
94          dateModification = new Timestamp( date.getTime( ) );
95          demand.setData( DATA2 );
96          demand.setIdCRMUser( ID_CRM_USER2 );
97          demand.setIdDemandType( ID_DEMAND_TYPE2 );
98          demand.setIdStatusCRM( ID_STATUS_CRM2 );
99          demand.setStatusText( STATUS_TEXT2 );
100         demand.setDateModification( dateModification );
101         DemandHome.update( demand );
102         demandStored = DemandHome.findByPrimaryKey( demand.getIdDemand( ) );
103         assertEquals( demand.getIdDemand( ), demandStored.getIdDemand( ) );
104         assertEquals( demand.getData( ), demandStored.getData( ) );
105         assertEquals( demand.getIdCRMUser( ), demandStored.getIdCRMUser( ) );
106         assertEquals( demand.getIdDemandType( ), demandStored.getIdDemandType( ) );
107         assertEquals( demand.getIdStatusCRM( ), demandStored.getIdStatusCRM( ) );
108         assertEquals( demand.getStatusText( ), demandStored.getStatusText( ) );
109 
110         // Test finders
111         DemandFilter dFilter = new DemandFilter( );
112         dFilter.setDateModification( dateModification );
113         dFilter.setIdCRMUser( ID_CRM_USER2 );
114         dFilter.setIdDemandType( ID_DEMAND_TYPE2 );
115         dFilter.setIdStatusCRM( ID_STATUS_CRM2 );
116         DemandHome.findByFilter( dFilter );
117         DemandHome.findAll( );
118 
119         // Test remove
120         DemandHome.remove( demand.getIdDemand( ) );
121         demandStored = DemandHome.findByPrimaryKey( demand.getIdDemand( ) );
122         assertNull( demandStored );
123     }
124 }