001    // Copyright Oct 21, 2006 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    package org.apache.tapestry.form;
015    
016    import static org.easymock.EasyMock.*;
017    
018    import org.apache.tapestry.IForm;
019    import org.apache.tapestry.IMarkupWriter;
020    import org.apache.tapestry.IRequestCycle;
021    import org.apache.tapestry.services.DataSqueezer;
022    import org.testng.annotations.Test;
023    
024    
025    /**
026     * Tests functionality of {@link Hidden}.
027     */
028    @Test
029    public class TestHidden extends BaseFormComponentTestCase
030    {
031    
032        public void test_Render()
033        {   
034            IRequestCycle cycle = newCycle();
035            IForm form = newMock(IForm.class);
036            DataSqueezer squeezer = newMock(DataSqueezer.class);
037            
038            IMarkupWriter writer = newMarkupWriter();
039    
040            MockDelegate delegate = new MockDelegate();
041            
042            Hidden component = newInstance(Hidden.class, new Object[]
043            { "name", "fred", "value", new Integer(10), 
044                "encode", Boolean.TRUE, "dataSqueezer", squeezer });
045            
046            expect(cycle.renderStackPush(component)).andReturn(component);
047            
048            trainGetForm(cycle, form);
049            trainWasPrerendered(form, writer, component, false);
050            trainGetDelegate(form, delegate);
051            
052            delegate.setFormComponent(component);
053            
054            trainGetElementId(form, component, "fred");
055            trainIsRewinding(form, false);
056            trainIsRewinding(cycle, false);
057            
058            form.setFormFieldUpdating(true);
059            
060            expect(squeezer.squeeze(10)).andReturn("i10");
061            
062            delegate.setFormComponent(component);
063            
064            form.addHiddenValue("fred", "fred", "i10");
065            
066            expect(cycle.renderStackPop()).andReturn(component);
067            
068            replay();
069    
070            component.render(writer, cycle);
071    
072            verify();
073        }
074    }