Package org.apache.axis.types

Examples of org.apache.axis.types.Duration


        org.apache.axis.types.MonthDay ym = new MonthDay(8, 5);
        deserialize("<result xsi:type=\"xsd:gMonthDay\">--08-05</result>",
                     ym);
    }
    public void testDuration() throws Exception {
        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);
    }
View Full Code Here


        org.apache.axis.types.MonthDay ym = new MonthDay(8, 5);
        deserialize("<result xsi:type=\"xsd:gMonthDay\">--08-05</result>",
                     ym);
    }
    public void testDuration() throws Exception {
        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);
    }
View Full Code Here

        org.apache.axis.types.MonthDay ym = new MonthDay(8, 5);
        deserialize("<result xsi:type=\"xsd:gMonthDay\">--08-05</result>",
                     ym);
    }
    public void testDuration() throws Exception {
        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);
    }
View Full Code Here

        durationStrings[9] = "-P1M";
        durationStrings[10] = "-P2Y3M8DT8H1M3.3S";

        for (int i = 0; i < durationStrings.length; i++) {
            String durationString = durationStrings[i];
            Duration duration = new Duration(durationString);

            assertTrue("Duration string \"" + durationString +
                       "\" not equal to returned: " + duration.toString(),
                       durationString.equals(duration.toString()));
        }
    }
View Full Code Here

                                          "P8Y1MT", "PT8Y1M3D", "PYMDTHMS"};
        // each of the above strings should result in an exception
        for (int i = 0; i < invalidDurationStrings.length; i++) {
            String durationString = invalidDurationStrings[i];
            try {
                Duration duration = new Duration(durationString);
                throw new junit.framework.AssertionFailedError(
                        "org.apache.axis.types.Duration constructor accepted invalid string: " +
                        durationString);
            } catch (IllegalArgumentException e) {
                // this is good
            }
        }

        /* need to test setTime(String) and setDate(String) for handling
         * invalid time and date strings. A handling of properly formatted
         * time and date strings is tested as part of testValidDurations()
         * test case.
         * NOTE: the code below can be removed if/when
         * parseDate(String) and parseTime(String) methods are changed
         * to private ones.
         */
        String[] invalidTimeStrings = {"", "-8H1M3.3S", "8Y1M3D", "HMS"};
        Duration duration = new Duration();
        for (int i = 0; i < invalidTimeStrings.length; i++) {
            String durationString = invalidTimeStrings[i];
            try {
                duration.parseTime(durationString);
                throw new junit.framework.AssertionFailedError(
                        "parseTime(String) method accepted invalid string: " +
                        durationString);
            } catch (IllegalArgumentException e) {
                // this is good
            }
        }

        String[] invalidDateStrings = {"", "-2Y3M8D", "8H1M3S", "-8Y1M"};
        for (int i = 0; i < invalidDateStrings.length; i++) {
            String durationString = invalidDateStrings[i];
            try {
                duration.parseDate(durationString);
                throw new junit.framework.AssertionFailedError(
                        "parseDate(String) method accepted invalid string: " +
                        durationString);
            } catch (IllegalArgumentException e) {
                // this is good
View Full Code Here

     * @throws Exception
     */
    public void testDurationFromCalendar() throws Exception {
        // negative date
        Calendar calendar = new GregorianCalendar(1, 3, 20);
        Duration duration = new Duration(true, calendar);
        assertTrue("Negative flag does not match", duration.isNegative());
        assertTrue("Years do not match", duration.getYears() == 1);
        assertTrue("Months do not match", duration.getMonths() == 3);
        assertTrue("Days do not match", duration.getDays() == 20);
        assertEquals("String representation does not match", duration.toString(),
                     "-P1Y3M20D");
        // positive date and time
        calendar.clear();
        calendar.set(1, 2, 20, 10, 3, 11);
        duration = new Duration(false, calendar);
        assertTrue("Negative flag does not match", !duration.isNegative());
        assertTrue("Years do not match", duration.getYears() == 1);
        assertTrue("Months do not match", duration.getMonths() == 2);
        assertTrue("Days do not match", duration.getDays() == 20);
        assertTrue("Hours do not match", duration.getHours() == 10);
        assertTrue("Minutes do not match", duration.getMinutes() == 3);
        assertTrue("Seconds do not match", duration.getSeconds() == 11);
        assertEquals("String representation does not match", duration.toString(),
                     "P1Y2M20DT10H3M11S");
    }
View Full Code Here

        // Check if a calendar object used to create a duration object and
        // a calendar object created from the same duration are equal
        // that's good test for handling of miliseconds
        Calendar calendar = new GregorianCalendar(1, 2, 20, 10, 3, 11);
        calendar.set(Calendar.MILLISECOND, 15);
        Duration duration = new Duration(true, calendar);
        Calendar durationCalendar = duration.getAsCalendar();
        assertTrue("Negative flag does not match", duration.isNegative());
        assertEquals("Years do not match",
                     calendar.get(Calendar.YEAR),
                     durationCalendar.get(Calendar.YEAR));
        assertEquals("Months do not match",
                     calendar.get(Calendar.MONTH),
                     durationCalendar.get(Calendar.MONTH));
        assertEquals("Days do not match",
                     calendar.get(Calendar.DATE),
                     durationCalendar.get(Calendar.DATE));
        assertEquals("Hours do not match",
                     calendar.get(Calendar.HOUR),
                     durationCalendar.get(Calendar.HOUR));
        assertEquals("Minutes do not match",
                     calendar.get(Calendar.MINUTE),
                     durationCalendar.get(Calendar.MINUTE));
        assertEquals("Seconds do not match",
                     calendar.get(Calendar.SECOND),
                     durationCalendar.get(Calendar.SECOND));
        assertEquals("Miliseconds do not match",
                     calendar.get(Calendar.MILLISECOND),
                     durationCalendar.get(Calendar.MILLISECOND));

        // test for overflows - Calendar class does automatic conversion
        // of dates
        duration.setMonths(20);
        durationCalendar = duration.getAsCalendar();
        assertEquals("Years do not match",
                     duration.getYears() + 1,
                     durationCalendar.get(Calendar.YEAR));
        assertEquals("Months do not match",
                     duration.getMonths() - 12,
                     durationCalendar.get(Calendar.MONTH));

        // make sure that Duration enforces milliseconds precision
        duration.setSeconds(10.1234);
        assertTrue("Milliseconds precision is not enforced",
                     duration.getSeconds() == 10.12);
    }
View Full Code Here

                     duration.getSeconds() == 10.12);
    }

    public void testHash() {
        // test if hash is taking milliseconds in account
        Duration d1 = new Duration(false, 10, 1, 2, 1, 20, 2.51);
        Duration d2 = new Duration(false, 10, 1, 2, 1, 20, 2.51);
        Duration d3 = new Duration(false, 10, 1, 2, 1, 20, 2);
        Duration d4 = new Duration(false, 10, 1, 2, 1, 20, 2.51233);
        assertEquals("Hash code values do not match", d1.hashCode(),
                     d2.hashCode());
        assertFalse("Hash code values match", d1.hashCode() == d3.hashCode());
        // test precistion
        assertEquals("Hash code values do not match", d1.hashCode(),
                     d4.hashCode());
    }
View Full Code Here

                     d4.hashCode());
    }

    public void testEquals() {
        // test if equals is taking milliseconds in account
        Duration d1 = new Duration(false, 10, 1, 2, 1, 20, 2.51);
        Duration d2 = new Duration(false, 10, 1, 2, 1, 20, 2.51);
        Duration d3 = new Duration(true, 10, 1, 2, 1, 20, 2.51);
        Duration d4 = new Duration(false, 8, 25, 2, 0, 80, 2.51);
        Duration d5 = new Duration(false, 8, 25, 2, 0, 80, 2.51);
        // the durations are equal: testing precision
        assertTrue("Comparison failed", d1.equals(d2));
        // the durations are equal, except of the sign
        assertFalse("Comparison failed", d1.equals(d3));
        // the durations are equal, but represented differently
View Full Code Here

        org.apache.axis.types.MonthDay ym = new MonthDay(8, 5);
        deserialize("<result xsi:type=\"xsd:gMonthDay\">--08-05</result>",
                     ym);
    }
    public void testDuration() throws Exception {
        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);
    }
View Full Code Here

TOP

Related Classes of org.apache.axis.types.Duration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.