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.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
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
67
68 public void testBusiness( )
69 {
70
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
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
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
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
120 DemandHome.remove( demand.getIdDemand( ) );
121 demandStored = DemandHome.findByPrimaryKey( demand.getIdDemand( ) );
122 assertNull( demandStored );
123 }
124 }