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.enhance; 016 017 import static org.easymock.EasyMock.checkOrder; 018 import static org.easymock.EasyMock.expect; 019 020 import org.apache.hivemind.Location; 021 import org.apache.tapestry.BaseComponentTestCase; 022 import org.apache.tapestry.engine.state.ApplicationStateManager; 023 import org.apache.tapestry.spec.IComponentSpecification; 024 025 /** 026 * Base class for common utilities when testing enhancement workers. 027 * 028 * @author Howard Lewis Ship 029 * @since 4.0 030 */ 031 public class BaseEnhancementTestCase extends BaseComponentTestCase 032 { 033 public IComponentSpecification newSpec(Location location) 034 { 035 IComponentSpecification spec = newSpec(); 036 checkOrder(spec, false); 037 038 expect(spec.getLocation()).andReturn(location); 039 040 return spec; 041 } 042 043 protected EnhancementOperation newOp() 044 { 045 return newMock(EnhancementOperation.class); 046 } 047 048 protected void trainAddInjectedField(EnhancementOperation op, String fieldName, 049 Class fieldType, Object injectedValue, String injectedFieldName) 050 { 051 expect(op.addInjectedField(fieldName, fieldType, injectedValue)) 052 .andReturn(injectedFieldName); 053 054 } 055 056 protected ApplicationStateManager newApplicationStateManager() 057 { 058 return newMock(ApplicationStateManager.class); 059 } 060 061 protected EnhancementOperation newEnhancementOp() 062 { 063 return newMock(EnhancementOperation.class); 064 } 065 066 protected void trainGetAccessorMethodName(EnhancementOperation op, String propertyName, 067 String methodName) 068 { 069 expect(op.getAccessorMethodName(propertyName)).andReturn(methodName); 070 } 071 072 protected void trainGetPropertyType(EnhancementOperation op, String propertyName, 073 Class propertyType) 074 { 075 expect(op.getPropertyType(propertyName)).andReturn(propertyType); 076 } 077 078 protected void trainGetBaseClass(EnhancementOperation op, Class baseClass) 079 { 080 expect(op.getBaseClass()).andReturn(baseClass); 081 } 082 }