| 1 |
// Copyright 2005 The Apache Software Foundation
|
| 2 |
//
|
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
// you may not use this file except in compliance with the License.
|
| 5 |
// You may obtain a copy of the License at
|
| 6 |
//
|
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
//
|
| 9 |
// Unless required by applicable law or agreed to in writing, software
|
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
// See the License for the specific language governing permissions and
|
| 13 |
// limitations under the License.
|
| 14 |
|
| 15 |
package org.apache.tapestry.form;
|
| 16 |
|
| 17 |
import org.apache.tapestry.BaseComponentTestCase;
|
| 18 |
import org.apache.tapestry.IBinding;
|
| 19 |
import org.apache.tapestry.IMarkupWriter;
|
| 20 |
import org.apache.tapestry.IRequestCycle;
|
| 21 |
import org.apache.tapestry.spec.ComponentSpecification;
|
| 22 |
import org.testng.annotations.Test;
|
| 23 |
|
| 24 |
@Test(sequential=true)
|
| 25 |
public class TestButton extends BaseComponentTestCase
|
| 26 |
{
|
| 27 |
public void testRender()
|
| 28 |
{
|
| 29 |
Button b = newInstance(Button.class, new Object[]
|
| 30 |
{ "name", "assignedName" });
|
| 31 |
|
| 32 |
IMarkupWriter writer = newBufferWriter();
|
| 33 |
IRequestCycle cycle = newCycle();
|
| 34 |
|
| 35 |
replay();
|
| 36 |
|
| 37 |
b.renderFormComponent(writer, cycle);
|
| 38 |
|
| 39 |
verify();
|
| 40 |
|
| 41 |
assertBuffer("<button type=\"button\" name=\"assignedName\"></button>");
|
| 42 |
}
|
| 43 |
|
| 44 |
public void testRenderLabel()
|
| 45 |
{
|
| 46 |
Button b = newInstance(Button.class, new Object[]
|
| 47 |
{ "name", "assignedName", "label", "Label" });
|
| 48 |
|
| 49 |
IMarkupWriter writer = newBufferWriter();
|
| 50 |
IRequestCycle cycle = newCycle();
|
| 51 |
|
| 52 |
replay();
|
| 53 |
|
| 54 |
b.renderFormComponent(writer, cycle);
|
| 55 |
|
| 56 |
verify();
|
| 57 |
|
| 58 |
assertBuffer("<button type=\"button\" name=\"assignedName\">Label</button>");
|
| 59 |
}
|
| 60 |
|
| 61 |
public void testRenderInformalParameters()
|
| 62 |
{
|
| 63 |
Button b = newInstance(Button.class, new Object[]
|
| 64 |
{ "name", "assignedName", "specification", new ComponentSpecification() });
|
| 65 |
|
| 66 |
IMarkupWriter writer = newBufferWriter();
|
| 67 |
IRequestCycle cycle = newCycle();
|
| 68 |
|
| 69 |
IBinding binding = newBinding("informal-value");
|
| 70 |
|
| 71 |
b.setBinding("informal", binding);
|
| 72 |
|
| 73 |
replay();
|
| 74 |
|
| 75 |
b.renderFormComponent(writer, cycle);
|
| 76 |
|
| 77 |
verify();
|
| 78 |
|
| 79 |
assertBuffer("<button type=\"button\" name=\"assignedName\" informal=\"informal-value\"></button>");
|
| 80 |
}
|
| 81 |
|
| 82 |
public void testRenderWithId()
|
| 83 |
{
|
| 84 |
Button b = newInstance(Button.class, new Object[]
|
| 85 |
{ "clientId", "assignedId", "name", "assignedId"});
|
| 86 |
|
| 87 |
IMarkupWriter writer = newBufferWriter();
|
| 88 |
IRequestCycle cycle = newCycle();
|
| 89 |
|
| 90 |
replay();
|
| 91 |
|
| 92 |
b.renderFormComponent(writer, cycle);
|
| 93 |
|
| 94 |
verify();
|
| 95 |
|
| 96 |
assertBuffer("<button type=\"button\" name=\"assignedId\" id=\"assignedId\"></button>");
|
| 97 |
}
|
| 98 |
|
| 99 |
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 |
}
|