1 15 package org.apache.tapestry.services.impl; 16 17 import org.apache.hivemind.test.HiveMindTestCase; 18 import org.apache.tapestry.IRequestCycle; 19 import org.apache.tapestry.engine.IEngineService; 20 import org.apache.tapestry.engine.ILink; 21 import org.easymock.MockControl; 22 23 29 public class TestEngineServiceInnerProxy extends HiveMindTestCase 30 { 31 private ILink newLink() 32 { 33 return (ILink) newMock(ILink.class); 34 } 35 36 private IRequestCycle newCycle() 37 { 38 return (IRequestCycle) newMock(IRequestCycle.class); 39 } 40 41 private EngineServiceSource newSource(String name, IEngineService service) 42 { 43 MockControl control = newControl(EngineServiceSource.class); 44 EngineServiceSource source = (EngineServiceSource) control.getMock(); 45 46 source.resolveEngineService(name); 47 control.setReturnValue(service); 48 49 return source; 50 } 51 52 public void testGetName() 53 { 54 EngineServiceOuterProxy outer = new EngineServiceOuterProxy("Outer"); 55 EngineServiceSource source = (EngineServiceSource) newMock(EngineServiceSource.class); 56 57 replayControls(); 58 59 EngineServiceInnerProxy proxy = new EngineServiceInnerProxy("Inner", outer, source); 60 61 assertEquals("Inner", proxy.getName()); 62 assertEquals("<InnerProxy for engine service 'Inner'>", proxy.toString()); 63 64 verifyControls(); 65 } 66 67 public void testGetLink() 68 { 69 ILink link = newLink(); 70 IRequestCycle cycle = newCycle(); 71 72 MockControl control = newControl(IEngineService.class); 73 IEngineService service = (IEngineService) control.getMock(); 74 75 Object parameter = new Object (); 76 77 service.getLink(cycle, parameter); 78 control.setReturnValue(link); 79 80 EngineServiceSource source = newSource("fred", service); 81 82 replayControls(); 83 84 EngineServiceOuterProxy outer = new EngineServiceOuterProxy("fred"); 85 EngineServiceInnerProxy inner = new EngineServiceInnerProxy("fred", outer, source); 86 87 outer.installDelegate(inner); 88 89 assertSame(link, outer.getLink(cycle, parameter)); 90 91 assertSame(service, outer.getDelegate()); 92 93 verifyControls(); 94 } 95 96 public void testService() throws Exception 97 { 98 IRequestCycle cycle = newCycle(); 99 IEngineService service = (IEngineService) newMock(IEngineService.class); 100 101 service.service(cycle); 102 103 EngineServiceSource source = newSource("fred", service); 104 105 replayControls(); 106 107 EngineServiceOuterProxy outer = new EngineServiceOuterProxy("fred"); 108 EngineServiceInnerProxy inner = new EngineServiceInnerProxy("fred", outer, source); 109 110 outer.installDelegate(inner); 111 112 outer.service(cycle); 113 114 assertSame(service, outer.getDelegate()); 115 116 verifyControls(); 117 } 118 } | Popular Tags |