1 5 6 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 ; 20 import javax.servlet.http.HttpServletResponse ; 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 ; 27 28 public class TestCaching extends BaseTest { 29 30 public TestCaching(String s) { 31 super(s); 32 } 33 34 public void testProgrammaticExpirationPeriodChange() throws PortletException { 35 ((ExoWindowID)input.getWindowID()).setPortletName("HelloWorld"); 36 HttpServletRequest request = new MockServletRequest(new MockHttpSession(), Locale.US, true); 37 HttpServletResponse response = new MockServletResponse(new EmptyResponse()); 38 try { 39 portletContainer.render(request, response, input); 40 assertEquals(6, portletMonitor.getCacheExpirationPeriod("hello", 41 "HelloWorld")); 42 } catch (Exception e) { 43 e.printStackTrace(); 44 } 45 } 46 47 public void testSimpleCache(){ 48 ((ExoWindowID)input.getWindowID()).setPortletName("HelloWorld"); 49 HttpServletRequest request = new MockServletRequest(new MockHttpSession(), Locale.US, true); 50 HttpServletResponse 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 e) { 57 e.printStackTrace(); 58 } 59 } 60 61 public void testNotExpirableCache(){ 62 ((ExoWindowID)input.getWindowID()).setPortletName("HelloWorld2"); 63 HttpServletRequest request = new MockServletRequest(new MockHttpSession(), Locale.US); 64 HttpServletResponse response = new MockServletResponse(new EmptyResponse()); 65 try { 66 portletContainer.render(request, response, input); 67 portletContainer.render(request, response, input); 69 } catch (Exception e) { 70 e.printStackTrace(); 71 } 72 } 73 74 public void testPortletWithNoCache(){ 75 ((ExoWindowID)input.getWindowID()).setPortletName("PortletWithNoCacheTag"); 76 HttpServletRequest request = new MockServletRequest(new MockHttpSession(), Locale.US); 77 HttpServletResponse response = new MockServletResponse(new EmptyResponse()); 78 try { 79 portletContainer.render(request, response, input); 80 portletContainer.render(request, response, input); 81 } catch (Exception e) { 82 e.printStackTrace(); 83 } 84 } 85 86 public void testModeAndStateChange(){ 87 ((ExoWindowID)input.getWindowID()).setPortletName("HelloWorld2"); 88 HttpServletRequest request = new MockServletRequest(new MockHttpSession(), Locale.US); 89 HttpServletResponse 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 e) { 100 e.printStackTrace(); 101 } 102 } 103 104 public void testRenderURLRequest(){ 105 ((ExoWindowID)input.getWindowID()).setPortletName("HelloWorld2"); 106 input.setPortletMode(PortletMode.EDIT); 107 HttpServletRequest request = new MockServletRequest(new MockHttpSession(), Locale.US); 108 HttpServletResponse 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 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 response = new MockServletResponse(new EmptyResponse()); 126 try { 127 portletContainer.render(request, response, input); 128 portletContainer.render(request, response, input); 130 request.setRemoteUser("new_remote"); 131 portletContainer.render(request, response, input); 132 } catch (Exception e) { 133 e.printStackTrace(); 134 } 135 } 136 } 137 | Popular Tags |