KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > convert > SelectSingleConverterTest


1 package com.tonbeller.wcf.convert;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import org.w3c.dom.Document JavaDoc;
7 import org.w3c.dom.Element JavaDoc;
8
9 import com.tonbeller.wcf.ui.ListBox1;
10 import com.tonbeller.wcf.ui.ListItem;
11
12 public class SelectSingleConverterTest extends ConverterTestBase {
13   Document JavaDoc doc;
14   Element JavaDoc lb;
15   Element JavaDoc i1;
16   Element JavaDoc i2;
17   Element JavaDoc i3;
18   Map JavaDoc map;
19
20   public void testSelection() throws Exception JavaDoc {
21     ListBox1.setSelection(lb, i2);
22     Element JavaDoc selection = ListBox1.getSelectedItem(lb);
23     assertEquals(selection, i2);
24     assertTrue(!ListItem.isSelected(i1));
25     assertTrue(ListItem.isSelected(i2));
26     assertTrue(!ListItem.isSelected(i3));
27   }
28
29   public void testUpdateBean() throws ConvertException {
30     map.put("lb.valid", new String JavaDoc[] { "x" });
31     map.put("lb", new String JavaDoc[] { "i3" });
32     conv.validate(map, null, doc, bean);
33     int value = bean.getIntValue();
34     assertTrue(!ListItem.isSelected(i1));
35     assertTrue(!ListItem.isSelected(i2));
36     assertTrue(ListItem.isSelected(i3));
37     assertEquals(3, value);
38   }
39
40   public void testUpdateDom() throws ConvertException {
41     bean.setIntValue(2);
42     conv.revert(bean, doc);
43     Element JavaDoc item = ListBox1.getSelectedItem(lb);
44     assertTrue(item == i2);
45     assertTrue(!ListItem.isSelected(i1));
46     assertTrue(ListItem.isSelected(i2));
47     assertTrue(!ListItem.isSelected(i3));
48   }
49
50
51   /**
52    * Constructor for SelectMultipleConverterTest.
53    * @param arg0
54    */

55   public SelectSingleConverterTest(String JavaDoc arg0) {
56     super(arg0);
57   }
58
59   public static void main(String JavaDoc[] args) {
60     junit.textui.TestRunner.run(SelectSingleConverterTest.class);
61   }
62
63   /**
64    * @see junit.framework.TestCase#setUp()
65    */

66   protected void setUp() throws Exception JavaDoc {
67     super.setUp();
68     doc = load("ListBox1.xml");
69     lb = getElement(doc, "//listBox1");
70     i1 = getElement(doc, "//listItem[@id='i1']");
71     i2 = getElement(doc, "//listItem[@id='i2']");
72     i3 = getElement(doc, "//listItem[@id='i3']");
73     map = new HashMap JavaDoc();
74   }
75
76 }
77
Popular Tags