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.portal.web.admin;
35  
36  import java.util.HashMap;
37  import java.util.Locale;
38  import java.util.Map;
39  
40  import org.springframework.mock.web.MockHttpServletRequest;
41  import org.springframework.mock.web.MockHttpServletResponse;
42  import org.springframework.mock.web.MockServletConfig;
43  
44  import fr.paris.lutece.portal.business.right.Right;
45  import fr.paris.lutece.portal.business.user.AdminUser;
46  import fr.paris.lutece.portal.service.admin.AccessDeniedException;
47  import fr.paris.lutece.portal.service.message.SiteMessageException;
48  import fr.paris.lutece.portal.service.security.UserNotSignedException;
49  import fr.paris.lutece.portal.web.LocalVariables;
50  import fr.paris.lutece.test.LuteceTestCase;
51  import fr.paris.lutece.test.MokeHttpServletRequest;
52  
53  
54  /**
55   * AdminJspBeanTest Test Class
56   *
57   */
58  public class AdminJspBeanTest extends LuteceTestCase
59  {
60      private static final String PARAMETER_PAGE_ID = "page_id"; // home page	
61      private static final String TEST_PAGE_ID = "1"; // home page
62      private static final String ATTRIBUTE_ADMIN_USER = "lutece_admin_user";
63  
64      /**
65       * Test of getAdminPage method, of class fr.paris.lutece.portal.web.admin.AdminJspBean.
66       */
67      public void testGetAdminPage(  ) throws AccessDeniedException
68      {
69          System.out.println( "getAdminPage" );
70  
71          MokeHttpServletRequest request = new MokeHttpServletRequest(  );
72          request.addMokeParameters( PARAMETER_PAGE_ID, TEST_PAGE_ID );
73          request.registerAdminUserWithRigth( new AdminUser(  ), AdminPageJspBean.RIGHT_MANAGE_ADMIN_SITE );
74  
75          AdminPageJspBean instance = new AdminPageJspBean(  );
76          instance.init( request, AdminPageJspBean.RIGHT_MANAGE_ADMIN_SITE );
77          instance.getAdminPage( request );
78      }
79  
80      /**
81       * Test of getAdminPagePreview method, of class fr.paris.lutece.portal.web.admin.AdminJspBean.
82       * @throws UserNotSignedException
83       */
84      public void testGetAdminPagePreview(  ) throws AccessDeniedException, UserNotSignedException
85      {
86          System.out.println( "getAdminPagePreview" );
87  
88          MockHttpServletRequest request = new MockHttpServletRequest(  );
89  
90          // FIXME : MokeHttpServletRequest should be fixed to support attributes
91          Map<String, Right> mapRights = new HashMap<String, Right>(  );
92          Right right = new Right(  );
93          right.setId( AdminPageJspBean.RIGHT_MANAGE_ADMIN_SITE  );
94          mapRights.put( AdminPageJspBean.RIGHT_MANAGE_ADMIN_SITE , right );
95          AdminUser user = new AdminUser( );
96          user.setRights( mapRights );
97          user.setLocale( new Locale( "fr", "FR", "" ) );
98          request.getSession( true ).setAttribute( ATTRIBUTE_ADMIN_USER, user );
99          LocalVariables.setLocal( new MockServletConfig( ), request, new MockHttpServletResponse( ) );
100 
101         AdminPageJspBean instance = new AdminPageJspBean(  );
102         instance.init( request, AdminPageJspBean.RIGHT_MANAGE_ADMIN_SITE );
103 
104         try
105         {
106             instance.getAdminPagePreview( request );
107         }
108         catch ( SiteMessageException e )
109         {
110             // TODO Auto-generated catch block
111             e.printStackTrace(  );
112         }
113     }
114 
115     @Override
116     public void tearDown( ) throws Exception
117     {
118         LocalVariables.setLocal( null, null, null );
119         super.tearDown( );
120     }
121 }