1 4 package com.tc.config.schema.dynamic; 5 6 import com.tc.config.schema.MockXmlObject; 7 import com.tc.util.TCAssertionError; 8 9 import java.math.BigInteger ; 10 11 public class IntXPathBasedConfigItemTest extends XPathBasedConfigItemTestBase { 12 13 private class SubBean extends MockXmlObject { 14 public BigInteger getBigIntegerValue() { 15 return currentValue; 16 } 17 } 18 19 private static class DefaultBean extends MockXmlObject { 20 private final BigInteger value; 21 22 public DefaultBean(BigInteger value) { 23 this.value = value; 24 } 25 26 public BigInteger getBigIntegerValue() { 27 return this.value; 28 } 29 } 30 31 private BigInteger currentValue; 32 33 protected MockXmlObject createSubBean() throws Exception { 34 return new SubBean(); 35 } 36 37 public void setUp() throws Exception { 38 super.setUp(); 39 40 this.currentValue = new BigInteger ("147"); 41 context.setReturnedHasDefaultFor(false); 42 context.setReturnedIsOptional(false); 43 } 44 45 public void testConstruction() throws Exception { 46 context.setReturnedIsOptional(true); 47 48 try { 49 new IntXPathBasedConfigItem(context, xpath); 50 fail("Didn't get TCAE on item that's optional with no default"); 51 } catch (TCAssertionError tcae) { 52 } 54 } 55 56 public void testNoDefault() throws Exception { 57 IntXPathBasedConfigItem item = new IntXPathBasedConfigItem(context, xpath); 58 59 assertEquals(147, item.getInt()); 60 assertEquals(new Integer (147), item.getObject()); 61 62 this.currentValue = new BigInteger ("-123854"); 63 64 item = new IntXPathBasedConfigItem(context, xpath); 65 assertEquals(-123854, item.getInt()); 66 assertEquals(new Integer (-123854), item.getObject()); 67 68 this.currentValue = new BigInteger ("43289058203953495739457489020092370897586768975042532"); 69 item = new IntXPathBasedConfigItem(context, xpath); 70 71 try { 72 item.getInt(); 73 fail("Didn't get TCAE on too-big value"); 74 } catch (TCAssertionError tcae) { 75 } 77 78 try { 79 item.getObject(); 80 fail("Didn't get TCAE on too-big value"); 81 } catch (TCAssertionError tcae) { 82 } 84 85 this.currentValue = new BigInteger ("-43289058203953495739457489020092370897586768975042532"); 86 item = new IntXPathBasedConfigItem(context, xpath); 87 88 try { 89 item.getInt(); 90 fail("Didn't get TCAE on too-small value"); 91 } catch (TCAssertionError tcae) { 92 } 94 95 try { 96 item.getObject(); 97 fail("Didn't get TCAE on too-small value"); 98 } catch (TCAssertionError tcae) { 99 } 101 } 102 103 public void testDefault() throws Exception { 104 context.setReturnedHasDefaultFor(true); 105 context.setReturnedDefaultFor(new DefaultBean(new BigInteger ("42"))); 106 107 this.currentValue = null; 108 IntXPathBasedConfigItem item = new IntXPathBasedConfigItem(context, xpath); 109 110 assertEquals(42, item.getInt()); 111 assertEquals(new Integer (42), item.getObject()); 112 113 this.currentValue = new BigInteger ("483290"); 114 item = new IntXPathBasedConfigItem(context, xpath); 115 116 assertEquals(483290, item.getInt()); 117 assertEquals(new Integer (483290), item.getObject()); 118 } 119 120 public void testTooBigDefault() throws Exception { 121 context.setReturnedHasDefaultFor(true); 122 context.setReturnedDefaultFor(new DefaultBean(new BigInteger ("424328904823905829058025739572230498074078"))); 123 124 try { 125 new IntXPathBasedConfigItem(context, xpath).defaultValue(); 126 fail("Didn't get TCAE on too-big default"); 127 } catch (TCAssertionError tcae) { 128 } 130 131 context.setReturnedDefaultFor(new DefaultBean(new BigInteger ("-424328904823905829058025739572230498074078"))); 132 133 try { 134 new IntXPathBasedConfigItem(context, xpath).defaultValue(); 135 fail("Didn't get TCAE on too-small default"); 136 } catch (TCAssertionError tcae) { 137 } 139 } 140 141 } 142 | Popular Tags |