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.BaseComponentTestCase;
018    import org.apache.tapestry.IBinding;
019    import org.apache.tapestry.IMarkupWriter;
020    import org.apache.tapestry.IRequestCycle;
021    import org.apache.tapestry.spec.ComponentSpecification;
022    import org.testng.annotations.Test;
023    
024    @Test(sequential=true)
025    public class TestButton extends BaseComponentTestCase
026    {
027        public void testRender()
028        {
029            Button b = newInstance(Button.class, new Object[]
030            { "name", "assignedName" });
031    
032            IMarkupWriter writer = newBufferWriter();
033            IRequestCycle cycle = newCycle();
034    
035            replay();
036    
037            b.renderFormComponent(writer, cycle);
038    
039            verify();
040    
041            assertBuffer("<button type=\"button\" name=\"assignedName\"></button>");
042        }
043    
044        public void testRenderLabel()
045        {
046            Button b = newInstance(Button.class, new Object[]
047            { "name", "assignedName", "label", "Label" });
048    
049            IMarkupWriter writer = newBufferWriter();
050            IRequestCycle cycle = newCycle();
051    
052            replay();
053    
054            b.renderFormComponent(writer, cycle);
055    
056            verify();
057    
058            assertBuffer("<button type=\"button\" name=\"assignedName\">Label</button>");
059        }
060    
061        public void testRenderInformalParameters()
062        {
063            Button b = newInstance(Button.class, new Object[]
064            { "name", "assignedName", "specification", new ComponentSpecification() });
065    
066            IMarkupWriter writer = newBufferWriter();
067            IRequestCycle cycle = newCycle();
068    
069            IBinding binding = newBinding("informal-value");
070    
071            b.setBinding("informal", binding);
072    
073            replay();
074    
075            b.renderFormComponent(writer, cycle);
076    
077            verify();
078    
079            assertBuffer("<button type=\"button\" name=\"assignedName\" informal=\"informal-value\"></button>");
080        }
081    
082        public void testRenderWithId()
083        {
084            Button b = newInstance(Button.class, new Object[]
085            { "clientId", "assignedId", "name", "assignedId"});
086            
087            IMarkupWriter writer = newBufferWriter();
088            IRequestCycle cycle = newCycle();
089            
090            replay();
091    
092            b.renderFormComponent(writer, cycle);
093    
094            verify();
095    
096            assertBuffer("<button type=\"button\" name=\"assignedId\" id=\"assignedId\"></button>");
097        }
098    
099        public void testSubmit()
100        {
101            Button b = (Button) newInstance(Button.class);
102    
103            IMarkupWriter writer = newWriter();
104            IRequestCycle cycle = newCycle();
105    
106            replay();
107    
108            b.rewindFormComponent(writer, cycle);
109    
110            verify();
111        }
112    }