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.myportal.business;
35  
36  import fr.paris.lutece.test.LuteceTestCase;
37  
38  /**
39   *
40   * WidgetTest
41   *
42   */
43  public class WidgetTest extends LuteceTestCase
44  {
45      private static final String CONFIGDATA1 = "ConfigData1";
46      private static final String CONFIGDATA2 = "ConfigData2";
47      private static final String DESCRIPTION1 = "Description1";
48      private static final String DESCRIPTION2 = "Description2";
49      private static final int IDICON1 = 1;
50      private static final int IDICON2 = 2;
51      private static final int IDCATEGORY1 = 1;
52      private static final int IDCATEGORY2 = 2;
53      private static final int IDSTYLE1 = 0;
54      private static final int IDSTYLE2 = 1;
55      private static final boolean ISESSENTIAL1 = true;
56      private static final boolean ISESSENTIAL2 = false;
57      private static final boolean ISNEW1 = true;
58      private static final boolean ISNEW2 = false;
59      private static final String NAME1 = "Name1";
60      private static final String NAME2 = "Name2";
61      private static final int STATUS1 = 1;
62      private static final int STATUS2 = 2;
63      private static final String WIDGETTYPE1 = "WIDGETTYPE1";
64      private static final String WIDGETTYPE2 = "WIDGETTYPE2";
65  
66      /**
67       * Test business of class fr.paris.lutece.plugins.myportal.business.Widget
68       */
69      public void testBusiness( )
70      {
71          // Initialize an object
72          Widget widget = new Widget( );
73          widget.setIdWidget( WidgetHome.newPrimaryKey( ) );
74          widget.setConfigData( CONFIGDATA1 );
75          widget.setDescription( DESCRIPTION1 );
76          widget.setIdIcon( IDICON1 );
77          widget.setIdCategory( IDCATEGORY1 );
78          widget.setIdStyle( IDSTYLE1 );
79          widget.setIsEssential( ISESSENTIAL1 );
80          widget.setIsNew( ISNEW1 );
81          widget.setName( NAME1 );
82          widget.setStatus( STATUS1 );
83          widget.setWidgetType( WIDGETTYPE1 );
84  
85          // Create test
86          WidgetHome.create( widget );
87  
88          Widget widgetStored = WidgetHome.findByPrimaryKey( widget.getIdWidget( ) );
89          assertEquals( widgetStored.getIdWidget( ), widget.getIdWidget( ) );
90          assertEquals( widgetStored.getConfigData( ), widget.getConfigData( ) );
91          assertEquals( widgetStored.getDescription( ), widget.getDescription( ) );
92          assertEquals( widgetStored.getIdIcon( ), widget.getIdIcon( ) );
93          assertEquals( widgetStored.getIdCategory( ), widget.getIdCategory( ) );
94          assertEquals( widgetStored.getIdStyle( ), widget.getIdStyle( ) );
95          assertEquals( widgetStored.getIsEssential( ), widget.getIsEssential( ) );
96          assertEquals( widgetStored.getIsNew( ), widget.getIsNew( ) );
97          assertEquals( widgetStored.getName( ), widget.getName( ) );
98          assertEquals( widgetStored.getStatus( ), widget.getStatus( ) );
99          assertEquals( widgetStored.getName( ), widget.getName( ) );
100         assertEquals( widgetStored.getWidgetType( ), widget.getWidgetType( ) );
101 
102         // Update test
103         widget.setConfigData( CONFIGDATA2 );
104         widget.setDescription( DESCRIPTION2 );
105         widget.setIdIcon( IDICON2 );
106         widget.setIdCategory( IDCATEGORY2 );
107         widget.setIdStyle( IDSTYLE2 );
108         widget.setIsEssential( ISESSENTIAL2 );
109         widget.setIsNew( ISNEW2 );
110         widget.setName( NAME2 );
111         widget.setStatus( STATUS2 );
112         widget.setWidgetType( WIDGETTYPE2 );
113         WidgetHome.update( widget );
114         widgetStored = WidgetHome.findByPrimaryKey( widget.getIdWidget( ) );
115         assertEquals( widgetStored.getIdWidget( ), widget.getIdWidget( ) );
116         assertEquals( widgetStored.getConfigData( ), widget.getConfigData( ) );
117         assertEquals( widgetStored.getDescription( ), widget.getDescription( ) );
118         assertEquals( widgetStored.getIdIcon( ), widget.getIdIcon( ) );
119         assertEquals( widgetStored.getIdCategory( ), widget.getIdCategory( ) );
120         assertEquals( widgetStored.getIdStyle( ), widget.getIdStyle( ) );
121         assertEquals( widgetStored.getIsEssential( ), widget.getIsEssential( ) );
122         assertEquals( widgetStored.getIsNew( ), widget.getIsNew( ) );
123         assertEquals( widgetStored.getName( ), widget.getName( ) );
124         assertEquals( widgetStored.getStatus( ), widget.getStatus( ) );
125         assertEquals( widgetStored.getName( ), widget.getName( ) );
126         assertEquals( widgetStored.getWidgetType( ), widget.getWidgetType( ) );
127 
128         // List test
129         WidgetHome.getWidgetsList( );
130 
131         // Delete test
132         WidgetHome.remove( widget.getIdWidget( ) );
133         widgetStored = WidgetHome.findByPrimaryKey( widget.getIdWidget( ) );
134         assertNull( widgetStored );
135     }
136 }