1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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.apache.commons.lang3.StringUtils;
41 import org.springframework.mock.web.MockHttpServletRequest;
42 import org.springframework.mock.web.MockHttpServletResponse;
43 import org.springframework.mock.web.MockServletConfig;
44
45 import fr.paris.lutece.portal.business.right.Right;
46 import fr.paris.lutece.portal.business.user.AdminUser;
47 import fr.paris.lutece.portal.service.admin.AccessDeniedException;
48 import fr.paris.lutece.portal.service.message.SiteMessageException;
49 import fr.paris.lutece.portal.service.security.UserNotSignedException;
50 import fr.paris.lutece.portal.web.LocalVariables;
51 import fr.paris.lutece.test.LuteceTestCase;
52 import fr.paris.lutece.test.Utils;
53
54
55
56
57
58 public class AdminJspBeanTest extends LuteceTestCase
59 {
60 private static final String PARAMETER_PAGE_ID = "page_id";
61 private static final String TEST_PAGE_ID = "1";
62 private static final String ATTRIBUTE_ADMIN_USER = "lutece_admin_user";
63
64
65
66
67 public void testGetAdminPage( ) throws AccessDeniedException
68 {
69 MockHttpServletRequest request = new MockHttpServletRequest( );
70 request.addParameter( PARAMETER_PAGE_ID, TEST_PAGE_ID );
71 Utils.registerAdminUserWithRigth( request, new AdminUser( ), AdminPageJspBean.RIGHT_MANAGE_ADMIN_SITE );
72
73 AdminPageJspBean instance = new AdminPageJspBean( );
74 instance.init( request, AdminPageJspBean.RIGHT_MANAGE_ADMIN_SITE );
75
76 assertTrue( StringUtils.isNotEmpty( instance.getAdminPage( request ) ) );
77 }
78
79
80
81
82
83
84 public void testGetAdminPagePreview( ) throws AccessDeniedException, UserNotSignedException
85 {
86 MockHttpServletRequest request = new MockHttpServletRequest( );
87
88
89 Map<String, Right> mapRights = new HashMap<>( );
90 Right right = new Right( );
91 right.setId( AdminPageJspBean.RIGHT_MANAGE_ADMIN_SITE );
92 mapRights.put( AdminPageJspBean.RIGHT_MANAGE_ADMIN_SITE, right );
93 AdminUser user = new AdminUser( );
94 user.setRights( mapRights );
95 user.setLocale( new Locale( "fr", "FR", "" ) );
96 request.getSession( true ).setAttribute( ATTRIBUTE_ADMIN_USER, user );
97 LocalVariables.setLocal( new MockServletConfig( ), request, new MockHttpServletResponse( ) );
98
99 AdminPageJspBean instance = new AdminPageJspBean( );
100 instance.init( request, AdminPageJspBean.RIGHT_MANAGE_ADMIN_SITE );
101
102 try
103 {
104 instance.getAdminPagePreview( request );
105 }
106 catch( SiteMessageException e )
107 {
108 fail( );
109 }
110 }
111
112 @Override
113 public void tearDown( ) throws Exception
114 {
115 LocalVariables.setLocal( null, null, null );
116 super.tearDown( );
117 }
118 }