KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portletcontainer > imp > TestCaching


1 /**
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  **/

5
6 /**
7  * Created by The eXo Platform SARL .
8  * Author : Mestrallet Benjamin
9  * benjmestrallet@users.sourceforge.net
10  * Date: Oct 9, 2003
11  * Time: 12:06:04 PM
12  */

13 package org.exoplatform.services.portletcontainer.imp;
14
15
16 import javax.portlet.PortletException;
17 import javax.portlet.PortletMode;
18 import javax.portlet.WindowState;
19 import javax.servlet.http.HttpServletRequest JavaDoc;
20 import javax.servlet.http.HttpServletResponse JavaDoc;
21 import org.exoplatform.services.portletcontainer.impl.portletAPIImp.pool.EmptyResponse;
22 import org.exoplatform.services.portletcontainer.pci.ExoWindowID;
23 import org.exoplatform.test.mocks.servlet.MockHttpSession;
24 import org.exoplatform.test.mocks.servlet.MockServletRequest;
25 import org.exoplatform.test.mocks.servlet.MockServletResponse;
26 import java.util.Locale JavaDoc;
27
28 public class TestCaching extends BaseTest {
29
30   public TestCaching(String JavaDoc s) {
31     super(s);
32   }
33
34   public void testProgrammaticExpirationPeriodChange() throws PortletException {
35     ((ExoWindowID)input.getWindowID()).setPortletName("HelloWorld");
36     HttpServletRequest JavaDoc request = new MockServletRequest(new MockHttpSession(), Locale.US, true);
37     HttpServletResponse JavaDoc response = new MockServletResponse(new EmptyResponse());
38     try {
39       portletContainer.render(request, response, input);
40       assertEquals(6, portletMonitor.getCacheExpirationPeriod("hello",
41                                                               "HelloWorld"));
42     } catch (Exception JavaDoc e) {
43       e.printStackTrace();
44     }
45   }
46
47   public void testSimpleCache(){
48     ((ExoWindowID)input.getWindowID()).setPortletName("HelloWorld");
49     HttpServletRequest JavaDoc request = new MockServletRequest(new MockHttpSession(), Locale.US, true);
50     HttpServletResponse JavaDoc response = new MockServletResponse(new EmptyResponse());
51     try {
52       portletContainer.render(request, response, input);
53       portletContainer.render(request, response, input);
54       Thread.sleep(8000);
55       portletContainer.render(request, response, input);
56     } catch (Exception JavaDoc e) {
57       e.printStackTrace();
58     }
59   }
60
61   public void testNotExpirableCache(){
62     ((ExoWindowID)input.getWindowID()).setPortletName("HelloWorld2");
63     HttpServletRequest JavaDoc request = new MockServletRequest(new MockHttpSession(), Locale.US);
64     HttpServletResponse JavaDoc response = new MockServletResponse(new EmptyResponse());
65     try {
66       portletContainer.render(request, response, input);
67       //the console output should appear once
68
portletContainer.render(request, response, input);
69     } catch (Exception JavaDoc e) {
70       e.printStackTrace();
71     }
72   }
73
74   public void testPortletWithNoCache(){
75     ((ExoWindowID)input.getWindowID()).setPortletName("PortletWithNoCacheTag");
76     HttpServletRequest JavaDoc request = new MockServletRequest(new MockHttpSession(), Locale.US);
77     HttpServletResponse JavaDoc response = new MockServletResponse(new EmptyResponse());
78     try {
79       portletContainer.render(request, response, input);
80       portletContainer.render(request, response, input);
81     } catch (Exception JavaDoc e) {
82       e.printStackTrace();
83     }
84   }
85
86   public void testModeAndStateChange(){
87     ((ExoWindowID)input.getWindowID()).setPortletName("HelloWorld2");
88     HttpServletRequest JavaDoc request = new MockServletRequest(new MockHttpSession(), Locale.US);
89     HttpServletResponse JavaDoc response = new MockServletResponse(new EmptyResponse());
90     try {
91       portletContainer.render(request, response, input);
92       portletContainer.render(request, response, input);
93       input.setPortletMode(PortletMode.EDIT);
94       portletContainer.render(request, response, input);
95       portletContainer.render(request, response, input);
96       input.setWindowState(WindowState.MAXIMIZED);
97       portletContainer.render(request, response, input);
98       portletContainer.render(request, response, input);
99     } catch (Exception JavaDoc e) {
100       e.printStackTrace();
101     }
102   }
103
104   public void testRenderURLRequest(){
105     ((ExoWindowID)input.getWindowID()).setPortletName("HelloWorld2");
106     input.setPortletMode(PortletMode.EDIT);
107     HttpServletRequest JavaDoc request = new MockServletRequest(new MockHttpSession(), Locale.US);
108     HttpServletResponse JavaDoc response = new MockServletResponse(new EmptyResponse());
109     try {
110       portletContainer.render(request, response, input);
111       input.setUpdateCache(true);
112       portletContainer.render(request, response, input);
113       input.setUpdateCache(false);
114       portletContainer.render(request, response, input);
115       input.setUpdateCache(true);
116       portletContainer.render(request, response, input);
117     } catch (Exception JavaDoc e) {
118       e.printStackTrace();
119     }
120   }
121
122   public void testGlobalCache(){
123     ((ExoWindowID)input.getWindowID()).setPortletName("PortletToTestGlobalCache");
124     MockServletRequest request = new MockServletRequest(new MockHttpSession(), Locale.US);
125     HttpServletResponse JavaDoc response = new MockServletResponse(new EmptyResponse());
126     try {
127       portletContainer.render(request, response, input);
128       //the console output should appear once
129
portletContainer.render(request, response, input);
130       request.setRemoteUser("new_remote");
131       portletContainer.render(request, response, input);
132     } catch (Exception JavaDoc e) {
133       e.printStackTrace();
134     }
135   }
136 }
137
Popular Tags