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 public ATestController(Application application)
33 {
34 super(application);
35 }
36
37 public View createView()
38 {
39 TextLabel label = new TextLabel();
40 label.setLabel("testar bara lite A");
41 return label;
42 }
43
44 public String getDisplayName()
45 {
46 return "a";
47 }
48 }
49
50 public class BTestController extends Controller
51 {
52 public BTestController(Application application)
53 {
54 super(application);
55 }
56
57 public View createView()
58 {
59 TextLabel label = new TextLabel();
60 label.setLabel("testar bara lite B");
61 return label;
62 }
63
64 public String getDisplayName()
65 {
66 return "b";
67 }
68 }
69
70 public void testMenu() throws Exception
71 {
72 Application application = new Application();
73 ATestController a = new ATestController(application);
74 BTestController b = new BTestController(application);
75 ViewLink link = new ViewLink(a);
76 Menu menu = new Menu();
77 MenuItem itemA = new MenuItem(new MenuItem.GotoAction(link, a));
78 menu.add(itemA);
79 MenuItem itemB = new MenuItem(new MenuItem.GotoAction(link, b));
80 menu.add(itemB);
81
82 Section section = new Section();
83 section.add(new SectionLine(menu));
84 section.add(new SectionLine(link));
85
86 section.render(context);
87
88 Document doc = context.parseRenderedHTML();
89 TestUtility.testComponent(doc, menu);
90 Element aElement = TestUtility.testComponent(doc, itemA);
91 Element bElement = TestUtility.testComponent(doc, itemB);
92 //TestUtility.testComponent(doc, (Component) a.getView());
93 assertSame("the link is not pointing at the correct factory", link.getTarget(), a);
94 assertTrue("a is shown but not disabled", !itemA.isEnabled());
95 assertTrue("a is disabled but still rendered as a link", !"A".equals(aElement.getTagName().toUpperCase()));
96 assertTrue("b is shown but not enabled", itemB.isEnabled());
97 assertTrue("b is enabled but not rendered as a link", "A".equals(bElement.getTagName().toUpperCase()));
98
99 // click the b item
100 context.setRequestParameter(itemB.getId(), "clicked");
101 itemA.parse(context);
102 itemB.parse(context);
103
104 context.getEventQueue().processEvents(application);
105
106 assertSame("the link is not pointing at the correct factory", link.getTarget(), b);
107
108 section.render(context);
109 doc = context.parseRenderedHTML();
110 //TestUtility.testComponent(doc, (Component) b.getView());
111 }
112 }
This page was automatically generated by Maven