FileDocCategorySizeDatePackage
TestDeser2001.javaAPI DocApache Axis 1.415504Sat Apr 22 18:57:26 BST 2006test.encoding

TestDeser2001

public class TestDeser2001 extends TestDeser
Test deserialization of SOAP responses

Fields Summary
private static final int
MILLISECONDS_IN_MINUTE
private static final int
MILLISECONDS_IN_HOUR
Constructors Summary
public TestDeser2001(String name)

        super(name, Constants.URI_2001_SCHEMA_XSI,
                    Constants.URI_2001_SCHEMA_XSD);
    
Methods Summary
public voidNotestListTimeZones()
this isnt a test, it is here to list timezones

        String ids[] = TimeZone.getAvailableIDs();
        for (int i = 9; i < ids.length; i++) {
            System.out.println(ids[i]);
        }
    
public voidNotestTimeLocal()
test local time costs

throws
Exception

        deserializeCalendar(TimeZone.getDefault());
    
private java.lang.StringcalcGMTOffset(java.util.Calendar cal)
calculate the offset from GMT of the current time zone. If the underlying time zone of the calendar contains historical summer time information, the offset will be corrected for summertime if the date of the calendar is a summertime date

param
cal
return
an offset string such as +3:00 or -2:30. GMT is returned as -00:00


                                                                 
        
        int msecOffset = cal.get(Calendar.ZONE_OFFSET) +
                cal.get(Calendar.DST_OFFSET);
        int hourOffset = Math.abs(msecOffset / MILLISECONDS_IN_HOUR);
        String offsetString = msecOffset > 0 ? "+" : "-";
        offsetString += hourOffset >= 10 ? "" + hourOffset : "0" + hourOffset;
        offsetString += ":";
        int minOffset = Math.abs(msecOffset % MILLISECONDS_IN_HOUR) / MILLISECONDS_IN_MINUTE;
        if (minOffset == 0) {
            offsetString += "00";
        }
        else {
            offsetString += minOffset >= 10 ? "" + minOffset : "0" + minOffset;
        }
        return offsetString;
    
private voiddeserializeCalendar(java.util.TimeZone tz)

        deserializeCalendar(2004, 1, 1, tz);
        deserializeCalendar(2004, 7, 1, tz);
    
private voiddeserializeCalendar(int year, int month, int day, java.util.TimeZone tz)

        Calendar date = Calendar.getInstance();
        date.set(Calendar.YEAR, year);
        date.set(Calendar.MONTH, month);
        date.set(Calendar.DAY_OF_MONTH, day);
        date.set(Calendar.HOUR_OF_DAY, 12);
        date.set(Calendar.MINUTE, 01);
        date.set(Calendar.SECOND, 30);
        date.set(Calendar.MILLISECOND, 150);
        date.setTimeZone(tz);
        Time time = new Time(date);
        String offset = calcGMTOffset(date);
        //diagnostics string
        String comment=" [time="+time.toString()+"; tz="+tz.getDisplayName()
                +"; offset="+offset+"]";

        deserialize("<result xsi:type=\"xsd:time\">" +
                       "12:01:30.150" + offset +
                     "</result>",
                     time,
                    false,
                    comment);
    
public static voidmain()

        TestDeser2001 deser=new TestDeser2001("");
        deser.testTimeUKWinter();
    
public voidtestAnyURI()

        org.apache.axis.types.URI uri = new URI("urn:this-is-a-test");
        deserialize("<result xsi:type=\"xsd:anyURI\">urn:this-is-a-test</result>",
                     uri);
        uri = new URI("http", "www.macromedia.com", "/testing", "query=1", null);
        deserialize("<result xsi:type=\"xsd:anyURI\">http://www.macromedia.com/testing?query=1</result>",
                     uri);
    
public voidtestArrayWithNilInt()

        ArrayList list = new ArrayList(4);
        list.add(new Integer(1));
        list.add(null);
        list.add(new Integer(3));
        deserialize("<result xsi:type=\"soapenc:Array\" " +
                            "soapenc:arrayType=\"xsd:int[3]\"> " +
                       "<item xsi:type=\"xsd:int\">1</item>" +
                       "<item xsi:nil=\"true\"/>" +
                       "<item xsi:type=\"xsd:int\">3</item>" +
                    "</result>",
                    list, true);
    
public voidtestArrayWithNilString()

        ArrayList list = new ArrayList(4);
        list.add("abc");
        list.add(null);
        list.add("def");
        deserialize("<result xsi:type=\"soapenc:Array\" " +
                            "soapenc:arrayType=\"xsd:string[3]\"> " +
                       "<item xsi:type=\"xsd:string\">abc</item>" +
                       "<item xsi:nil=\"true\"/>" +
                       "<item xsi:type=\"xsd:string\">def</item>" +
                    "</result>",
                    list, true);
    
public voidtestBase64()

        deserialize("<result xsi:type=\"xsd:base64Binary\">QmFzZTY0</result>",
                    "Base64".getBytes());
    
public voidtestBase64Null()

        deserialize("<result xsi:type=\"xsd:base64Binary\"></result>",
                    new byte[0]);
    
public voidtestDateTZ()

        Calendar date = Calendar.getInstance();
        date.set(1999, 04, 31, 0, 0, 0);
        date.set(Calendar.MILLISECOND,0);
        deserialize("<result xsi:type=\"xsd:date\">" +
                       "1999-05-31" +
                     "</result>",
                     date.getTime());
    
public voidtestDateTimeTZ()

        Calendar date = Calendar.getInstance();
        date.set(1999,04,31,12,01,30);
        date.set(Calendar.MILLISECOND,150);
        deserialize("<result xsi:type=\"xsd:dateTime\">" +
                       "1999-05-31T12:01:30.150" + calcGMTOffset(date) +
                     "</result>",
                     date);
    
public voidtestDateTimeZ()

        Calendar date = Calendar.getInstance();
        date.set(1999,04,31,12,01,30);
        date.setTimeZone(TimeZone.getTimeZone("GMT"));
        date.set(Calendar.MILLISECOND,150);
        deserialize("<result xsi:type=\"xsd:dateTime\">" +
                       "1999-05-31T12:01:30.150Z" +
                     "</result>",
                     date);
    
public voidtestDay()

        org.apache.axis.types.Day ym = new Day(15);
        deserialize("<result xsi:type=\"xsd:gDay\">---15</result>",
                     ym);
    
public voidtestDuration()

        org.apache.axis.types.Duration ym = new Duration(false, 2, 3, 8, 8, 1, 3.3);
        deserialize("<result xsi:type=\"xsd:duration\">P2Y3M8DT8H1M3.3S</result>",
                     ym);
        org.apache.axis.types.Duration ym2 = new Duration(true, 2, 3, 8, 8, 1, 3.3);
        deserialize("<result xsi:type=\"xsd:duration\">-P2Y3M8DT8H1M3.3S</result>",
                     ym2);
    
public voidtestHex()

        deserialize("<result xsi:type=\"xsd:hexBinary\">50A9</result>",
                    new HexBinary("50A9"),true);
    
public voidtestHexNull()

        deserialize("<result xsi:type=\"xsd:hexBinary\"></result>",
                    new HexBinary(""),true);
    
public voidtestMapWithNils()

        HashMap m = new HashMap();
        m.put(null, new Boolean("false"));
        m.put("hi", null);
        deserialize("<result xsi:type=\"xmlsoap:Map\" " +
                    "xmlns:xmlsoap=\"http://xml.apache.org/xml-soap\"> " +
                      "<item>" +
                       "<key xsi:nil=\"true\"/>" +
                       "<value xsi:type=\"xsd:boolean\">false</value>" +
                      "</item><item>" +
                       "<key xsi:type=\"xsd:string\">hi</key>" +
                       "<value xsi:nil=\"true\"/>" +
                      "</item>" +
                    "</result>",
                    m);
    
public voidtestMinDate()
Test deserialization of Date responses

        Calendar date = Calendar.getInstance();
        date.set(1999, 04, 31, 0, 0, 0);
        date.set(Calendar.MILLISECOND,0);
        deserialize("<result xsi:type=\"xsd:date\">" +
                       "1999-05-31" +
                     "</result>",
                     date.getTime());
    
public voidtestMinDateTime()
Test deserialization of dateTime (Calendar) responses

        Calendar date = Calendar.getInstance();
        date.set(1999,04,31, 12, 01, 30);
        date.setTimeZone(TimeZone.getTimeZone("GMT"));
        date.set(Calendar.MILLISECOND,0);
        deserialize("<result xsi:type=\"xsd:dateTime\">" +
                       "1999-05-31T12:01:30Z" +
                     "</result>",
                     date);
    
public voidtestMonth()

        org.apache.axis.types.Month ym = new Month(8);
        deserialize("<result xsi:type=\"xsd:gMonth\">--08--</result>",
                     ym);
    
public voidtestMonthDay()

        org.apache.axis.types.MonthDay ym = new MonthDay(8, 5);
        deserialize("<result xsi:type=\"xsd:gMonthDay\">--08-05</result>",
                     ym);
    
public voidtestNCName()

        deserialize("<result xsi:type=\"xsd:NCName\">_Atlanta.Braves</result>",
                    new NCName("_Atlanta.Braves"),true);
    
public voidtestNMToken()

        deserialize("<result xsi:type=\"xsd:NMTOKEN\">_A.B.C.1-2-3</result>",
                    new NMToken("_A.B.C.1-2-3"),true);
    
public voidtestName()

        deserialize("<result xsi:type=\"xsd:Name\">:Braves</result>",
                    new Name(":Braves"),true);
    
public voidtestNegativeInteger()

        deserialize("<result xsi:type=\"xsd:negativeInteger\">-12345678901234567890</result>",
                    new NegativeInteger("-12345678901234567890"), true);
    
public voidtestNilSOAPBoolean()

        deserialize("<result xsi:type=\"soapenc:boolean\" xsi:nil=\"true\" />",
                    null);
    
public voidtestNonNegativeInteger()

        deserialize("<result xsi:type=\"xsd:nonNegativeInteger\">12345678901234567890</result>",
                    new NonNegativeInteger("12345678901234567890"), true);
    
public voidtestNonPositiveInteger()

        deserialize("<result xsi:type=\"xsd:nonPositiveInteger\">-12345678901234567890</result>",
                    new NonPositiveInteger("-12345678901234567890"), true);
    
public voidtestNormalizedString()

        deserialize("<result xsi:type=\"xsd:normalizedString\">abcdefg</result>",
                    new NormalizedString("abcdefg"),true);
    
public voidtestPositiveInteger()

        deserialize("<result xsi:type=\"xsd:positiveInteger\">12345678901234567890</result>",
                    new PositiveInteger("12345678901234567890"), true);
    
public voidtestQName()

        deserialize("<result xsi:type=\"xsd:QName\" xmlns:qns=\"namespace\">qns:localPart</result>", new QName("namespace", "localPart"), true);
    
public voidtestTimeUK()

        deserializeCalendar(TimeZone.getTimeZone("Europe/London"));
    
public voidtestTimeUKSummer()

        deserializeCalendar(TimeZone.getTimeZone("GMT+1:00"));
    
public voidtestTimeUKWinter()

        deserializeCalendar(TimeZone.getTimeZone("GMT+0:00"));
    
public voidtestTimeZ()
Test the xsd:Time deserialization

        Calendar date = Calendar.getInstance();
        date.set(Calendar.HOUR_OF_DAY, 12);
        date.set(Calendar.MINUTE, 01);
        date.set(Calendar.SECOND, 30);
        date.set(Calendar.MILLISECOND,150);
        date.setTimeZone(TimeZone.getTimeZone("GMT"));
        Time time = new Time(date);
        deserialize("<result xsi:type=\"xsd:time\">" +
                       "12:01:30.150Z" +
                     "</result>",
                     time);
    
public voidtestTimeZoneLogicWorks()
this test is here to track down odd behaviour on one system related to these TZ tests


        TimeZone tz=TimeZone.getTimeZone("GMT");
        //assertEquals(0,tz.getDSTSavings());
        assertEquals(0,tz.getRawOffset());
        Time time=new Time("12:01:30.150+00:00");
        String timeVal=time.toString();
        assertEquals("12:01:30.150Z",timeVal);
    
public voidtestToken()

        deserialize("<result xsi:type=\"xsd:token\">abcdefg</result>",
                    new Token("abcdefg"),true);
    
public voidtestUnsignedByte()

        deserialize("<result xsi:type=\"xsd:unsignedByte\">103</result>",
                    new UnsignedByte(103),true);
    
public voidtestUnsignedInt()

        deserialize("<result xsi:type=\"xsd:unsignedInt\">101</result>",
                    new UnsignedInt(101),true);
    
public voidtestUnsignedLong()

        deserialize("<result xsi:type=\"xsd:unsignedLong\">100</result>",
                    new UnsignedLong(100),true);
    
public voidtestUnsignedShort()

        deserialize("<result xsi:type=\"xsd:unsignedShort\">102</result>",
                    new UnsignedShort(102),true);
    
public voidtestYear()

        org.apache.axis.types.Year ym = new Year(2002);
        deserialize("<result xsi:type=\"xsd:gYear\">2002</result>",
                     ym);
    
public voidtestYearMonth()

        org.apache.axis.types.YearMonth ym = new YearMonth(2002, 8);
        deserialize("<result xsi:type=\"xsd:gYearMonth\">2002-08</result>",
                     ym);