1 package com.tonbeller.wcf.convert; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 6 import org.w3c.dom.Document ; 7 import org.w3c.dom.Element ; 8 9 import com.tonbeller.wcf.ui.ListBox1; 10 import com.tonbeller.wcf.ui.ListItem; 11 12 public class SelectSingleConverterTest extends ConverterTestBase { 13 Document doc; 14 Element lb; 15 Element i1; 16 Element i2; 17 Element i3; 18 Map map; 19 20 public void testSelection() throws Exception { 21 ListBox1.setSelection(lb, i2); 22 Element 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 [] { "x" }); 31 map.put("lb", new String [] { "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 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 55 public SelectSingleConverterTest(String arg0) { 56 super(arg0); 57 } 58 59 public static void main(String [] args) { 60 junit.textui.TestRunner.run(SelectSingleConverterTest.class); 61 } 62 63 66 protected void setUp() throws Exception { 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 (); 74 } 75 76 } 77 | Popular Tags |