|
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 com.tirsen.angkor.widget.TextLabel;
|
|
11
|
|
import com.tirsen.angkor.widget.BasicValueModel;
|
|
12
|
|
import com.tirsen.angkor.test.unit.*;
|
|
13
|
|
import com.tirsen.angkor.test.unit.mock.MockRenderContext;
|
|
14
|
|
import junit.framework.TestCase;
|
|
15
|
|
import org.w3c.tidy.Tidy;
|
|
16
|
|
import org.w3c.dom.Document;
|
|
17
|
|
import org.w3c.dom.Element;
|
|
18
|
|
|
|
19
|
|
/**
|
|
20
|
|
* Unit tests for {@link com.tirsen.angkor.widget.TextLabel} widget.
|
|
21
|
|
*
|
|
22
|
|
* @author $Author: tirsen $
|
|
23
|
|
* @version $Revision: 1.2 $
|
|
24
|
|
* <BR>
|
|
25
|
|
* $Id: TextLabelTest.java,v 1.2 2002/10/13 13:37:27 tirsen Exp $
|
|
26
|
|
*/
|
|
27
|
|
public class TextLabelTest extends AbstractPipelineTest
|
|
28
|
|
{
|
|
29
|
|
private TextLabel textLabel;
|
|
30
|
|
|
|
31
|
|
//private int size = 20;
|
|
32
|
|
private String id = "myid";
|
|
33
|
|
private String value = "myvalue";
|
|
34
|
|
private BasicValueModel model;
|
|
35
|
|
private MockRenderContext context;
|
|
36
|
|
|
|
37
|
1
|
protected void setUp() throws Exception
|
|
38
|
|
{
|
|
39
|
1
|
super.setUp();
|
|
40
|
|
|
|
41
|
|
// create the instances
|
|
42
|
1
|
context = new MockRenderContext();
|
|
43
|
1
|
model = new BasicValueModel();
|
|
44
|
1
|
textLabel = new TextLabel();
|
|
45
|
|
|
|
46
|
|
// setup the test-data
|
|
47
|
1
|
textLabel.setId(id);
|
|
48
|
1
|
model.setValue(value);
|
|
49
|
1
|
textLabel.setModel(model);
|
|
50
|
|
}
|
|
51
|
|
|
|
52
|
|
/**
|
|
53
|
|
* Tests the following functionality
|
|
54
|
|
* <li> fetches data from one model and displays it correctly.
|
|
55
|
|
*/
|
|
56
|
1
|
public void testRender() throws Exception
|
|
57
|
|
{
|
|
58
|
|
// render the component
|
|
59
|
1
|
textLabel.render(context);
|
|
60
|
|
|
|
61
|
|
// parse the rendered HTML
|
|
62
|
1
|
Tidy tidy = new Tidy();
|
|
63
|
1
|
Document doc = tidy.parseDOM(context.getRenderedInputStream(), System.out);
|
|
64
|
|
|
|
65
|
1
|
validateRendering(doc, textLabel);
|
|
66
|
|
}
|
|
67
|
|
|
|
68
|
2
|
public static void validateRendering(Document doc, TextLabel label)
|
|
69
|
|
{
|
|
70
|
2
|
Element element = TestUtility.findElementById(doc, label.getId());
|
|
71
|
|
|
|
72
|
|
// check the test-data
|
|
73
|
2
|
assertNotNull("did not render text-label", element);
|
|
74
|
2
|
assertTrue("did not display the correct text", label.getFormattedText().equals(element.getFirstChild().getNodeValue()));
|
|
75
|
|
}
|
|
76
|
|
}
|
|
77
|
|
|