1 /*
2 * Angkor Web Framework
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */
7
8 package com.tirsen.angkor.test.unit.widget;
9
10 import junit.framework.TestCase;
11 import com.tirsen.angkor.widget.*;
12 import com.tirsen.angkor.test.unit.widget.TextLabelTest;
13 import com.tirsen.angkor.test.unit.AbstractPipelineTest;
14 import com.tirsen.angkor.test.unit.TestUtility;
15 import org.w3c.dom.*;
16
17 /***
18 * Unit tests for the {@link com.tirsen.angkor.widget.TextInput} widget.
19 * @author $Author: tirsen $
20 * @version $Revision: 1.1 $
21 * <BR>
22 * $Id: TextInputTest.java,v 1.1 2002/10/07 19:49:23 tirsen Exp $
23 */
24 public class TextInputTest extends AbstractPipelineTest
25 {
26 private TextInput textInput;
27
28 private int size = 20;
29 private String id = "myid";
30 private String value = "myvalue";
31 private String newvalue = "mynewvalue";
32 private String prompt = "myprompt";
33 private BasicValueModel model;
34 private TextLabel textLabel;
35
36 protected void setUp() throws Exception
37 {
38 super.setUp();
39
40 // create the instances
41 textInput = new TextInput();
42 model = new BasicValueModel();
43 textLabel = new TextLabel();
44 textLabel.setId("labelID");
45
46 // setup the test-data
47 textInput.setId(id);
48 textInput.setSize(size);
49 model.setValue(value);
50 textInput.setModel(model);
51 textLabel.setLabel(prompt);
52 textInput.setPrompt(textLabel);
53 }
54
55 /***
56 * Features tested:
57 * <li> update of model according to parse of request
58 */
59 public void testParse() throws Exception
60 {
61 context.setRequestParameter(id, newvalue);
62
63 textInput.parse(context);
64
65 assertTrue("did not parse the request correctly", model.getValue().equals(newvalue));
66
67 model.setValue(value);
68 }
69
70 /***
71 * Features tested:
72 * <li> size
73 * <li> retrieving value from model
74 * <li> id
75 * <li> it registers for parsing correctly
76 * <li> renders the correct prompt
77 */
78 public void testRender() throws Exception
79 {
80 // render the component
81 textInput.render(context);
82
83 // parse the rendered HTML
84 Document doc = context.parseRenderedHTML();
85 Element element = TestUtility.findElementById(doc, id);
86
87 // check the test-data
88 assertNotNull("did not render input-element", element);
89 assertTrue("id not rendered correctly", id.equals(element.getAttribute("name")));
90 assertTrue("size not rendered correctly", ("" + size).equals(element.getAttribute("size")));
91 assertTrue("value not rendered correctly", value.equals(element.getAttribute("value")));
92 assertTrue("did not register for parsing", context.isRegisteredForParsing(textInput));
93
94 TextLabelTest.validateRendering(doc, textLabel);
95 }
96 }
This page was automatically generated by Maven