KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > dynamic > IntXPathBasedConfigItemTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 JavaDoc;
10
11 public class IntXPathBasedConfigItemTest extends XPathBasedConfigItemTestBase {
12
13   private class SubBean extends MockXmlObject {
14     public BigInteger JavaDoc getBigIntegerValue() {
15       return currentValue;
16     }
17   }
18
19   private static class DefaultBean extends MockXmlObject {
20     private final BigInteger JavaDoc value;
21
22     public DefaultBean(BigInteger JavaDoc value) {
23       this.value = value;
24     }
25
26     public BigInteger JavaDoc getBigIntegerValue() {
27       return this.value;
28     }
29   }
30
31   private BigInteger JavaDoc currentValue;
32
33   protected MockXmlObject createSubBean() throws Exception JavaDoc {
34     return new SubBean();
35   }
36
37   public void setUp() throws Exception JavaDoc {
38     super.setUp();
39
40     this.currentValue = new BigInteger JavaDoc("147");
41     context.setReturnedHasDefaultFor(false);
42     context.setReturnedIsOptional(false);
43   }
44
45   public void testConstruction() throws Exception JavaDoc {
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       // ok
53
}
54   }
55
56   public void testNoDefault() throws Exception JavaDoc {
57     IntXPathBasedConfigItem item = new IntXPathBasedConfigItem(context, xpath);
58
59     assertEquals(147, item.getInt());
60     assertEquals(new Integer JavaDoc(147), item.getObject());
61
62     this.currentValue = new BigInteger JavaDoc("-123854");
63
64     item = new IntXPathBasedConfigItem(context, xpath);
65     assertEquals(-123854, item.getInt());
66     assertEquals(new Integer JavaDoc(-123854), item.getObject());
67
68     this.currentValue = new BigInteger JavaDoc("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       // ok
76
}
77
78     try {
79       item.getObject();
80       fail("Didn't get TCAE on too-big value");
81     } catch (TCAssertionError tcae) {
82       // ok
83
}
84
85     this.currentValue = new BigInteger JavaDoc("-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       // ok
93
}
94
95     try {
96       item.getObject();
97       fail("Didn't get TCAE on too-small value");
98     } catch (TCAssertionError tcae) {
99       // ok
100
}
101   }
102
103   public void testDefault() throws Exception JavaDoc {
104     context.setReturnedHasDefaultFor(true);
105     context.setReturnedDefaultFor(new DefaultBean(new BigInteger JavaDoc("42")));
106
107     this.currentValue = null;
108     IntXPathBasedConfigItem item = new IntXPathBasedConfigItem(context, xpath);
109
110     assertEquals(42, item.getInt());
111     assertEquals(new Integer JavaDoc(42), item.getObject());
112
113     this.currentValue = new BigInteger JavaDoc("483290");
114     item = new IntXPathBasedConfigItem(context, xpath);
115
116     assertEquals(483290, item.getInt());
117     assertEquals(new Integer JavaDoc(483290), item.getObject());
118   }
119
120   public void testTooBigDefault() throws Exception JavaDoc {
121     context.setReturnedHasDefaultFor(true);
122     context.setReturnedDefaultFor(new DefaultBean(new BigInteger JavaDoc("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       // ok
129
}
130
131     context.setReturnedDefaultFor(new DefaultBean(new BigInteger JavaDoc("-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       // ok
138
}
139   }
140
141 }
142
Popular Tags