Debian Codegraph @

test/types/TestUnsignedLong.java

raw
1 /*
2 * Copyright 2001-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package test.types;
18
19 import junit.framework.TestCase;
20 import org.apache.axis.types.UnsignedLong;
21
22 import java.math.BigInteger;
23
24 /**
25 * Test validation of types.UnsignedLong
26 */
27 public class TestUnsignedLong extends TestCase {
28
29 public TestUnsignedLong(String name) {
30 super(name);
31 }
32
33 /**
34 * Run a failure test. value should be invalid.
35 */
36 private void runFailTest(BigInteger value) throws Exception {
37 UnsignedLong oUnsignedLong = null;
38 try {
39 oUnsignedLong = new UnsignedLong(value);
40 } catch (Exception e) { // catch the validation exception
41 }
42 // object is not iNstantiated on bad data value
43 assertNull("validation restriction failed [" +
44 String.valueOf(value) + "]. did not restrict bad value.",
45 oUnsignedLong);
46 }
47
48 /**
49 * Run a successful test. value should be valid. String should come out
50 * as expected.
51 */
52 private void runPassTest(BigInteger value, String strValue)
53 throws Exception {
54 UnsignedLong oUnsignedLong = null;
55 try {
56 oUnsignedLong = new UnsignedLong(value);
57 } catch (Exception e) { // catch the validation exception
58 // error!
59 assertTrue("validation error thrown and it shouldn't be", false);
60 }
61 assertEquals("unsigned long not equal: " +
62 String.valueOf(value), strValue, oUnsignedLong.toString());
63 }
64
65 /**
66 * Test that a positive value succeeeds
67 */
68 public void testPositiveValue() throws Exception {
69 runPassTest(new BigInteger("100"), "100");
70 }
71
72 /**
73 * Test that a negative number fails
74 */
75 public void testNegativeValue() throws Exception {
76 runFailTest(new BigInteger("-100"));
77 }
78
79 /**
80 * Test Max unsigned long
81 */
82 public void testMaxInclusive() throws Exception {
83 runPassTest(new BigInteger("18446744073709551615"),
84 "18446744073709551615");
85 }
86
87 public void testTooLarge() throws Exception {
88 runFailTest(new BigInteger("184467440737095516152"));
89 }
90
91 /**
92 * Test that a number at MinInclusive succeeds
93 */
94 public void testMinExclusive() throws Exception {
95 runPassTest(BigInteger.ZERO, "0");
96 }
97 }