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.service.page;
35
36 import java.util.List;
37
38 import javax.servlet.http.HttpServletResponse;
39
40 import org.junit.Test;
41 import org.springframework.mock.web.MockHttpServletRequest;
42 import org.springframework.mock.web.MockHttpServletResponse;
43
44 import fr.paris.lutece.portal.service.cache.CacheService;
45 import fr.paris.lutece.portal.service.cache.CacheableService;
46 import fr.paris.lutece.portal.service.message.SiteMessageException;
47 import fr.paris.lutece.portal.service.spring.SpringContextService;
48 import fr.paris.lutece.portal.web.LocalVariables;
49 import fr.paris.lutece.portal.web.constants.Parameters;
50 import fr.paris.lutece.test.LuteceTestCase;
51
52 public class PageServiceTest extends LuteceTestCase
53 {
54 private boolean _pageCacheStatus;
55
56 @Override
57 public void setUp( ) throws Exception
58 {
59 super.setUp( );
60
61
62 List<CacheableService> services = CacheService.getCacheableServicesList( );
63
64 for ( CacheableService cs : services )
65 {
66 if ( cs instanceof PageCacheService )
67 {
68 _pageCacheStatus = cs.isCacheEnable( );
69 cs.enableCache( true );
70
71 break;
72 }
73 }
74 }
75
76 @Override
77 public void tearDown( ) throws Exception
78 {
79
80 List<CacheableService> services = CacheService.getCacheableServicesList( );
81
82 for ( CacheableService cs : services )
83 {
84 if ( cs instanceof PageCacheService )
85 {
86 cs.enableCache( _pageCacheStatus );
87
88 break;
89 }
90 }
91
92 super.tearDown( );
93 }
94
95
96
97
98
99
100 @Test
101 public void testBaseUrl( ) throws SiteMessageException
102 {
103 IPageService pageService = (IPageService) SpringContextService.getBean( "pageService" );
104 HttpServletResponse response = new MockHttpServletResponse( );
105
106 MockHttpServletRequest request = new MockHttpServletRequest( );
107
108 LocalVariables.setLocal( null, request, response );
109 request.addParameter( Parameters.PAGE_ID, "1" );
110
111 String pageContent = pageService.getPage( request, 0 );
112 assertTrue( pageContent.contains( "<base href=\"http://localhost/\">" ) );
113
114
115 request = new MockHttpServletRequest( );
116 request.setServerName( "junit" );
117
118 LocalVariables.setLocal( null, request, response );
119 request.addParameter( Parameters.PAGE_ID, "1" );
120 pageContent = pageService.getPage( request, 0 );
121 assertTrue( pageContent.contains( "<base href=\"http://junit/\">" ) );
122 }
123 }