01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.xs.bindings;
17:
18: import java.math.BigInteger;
19:
20: import javax.xml.namespace.QName;
21:
22: import org.geotools.xs.TestSchema;
23:
24: public class XSNegativeIntegerStrategyTest extends TestSchema {
25: /**
26: * negativeInteger has a lexical representation consisting of a negative
27: * sign ("-") followed by a finite-length sequence of decimal digits
28: * (#x30-#x39).
29: *
30: * For example: -1, -12678967543233, -100000.
31: * @throws Exception
32: *
33: */
34: public void validateValues(String text, Number expected)
35: throws Exception {
36: Object value = new BigInteger(text.trim());
37:
38: Object result = strategy.parse(element(text, qname), value);
39:
40: if (!(result instanceof BigInteger) && result instanceof Number) {
41: result = BigInteger.valueOf(((Number) result).longValue());
42: }
43:
44: assertEquals(integer(expected), integer(result));
45: }
46:
47: public BigInteger integer(Object value) {
48: return (value instanceof BigInteger) ? ((BigInteger) value)
49: : BigInteger.valueOf(((Number) value).longValue());
50: }
51:
52: public Number number(String number) {
53: return BigInteger.valueOf(Integer.valueOf(number).longValue());
54: }
55:
56: /*
57: * Test method for 'org.geotools.xs.strategies.XSNegativeIntegerStrategy.parse(Element, Node[], Object)'
58: */
59: public void testParse() throws Exception {
60: validateValues("-1", new BigInteger("-1"));
61: validateValues("-12678967543233", new BigInteger(
62: "-12678967543233"));
63: validateValues("-100000", new BigInteger("-100000"));
64: }
65:
66: protected QName getQName() {
67: return XS.NEGATIVEINTEGER;
68: }
69: }
|