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.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   * FormSubmitHomeTest
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 }