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.util.Date;
40  import java.util.Locale;
41  
42  /**
43   *
44   * DemandTypeTest
45   *
46   */
47  public class DemandTypeTest extends LuteceTestCase
48  {
49      private static final String DATE_BEGIN1 = "01/09/2011";
50      private static final String DATE_BEGIN2 = "02/10/2011";
51      private static final String DATE_END1 = "10/09/2011";
52      private static final String DATE_END2 = "11/10/2011";
53      private static final int ID_CATEGORY1 = 1;
54      private static final int ID_CATEGORY2 = 2;
55      private static final String LABEL1 = "Label1";
56      private static final String LABEL2 = "Label2";
57      private static final int ORDER1 = 1;
58      private static final int ORDER2 = 2;
59      private static final String ROLE1 = "Role1";
60      private static final String ROLE2 = "Role2";
61      private static final String URL_CONTACT1 = "UrlContact1";
62      private static final String URL_CONTACT2 = "UrlContact2";
63      private static final String URL_INFO1 = "UrlInfo1";
64      private static final String URL_INFO2 = "UrlInfo2";
65      private static final String URL_RESOURCE1 = "UrlResource1";
66      private static final String URL_RESOURCE2 = "UrlResource2";
67      private static final String WORKGROUP1 = "Workgroup1";
68      private static final String WORKGROUP2 = "Workgroup2";
69      private static Locale _locale = Locale.getDefault( );
70  
71      /**
72       * Test business of class fr.paris.lutece.plugins.crm.business.demand.DemandType
73       */
74      public void testBusiness( )
75      {
76          // Initialize an object
77          DemandType demandType = new DemandType( );
78          Date dateBegin = DateUtil.formatDateLongYear( DATE_BEGIN1, _locale );
79          Date dateEnd = DateUtil.formatDateLongYear( DATE_END1, _locale );
80          demandType.setDateBegin( dateBegin );
81          demandType.setDateEnd( dateEnd );
82          demandType.setIdCategory( ID_CATEGORY1 );
83          demandType.setLabel( LABEL1 );
84          demandType.setOrder( ORDER1 );
85          demandType.setRole( ROLE1 );
86          demandType.setUrlContact( URL_CONTACT1 );
87          demandType.setUrlInfo( URL_INFO1 );
88          demandType.setUrlResource( URL_RESOURCE1 );
89          demandType.setWorkgroup( WORKGROUP1 );
90  
91          // Test create
92          DemandTypeHome.create( demandType );
93  
94          DemandType demandTypeStored = DemandTypeHome.findByPrimaryKey( demandType.getIdDemandType( ) );
95          assertEquals( demandType.getIdDemandType( ), demandTypeStored.getIdDemandType( ) );
96          assertEquals( demandType.getDateBegin( ), demandTypeStored.getDateBegin( ) );
97          assertEquals( demandType.getDateEnd( ), demandTypeStored.getDateEnd( ) );
98          assertEquals( demandType.getIdCategory( ), demandTypeStored.getIdCategory( ) );
99          assertEquals( demandType.getLabel( ), demandTypeStored.getLabel( ) );
100         assertEquals( demandType.getOrder( ), demandTypeStored.getOrder( ) );
101         assertEquals( demandType.getRole( ), demandTypeStored.getRole( ) );
102         assertEquals( demandType.getUrlContact( ), demandTypeStored.getUrlContact( ) );
103         assertEquals( demandType.getUrlInfo( ), demandTypeStored.getUrlInfo( ) );
104         assertEquals( demandType.getUrlResource( ), demandTypeStored.getUrlResource( ) );
105         assertEquals( demandType.getWorkgroup( ), demandTypeStored.getWorkgroup( ) );
106 
107         // Test update
108         dateBegin = DateUtil.formatDateLongYear( DATE_BEGIN2, _locale );
109         dateEnd = DateUtil.formatDateLongYear( DATE_END2, _locale );
110         demandType.setDateBegin( dateBegin );
111         demandType.setDateEnd( dateEnd );
112         demandType.setIdCategory( ID_CATEGORY2 );
113         demandType.setLabel( LABEL2 );
114         demandType.setOrder( ORDER2 );
115         demandType.setRole( ROLE2 );
116         demandType.setUrlContact( URL_CONTACT2 );
117         demandType.setUrlInfo( URL_INFO2 );
118         demandType.setUrlResource( URL_RESOURCE2 );
119         demandType.setWorkgroup( WORKGROUP2 );
120         DemandTypeHome.update( demandType );
121         demandTypeStored = DemandTypeHome.findByPrimaryKey( demandType.getIdDemandType( ) );
122         assertEquals( demandType.getIdDemandType( ), demandTypeStored.getIdDemandType( ) );
123         assertEquals( demandType.getDateBegin( ), demandTypeStored.getDateBegin( ) );
124         assertEquals( demandType.getDateEnd( ), demandTypeStored.getDateEnd( ) );
125         assertEquals( demandType.getIdCategory( ), demandTypeStored.getIdCategory( ) );
126         assertEquals( demandType.getLabel( ), demandTypeStored.getLabel( ) );
127         assertEquals( demandType.getOrder( ), demandTypeStored.getOrder( ) );
128         assertEquals( demandType.getRole( ), demandTypeStored.getRole( ) );
129         assertEquals( demandType.getUrlContact( ), demandTypeStored.getUrlContact( ) );
130         assertEquals( demandType.getUrlInfo( ), demandTypeStored.getUrlInfo( ) );
131         assertEquals( demandType.getUrlResource( ), demandTypeStored.getUrlResource( ) );
132         assertEquals( demandType.getWorkgroup( ), demandTypeStored.getWorkgroup( ) );
133 
134         // Test finders
135         DemandTypeFilter dtFilter = new DemandTypeFilter( );
136         DemandTypeHome.findByFilter( dtFilter );
137         dtFilter.setDateBegin( dateBegin );
138         dtFilter.setDateEnd( dateEnd );
139         dtFilter.setIdCategory( ID_CATEGORY2 );
140         dtFilter.setLabel( LABEL2 );
141         dtFilter.setOrder( ORDER2 );
142         dtFilter.setRole( ROLE2 );
143         dtFilter.setUrlResource( URL_RESOURCE2 );
144         dtFilter.setWorkgroup( WORKGROUP2 );
145         DemandTypeHome.findAll( );
146         DemandTypeHome.findDemandTypes( );
147         DemandTypeHome.findMaxOrder( );
148         DemandTypeHome.findByIdCategoryAndDate( ID_CATEGORY2, new Date( ) );
149         DemandTypeHome.findByOrder( ORDER2 );
150 
151         // Test remove
152         DemandTypeHome.remove( demandType.getIdDemandType( ) );
153         demandTypeStored = DemandTypeHome.findByPrimaryKey( demandType.getIdDemandType( ) );
154         assertNull( demandTypeStored );
155     }
156 }