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.form;
016    
017    import org.apache.tapestry.*;
018    import org.apache.tapestry.valid.IValidationDelegate;
019    import static org.easymock.EasyMock.*;
020    
021    /**
022     * Base class for tests of implementations of {@link org.apache.tapestry.form.IFormComponent}.
023     * 
024     * @author Howard M. Lewis Ship
025     * @since 4.0
026     */
027    public abstract class BaseFormComponentTestCase extends BaseComponentTestCase
028    {
029    
030        protected IValidationDelegate newDelegate()
031        {
032            return newMock(IValidationDelegate.class);
033        }
034    
035        protected void trainIsInError(IValidationDelegate delegate, boolean isInError)
036        {
037            expect(delegate.isInError()).andReturn(isInError);
038        }
039    
040        protected IForm newForm()
041        {
042            IForm mock = newMock(IForm.class);
043            
044            checkOrder(mock, false);
045            
046            return mock;
047        }
048    
049        protected void trainGetForm(IRequestCycle cycle, IForm form)
050        {
051            expect(cycle.getAttribute(TapestryUtils.FORM_ATTRIBUTE)).andReturn(form).anyTimes();
052        }
053    
054        protected void trainGetDelegate(IForm form, IValidationDelegate delegate)
055        {
056            expect(form.getDelegate()).andReturn(delegate).anyTimes();
057        }
058    
059        protected void trainGetParameter(IRequestCycle cycle, String parameterName,
060                String parameterValue)
061        {
062            expect(cycle.getParameter(parameterName)).andReturn(parameterValue);
063        }
064    
065        protected void trainWasPrerendered(IForm form, IMarkupWriter writer, IComponent component,
066                boolean wasPrerendered)
067        {
068            expect(form.wasPrerendered(writer, component)).andReturn(wasPrerendered);
069        }
070    
071        protected void trainIsRewinding(IForm form, boolean isRewinding)
072        {
073            expect(form.isRewinding()).andReturn(isRewinding);
074        }
075        
076        protected void trainGetElementId(IForm form, IFormComponent component, String name)
077        {
078            form.getElementId(component);
079            component.setName(name);
080            component.setClientId(name);
081            expectLastCall().andReturn(name);
082        }
083    
084        protected IBinding newBinding()
085        {
086            return newMock(IBinding.class);
087        }
088    
089        protected IActionListener newListener()
090        {
091            return newMock(IActionListener.class);
092        }
093    
094        protected IFormComponent newField()
095        {
096            return newMock(IFormComponent.class);
097        }
098    }