001 // Copyright 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.services.impl; 016 017 import static org.easymock.EasyMock.expect; 018 019 import org.apache.tapestry.IRequestCycle; 020 import org.apache.tapestry.engine.IEngineService; 021 import org.apache.tapestry.engine.ILink; 022 import org.testng.annotations.Test; 023 024 /** 025 * Tests for {@link org.apache.tapestry.services.impl.EngineServiceInnerProxy}. 026 * 027 * @author Howard M. Lewis Ship 028 * @since 4.0 029 */ 030 @Test 031 public class EngineServiceInnerProxyTest extends AbstractEngineServiceProxyTestCase 032 { 033 private EngineServiceSource newSource(String name, IEngineService service) 034 { 035 EngineServiceSource source = newSource(); 036 037 expect(source.resolveEngineService(name)).andReturn(service); 038 039 return source; 040 } 041 042 public void testGetName() 043 { 044 EngineServiceOuterProxy outer = new EngineServiceOuterProxy("Outer"); 045 EngineServiceSource source = newSource(); 046 047 replay(); 048 049 EngineServiceInnerProxy proxy = new EngineServiceInnerProxy("Inner", outer, source); 050 051 assertEquals("Inner", proxy.getName()); 052 assertEquals("<InnerProxy for engine service 'Inner'>", proxy.toString()); 053 054 verify(); 055 } 056 057 protected EngineServiceSource newSource() 058 { 059 return newMock(EngineServiceSource.class); 060 } 061 062 public void testGetLinkNonPost() 063 { 064 ILink link = newLink(); 065 066 IEngineService service = newEngineService(); 067 068 Object parameter = new Object(); 069 070 EngineServiceSource source = newSource("fred", service); 071 072 trainGetLink(service, false, parameter, link); 073 074 replay(); 075 076 EngineServiceOuterProxy outer = new EngineServiceOuterProxy("fred"); 077 EngineServiceInnerProxy inner = new EngineServiceInnerProxy("fred", outer, source); 078 079 outer.installDelegate(inner); 080 081 assertSame(link, outer.getLink(false, parameter)); 082 083 assertSame(service, outer.getDelegate()); 084 085 verify(); 086 } 087 088 public void testGetLinkPost() 089 { 090 ILink link = newLink(); 091 092 IEngineService service = newEngineService(); 093 094 Object parameter = new Object(); 095 096 EngineServiceSource source = newSource("fred", service); 097 098 trainGetLink(service, true, parameter, link); 099 100 replay(); 101 102 EngineServiceOuterProxy outer = new EngineServiceOuterProxy("fred"); 103 EngineServiceInnerProxy inner = new EngineServiceInnerProxy("fred", outer, source); 104 105 outer.installDelegate(inner); 106 107 assertSame(link, outer.getLink(true, parameter)); 108 109 assertSame(service, outer.getDelegate()); 110 111 verify(); 112 } 113 public void testService() throws Exception 114 { 115 IRequestCycle cycle = newCycle(); 116 IEngineService service = newEngineService(); 117 118 EngineServiceSource source = newSource("fred", service); 119 120 service.service(cycle); 121 122 replay(); 123 124 EngineServiceOuterProxy outer = new EngineServiceOuterProxy("fred"); 125 EngineServiceInnerProxy inner = new EngineServiceInnerProxy("fred", outer, source); 126 127 outer.installDelegate(inner); 128 129 outer.service(cycle); 130 131 assertSame(service, outer.getDelegate()); 132 133 verify(); 134 } 135 }