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.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
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 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
82
83
84 public void testGetAdminPagePreview( ) throws AccessDeniedException, UserNotSignedException
85 {
86 System.out.println( "getAdminPagePreview" );
87
88 MockHttpServletRequest request = new MockHttpServletRequest( );
89
90
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
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 }