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.CheckBox; 10 import com.tonbeller.wcf.ui.Item; 11 12 15 public class BooleanConverterTest extends ConverterTestBase { 16 Document doc; 17 Map map; 18 Element cb1; 19 Element cb2; 20 Element rb1; 21 Element rb2; 22 23 27 public BooleanConverterTest(String arg0) { 28 super(arg0); 29 } 30 31 34 public void testConvertFormatterMapElementObject() throws Exception { 35 bean.setBooleanValue(false); 36 map.put("cb1", new String [] {"x"}); 37 conv.validate(map, null, doc, bean); 38 assertTrue(!bean.isBooleanValue()); 39 map.put("cb1.valid", new String [] {"x"}); 40 conv.validate(map, null, doc, bean); 41 assertTrue(bean.isBooleanValue()); 42 map.remove("cb1"); 43 conv.validate(map, null, doc, bean); 44 assertTrue(!bean.isBooleanValue()); 45 } 46 47 public void testMissingModelReference() throws Exception { 48 CheckBox.setModelReference(cb1, ""); 49 bean.setBooleanValue(false); 50 map.put("cb1", new String [] {"x"}); 51 map.put("cb1.valid", new String [] {"x"}); 52 conv.validate(map, null, doc, bean); 53 assertTrue(Item.isSelected(cb1)); 54 assertTrue(!bean.isBooleanValue()); 55 } 56 57 58 public void testMissingBean() throws Exception { 59 Item.setSelected(cb1, false); 60 assertTrue(!Item.isSelected(cb1)); 61 map.put("cb1", new String [] {"x"}); 62 conv.validate(map, null, doc, null); 63 assertTrue(!Item.isSelected(cb1)); 64 map.put("cb1.valid", new String [] {"x"}); 65 conv.validate(map, null, doc, null); 66 assertTrue(Item.isSelected(cb1)); 67 } 68 69 72 public void testConvertFormatterObjectElement() throws Exception { 73 bean.setBooleanValue(true); 74 conv.revert(bean, doc); 75 assertTrue(Item.isSelected(cb1)); 76 bean.setBooleanValue(false); 77 conv.revert(bean, cb1); 78 assertTrue(!Item.isSelected(cb1)); 79 } 80 81 82 83 86 protected void setUp() throws Exception { 87 super.setUp(); 88 doc = load("BooleanConverterTest.xml"); 89 map = new HashMap (); 90 cb1 = getElement(doc, "//checkBox[@id='cb1']"); 91 cb2 = getElement(doc, "//checkBox[@id='cb2']"); 92 rb1 = getElement(doc, "//radioButton[@id='rb1']"); 93 rb2 = getElement(doc, "//radioButton[@id='rb2']"); 94 } 95 96 } 97 | Popular Tags |