1 15 package org.apache.tapestry.portlet; 16 17 import java.util.HashMap ; 18 import java.util.Map ; 19 20 import org.apache.hivemind.test.HiveMindTestCase; 21 import org.apache.tapestry.IRequestCycle; 22 import org.apache.tapestry.Tapestry; 23 import org.apache.tapestry.engine.ILink; 24 import org.apache.tapestry.services.LinkFactory; 25 import org.apache.tapestry.services.ResponseRenderer; 26 import org.apache.tapestry.services.ServiceConstants; 27 import org.easymock.MockControl; 28 29 35 public class TestPortletHomeService extends HiveMindTestCase 36 { 37 private ResponseRenderer newResponseRenderer() 38 { 39 return (ResponseRenderer) newMock(ResponseRenderer.class); 40 } 41 42 private IRequestCycle newCycle() 43 { 44 return (IRequestCycle) newMock(IRequestCycle.class); 45 } 46 47 private PortletRequestGlobals newRequestGlobals(boolean isRender) 48 { 49 MockControl control = newControl(PortletRequestGlobals.class); 50 PortletRequestGlobals globals = (PortletRequestGlobals) control.getMock(); 51 52 globals.isRenderRequest(); 53 control.setReturnValue(isRender); 54 55 return globals; 56 } 57 58 private PortletRenderer newPortletRenderer() 59 { 60 return (PortletRenderer) newMock(PortletRenderer.class); 61 } 62 63 private PortletPageResolver newResolver(IRequestCycle cycle, String pageName) 64 { 65 MockControl control = newControl(PortletPageResolver.class); 66 PortletPageResolver resolver = (PortletPageResolver) control.getMock(); 67 68 resolver.getPageNameForRequest(cycle); 69 control.setReturnValue(pageName); 70 71 return resolver; 72 } 73 74 public void testIsRenderRequest() throws Exception 75 { 76 IRequestCycle cycle = newCycle(); 77 PortletRequestGlobals globals = newRequestGlobals(true); 78 PortletRenderer renderer = newPortletRenderer(); 79 PortletPageResolver resolver = newResolver(cycle, "ZePage"); 80 81 renderer.renderPage(cycle, "ZePage"); 82 83 replayControls(); 84 85 PortletHomeService phs = new PortletHomeService(); 86 phs.setPageResolver(resolver); 87 phs.setPortletRenderer(renderer); 88 phs.setRequestGlobals(globals); 89 90 phs.service(cycle); 91 92 verifyControls(); 93 } 94 95 public void testIsActionRequest() throws Exception 96 { 97 IRequestCycle cycle = newCycle(); 98 PortletRequestGlobals globals = newRequestGlobals(false); 99 ResponseRenderer renderer = newResponseRenderer(); 100 PortletPageResolver resolver = newResolver(cycle, "ZePage"); 101 102 cycle.activate("ZePage"); 103 renderer.renderResponse(cycle); 104 105 replayControls(); 106 107 PortletHomeService phs = new PortletHomeService(); 108 phs.setResponseRenderer(renderer); 109 phs.setRequestGlobals(globals); 110 phs.setPageResolver(resolver); 111 112 phs.service(cycle); 113 114 verifyControls(); 115 } 116 117 public void testGetLink() 118 { 119 Map parameters = new HashMap (); 120 parameters.put(ServiceConstants.SERVICE, Tapestry.HOME_SERVICE); 121 122 MockControl factoryc = newControl(LinkFactory.class); 123 LinkFactory factory = (LinkFactory) factoryc.getMock(); 124 125 ILink link = (ILink) newMock(ILink.class); 126 IRequestCycle cycle = newCycle(); 127 128 factory.constructLink(cycle, parameters, true); 129 factoryc.setReturnValue(link); 130 131 replayControls(); 132 133 PortletHomeService phs = new PortletHomeService(); 134 phs.setLinkFactory(factory); 135 136 assertSame(link, phs.getLink(cycle, null)); 137 138 verifyControls(); 139 } 140 141 public void testGetLinkWithParameter() 142 { 143 try 144 { 145 new PortletHomeService().getLink(null, "PARAMETER"); 146 unreachable(); 147 } 148 catch (IllegalArgumentException ex) 149 { 150 assertEquals("The home service does not require a parameter object.", ex.getMessage()); 151 } 152 } 153 } | Popular Tags |