File: DecimalDeserializerTest.java

package info (click to toggle)
xml-soap 2.2-6
  • links: PTS
  • area: contrib
  • in suites: woody
  • size: 2,492 kB
  • ctags: 1,934
  • sloc: java: 15,895; xml: 740; jsp: 580; cpp: 561; sh: 235; makefile: 127
file content (83 lines) | stat: -rw-r--r-- 2,463 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package test.encoding.soapenc;

import javax.xml.parsers.*;  // JAXP interfaces
import org.w3c.dom.*;
import org.apache.soap.util.Bean;
import org.apache.soap.util.xml.Deserializer;
import java.io.ByteArrayInputStream;
import org.apache.soap.encoding.soapenc.DecimalDeserializer;
import java.math.BigDecimal;

import junit.framework.TestCase;

/**
 * This decimal deserializer test provides basic test
 * coverage for verifying that decimal numbers are
 * deserialized correctly.
 *
 * @author Sam Ruby (rubys@us.ibm.com)
 * @author Jim Stearns (Jim_Stearns@hp.com)
 */
public class DecimalDeserializerTest extends TestCase
{
    private Deserializer objectToTest;

    public DecimalDeserializerTest(String name)
    {
        super(name);
        objectToTest = new DecimalDeserializer();
    }

    private Node domFromXMLString(String str) throws Exception
    {
        DocumentBuilderFactory  factory = 
            DocumentBuilderFactory.newInstance();
        DocumentBuilder         builder;
        Document                document;
        builder = factory.newDocumentBuilder();

        ByteArrayInputStream bais = new ByteArrayInputStream(str.getBytes());
        document = builder.parse(bais);
        return document.getDocumentElement();
    }

    private Bean runUnmarshall(String value) throws Exception
    {
        Node myNode = domFromXMLString(
            "<value>" + value + "</value>");
        return objectToTest.unmarshall("dontCare", /* inScopeEncStyle */
                null,       /* QName: dontcare */
                myNode,
                null,       /* XMLJavaMappingRegistry: dontcare */
                null);      /* SOAPContext: dontcare */
    }

    public void testGoodPositiveDecimal() throws Exception
    {
        Bean bean = runUnmarshall("1.1");
        assertEquals(bean.value, new BigDecimal("1.1"));
    }

    public void testGoodZeroDecimal() throws Exception
    {
        Bean bean = runUnmarshall("0");
        assertEquals(bean.value, new BigDecimal("0"));
    }

    public void testGoodNegativeDecimal() throws Exception
    {
        Bean bean = runUnmarshall("-3.1");
        assertEquals(bean.value, new BigDecimal("-3.1"));
    }

    public void testBadDecimal() throws Exception
    {
        try {
            runUnmarshall("InvalidDecimal");
            fail("Didn't get expected NumberFormatException");
        } catch (NumberFormatException nfe) {
            return;
        }
    }

}