|
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 junit.framework.Assert;
|
|
12
|
|
import com.tirsen.angkor.*;
|
|
13
|
|
import com.tirsen.angkor.test.unit.AbstractPipelineTest;
|
|
14
|
|
import com.tirsen.angkor.test.unit.TestUtility;
|
|
15
|
|
import com.tirsen.angkor.widget.*;
|
|
16
|
|
import org.w3c.dom.Element;
|
|
17
|
|
import org.w3c.dom.Document;
|
|
18
|
|
|
|
19
|
|
/**
|
|
20
|
|
* TODO document MenuTest
|
|
21
|
|
*
|
|
22
|
|
* <!-- $Id: MenuTest.java,v 1.1 2002/10/07 19:49:23 tirsen Exp $ -->
|
|
23
|
|
* <!-- $Author: tirsen $ -->
|
|
24
|
|
*
|
|
25
|
|
* @author Jon Tirsén (tirsen@users.sourceforge.net)
|
|
26
|
|
* @version $Revision: 1.1 $
|
|
27
|
|
*/
|
|
28
|
|
public class MenuTest extends AbstractPipelineTest
|
|
29
|
|
{
|
|
30
|
|
public class ATestController extends Controller
|
|
31
|
|
{
|
|
32
|
1
|
public ATestController(Application application)
|
|
33
|
|
{
|
|
34
|
1
|
super(application);
|
|
35
|
|
}
|
|
36
|
|
|
|
37
|
1
|
public View createView()
|
|
38
|
|
{
|
|
39
|
1
|
TextLabel label = new TextLabel();
|
|
40
|
1
|
label.setLabel("testar bara lite A");
|
|
41
|
1
|
return label;
|
|
42
|
|
}
|
|
43
|
|
|
|
44
|
1
|
public String getDisplayName()
|
|
45
|
|
{
|
|
46
|
1
|
return "a";
|
|
47
|
|
}
|
|
48
|
|
}
|
|
49
|
|
|
|
50
|
|
public class BTestController extends Controller
|
|
51
|
|
{
|
|
52
|
1
|
public BTestController(Application application)
|
|
53
|
|
{
|
|
54
|
1
|
super(application);
|
|
55
|
|
}
|
|
56
|
|
|
|
57
|
1
|
public View createView()
|
|
58
|
|
{
|
|
59
|
1
|
TextLabel label = new TextLabel();
|
|
60
|
1
|
label.setLabel("testar bara lite B");
|
|
61
|
1
|
return label;
|
|
62
|
|
}
|
|
63
|
|
|
|
64
|
1
|
public String getDisplayName()
|
|
65
|
|
{
|
|
66
|
1
|
return "b";
|
|
67
|
|
}
|
|
68
|
|
}
|
|
69
|
|
|
|
70
|
1
|
public void testMenu() throws Exception
|
|
71
|
|
{
|
|
72
|
1
|
Application application = new Application();
|
|
73
|
1
|
ATestController a = new ATestController(application);
|
|
74
|
1
|
BTestController b = new BTestController(application);
|
|
75
|
1
|
ViewLink link = new ViewLink(a);
|
|
76
|
1
|
Menu menu = new Menu();
|
|
77
|
1
|
MenuItem itemA = new MenuItem(new MenuItem.GotoAction(link, a));
|
|
78
|
1
|
menu.add(itemA);
|
|
79
|
1
|
MenuItem itemB = new MenuItem(new MenuItem.GotoAction(link, b));
|
|
80
|
1
|
menu.add(itemB);
|
|
81
|
|
|
|
82
|
1
|
Section section = new Section();
|
|
83
|
1
|
section.add(new SectionLine(menu));
|
|
84
|
1
|
section.add(new SectionLine(link));
|
|
85
|
|
|
|
86
|
1
|
section.render(context);
|
|
87
|
|
|
|
88
|
1
|
Document doc = context.parseRenderedHTML();
|
|
89
|
1
|
TestUtility.testComponent(doc, menu);
|
|
90
|
1
|
Element aElement = TestUtility.testComponent(doc, itemA);
|
|
91
|
1
|
Element bElement = TestUtility.testComponent(doc, itemB);
|
|
92
|
|
//TestUtility.testComponent(doc, (Component) a.getView());
|
|
93
|
1
|
assertSame("the link is not pointing at the correct factory", link.getTarget(), a);
|
|
94
|
1
|
assertTrue("a is shown but not disabled", !itemA.isEnabled());
|
|
95
|
1
|
assertTrue("a is disabled but still rendered as a link", !"A".equals(aElement.getTagName().toUpperCase()));
|
|
96
|
1
|
assertTrue("b is shown but not enabled", itemB.isEnabled());
|
|
97
|
1
|
assertTrue("b is enabled but not rendered as a link", "A".equals(bElement.getTagName().toUpperCase()));
|
|
98
|
|
|
|
99
|
|
// click the b item
|
|
100
|
1
|
context.setRequestParameter(itemB.getId(), "clicked");
|
|
101
|
1
|
itemA.parse(context);
|
|
102
|
1
|
itemB.parse(context);
|
|
103
|
|
|
|
104
|
1
|
context.getEventQueue().processEvents(application);
|
|
105
|
|
|
|
106
|
1
|
assertSame("the link is not pointing at the correct factory", link.getTarget(), b);
|
|
107
|
|
|
|
108
|
1
|
section.render(context);
|
|
109
|
1
|
doc = context.parseRenderedHTML();
|
|
110
|
|
//TestUtility.testComponent(doc, (Component) b.getView());
|
|
111
|
|
}
|
|
112
|
|
}
|
|
113
|
|
|