1 15 package org.apache.tapestry.engine; 16 17 import java.util.HashMap ; 18 import java.util.Map ; 19 20 import org.apache.tapestry.IRequestCycle; 21 import org.apache.tapestry.Tapestry; 22 import org.apache.tapestry.services.LinkFactory; 23 import org.apache.tapestry.services.ResponseRenderer; 24 import org.apache.tapestry.services.ServiceConstants; 25 import org.easymock.MockControl; 26 27 31 public class TestPageService extends ServiceTestCase 32 { 33 public void testGetLink() 34 { 35 Map parameters = new HashMap (); 36 parameters.put(ServiceConstants.SERVICE, Tapestry.PAGE_SERVICE); 37 parameters.put(ServiceConstants.PAGE, "TargetPage"); 38 39 ILink link = newLink(); 40 41 MockControl lfc = newControl(LinkFactory.class); 42 LinkFactory lf = (LinkFactory) lfc.getMock(); 43 44 IRequestCycle cycle = newRequestCycle(); 45 46 lf.constructLink(cycle, parameters, true); 47 lfc.setReturnValue(link); 48 49 replayControls(); 50 51 PageService ps = new PageService(); 52 ps.setLinkFactory(lf); 53 54 assertSame(link, ps.getLink(cycle, "TargetPage")); 55 56 verifyControls(); 57 } 58 59 public void testService() throws Exception 60 { 61 MockControl cyclec = newControl(IRequestCycle.class); 62 IRequestCycle cycle = (IRequestCycle) cyclec.getMock(); 63 64 cycle.getParameter(ServiceConstants.PAGE); 65 cyclec.setReturnValue("TargetPage"); 66 67 cycle.activate("TargetPage"); 68 69 ResponseRenderer rr = newResponseRenderer(); 70 71 rr.renderResponse(cycle); 72 73 replayControls(); 74 75 PageService ps = new PageService(); 76 ps.setResponseRenderer(rr); 77 78 ps.service(cycle); 79 80 verifyControls(); 81 } 82 } | Popular Tags |