01: /*
02: * Copyright 2004,2005 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package org.apache.axis2.schema.decimal;
17:
18: import junit.framework.TestCase;
19: import org.tempuri.boolean1.GetHistoricNavResponse;
20: import org.tempuri.boolean1.ArrayOfDecimal;
21: import org.apache.axiom.om.OMElement;
22: import org.apache.axiom.om.OMAbstractFactory;
23: import org.apache.axiom.om.util.StAXUtils;
24: import org.apache.axis2.databinding.ADBException;
25: import org.apache.axis2.databinding.types.Duration;
26:
27: import javax.xml.stream.XMLStreamException;
28: import javax.xml.stream.XMLStreamReader;
29: import java.math.BigDecimal;
30: import java.io.ByteArrayInputStream;
31: import java.util.Calendar;
32:
33: public class DecimalTest extends TestCase {
34:
35: public void testDecimal() {
36: GetHistoricNavResponse getHistoricNavResponse = new GetHistoricNavResponse();
37: ArrayOfDecimal arrayOfDecimal = new ArrayOfDecimal();
38: getHistoricNavResponse.setOut(arrayOfDecimal);
39: arrayOfDecimal.addDecimal(null);
40: arrayOfDecimal.addDecimal(null);
41: arrayOfDecimal.addDecimal(new BigDecimal("111.38"));
42: arrayOfDecimal.addDecimal(new BigDecimal("111.38"));
43: arrayOfDecimal.addDecimal(new BigDecimal("111.38"));
44: arrayOfDecimal.addDecimal(new BigDecimal("111.54"));
45:
46: try {
47: OMElement omElement = getHistoricNavResponse.getOMElement(
48: GetHistoricNavResponse.MY_QNAME, OMAbstractFactory
49: .getOMFactory());
50: String omElementString = omElement.toStringWithConsume();
51: System.out.println("OM String ==> " + omElementString);
52: XMLStreamReader xmlReader = StAXUtils
53: .createXMLStreamReader(new ByteArrayInputStream(
54: omElementString.getBytes()));
55: GetHistoricNavResponse result = GetHistoricNavResponse.Factory
56: .parse(xmlReader);
57: assertEquals(result.getOut().getDecimal()[0], null);
58: assertEquals(result.getOut().getDecimal()[1], null);
59: assertEquals(result.getOut().getDecimal()[2].toString(),
60: "111.38");
61: assertEquals(result.getOut().getDecimal()[3].toString(),
62: "111.38");
63: assertEquals(result.getOut().getDecimal()[4].toString(),
64: "111.38");
65: assertEquals(result.getOut().getDecimal()[5].toString(),
66: "111.54");
67: } catch (ADBException e) {
68: fail();
69: } catch (XMLStreamException e) {
70: fail();
71: } catch (Exception e) {
72: fail();
73: }
74: }
75:
76: public void testDuration() {
77: Calendar calendar = Calendar.getInstance();
78: Duration duration = new Duration(false, 0, 0, 23, 12, 24, 23.45);
79: System.out.println("Duration ==> " + duration.toString());
80: // P2007Y5M30DT8H40M55.87S
81: // "\\-?P(\\d*D)?(T(\\d*H)?(\\d*M)?(\\d*(\\.\\d*)?S)?)?"
82: if (duration.toString().matches(
83: "\\-?P(\\d*D)?(T(\\d*H)?(\\d*M)?(\\d*(\\.\\d*)?S)?)?")) {
84: System.out.println("Matches");
85: }
86: }
87: }
|