View Javadoc
1   /*
2    * Copyright (c) 2002-2018, 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.directory.modules.multiview.business.record.column.querypart;
35  
36  import static org.hamcrest.CoreMatchers.is;
37  import static org.hamcrest.CoreMatchers.not;
38  import static org.hamcrest.CoreMatchers.nullValue;
39  import static org.junit.Assert.assertThat;
40  
41  import java.util.Date;
42  import java.util.Map;
43  
44  import org.apache.commons.lang3.StringUtils;
45  
46  import fr.paris.lutece.plugins.directory.modules.multiview.business.record.column.IRecordColumn;
47  import fr.paris.lutece.plugins.directory.modules.multiview.business.record.column.RecordColumnCell;
48  import fr.paris.lutece.plugins.directory.modules.multiview.business.record.column.impl.RecordColumnRecordDateCreation;
49  import fr.paris.lutece.plugins.directory.modules.multiview.business.record.column.querypart.impl.RecordColumnRecordDateCreationQueryPart;
50  import fr.paris.lutece.plugins.directory.modules.multiview.business.record.column.querypart.mock.DAOUtilMock;
51  import fr.paris.lutece.plugins.directory.modules.multiview.util.RecordRecordDateCreationNameConstants;
52  import fr.paris.lutece.portal.service.util.AppException;
53  import fr.paris.lutece.test.LuteceTestCase;
54  import fr.paris.lutece.util.sql.DAOUtil;
55  
56  /**
57   * Test of the implementation of the IRecordColumnQueryPart for the Record Date Creation column
58   */
59  public class RecordColumnRecordDateCreationQueryPartTest extends LuteceTestCase
60  {
61      /**
62       * {@inheritDoc}
63       */
64      @Override
65      protected void setUp( ) throws Exception
66      {
67          super.setUp( );
68      }
69  
70      /**
71       * {@inheritDoc}
72       */
73      @Override
74      protected void tearDown( ) throws Exception
75      {
76          super.tearDown( );
77      }
78  
79      /**
80       * Test for the {@link IRecordColumnQueryPart#getRecordColumnCell(fr.paris.lutece.util.sql.DAOUtil)}
81       */
82      public void testGetRecordColumnCellRecordDateCreation( )
83      {
84          Date dateRecordDateCreationValueToRetrieve = new Date( );
85          DAOUtil daoUtil = new DAOUtilMock( StringUtils.EMPTY, RecordRecordDateCreationNameConstants.COLUMN_RECORD_DATE_CREATION,
86                  dateRecordDateCreationValueToRetrieve );
87  
88          IRecordColumn recordColumn = new RecordColumnRecordDateCreation( 1, "Record Date Creation" );
89          RecordColumnRecordDateCreationQueryPart recordColumnRecordDateCreationQueryPart = new RecordColumnRecordDateCreationQueryPart( );
90          recordColumnRecordDateCreationQueryPart.setRecordColumn( recordColumn );
91  
92          RecordColumnCell recordColumnCell = recordColumnRecordDateCreationQueryPart.getRecordColumnCell( daoUtil );
93          assertThat( recordColumnCell, is( not( nullValue( ) ) ) );
94  
95          Map<String, Object> mapRecordColumnCellValues = recordColumnCell.getRecordColumnCellValues( );
96          assertThat( mapRecordColumnCellValues, is( not( nullValue( ) ) ) );
97          assertThat( mapRecordColumnCellValues.size( ), is( 1 ) );
98  
99          Object objDirectoryResult = recordColumnCell.getRecordColumnCellValueByName( RecordRecordDateCreationNameConstants.COLUMN_RECORD_DATE_CREATION );
100         assertThat( objDirectoryResult, is( not( nullValue( ) ) ) );
101         assertThat( (Date) objDirectoryResult, is( dateRecordDateCreationValueToRetrieve ) );
102     }
103 
104     /**
105      * Test for the {@link IRecordColumnQueryPart#getRecordColumnCell(fr.paris.lutece.util.sql.DAOUtil)} using a column that doesn't exist
106      */
107     public void testGetRecordColumnCellRecordDateCreationWithWrongColumnName( )
108     {
109         String strRecordDateCreationValueToRetrieve = "creation date";
110         DAOUtil daoUtil = new DAOUtilMock( StringUtils.EMPTY, "colonne", strRecordDateCreationValueToRetrieve );
111 
112         IRecordColumn recordColumn = new RecordColumnRecordDateCreation( 1, "Record Date Creation" );
113         RecordColumnRecordDateCreationQueryPart recordColumnRecordDateCreationQueryPart = new RecordColumnRecordDateCreationQueryPart( );
114         recordColumnRecordDateCreationQueryPart.setRecordColumn( recordColumn );
115 
116         try
117         {
118             recordColumnRecordDateCreationQueryPart.getRecordColumnCell( daoUtil );
119             fail( "Test fail : AppException hasn't been thrown !" );
120         }
121         catch( AppException exception )
122         {
123 
124         }
125     }
126 }