|
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
|
2
|
protected void setUp() throws Exception
|
|
37
|
|
{
|
|
38
|
2
|
super.setUp();
|
|
39
|
|
|
|
40
|
|
// create the instances
|
|
41
|
2
|
textInput = new TextInput();
|
|
42
|
2
|
model = new BasicValueModel();
|
|
43
|
2
|
textLabel = new TextLabel();
|
|
44
|
2
|
textLabel.setId("labelID");
|
|
45
|
|
|
|
46
|
|
// setup the test-data
|
|
47
|
2
|
textInput.setId(id);
|
|
48
|
2
|
textInput.setSize(size);
|
|
49
|
2
|
model.setValue(value);
|
|
50
|
2
|
textInput.setModel(model);
|
|
51
|
2
|
textLabel.setLabel(prompt);
|
|
52
|
2
|
textInput.setPrompt(textLabel);
|
|
53
|
|
}
|
|
54
|
|
|
|
55
|
|
/**
|
|
56
|
|
* Features tested:
|
|
57
|
|
* <li> update of model according to parse of request
|
|
58
|
|
*/
|
|
59
|
1
|
public void testParse() throws Exception
|
|
60
|
|
{
|
|
61
|
1
|
context.setRequestParameter(id, newvalue);
|
|
62
|
|
|
|
63
|
1
|
textInput.parse(context);
|
|
64
|
|
|
|
65
|
1
|
assertTrue("did not parse the request correctly", model.getValue().equals(newvalue));
|
|
66
|
|
|
|
67
|
1
|
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
|
1
|
public void testRender() throws Exception
|
|
79
|
|
{
|
|
80
|
|
// render the component
|
|
81
|
1
|
textInput.render(context);
|
|
82
|
|
|
|
83
|
|
// parse the rendered HTML
|
|
84
|
1
|
Document doc = context.parseRenderedHTML();
|
|
85
|
1
|
Element element = TestUtility.findElementById(doc, id);
|
|
86
|
|
|
|
87
|
|
// check the test-data
|
|
88
|
1
|
assertNotNull("did not render input-element", element);
|
|
89
|
1
|
assertTrue("id not rendered correctly", id.equals(element.getAttribute("name")));
|
|
90
|
1
|
assertTrue("size not rendered correctly", ("" + size).equals(element.getAttribute("size")));
|
|
91
|
1
|
assertTrue("value not rendered correctly", value.equals(element.getAttribute("value")));
|
|
92
|
1
|
assertTrue("did not register for parsing", context.isRegisteredForParsing(textInput));
|
|
93
|
|
|
|
94
|
1
|
TextLabelTest.validateRendering(doc, textLabel);
|
|
95
|
|
}
|
|
96
|
|
}
|
|
97
|
|
|