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.form.business;
35
36 import fr.paris.lutece.plugins.form.utils.FormUtils;
37 import fr.paris.lutece.plugins.genericattributes.business.ResponseFilter;
38 import fr.paris.lutece.portal.service.plugin.Plugin;
39 import fr.paris.lutece.portal.service.plugin.PluginService;
40 import fr.paris.lutece.test.LuteceTestCase;
41
42 import java.util.List;
43
44
45
46
47 public class FormSubmitHomeTest extends LuteceTestCase
48 {
49 private final static int ID_FORM_RESPONSE_1 = 1;
50 private final static String IP_1 = "Adresse ip 1";
51 private final static String IP_2 = "Adresse ip 2";
52 private final Plugin _plugin = PluginService.getPlugin( "form" );
53
54 public void testCreate( )
55 {
56 FormSubmit formSubmit = new FormSubmit( );
57
58 FormDAO formDAO = new FormDAO( );
59 int LastPrimaryKey = formDAO.newPrimaryKey( _plugin ) - 1;
60 Form form = FormHome.findByPrimaryKey( LastPrimaryKey, _plugin );
61
62 formSubmit.setIdFormSubmit( ID_FORM_RESPONSE_1 );
63 formSubmit.setIp( IP_1 );
64 formSubmit.setForm( form );
65 formSubmit.setDateResponse( FormUtils.getCurrentTimestamp( ) );
66 FormSubmitHome.create( formSubmit, _plugin );
67
68 FormSubmit storedFormSubmit = FormSubmitHome.findByPrimaryKey( formSubmit.getIdFormSubmit( ), _plugin );
69
70 assertEquals( storedFormSubmit.getIdFormSubmit( ), formSubmit.getIdFormSubmit( ) );
71 assertEquals( storedFormSubmit.getIp( ), formSubmit.getIp( ) );
72 assertEquals( storedFormSubmit.getForm( ).getIdForm( ), formSubmit.getForm( ).getIdForm( ) );
73 }
74
75 public void testUpdate( )
76 {
77 FormSubmit loadformSubmit = FormSubmitHome.findByPrimaryKey( ID_FORM_RESPONSE_1, _plugin );
78
79 FormSubmit formSubmit = new FormSubmit( );
80
81 FormDAO formDAO = new FormDAO( );
82 int LastPrimaryKey = formDAO.newPrimaryKey( _plugin ) - 1;
83 Form form = FormHome.findByPrimaryKey( LastPrimaryKey, _plugin );
84
85 formSubmit.setIdFormSubmit( loadformSubmit.getIdFormSubmit( ) );
86 formSubmit.setIp( IP_2 );
87 formSubmit.setForm( form );
88
89 FormSubmitHome.update( formSubmit, _plugin );
90
91 FormSubmit storedFormSubmit = FormSubmitHome.findByPrimaryKey( formSubmit.getIdFormSubmit( ), _plugin );
92
93 assertEquals( storedFormSubmit.getIdFormSubmit( ), formSubmit.getIdFormSubmit( ) );
94 assertEquals( storedFormSubmit.getIp( ), formSubmit.getIp( ) );
95 assertEquals( storedFormSubmit.getForm( ).getIdForm( ), formSubmit.getForm( ).getIdForm( ) );
96 }
97
98 public void testGetFormSubmitList( )
99 {
100 List<FormSubmit> listFormSubmit = null;
101
102 ResponseFilter responseFilter = new ResponseFilter( );
103
104 listFormSubmit = FormSubmitHome.getFormSubmitList( responseFilter, _plugin );
105
106 assertNotNull( listFormSubmit );
107 }
108
109 public void testGetCountFormSubmit( )
110 {
111 int nbFormSubmit;
112
113 ResponseFilter responseFilter = new ResponseFilter( );
114
115 nbFormSubmit = FormSubmitHome.getCountFormSubmit( responseFilter, _plugin );
116
117 assertNotNull( nbFormSubmit );
118 }
119
120 public void testGetStatisticFormSubmit( )
121 {
122 List<StatisticFormSubmit> statisticFormSubmit = null;
123
124 ResponseFilter responseFilter = new ResponseFilter( );
125 responseFilter.setGroupbyDay( true );
126
127 statisticFormSubmit = FormSubmitHome.getStatisticFormSubmit( responseFilter, _plugin );
128
129 assertNotNull( statisticFormSubmit );
130 }
131
132 public void testRemove( )
133 {
134 FormSubmit formSubmit = new FormSubmit( );
135
136 FormDAO formDAO = new FormDAO( );
137 int LastPrimaryKey = formDAO.newPrimaryKey( _plugin ) - 1;
138 Form form = FormHome.findByPrimaryKey( LastPrimaryKey, _plugin );
139
140 formSubmit.setIdFormSubmit( ID_FORM_RESPONSE_1 );
141 formSubmit.setIp( IP_1 );
142 formSubmit.setForm( form );
143 formSubmit.setDateResponse( FormUtils.getCurrentTimestamp( ) );
144
145 int LastIdFormSubmit = FormSubmitHome.create( formSubmit, _plugin );
146
147 FormSubmit loadformSubmit = FormSubmitHome.findByPrimaryKey( LastIdFormSubmit, _plugin );
148
149 FormSubmitHome.remove( loadformSubmit.getIdFormSubmit( ), _plugin );
150
151 FormSubmit formSubmitStored = FormSubmitHome.findByPrimaryKey( loadformSubmit.getIdFormSubmit( ), _plugin );
152
153 assertNull( formSubmitStored );
154 }
155 }