1 package org.exoplatform.services.portletcontainer.imp; 2 3 4 5 import javax.portlet.PortletMode; 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.http.HttpServletResponse ; 8 import org.exoplatform.services.portletcontainer.PortletContainerException; 9 import org.exoplatform.services.portletcontainer.impl.portletAPIImp.pool.EmptyResponse; 10 import org.exoplatform.services.portletcontainer.pci.ExoWindowID; 11 import org.exoplatform.test.mocks.servlet.MockHttpSession; 12 import org.exoplatform.test.mocks.servlet.MockServletRequest; 13 import org.exoplatform.test.mocks.servlet.MockServletResponse; 14 import java.util.Collection ; 15 import java.util.Iterator ; 16 import java.util.Locale ; 17 18 22 23 30 public class TestPortletMode extends BaseTest{ 31 32 public TestPortletMode(String s) { 33 super(s); 34 } 35 36 42 public void testImplicitViewMode(){ 43 Collection c = portletContainer.getPortletModes("hello", "HelloWorld", "text/html"); 44 45 assertTrue(contains(c, PortletMode.VIEW)); 46 } 47 48 public void testOtherModes(){ 49 Collection c = portletContainer.getPortletModes("hello", "HelloWorld", "text/html"); 50 51 assertTrue(contains(c, PortletMode.EDIT)); 52 assertTrue(contains(c, PortletMode.HELP)); 53 assertTrue(contains(c, new PortletMode("config"))); 54 assertFalse(contains(c, new PortletMode("about"))); 55 assertFalse(contains(c, new PortletMode("not_exist"))); 56 57 assertTrue(portletContainer.isModeSuported("hello", "HelloWorld", "text/html", PortletMode.VIEW)); 58 assertTrue(portletContainer.isModeSuported("hello", "HelloWorld", "text/html", PortletMode.EDIT)); 59 assertTrue(portletContainer.isModeSuported("hello", "HelloWorld", "text/html", new PortletMode("config"))); 60 assertFalse(portletContainer.isModeSuported("hello", "HelloWorld", "text/html", new PortletMode("about"))); 61 assertFalse(portletContainer.isModeSuported("hello", "HelloWorld", "text/html", new PortletMode("not_exist"))); 62 } 63 64 public void testOtherMarkup(){ 65 Collection c = portletContainer.getPortletModes("hello", "HelloWorld", "text/wml"); 66 67 assertTrue(contains(c, PortletMode.EDIT)); 68 assertTrue(contains(c, PortletMode.HELP)); 69 assertFalse(contains(c, new PortletMode("config"))); 70 assertFalse(contains(c, new PortletMode("not_exist"))); 71 72 assertTrue(portletContainer.isModeSuported("hello", "HelloWorld", "text/wml", PortletMode.VIEW)); 73 assertTrue(portletContainer.isModeSuported("hello", "HelloWorld", "text/wml", PortletMode.EDIT)); 74 assertTrue(portletContainer.isModeSuported("hello", "HelloWorld", "text/wml", PortletMode.HELP)); 75 assertFalse(portletContainer.isModeSuported("hello", "HelloWorld", "text/wml", new PortletMode("config"))); 76 assertFalse(portletContainer.isModeSuported("hello", "HelloWorld", "text/wml", new PortletMode("not_exist"))); 77 } 78 79 85 public void testNonPortletAccessWhenModeIsNotDefined() { 86 ((ExoWindowID)actionInput.getWindowID()).setPortletName("HelloWorld"); 87 actionInput.setPortletMode(new PortletMode("config")); 88 actionInput.setMarkup("text/wml"); 89 90 ((ExoWindowID)input.getWindowID()).setPortletName("HelloWorld2"); 91 input.setPortletMode(PortletMode.HELP); 92 HttpServletRequest request = new MockServletRequest(new MockHttpSession(), Locale.US, true); 93 HttpServletResponse response = new MockServletResponse(new EmptyResponse()); 94 try { 95 portletContainer.processAction(request, response, actionInput); 96 } catch (PortletContainerException e) { 97 assertEquals( "The portlet mode config is not supported for the text/wml markup language.", e.getMessage()); 98 } 99 try { 100 portletContainer.render(request, response, input); 101 } catch (PortletContainerException e) { 102 assertEquals( "The portlet mode help is not supported for the text/html markup language.", e.getMessage()); 103 } 104 } 105 106 113 public void testIgnoreCustomModesNotSupportedByPortal(){ 114 Collection c = portletContainer.getPortletModes("hello", "HelloWorld2", "text/html"); 115 116 assertFalse(contains(c, new PortletMode("not_supported"))); 117 } 118 119 120 private boolean contains(Collection modes, PortletMode mode){ 121 for (Iterator iterator = modes.iterator(); iterator.hasNext();) { 122 PortletMode portletMode = (PortletMode) iterator.next(); 123 if(portletMode.toString().equals(mode.toString())) 124 return true; 125 } 126 return false; 127 } 128 129 } 130 | Popular Tags |